mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 10:06:53 +08:00
Merge pull request #4170 from okriuchykhin/ok_SCI_6915
Add team reference to user assignments model [SCI-6915]
This commit is contained in:
commit
34c8960097
5 changed files with 41 additions and 3 deletions
|
@ -15,6 +15,7 @@ class Experiment < ApplicationRecord
|
|||
before_save -> { report_elements.destroy_all }, if: -> { !new_record? && project_id_changed? }
|
||||
|
||||
belongs_to :project, inverse_of: :experiments, touch: true
|
||||
delegate :team, to: :project
|
||||
belongs_to :created_by,
|
||||
class_name: 'User'
|
||||
belongs_to :last_modified_by,
|
||||
|
|
|
@ -44,6 +44,7 @@ class MyModule < ApplicationRecord
|
|||
belongs_to :restored_by, foreign_key: 'restored_by_id', class_name: 'User', optional: true
|
||||
belongs_to :experiment, inverse_of: :my_modules, touch: true
|
||||
has_one :project, through: :experiment, autosave: false
|
||||
delegate :team, to: :project
|
||||
belongs_to :my_module_group, inverse_of: :my_modules, optional: true
|
||||
belongs_to :my_module_status, optional: true
|
||||
belongs_to :changing_from_my_module_status, optional: true, class_name: 'MyModuleStatus'
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UserAssignment < ApplicationRecord
|
||||
before_validation -> { self.team ||= (assignable.is_a?(Team) ? assignable : assignable.team) }
|
||||
|
||||
belongs_to :assignable, polymorphic: true, touch: true
|
||||
belongs_to :user_role
|
||||
belongs_to :user
|
||||
belongs_to :team
|
||||
belongs_to :assigned_by, class_name: 'User', optional: true
|
||||
|
||||
enum assigned: { automatically: 0, manually: 1 }, _suffix: true
|
||||
|
||||
validates :user, uniqueness: { scope: :assignable }
|
||||
validates :user, uniqueness: { scope: %i(assignable team_id) }
|
||||
end
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddTeamReferenceToUserAssignments < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_reference :user_assignments, :team, index: true, foreign_key: true
|
||||
|
||||
UserAssignment.preload(:assignable).find_each do |user_assignment|
|
||||
team = user_assignment.assignable.is_a?(Team) ? user_assignment.assignable : user_assignment.assignable.team
|
||||
user_assignment.update_column(:team_id, team.id)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_reference :user_assignments, :team, index: true, foreign_key: true
|
||||
end
|
||||
end
|
|
@ -2834,7 +2834,8 @@ CREATE TABLE public.user_assignments (
|
|||
assigned_by_id bigint,
|
||||
assigned integer DEFAULT 0 NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
team_id bigint
|
||||
);
|
||||
|
||||
|
||||
|
@ -6468,6 +6469,13 @@ CREATE INDEX index_user_assignments_on_assignable ON public.user_assignments USI
|
|||
CREATE INDEX index_user_assignments_on_assigned_by_id ON public.user_assignments USING btree (assigned_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_assignments_on_team_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_user_assignments_on_team_id ON public.user_assignments USING btree (team_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_user_assignments_on_user_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -7075,6 +7083,14 @@ ALTER TABLE ONLY public.result_assets
|
|||
ADD CONSTRAINT fk_rails_48803d79ff FOREIGN KEY (asset_id) REFERENCES public.assets(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_assignments fk_rails_4a5764985b; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_assignments
|
||||
ADD CONSTRAINT fk_rails_4a5764985b FOREIGN KEY (team_id) REFERENCES public.teams(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: experiments fk_rails_4a63cb023e; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -8371,6 +8387,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20220321122111'),
|
||||
('20220325101011'),
|
||||
('20220328164215'),
|
||||
('20220516111152');
|
||||
('20220516111152'),
|
||||
('20220621153016');
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue