fixes experiment page [fixes SCI-1395]

This commit is contained in:
zmagod 2017-06-28 15:21:32 +02:00
parent f7cef48f9f
commit 525c9770ac
57 changed files with 373 additions and 170 deletions

View file

@ -66,10 +66,10 @@ class Activity < ApplicationRecord
validates :type_of, presence: true
validates :project, :user, presence: true
belongs_to :project, inverse_of: :activities
belongs_to :experiment, inverse_of: :activities
belongs_to :my_module, inverse_of: :activities
belongs_to :user, inverse_of: :activities
belongs_to :project, inverse_of: :activities, optional: true
belongs_to :experiment, inverse_of: :activities, optional: true
belongs_to :my_module, inverse_of: :activities, optional: true
belongs_to :user, inverse_of: :activities, optional: true
private

View file

@ -44,11 +44,15 @@ class Asset < ApplicationRecord
# assign it to result
validate :step_or_result
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User'
belongs_to :team
class_name: 'User',
optional: true
belongs_to :team, optional: true
has_one :step_asset,
inverse_of: :asset,
dependent: :destroy

View file

@ -3,7 +3,7 @@ class AssetTextDatum < ApplicationRecord
validates :data, presence: true
validates :asset, presence: true, uniqueness: true
belongs_to :asset, inverse_of: :asset_text_datum
belongs_to :asset, inverse_of: :asset_text_datum, optional: true
after_save :update_ts_index

View file

@ -7,9 +7,15 @@ class Checklist < ApplicationRecord
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :step, presence: true
belongs_to :step, inverse_of: :checklists
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :step, inverse_of: :checklists, optional: true
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
has_many :checklist_items,
-> { order(:position) },
inverse_of: :checklist,

View file

@ -6,7 +6,15 @@ class ChecklistItem < ApplicationRecord
validates :checklist, presence: true
validates :checked, inclusion: { in: [true, false] }
belongs_to :checklist, inverse_of: :checklist_items
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :checklist,
inverse_of: :checklist_items,
optional: true
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
end

View file

@ -7,9 +7,11 @@ class Comment < ApplicationRecord
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :user, presence: true
belongs_to :user, inverse_of: :comments
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id',
class_name: 'User'
belongs_to :user, inverse_of: :comments, optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
def self.search(
user,

View file

@ -1,4 +1,12 @@
class Connection < ApplicationRecord
belongs_to :to, :class_name => 'MyModule', :foreign_key => 'input_id', inverse_of: :inputs
belongs_to :from, :class_name => 'MyModule', :foreign_key => 'output_id', inverse_of: :outputs
belongs_to :to,
class_name: 'MyModule',
foreign_key: 'input_id',
inverse_of: :inputs,
optional: true
belongs_to :from,
class_name: 'MyModule',
foreign_key: 'output_id',
inverse_of: :outputs,
optional: true
end

View file

@ -8,11 +8,12 @@ class CustomField < ApplicationRecord
'Sample group', 'Added on', 'Added by'] }
validates :user, :team, presence: true
belongs_to :user, inverse_of: :custom_fields
belongs_to :team, inverse_of: :custom_fields
belongs_to :user, inverse_of: :custom_fields, optional: true
belongs_to :team, inverse_of: :custom_fields, optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User'
class_name: 'User',
optional: true
has_many :sample_custom_fields, inverse_of: :custom_field, dependent: :destroy
after_create :update_samples_table_state

View file

@ -2,12 +2,21 @@ class Experiment < ApplicationRecord
include ArchivableModel
include SearchableModel
belongs_to :project, inverse_of: :experiments
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
belongs_to :last_modified_by, foreign_key: :last_modified_by_id,
class_name: 'User'
belongs_to :archived_by, foreign_key: :archived_by_id, class_name: 'User'
belongs_to :restored_by, foreign_key: :restored_by_id, class_name: 'User'
belongs_to :project, inverse_of: :experiments, optional: true
belongs_to :created_by,
foreign_key: :created_by_id,
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: :last_modified_by_id,
class_name: 'User',
optional: true
belongs_to :archived_by,
foreign_key: :archived_by_id, class_name: 'User', optional: true
belongs_to :restored_by,
foreign_key: :restored_by_id,
class_name: 'User',
optional: true
has_many :my_modules, inverse_of: :experiment, dependent: :destroy
has_many :my_module_groups, inverse_of: :experiment, dependent: :destroy

