mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-08 07:21:03 +08:00
Merge pull request #8671 from andrej-scinote/aj_SCI_12053
Move the user's logic to a shareable concern [SCI-12053]
This commit is contained in:
commit
22777b4135
13 changed files with 16 additions and 12 deletions
|
|
@ -134,7 +134,7 @@ module AccessPermissions
|
|||
end
|
||||
|
||||
def load_available_users
|
||||
@available_users = current_team.users.where.not(id: @model.users.select(:id)).order(users: { full_name: :asc })
|
||||
@available_users = current_team.users.where.not(id: @model.user_assignments.select(:user_id)).order(users: { full_name: :asc })
|
||||
end
|
||||
|
||||
def propagate_job(destroy: false)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,21 @@ module Assignable
|
|||
|
||||
after_create :create_users_assignments
|
||||
|
||||
def users
|
||||
direct_user_ids = user_assignments.select(:user_id)
|
||||
|
||||
# Users through user_groups assigned
|
||||
group_user_ids = UserGroupMembership.joins(:user_group)
|
||||
.where(user_group_id: UserGroupAssignment.where(assignable: self).select(:user_group_id))
|
||||
.select(:user_id)
|
||||
|
||||
# Users through teams assigned
|
||||
team_user_ids = UserAssignment.where(assignable_id: team_assignments.select(:team_id), assignable_type: 'Team')
|
||||
.select(:user_id)
|
||||
|
||||
User.where(id: direct_user_ids).or(User.where(id: group_user_ids)).or(User.where(id: team_user_ids))
|
||||
end
|
||||
|
||||
def default_public_user_role_id
|
||||
team_assignments.where(team_id: team.id).pick(:user_role_id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ class Experiment < ApplicationRecord
|
|||
has_many :report_elements, inverse_of: :experiment, dependent: :destroy
|
||||
# Associations for old activity type
|
||||
has_many :activities, inverse_of: :experiment
|
||||
has_many :users, through: :user_assignments, dependent: :destroy
|
||||
|
||||
has_one_attached :workflowimg
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ class Form < ApplicationRecord
|
|||
|
||||
has_many :form_fields, -> { order(:position) }, inverse_of: :form, dependent: :destroy
|
||||
has_many :form_responses, dependent: :destroy
|
||||
has_many :users, through: :user_assignments
|
||||
|
||||
scope :published, -> { where.not(published_on: nil) }
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ class MyModule < ApplicationRecord
|
|||
has_many :repository_rows, through: :my_module_repository_rows
|
||||
has_many :repository_snapshots, dependent: :destroy, inverse_of: :my_module
|
||||
has_many :user_my_modules, inverse_of: :my_module, dependent: :destroy
|
||||
has_many :users, through: :user_assignments
|
||||
has_many :designated_users, through: :user_my_modules, source: :user
|
||||
has_many :report_elements, inverse_of: :my_module, dependent: :destroy
|
||||
has_many :protocols, inverse_of: :my_module, dependent: :destroy
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ class Project < ApplicationRecord
|
|||
belongs_to :team, inverse_of: :projects, touch: true
|
||||
belongs_to :project_folder, inverse_of: :projects, optional: true, touch: true
|
||||
has_many :user_projects, inverse_of: :project
|
||||
has_many :users, through: :user_assignments
|
||||
has_many :experiments, inverse_of: :project
|
||||
has_many :active_experiments, -> { where(archived: false) },
|
||||
class_name: 'Experiment'
|
||||
|
|
|
|||
|
|
@ -141,7 +141,6 @@ class Protocol < ApplicationRecord
|
|||
has_many :protocol_keywords, through: :protocol_protocol_keywords
|
||||
has_many :steps, inverse_of: :protocol, dependent: :destroy
|
||||
has_many :original_steps, class_name: 'Step', foreign_key: :original_protocol_id, inverse_of: :original_protocol, dependent: :nullify
|
||||
has_many :users, through: :user_assignments
|
||||
|
||||
def self.search(user,
|
||||
include_archived,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ class Report < ApplicationRecord
|
|||
belongs_to :user, inverse_of: :reports
|
||||
belongs_to :team, inverse_of: :reports
|
||||
belongs_to :last_modified_by, class_name: 'User', optional: true
|
||||
has_many :users, through: :user_assignments
|
||||
has_many :report_template_values, dependent: :destroy
|
||||
|
||||
# Report either has many report elements (if grouped by timestamp),
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ class Repository < RepositoryBase
|
|||
inverse_of: :original_repository
|
||||
has_many :repository_ledger_records, as: :reference, dependent: :nullify
|
||||
has_many :repository_table_filters, dependent: :destroy
|
||||
has_many :users, through: :user_assignments
|
||||
|
||||
before_save :sync_name_with_snapshots, if: :name_changed?
|
||||
before_destroy :refresh_report_references_on_destroy, prepend: true
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ class Team < ApplicationRecord
|
|||
|
||||
belongs_to :created_by, class_name: 'User', optional: true
|
||||
belongs_to :last_modified_by, class_name: 'User', optional: true
|
||||
has_many :users, through: :user_assignments, dependent: :destroy
|
||||
has_many :user_groups, dependent: :destroy
|
||||
has_many :projects, inverse_of: :team, dependent: :destroy
|
||||
has_many :project_folders, inverse_of: :team, dependent: :destroy
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ describe MyModule, type: :model do
|
|||
it { should have_many :my_module_repository_rows }
|
||||
it { should have_many :repository_rows }
|
||||
it { should have_many :user_my_modules }
|
||||
it { should have_many :users }
|
||||
it { should have_many :activities }
|
||||
it { should have_many :report_elements }
|
||||
it { should have_many :protocols }
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ describe Project, type: :model do
|
|||
it { should belong_to(:restored_by).class_name('User').optional }
|
||||
it { should belong_to(:supervised_by).class_name('User').optional }
|
||||
it { should have_many :user_projects }
|
||||
it { should have_many :users }
|
||||
it { should have_many :experiments }
|
||||
it { should have_many :project_comments }
|
||||
it { should have_many :activities }
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ describe Team, type: :model do
|
|||
describe 'Relations' do
|
||||
it { should belong_to(:created_by).class_name('User').optional }
|
||||
it { should belong_to(:last_modified_by).class_name('User').optional }
|
||||
it { should have_many :users }
|
||||
it { should have_many :projects }
|
||||
it { should have_many :protocols }
|
||||
it { should have_many :protocol_keywords }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue