From f150a11c4f3dd3644008f765eb02669df60355d2 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 10 Dec 2020 12:10:32 +0100 Subject: [PATCH] Archiving: add 'archived' flag on folder [SCI-5268] --- app/models/project_folder.rb | 9 ++++++ app/models/user.rb | 8 ++++++ app/services/projects_overview_service.rb | 2 ++ ...26_add_archived_flag_to_project_folders.rb | 13 +++++++++ db/structure.sql | 28 ++++++++++++++++--- 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20201209165626_add_archived_flag_to_project_folders.rb diff --git a/app/models/project_folder.rb b/app/models/project_folder.rb index 8d7aef7ec..a1ee454b6 100644 --- a/app/models/project_folder.rb +++ b/app/models/project_folder.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class ProjectFolder < ApplicationRecord + include ArchivableModel include SearchableModel include SearchableByNameModel @@ -14,6 +15,14 @@ class ProjectFolder < ApplicationRecord belongs_to :team, inverse_of: :project_folders, touch: true belongs_to :parent_folder, class_name: 'ProjectFolder', optional: true + belongs_to :archived_by, foreign_key: 'archived_by_id', + class_name: 'User', + inverse_of: :archived_project_folders, + optional: true + belongs_to :restored_by, foreign_key: 'restored_by_id', + class_name: 'User', + inverse_of: :restored_project_folders, + optional: true has_many :projects, inverse_of: :project_folder, dependent: :nullify has_many :project_folders, foreign_key: 'parent_folder_id', inverse_of: :parent_folder, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index f89d7cf6e..c3f481a00 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -125,6 +125,14 @@ class User < ApplicationRecord has_many :restored_projects, class_name: 'Project', foreign_key: 'restored_by_id' + has_many :archived_project_folders, + class_name: 'ProjectFolder', + foreign_key: 'archived_by_id', + inverse_of: :arhived_by + has_many :restored_project_folders, + class_name: 'ProjectFolder', + foreign_key: 'restored_by_id', + inverse_of: :restored_by has_many :modified_reports, class_name: 'Report', foreign_key: 'last_modified_by_id' diff --git a/app/services/projects_overview_service.rb b/app/services/projects_overview_service.rb index 6cfe7dbca..935e6dfc9 100644 --- a/app/services/projects_overview_service.rb +++ b/app/services/projects_overview_service.rb @@ -107,6 +107,8 @@ class ProjectsOverviewService end def filter_project_folder_records(records) + records = records.where(archived: true) if @params[:filter] == 'archived' + records = records.where(archived: false) if @params[:filter] == 'active' records = records.where_attributes_like('project_folders.name', @params[:search]) if @params[:search].present? records end diff --git a/db/migrate/20201209165626_add_archived_flag_to_project_folders.rb b/db/migrate/20201209165626_add_archived_flag_to_project_folders.rb new file mode 100644 index 000000000..0bfea34e6 --- /dev/null +++ b/db/migrate/20201209165626_add_archived_flag_to_project_folders.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddArchivedFlagToProjectFolders < ActiveRecord::Migration[6.0] + def change + change_table :project_folders, bulk: true do |t| + t.boolean :archived, default: false + t.references :archived_by, foreign_key: { to_table: :users }, index: false + t.datetime :archived_on + t.references :restored_by, foreign_key: { to_table: :users }, index: false + t.datetime :restored_on + end + end +end diff --git a/db/structure.sql b/db/structure.sql index d3e3a6928..c0838778f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -996,7 +996,12 @@ CREATE TABLE public.project_folders ( team_id bigint NOT NULL, parent_folder_id bigint, 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, + archived boolean DEFAULT false, + archived_by_id bigint, + archived_on timestamp without time zone, + restored_by_id bigint, + restored_on timestamp without time zone ); @@ -6111,6 +6116,14 @@ ALTER TABLE ONLY public.repository_status_items ADD CONSTRAINT fk_rails_74e5e4cacc FOREIGN KEY (repository_column_id) REFERENCES public.repository_columns(id); +-- +-- Name: project_folders fk_rails_7931975dd0; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.project_folders + ADD CONSTRAINT fk_rails_7931975dd0 FOREIGN KEY (restored_by_id) REFERENCES public.users(id); + + -- -- Name: project_folders fk_rails_795296de66; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -6807,6 +6820,14 @@ ALTER TABLE ONLY public.protocol_protocol_keywords ADD CONSTRAINT fk_rails_f04cc911dd FOREIGN KEY (protocol_id) REFERENCES public.protocols(id); +-- +-- Name: project_folders fk_rails_f27fa590f4; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.project_folders + ADD CONSTRAINT fk_rails_f27fa590f4 FOREIGN KEY (archived_by_id) REFERENCES public.users(id); + + -- -- Name: report_elements fk_rails_f36eac136b; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -7064,6 +7085,5 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200826143431'), ('20200909121441'), ('20201028103608'), -('20201126203713'); - - +('20201126203713'), +('20201209165626');