View file

@ -14,29 +14,54 @@ class MyModule < ApplicationRecord
validates :experiment, presence: true
validates :my_module_group, presence: true, if: "!my_module_group_id.nil?"
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :archived_by, foreign_key: 'archived_by_id', class_name: 'User'
belongs_to :restored_by, foreign_key: 'restored_by_id', class_name: 'User'
belongs_to :experiment, inverse_of: :my_modules
belongs_to :my_module_group, inverse_of: :my_modules
has_many :results, inverse_of: :my_module, :dependent => :destroy
has_many :my_module_tags, inverse_of: :my_module, :dependent => :destroy
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
belongs_to :archived_by,
foreign_key: 'archived_by_id',
class_name: 'User',
optional: true
belongs_to :restored_by,
foreign_key: 'restored_by_id',
class_name: 'User',
optional: true
belongs_to :experiment, inverse_of: :my_modules, optional: true
belongs_to :my_module_group, inverse_of: :my_modules, optional: true
has_many :results, inverse_of: :my_module, dependent: :destroy
has_many :my_module_tags, inverse_of: :my_module, dependent: :destroy
has_many :tags, through: :my_module_tags
has_many :task_comments, foreign_key: :associated_id, dependent: :destroy
has_many :inputs, :class_name => 'Connection', :foreign_key => "input_id", inverse_of: :to, :dependent => :destroy
has_many :outputs, :class_name => 'Connection', :foreign_key => "output_id", inverse_of: :from, :dependent => :destroy
has_many :inputs,
class_name: 'Connection',
foreign_key: 'input_id',
inverse_of: :to,
dependent: :destroy
has_many :outputs,
class_name: 'Connection',
foreign_key: 'output_id',
inverse_of: :from,
dependent: :destroy
has_many :my_modules, through: :outputs, source: :to
has_many :my_module_antecessors, through: :inputs, source: :from, class_name: 'MyModule'
has_many :sample_my_modules, inverse_of: :my_module, :dependent => :destroy
has_many :my_module_antecessors,
through: :inputs,
source: :from,
class_name: 'MyModule'
has_many :sample_my_modules,
inverse_of: :my_module,
dependent: :destroy
has_many :samples, through: :sample_my_modules
has_many :my_module_repository_rows,
inverse_of: :my_module, dependent: :destroy
has_many :repository_rows, through: :my_module_repository_rows
has_many :user_my_modules, inverse_of: :my_module, :dependent => :destroy
has_many :user_my_modules, inverse_of: :my_module, dependent: :destroy
has_many :users, through: :user_my_modules
has_many :activities, inverse_of: :my_module
has_many :report_elements, inverse_of: :my_module, :dependent => :destroy
has_many :report_elements, inverse_of: :my_module, dependent: :destroy
has_many :protocols, inverse_of: :my_module, dependent: :destroy
scope :is_archived, ->(is_archived) { where('archived = ?', is_archived) }
@ -349,7 +374,7 @@ class MyModule < ApplicationRecord
x: self.x,
y: self.y)
clone.save
# Remove the automatically generated protocol,
# & clone the protocol instead
clone.protocol.destroy

View file

