Merge pull request #3003 from okriuchykhin/ok_SCI_5268

Archiving: add 'archived' flag on folder [SCI-5268]
This commit is contained in:
Miha Mencin 2020-12-17 13:13:26 +01:00 committed by GitHub
commit 6dc4fae45b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 4 deletions

View file

@ -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

View file

@ -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'

View file

@ -121,6 +121,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

View file

@ -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

View file

@ -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');