diff --git a/app/controllers/release_template_imports_controller.rb b/app/controllers/release_template_imports_controller.rb index 9efb566..56c33cf 100644 --- a/app/controllers/release_template_imports_controller.rb +++ b/app/controllers/release_template_imports_controller.rb @@ -11,7 +11,9 @@ class ReleaseTemplateImportsController < ApplicationController templates = [] filtered_contract_templates.each do |contract_template| - next if contract_template.duplicated? || contract_template.project == @project + next if contract_template.duplicated? || + contract_template.archived? || + contract_template.project == @project already_imported = contract_template.duplicates.non_archived.pluck(:project_id).include?(@project.id) templates << OpenStruct.new(template: contract_template, already_imported?: already_imported) diff --git a/app/models/contract_template.rb b/app/models/contract_template.rb index 16f87be..b492be1 100644 --- a/app/models/contract_template.rb +++ b/app/models/contract_template.rb @@ -51,6 +51,10 @@ class ContractTemplate < ApplicationRecord parent.present? end + def archived? + archived_at.present? + end + def archive update(archived_at: Time.zone.now) end diff --git a/spec/factories/contract_templates.rb b/spec/factories/contract_templates.rb index 80c8772..caf8088 100644 --- a/spec/factories/contract_templates.rb +++ b/spec/factories/contract_templates.rb @@ -8,6 +8,10 @@ FactoryBot.define do guardian_clause "Is the signer a minor?" fee "$0.00" + trait :archived do + archived_at Time.zone.now + end + factory :appearance_release_contract_template do release_type "appearance" end diff --git a/spec/features/user_manages_contract_templates_spec.rb b/spec/features/user_manages_contract_templates_spec.rb index 1af8733..a81b0a4 100644 --- a/spec/features/user_manages_contract_templates_spec.rb +++ b/spec/features/user_manages_contract_templates_spec.rb @@ -5,6 +5,7 @@ require 'rails_helper' RSpec.feature 'User manages contract templates', type: :feature do let(:current_user) { create(:user, :manager) } let(:project) { create(:project, members: current_user, account: current_user.primary_account) } + let(:project2) { create(:project, members: current_user, account: current_user.primary_account, name: 'New project') } before do sign_in(current_user) @@ -191,6 +192,21 @@ RSpec.feature 'User manages contract templates', type: :feature do expect(page).not_to have_content('Test template') end + scenario 'archived contract templates from other projects are not shown when importing contract templates' do + create(:contract_template, :archived, project: project2, name: 'Archived template') + create(:contract_template, project: project2, name: 'Active template') + create(:contract_template, project: project) + + visit project_contract_templates_path(project) + expect(page).to have_content('Test template') + + click_on import_template_button + + expect(page).not_to have_content('Test template') + expect(page).not_to have_content('Archived template') + expect(page).to have_content('Active template') + end + context 'When the user is associate' do let(:current_user) { create(:user, :associate) } @@ -198,7 +214,7 @@ RSpec.feature 'User manages contract templates', type: :feature do visit project_contract_templates_path(project) expect(page).not_to have_content('Create New Release Template') - expect(page).not_to have_content('Import Release Template') + expect(page).not_to have_content(import_template_button) expect(page).not_to have_content('Delete') end end @@ -218,6 +234,14 @@ RSpec.feature 'User manages contract templates', type: :feature do private + def import_template_button + t 'contract_templates.index.actions.import' + end + + def import_selected_templates_button + t 'release_template_imports.new.actions.import' + end + def preview_heading t 'blank_contracts.new.preview_heading' end