@ -7,8 +7,11 @@ class MyModuleGroup < ApplicationRecord
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :experiment, presence: true
belongs_to :experiment, inverse_of: :my_module_groups
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :experiment, inverse_of: :my_module_groups, optional: true
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
has_many :my_modules, inverse_of: :my_module_group, dependent: :nullify
def self.search(user,

View file

@ -1,7 +1,10 @@
class MyModuleRepositoryRow < ApplicationRecord
belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User'
belongs_to :repository_row
belongs_to :my_module
belongs_to :assigned_by,
foreign_key: 'assigned_by_id',
class_name: 'User',
optional: true
belongs_to :repository_row, optional: true
belongs_to :my_module, optional: true
validates :repository_row, :my_module, presence: true
validates :repository_row, uniqueness: { scope: :my_module }

View file

@ -2,7 +2,10 @@ class MyModuleTag < ApplicationRecord
validates :my_module, :tag, presence: true
validates :tag_id, uniqueness: { scope: :my_module_id }
belongs_to :my_module, inverse_of: :my_module_tags
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :tag, inverse_of: :my_module_tags
belongs_to :my_module, inverse_of: :my_module_tags, optional: true
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :tag, inverse_of: :my_module_tags, optional: true
end

View file

@ -1,7 +1,7 @@
class Notification < ApplicationRecord
has_many :user_notifications, inverse_of: :notification, dependent: :destroy
has_many :users, through: :user_notifications
belongs_to :generator_user, class_name: 'User'
belongs_to :generator_user, class_name: 'User', optional: true
enum type_of: Extends::NOTIFICATIONS_TYPES

View file

@ -12,10 +12,23 @@ class Project < ApplicationRecord
validates :visibility, presence: true
validates :team, presence: true
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :archived_by, foreign_key: 'archived_by_id', class_name: 'User'
belongs_to :restored_by, foreign_key: 'restored_by_id', class_name: 'User'
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
belongs_to :archived_by,
foreign_key: 'archived_by_id',
class_name: 'User',
optional: true
belongs_to :restored_by,
foreign_key: 'restored_by_id',
class_name: 'User',
optional: true
belongs_to :team, inverse_of: :projects, optional: true
has_many :user_projects, inverse_of: :project
has_many :users, through: :user_projects
has_many :experiments, inverse_of: :project
@ -24,7 +37,6 @@ class Project < ApplicationRecord
has_many :tags, inverse_of: :project
has_many :reports, inverse_of: :project, dependent: :destroy
has_many :report_elements, inverse_of: :project, dependent: :destroy
belongs_to :team, inverse_of: :projects
def self.search(
user,

View file

@ -1,6 +1,8 @@
class ProjectComment < Comment
belongs_to :project, foreign_key: :associated_id,
inverse_of: :project_comments
belongs_to :project,
foreign_key: :associated_id,
inverse_of: :project_comments,
optional: true
validates :project, presence: true
end

View file

@ -85,18 +85,24 @@ class Protocol < ApplicationRecord
belongs_to :added_by,
foreign_key: 'added_by_id',
class_name: 'User',
inverse_of: :added_protocols
belongs_to :my_module, inverse_of: :protocols
belongs_to :team, inverse_of: :protocols
belongs_to :parent, foreign_key: 'parent_id', class_name: 'Protocol'
inverse_of: :added_protocols,
optional: true
belongs_to :my_module,
inverse_of: :protocols,
optional: true
belongs_to :team, inverse_of: :protocols, optional: true
belongs_to :parent,
foreign_key: 'parent_id',
class_name: 'Protocol',
optional: true
belongs_to :archived_by,
foreign_key: 'archived_by_id',
class_name: 'User',
inverse_of: :archived_protocols
inverse_of: :archived_protocols, optional: true
belongs_to :restored_by,
foreign_key: 'restored_by_id',
class_name: 'User',
inverse_of: :restored_protocols
inverse_of: :restored_protocols, optional: true
has_many :linked_children,
class_name: 'Protocol',
foreign_key: 'parent_id'

View file

@ -5,7 +5,7 @@ class ProtocolKeyword < ApplicationRecord
maximum: Constants::NAME_MAX_LENGTH }
validates :team, presence: true
belongs_to :team, inverse_of: :protocol_keywords
belongs_to :team, inverse_of: :protocol_keywords, optional: true
has_many :protocol_protocol_keywords,
inverse_of: :protocol_keyword,

View file

@ -5,8 +5,10 @@ class ProtocolProtocolKeyword < ApplicationRecord
validates :protocol, presence: true
validates :protocol_keyword, presence: true
belongs_to :protocol, inverse_of: :protocol_protocol_keywords
belongs_to :protocol_keyword, inverse_of: :protocol_protocol_keywords
belongs_to :protocol, inverse_of: :protocol_protocol_keywords, optional: true
belongs_to :protocol_keyword,
inverse_of: :protocol_protocol_keywords,
optional: true
private

View file

@ -10,9 +10,12 @@ class Report < ApplicationRecord
validates :project, presence: true
validates :user, presence: true
belongs_to :project, inverse_of: :reports
belongs_to :user, inverse_of: :reports
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :project, inverse_of: :reports, optional: true
belongs_to :user, inverse_of: :reports, optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
# Report either has many report elements (if grouped by timestamp),
# or many module elements (if grouped by module)

View file

@ -12,7 +12,7 @@ class ReportElement < ApplicationRecord
validates :type_of, presence: true
validate :has_one_of_referenced_elements
belongs_to :report, inverse_of: :report_elements
belongs_to :report, inverse_of: :report_elements, optional: true
# Hierarchical structure representation
has_many :children,
@ -20,18 +20,18 @@ class ReportElement < ApplicationRecord
class_name: 'ReportElement',
foreign_key: 'parent_id',
dependent: :destroy
belongs_to :parent, class_name: 'ReportElement'
belongs_to :parent, class_name: 'ReportElement', optional: true
# References to various report entities
belongs_to :project, inverse_of: :report_elements
belongs_to :experiment, inverse_of: :report_elements
belongs_to :my_module, inverse_of: :report_elements
belongs_to :step, inverse_of: :report_elements
belongs_to :result, inverse_of: :report_elements
belongs_to :checklist, inverse_of: :report_elements
belongs_to :asset, inverse_of: :report_elements
belongs_to :table, inverse_of: :report_elements
belongs_to :repository, inverse_of: :report_elements
belongs_to :project, inverse_of: :report_elements, optional: true
belongs_to :experiment, inverse_of: :report_elements, optional: true
belongs_to :my_module, inverse_of: :report_elements, optional: true
belongs_to :step, inverse_of: :report_elements, optional: true
belongs_to :result, inverse_of: :report_elements, optional: true
belongs_to :checklist, inverse_of: :report_elements, optional: true
belongs_to :asset, inverse_of: :report_elements, optional: true
belongs_to :table, inverse_of: :report_elements, optional: true
belongs_to :repository, inverse_of: :report_elements, optional: true
def has_children?
children.length > 0

View file

@ -1,6 +1,9 @@
class Repository < ApplicationRecord
belongs_to :team
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
belongs_to :team, optional: true
belongs_to :created_by,
foreign_key: :created_by_id,
class_name: 'User',
optional: true
has_many :repository_columns
has_many :repository_rows
has_many :repository_table_states,

View file

@ -1,7 +1,7 @@
class RepositoryCell < ApplicationRecord
belongs_to :repository_row
belongs_to :repository_column
belongs_to :value, polymorphic: true, dependent: :destroy
belongs_to :repository_row, optional: true
belongs_to :repository_column, optional: true
belongs_to :value, polymorphic: true, dependent: :destroy, optional: true
validates :repository_column, presence: true
validate :repository_column_data_type

View file

@ -1,6 +1,9 @@
class RepositoryColumn < ApplicationRecord
belongs_to :repository
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
belongs_to :repository, optional: true
belongs_to :created_by,
foreign_key: :created_by_id,
class_name: 'User',
optional: true
has_many :repository_cells, dependent: :destroy
has_many :repository_rows, through: :repository_cells

View file

@ -1,7 +1,12 @@
class RepositoryDateValue < ApplicationRecord
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
belongs_to :last_modified_by, foreign_key: :last_modified_by_id,
class_name: 'User'
belongs_to :created_by,
foreign_key: :created_by_id,
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: :last_modified_by_id,
class_name: 'User',
optional: true
has_one :repository_cell, as: :value, dependent: :destroy
accepts_nested_attributes_for :repository_cell

View file

@ -1,8 +1,13 @@
class RepositoryRow < ApplicationRecord
belongs_to :repository
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
belongs_to :last_modified_by, foreign_key: :last_modified_by_id,
class_name: 'User'
belongs_to :repository, optional: true
belongs_to :created_by,
foreign_key: :created_by_id,
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: :last_modified_by_id,
class_name: 'User',
optional: true
has_many :repository_cells, dependent: :destroy
has_many :repository_columns, through: :repository_cells
has_many :my_module_repository_rows,

View file

@ -1,6 +1,6 @@
class RepositoryTableState < ApplicationRecord
belongs_to :user, inverse_of: :repository_table_states
belongs_to :repository, inverse_of: :repository_table_states
belongs_to :user, inverse_of: :repository_table_states, optional: true
belongs_to :repository, inverse_of: :repository_table_states, optional: true
validates :user, :repository, presence: true

View file

@ -1,7 +1,12 @@
class RepositoryTextValue < ApplicationRecord
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
belongs_to :last_modified_by, foreign_key: :last_modified_by_id,
class_name: 'User'
belongs_to :created_by,
foreign_key: :created_by_id,
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: :last_modified_by_id,
class_name: 'User',
optional: true
has_one :repository_cell, as: :value, dependent: :destroy
accepts_nested_attributes_for :repository_cell

View file

@ -6,11 +6,20 @@ class Result < ApplicationRecord
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
validate :text_or_asset_or_table
belongs_to :user, inverse_of: :results
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :archived_by, foreign_key: 'archived_by_id', class_name: 'User'
belongs_to :restored_by, foreign_key: 'restored_by_id', class_name: 'User'
belongs_to :my_module, inverse_of: :results
belongs_to :user, inverse_of: :results, optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
belongs_to :archived_by,
foreign_key: 'archived_by_id',
class_name: 'User',
optional: true
belongs_to :restored_by,
foreign_key: 'restored_by_id',
class_name: 'User',
optional: true
belongs_to :my_module, inverse_of: :results, optional: true
has_one :result_asset,
inverse_of: :result,
dependent: :destroy

View file

@ -1,8 +1,11 @@
class ResultAsset < ApplicationRecord
validates :result, :asset, presence: true
belongs_to :result, inverse_of: :result_asset
belongs_to :asset, inverse_of: :result_asset, dependent: :destroy
belongs_to :result, inverse_of: :result_asset, optional: true
belongs_to :asset,
inverse_of: :result_asset,
dependent: :destroy,
optional: true
def space_taken
asset.present? ? asset.estimated_size : 0

View file

@ -1,5 +1,8 @@
class ResultComment < Comment
belongs_to :result, foreign_key: :associated_id, inverse_of: :result_comments
belongs_to :result,
foreign_key: :associated_id,
inverse_of: :result_comments,
optional: true
validates :result, presence: true
end

View file

@ -1,6 +1,9 @@
class ResultTable < ApplicationRecord
validates :result, :table, presence: true
belongs_to :result, inverse_of: :result_table
belongs_to :table, inverse_of: :result_table, dependent: :destroy
belongs_to :result, inverse_of: :result_table, optional: true
belongs_to :table,
inverse_of: :result_table,
dependent: :destroy,
optional: true
end

View file

@ -4,6 +4,6 @@ class ResultText < ApplicationRecord
presence: true,
length: { maximum: Constants::RICH_TEXT_MAX_LENGTH }
validates :result, presence: true
belongs_to :result, inverse_of: :result_text
belongs_to :result, inverse_of: :result_text, optional: true
has_many :tiny_mce_assets, inverse_of: :result_text, dependent: :destroy
end

View file

@ -7,11 +7,14 @@ class Sample < ApplicationRecord
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :user, :team, presence: true
belongs_to :user, inverse_of: :samples
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :team, inverse_of: :samples
belongs_to :sample_group, inverse_of: :samples
belongs_to :sample_type, inverse_of: :samples
belongs_to :user, inverse_of: :samples, optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
belongs_to :team, inverse_of: :samples, optional: true
belongs_to :sample_group, inverse_of: :samples, optional: true
belongs_to :sample_type, inverse_of: :samples, optional: true
has_many :sample_my_modules, inverse_of: :sample, dependent: :destroy
has_many :my_modules, through: :sample_my_modules
has_many :sample_custom_fields, inverse_of: :sample, dependent: :destroy

View file

@ -7,6 +7,6 @@ class SampleCustomField < ApplicationRecord
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :custom_field, :sample, presence: true
belongs_to :custom_field, inverse_of: :sample_custom_fields
belongs_to :sample, inverse_of: :sample_custom_fields
belongs_to :custom_field, inverse_of: :sample_custom_fields, optional: true
belongs_to :sample, inverse_of: :sample_custom_fields, optional: true
end

View file

@ -11,11 +11,15 @@ class SampleGroup < ApplicationRecord
length: { maximum: Constants::COLOR_MAX_LENGTH }
validates :team, presence: true
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User'
belongs_to :team, inverse_of: :sample_groups
class_name: 'User',
optional: true
belongs_to :team, inverse_of: :sample_groups, optional: true
has_many :samples, inverse_of: :sample_groups
scope :sorted, -> { order(name: :asc) }

View file

@ -5,14 +5,19 @@ class SampleMyModule < ApplicationRecord
validates :sample, :my_module, presence: true
# One sample can only be assigned once to a specific module
validates_uniqueness_of :sample_id, :scope => :my_module_id
validates_uniqueness_of :sample_id, scope: :my_module_id
belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User'
belongs_to :assigned_by,
foreign_key: 'assigned_by_id',
class_name: 'User',
optional: true
belongs_to :sample,
inverse_of: :sample_my_modules
inverse_of: :sample_my_modules,
optional: true
belongs_to :my_module,
inverse_of: :sample_my_modules
inverse_of: :sample_my_modules,
optional: true
def increment_nr_of_module_samples
my_module.increment!(:nr_of_assigned_samples)
sample.increment!(:nr_of_modules_assigned_to)

View file

@ -8,11 +8,15 @@ class SampleType < ApplicationRecord
uniqueness: { scope: :team, case_sensitive: false }
validates :team, presence: true
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User'
belongs_to :team, inverse_of: :sample_types
class_name: 'User',
optional: true
belongs_to :team, inverse_of: :sample_types, optional: true
has_many :samples, inverse_of: :sample_types
scope :sorted, -> { order(name: :asc) }

View file

@ -1,8 +1,8 @@
class SamplesTable < ApplicationRecord
validates :user, :team, presence: true
belongs_to :user, inverse_of: :samples_tables
belongs_to :team, inverse_of: :samples_tables
belongs_to :user, inverse_of: :samples_tables, optional: true
belongs_to :team, inverse_of: :samples_tables, optional: true
scope :find_status,
->(user, team) { where(user: user, team: team).pluck(:status) }

View file

@ -11,9 +11,14 @@ class Step < ApplicationRecord
validates :user, :protocol, presence: true
validates :completed_on, presence: true, if: "completed?"
belongs_to :user, inverse_of: :steps
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :protocol, inverse_of: :steps
belongs_to :user, inverse_of: :steps, optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
belongs_to :protocol,
inverse_of: :steps,
optional: true
has_many :checklists, inverse_of: :step,
dependent: :destroy
has_many :step_comments, foreign_key: :associated_id, dependent: :destroy

View file

@ -1,6 +1,11 @@
class StepAsset < ApplicationRecord
validates :step, :asset, presence: true
belongs_to :step, inverse_of: :step_assets
belongs_to :asset, inverse_of: :step_asset, dependent: :destroy
belongs_to :step,
inverse_of: :step_assets,
optional: true
belongs_to :asset,
inverse_of: :step_asset,
dependent: :destroy,
optional: true
end

View file

@ -1,5 +1,8 @@
class StepComment < Comment
belongs_to :step, foreign_key: :associated_id, inverse_of: :step_comments
belongs_to :step,
foreign_key: :associated_id,
inverse_of: :step_comments,
optional: true
validates :step, presence: true
end

View file

@ -1,6 +1,6 @@
class StepTable < ApplicationRecord
validates :step, :table, presence: true
belongs_to :step, inverse_of: :step_tables
belongs_to :table, inverse_of: :step_table
belongs_to :step, inverse_of: :step_tables, optional: true
belongs_to :table, inverse_of: :step_table, optional: true
end

View file

@ -8,9 +8,15 @@ class Table < ApplicationRecord
presence: true,
length: { maximum: Constants::TABLE_JSON_MAX_SIZE_MB.megabytes }
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :team
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
belongs_to :team, optional: true
has_one :step_table, inverse_of: :table
has_one :step, through: :step_table

View file

@ -10,10 +10,16 @@ class Tag < ApplicationRecord
length: { maximum: Constants::COLOR_MAX_LENGTH }
validates :project, presence: true
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :project
has_many :my_module_tags, inverse_of: :tag, :dependent => :destroy
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
belongs_to :project, optional: true
has_many :my_module_tags, inverse_of: :tag, dependent: :destroy
has_many :my_modules, through: :my_module_tags
def self.search(user,

View file

@ -1,5 +1,8 @@
class TaskComment < Comment
belongs_to :my_module, foreign_key: :associated_id, inverse_of: :task_comments
belongs_to :my_module,
foreign_key: :associated_id,
inverse_of: :task_comments,
optional: true
validates :my_module, presence: true
end

View file

@ -12,8 +12,14 @@ class Team < ApplicationRecord
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :space_taken, presence: true
belongs_to :created_by, :foreign_key => 'created_by_id', :class_name => 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',
class_name: 'User',
optional: true
has_many :user_teams, inverse_of: :team, dependent: :destroy
has_many :users, through: :user_teams
has_many :samples, inverse_of: :team

View file

@ -1,12 +1,12 @@
class TinyMceAsset < ApplicationRecord
attr_accessor :reference
before_create :set_reference
before_create :set_reference, optional: true
after_create :update_estimated_size
after_destroy :release_team_space
belongs_to :team, inverse_of: :tiny_mce_assets
belongs_to :step, inverse_of: :tiny_mce_assets
belongs_to :result_text, inverse_of: :tiny_mce_assets
belongs_to :team, inverse_of: :tiny_mce_assets, optional: true
belongs_to :step, inverse_of: :tiny_mce_assets, optional: true
belongs_to :result_text, inverse_of: :tiny_mce_assets, optional: true
has_attached_file :image,
styles: { large: [Constants::LARGE_PIC_FORMAT, :jpg] },
convert_options: { large: '-quality 100 -strip' }

View file

@ -1,8 +1,11 @@
class Token < ApplicationRecord
validates :token, presence: true
validates :ttl, presence: true
belongs_to :user, foreign_key: 'user_id', class_name: 'User', inverse_of: :tokens
belongs_to :user,
foreign_key: 'user_id',
class_name: 'User',
inverse_of: :tokens,
optional: true
end

View file

@ -1,7 +1,10 @@
class UserMyModule < ApplicationRecord
validates :user, :my_module, presence: true
belongs_to :user, inverse_of: :user_my_modules
belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User'
belongs_to :my_module, inverse_of: :user_my_modules
belongs_to :user, inverse_of: :user_my_modules, optional: true
belongs_to :assigned_by,
foreign_key: 'assigned_by_id',
class_name: 'User',
optional: true
belongs_to :my_module, inverse_of: :user_my_modules, optional: true
end

View file

@ -1,8 +1,8 @@
class UserNotification < ApplicationRecord
include NotificationsHelper
belongs_to :user
belongs_to :notification
belongs_to :user, optional: true
belongs_to :notification, optional: true
after_save :send_email

View file

@ -5,9 +5,12 @@ class UserProject < ApplicationRecord
validates :user, presence: true
validates :project, presence: true
belongs_to :user, inverse_of: :user_projects
belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User'
belongs_to :project, inverse_of: :user_projects
belongs_to :user, inverse_of: :user_projects, optional: true
belongs_to :assigned_by,
foreign_key: 'assigned_by_id',
class_name: 'User',
optional: true
belongs_to :project, inverse_of: :user_projects, optional: true
before_destroy :destroy_associations

View file

@ -5,9 +5,12 @@ class UserTeam < ApplicationRecord
validates :user, presence: true
validates :team, presence: true
belongs_to :user, inverse_of: :user_teams
belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User'
belongs_to :team, inverse_of: :user_teams
belongs_to :user, inverse_of: :user_teams, optional: true
belongs_to :assigned_by,
foreign_key: 'assigned_by_id',
class_name: 'User',
optional: true
belongs_to :team, inverse_of: :user_teams, optional: true
before_destroy :destroy_associations
after_create :create_samples_table_state

View file

@ -1,5 +1,8 @@
class WopiAction < ApplicationRecord
belongs_to :wopi_app, foreign_key: 'wopi_app_id', class_name: 'WopiApp'
belongs_to :wopi_app,
foreign_key: 'wopi_app_id',
class_name: 'WopiApp',
optional: true
validates :action, :extension, :urlsrc, :wopi_app, presence: true
def self.find_action(extension, activity)

View file

@ -1,7 +1,8 @@
class WopiApp < ApplicationRecord
belongs_to :wopi_discovery,
foreign_key: 'wopi_discovery_id',
class_name: 'WopiDiscovery'
class_name: 'WopiDiscovery',
optional: true
has_many :wopi_actions,
class_name: 'WopiAction',
foreign_key: 'wopi_app_id',

View file

@ -16,7 +16,7 @@ require 'fileutils'
# end
class ZipExport < ApplicationRecord
belongs_to :user
belongs_to :user, optional: true
has_attached_file :zip_file
validates_attachment :zip_file,
content_type: { content_type: 'application/zip' }

View file

@ -23,6 +23,7 @@ if ENV['PAPERCLIP_STORAGE'] == "s3"
url: ':s3_domain_url',
path: '/:class/:attachment/:id_partition/:hash/:style/:filename',
storage: :s3,
s3_region: ENV['AWS_REGION'],
s3_host_name: "s3.#{ENV['AWS_REGION']}.amazonaws.com",
s3_protocol: 'https',
s3_credentials: {