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

Hide custom field values for projects without a view_project_attributes permission on the project list.

Dombi Attilacd9da942b583
diff --git a/app/components/projects/row_component.rb b/app/components/projects/row_component.rb
index d3a8c9b6f32..6299b38d674 100644
--- a/app/components/projects/row_component.rb
+++ b/app/components/projects/row_component.rb
@@ -359,7 +359,7 @@ module Projects
end
def user_can_view_project?
- User.current.allowed_in_project?(:view_project, project)
+ User.current.allowed_in_project?(:view_project_attributes, project)
end
def custom_field_column?(column)
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index 9bb8105f8c1..e770aa7151f 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -172,6 +172,7 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
)
end
end
+
context "with project attributes" do
let!(:list_custom_field) do
create(:list_project_custom_field, multi_value: true).tap do |cf|
@@ -281,6 +282,50 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
end
end
+ describe "project attributes visibility restrictions", with_ee: %i[custom_fields_in_projects_list] do
+ let(:user) do
+ create(:user,
+ member_with_roles: {
+ development_project => create(:existing_project_role, permissions:),
+ project => create(:existing_project_role)
+ })
+ end
+
+ let!(:list_custom_field) do
+ create(:list_project_custom_field, multi_value: true).tap do |cf|
+ development_project.update(custom_field_values: { cf.id => [cf.value_of("A"), cf.value_of("B")] })
+ project.update(custom_field_values: { cf.id => [cf.value_of("A"), cf.value_of("B")] })
+ end
+ end
+
+ before do
+ login_as(user)
+ projects_page.visit!
+ end
+
+ context "with view_project_attributes permission" do
+ let(:permissions) { %i(view_project_attributes) }
+
+ it "can see the project attribute field value in the project list" do
+ projects_page.set_columns(list_custom_field.name)
+ projects_page.expect_columns(list_custom_field.name)
+
+ projects_page
+ .expect_project_attribute_value(development_project, list_custom_field, "A, B")
+ projects_page
+ .expect_empty_project_attribute_value(project, list_custom_field)
+ end
+ end
+
+ context "without view_project_attributes permission" do
+ let(:permissions) { [] }
+
+ it "cannot see the project attribute field in the table configuration" do
+ projects_page.expect_no_config_columns(list_custom_field.name)
+ end
+ end
+ end
+
context "without valid Enterprise token" do
specify "CF columns and filters are not visible" do
load_and_open_filters admin
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index a59dcf5add1..af561211aed 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -331,6 +331,20 @@ module Pages
end
end
+ def expect_no_config_columns(*columns)
+ open_configure_view
+
+ columns.each do |column|
+ expect_no_ng_option find(".op-draggable-autocomplete--input"),
+ column,
+ results_selector: ".ng-dropdown-panel-items"
+ end
+
+ within "dialog" do
+ click_on "Cancel"
+ end
+ end
+
def mark_query_favorite
page.find('[data-test-selector="project-query-favorite"]').click
end