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 allowed_in_any_entity early exit for archived projects

Klaus Zanders3e782e46e133
diff --git a/app/models/users/permission_checks.rb b/app/models/users/permission_checks.rb
index 2d0453d875d..5f906b9e597 100644
--- a/app/models/users/permission_checks.rb
+++ b/app/models/users/permission_checks.rb
@@ -118,9 +118,9 @@ module Users::PermissionChecks
def allowed_based_on_permission_context?(permission, project: nil, entity: nil) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
permissions = Authorization.permissions_for(permission, raise_on_unknown: true)
- entity_blank_or_not_project_scoped = (entity.blank? || !entity.respond_to?(:project) || (entity.respond_to?(:project) && entity.project.blank?))
- entity_is_work_package_or_list = ((entity.is_a?(WorkPackage) && entity.persisted?) || (entity.is_a?(Enumerable) && entity.all?(WorkPackage)))
- entity_is_project_scoped_and_project_is_present = (entity.respond_to?(:project) && entity.project.present?)
+ entity_blank_or_not_project_scoped = entity.blank? || !entity.respond_to?(:project) || (entity.respond_to?(:project) && entity.project.blank?)
+ entity_is_work_package_or_list = (entity.is_a?(WorkPackage) && entity.persisted?) || (entity.is_a?(Enumerable) && entity.all?(WorkPackage))
+ entity_is_project_scoped_and_project_is_present = entity.respond_to?(:project) && entity.project.present?
permissions.any? do |perm|
if perm.global?
diff --git a/app/services/authorization/user_permissible_service.rb b/app/services/authorization/user_permissible_service.rb
index 127b023731a..de731bb2ac1 100644
--- a/app/services/authorization/user_permissible_service.rb
+++ b/app/services/authorization/user_permissible_service.rb
@@ -47,9 +47,10 @@ module Authorization
end
end
- def allowed_in_any_entity?(permission, entity_class, in_project: nil)
+ def allowed_in_any_entity?(permission, entity_class, in_project: nil) # rubocop:disable Metrics/PerceivedComplexity
perms = contextual_permissions(permission, context_name(entity_class))
return false unless authorizable_user?
+ return false if in_project && !(in_project.active? || in_project.being_archived?)
return true if admin_and_all_granted_to_admin?(perms)
# entity_class.allowed_to will also check whether the user has the permission via a membership in the project.
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index a1c872de1ea..315319d3847 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -92,7 +92,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
expect(page).to have_text(public_project.name)
# Test that the 'More' menu stays invisible on hover
- expect(page).not_to have_selector('.icon-show-more-horizontal')
+ expect(page).not_to have_css('.icon-show-more-horizontal')
end
end
@@ -149,15 +149,15 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
# Test visibility of admin only properties
within('#project-table') do
expect(page)
- .to have_selector('th', text: 'REQUIRED DISK STORAGE')
+ .to have_css('th', text: 'REQUIRED DISK STORAGE')
expect(page)
- .to have_selector('th', text: 'CREATED ON')
+ .to have_css('th', text: 'CREATED ON')
expect(page)
- .to have_selector('td', text: project.created_at.strftime('%m/%d/%Y'))
+ .to have_css('td', text: project.created_at.strftime('%m/%d/%Y'))
expect(page)
- .to have_selector('th', text: 'LATEST ACTIVITY AT')
+ .to have_css('th', text: 'LATEST ACTIVITY AT')
expect(page)
- .to have_selector('td', text: news.created_at.strftime('%m/%d/%Y'))
+ .to have_css('td', text: news.created_at.strftime('%m/%d/%Y'))
end
end
@@ -167,7 +167,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
error_text = "Orders ><script src='/foobar js'></script> is not set to one of the allowed values. and does not exist."
error_html = "Orders &gt;&lt;script src='/foobar js'&gt;&lt;/script&gt; is not set to one of the allowed values. and does not exist."
- expect(page).to have_selector('.op-toast.-error', text: error_text)
+ expect(page).to have_css('.op-toast.-error', text: error_text)
error_container = page.find('.op-toast.-error')
expect(error_container['innerHTML']).to include error_html
@@ -306,7 +306,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
projects_page.expect_projects_listed(project)
projects_page.expect_projects_not_listed(public_project)
# Filter form is visible and the filter is still set.
- expect(page).to have_selector('li[filter-name="name_and_identifier"]')
+ expect(page).to have_css('li[filter-name="name_and_identifier"]')
end
end
@@ -359,7 +359,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
public_project) # Present on page 1
expect(page).not_to have_text('Next') # Filters kept active, so there is no third page.
- expect(page).to have_selector('.sort.desc', text: 'NAME')
+ expect(page).to have_css('.sort.desc', text: 'NAME')
# Sending the filter form again what implies to compose the request freshly
click_on 'Apply'
@@ -371,7 +371,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
projects_page.expect_projects_not_listed(development_project, # as it is on the second page
project) # as it filtered out
expect(page).to have_text('Next') # as the result set is larger than 1
- expect(page).to have_selector('.sort.desc', text: 'NAME')
+ expect(page).to have_css('.sort.desc', text: 'NAME')
end
end
@@ -423,7 +423,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
load_and_open_filters admin
# value selection defaults to "active"'
- expect(page).to have_selector('li[filter-name="active"]')
+ expect(page).to have_css('li[filter-name="active"]')
projects_page.expect_projects_listed(parent_project,
child_project,
@@ -886,7 +886,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
# 'More' does not become visible on hover
page.find('tbody tr').hover
- expect(page).not_to have_selector('.icon-show-more-horizontal')
+ expect(page).not_to have_css('.icon-show-more-horizontal')
# For a project member with :copy_projects privilege the 'More' menu is visible.
login_as(can_copy_projects_manager)
@@ -897,7 +897,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
# 'More' becomes visible on hover
# because we use css opacity we can not test for the visibility changes
page.find('tbody tr').hover
- expect(page).to have_selector('.icon-show-more-horizontal')
+ expect(page).to have_css('.icon-show-more-horizontal')
# Test visibility of 'more' menu list items
page.find('tbody tr .icon-show-more-horizontal').click
@@ -915,7 +915,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
# 'More' becomes visible on hover
# because we use css opacity we can not test for the visibility changes
page.find('tbody tr').hover
- expect(page).to have_selector('.icon-show-more-horizontal')
+ expect(page).to have_css('.icon-show-more-horizontal')
# Test visibility of 'more' menu list items
page.find('tbody tr .icon-show-more-horizontal').click
@@ -929,15 +929,15 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
# Test admin only properties are invisible
within('#project-table') do
expect(page)
- .not_to have_selector('th', text: 'REQUIRED DISK STORAGE')
+ .not_to have_css('th', text: 'REQUIRED DISK STORAGE')
expect(page)
- .not_to have_selector('th', text: 'CREATED ON')
+ .not_to have_css('th', text: 'CREATED ON')
expect(page)
- .not_to have_selector('td', text: project.created_at.strftime('%m/%d/%Y'))
+ .not_to have_css('td', text: project.created_at.strftime('%m/%d/%Y'))
expect(page)
- .not_to have_selector('th', text: 'LATEST ACTIVITY AT')
+ .not_to have_css('th', text: 'LATEST ACTIVITY AT')
expect(page)
- .not_to have_selector('td', text: news.created_at.strftime('%m/%d/%Y'))
+ .not_to have_css('td', text: news.created_at.strftime('%m/%d/%Y'))
end
end
end
@@ -1098,7 +1098,7 @@ RSpec.describe 'Projects index page', :js, :with_cuprite,
# 'More' becomes visible on hover
# because we use css opacity we can not test for the visibility changes
page.find('tbody tr').hover
- expect(page).to have_selector('.icon-show-more-horizontal')
+ expect(page).to have_css('.icon-show-more-horizontal')
# "Project activity" item should be displayed in the 'more' menu
page.find('tbody tr .icon-show-more-horizontal').click