only require copy_project permission to show button

pull/7852/head
ulferts 5 years ago
parent 13c8d2600d
commit c96c5b89d5
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 2
      app/models/project.rb
  2. 43
      spec/models/project_spec.rb

@ -191,7 +191,7 @@ class Project < ActiveRecord::Base
end
def copy_allowed?
User.current.allowed_to?(:copy_projects, self) && (parent.nil? || User.current.allowed_to?(:add_subprojects, parent))
User.current.allowed_to?(:copy_projects, self)
end
def self.selectable_projects

@ -89,38 +89,31 @@ describe Project, type: :model do
end
end
describe 'copy_allowed?' do
let(:user) { FactoryBot.create(:user) }
let(:role_add_subproject) { FactoryBot.create(:role, permissions: [:add_subprojects]) }
let(:role_copy_projects) { FactoryBot.create(:role, permissions: [:edit_project, :copy_projects, :add_project]) }
let(:parent_project) { FactoryBot.create(:project) }
let(:project) { FactoryBot.create(:project, parent: parent_project) }
let!(:subproject_member) do
FactoryBot.create(:member,
user: user,
project: project,
roles: [role_copy_projects])
end
describe '#copy_allowed?' do
let(:user) { FactoryBot.build_stubbed(:user) }
let(:project) { FactoryBot.build_stubbed(:project) }
let(:permission_granted) { true }
before do
allow(user)
.to receive(:allowed_to?)
.with(:copy_projects, project)
.and_return(permission_granted)
login_as(user)
end
context 'with permission to add subprojects' do
let!(:member_add_subproject) do
FactoryBot.create(:member,
user: user,
project: parent_project,
roles: [role_add_subproject])
end
it 'should allow copy' do
expect(project.copy_allowed?).to eq(true)
context 'with copy project permission' do
it 'is true' do
expect(project.copy_allowed?).to be_truthy
end
end
context 'with permission to add subprojects' do
it 'should not allow copy' do
expect(project.copy_allowed?).to eq(false)
context 'without copy project permission' do
let(:permission_granted) { false }
it 'is false' do
expect(project.copy_allowed?).to be_falsey
end
end
end

Loading…
Cancel
Save