Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

fix check for permission without module

ulfertsfe0adb915124
diff --git a/app/models/projects/scopes/allowed_to.rb b/app/models/projects/scopes/allowed_to.rb
index d7b60276558..a2118d15982 100644
--- a/app/models/projects/scopes/allowed_to.rb
+++ b/app/models/projects/scopes/allowed_to.rb
@@ -51,7 +51,7 @@ module Projects::Scopes
def allowed_to_admin_relation(permissions)
joins(allowed_to_enabled_module_join(permissions))
- .where(active: true)
+ .where(arel_table[:active].eq(true))
end
def allowed_to_non_member_relation(user, permissions)
@@ -93,7 +93,7 @@ module Projects::Scopes
condition = permissions.inject(Arel::Nodes::False.new) do |or_condition, permission|
permission_condition = role_permissions_table[:permission].eq(permission.name)
- unless permission.public?
+ if permission.project_module.present?
permission_condition = permission_condition.and(enabled_modules_table[:name].eq(permission.project_module))
end
diff --git a/spec/models/projects/allowed_to_scope_spec.rb b/spec/models/projects/allowed_to_scope_spec.rb
index 68b0ce94c08..90bcff1c9c0 100644
--- a/spec/models/projects/allowed_to_scope_spec.rb
+++ b/spec/models/projects/allowed_to_scope_spec.rb
@@ -63,6 +63,7 @@ RSpec.describe Project, 'allowed to' do
let(:action) { :view_work_packages }
let(:public_action) { :view_news }
let(:public_non_module_action) { :view_project }
+ let(:non_module_action) { :edit_project }
let(:member) do
build(:member,
user:,
@@ -163,7 +164,7 @@ RSpec.describe Project, 'allowed to' do
context 'with the user being member
with the permission being public and not module bound
- with no module bing active' do
+ with no module being active' do
before do
member.save!
project.enabled_modules = []
@@ -173,6 +174,36 @@ RSpec.describe Project, 'allowed to' do
expect(described_class.allowed_to(user, public_non_module_action)).to contain_exactly(project)
end
end
+
+ context 'with the user being member
+ with the permission being module bound
+ with the role having the permission
+ with no module active' do
+ let(:permissions) { [non_module_action] }
+
+ before do
+ member.save!
+ end
+
+ it 'includes the project' do
+ expect(described_class.allowed_to(user, non_module_action)).to contain_exactly(project)
+ end
+ end
+
+ context 'with the user being member
+ with the permission being module bound
+ without the role having the permission
+ with no module active' do
+ let(:permissions) { [] }
+
+ before do
+ member.save!
+ end
+
+ it 'is empty' do
+ expect(described_class.allowed_to(user, non_module_action)).to be_empty
+ end
+ end
end
shared_examples_for 'with an admin user' do