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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
disable editing for project members without editing permission
Jonas Jabari82c2209a97ae
diff --git a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erbindex 92fa94b6168..3a573264c34 100644--- a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb@@ -20,7 +20,7 @@qa_selector: "project-custom-field-section-edit-button"} }))- end+ end if allowed_to_edit?endenddiff --git a/modules/overviews/app/components/project_custom_fields/sections/show_component.rb b/modules/overviews/app/components/project_custom_fields/sections/show_component.rbindex 45a49107b7d..e3352cad3e9 100644--- a/modules/overviews/app/components/project_custom_fields/sections/show_component.rb+++ b/modules/overviews/app/components/project_custom_fields/sections/show_component.rb@@ -45,6 +45,10 @@ module ProjectCustomFieldsprivate+ def allowed_to_edit?+ User.current.allowed_in_project?(:edit_project, @project)+ end+def eager_load_project_custom_field_values# TODO: move to service@eager_loaded_project_custom_field_values = CustomValuediff --git a/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb b/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rbindex 685dff43762..977d7fddef1 100644--- a/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb+++ b/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb@@ -34,16 +34,34 @@ RSpec.describe 'Edit project custom fields on project overview page', :js dolet(:overview_page) { Pages::Projects::Show.new(project) }- before do- login_as admin- end-describe 'with enabled project attributes feature', with_flag: { project_attributes: true } do- before do- overview_page.visit_page+ describe 'with insufficient permissions' do+ # TODO: turboframe sidebar request needs to be covered by a controller spec checking for 403+ # TODO: async dialog content request needs to be covered by a controller spec checking for 403+ before do+ login_as member_without_project_edit_permissions+ overview_page.visit_page+ end++ it 'does not show the edit buttons' do+ overview_page.within_async_loaded_sidebar do+ expect(page).to have_no_css("[data-qa-selector='project-custom-field-section-edit-button']")+ end+ endenddescribe 'with sufficient permissions' do+ before do+ login_as member_with_project_edit_permissions+ overview_page.visit_page+ end++ it 'shows the edit buttons' do+ overview_page.within_async_loaded_sidebar do+ expect(page).to have_css("[data-qa-selector='project-custom-field-section-edit-button']", count: 3)+ end+ end+describe 'enables editing of project custom field values via dialog' dolet(:dialog) { Components::Projects::ProjectCustomFields::EditDialog.new(project, section_for_input_fields) }@@ -147,7 +165,7 @@ RSpec.describe 'Edit project custom fields on project overview page', :js doendend- describe 'with correct inital values' do+ describe 'with correct initialization and input behaviour' dodescribe 'with input fields' dolet(:section) { section_for_input_fields }let(:dialog) { Components::Projects::ProjectCustomFields::EditDialog.new(project, section) }diff --git a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb b/spec/features/projects/project_custom_fields/overview_page/shared_context.rbindex f38bcfa26b1..5af4fb30494 100644--- a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb+++ b/spec/features/projects/project_custom_fields/overview_page/shared_context.rb@@ -38,6 +38,10 @@ RSpec.shared_context 'with seeded projects, members and project custom fields' dcreate(:project_role, permissions: %i[view_work_packages])end+ shared_let(:edit_role) do+ create(:project_role, permissions: %i[view_work_packages edit_project])+ end+let!(:admin) docreate(:admin)end@@ -63,6 +67,17 @@ RSpec.shared_context 'with seeded projects, members and project custom fields' dmember_with_roles: { project => reader_role })end+ let!(:member_with_project_edit_permissions) do+ create(:user,+ firstname: 'Member',+ lastname: 'With Project Edit Permissions',+ member_with_roles: { project => edit_role })+ end++ let!(:member_without_project_edit_permissions) do+ member_in_project+ end+let!(:section_for_input_fields) { create(:project_custom_field_section, name: 'Input fields') }let!(:section_for_select_fields) { create(:project_custom_field_section, name: 'Select fields') }let!(:section_for_multi_select_fields) { create(:project_custom_field_section, name: 'Multi select fields') }diff --git a/spec/support/components/projects/project_custom_fields/edit_dialog.rb b/spec/support/components/projects/project_custom_fields/edit_dialog.rbindex 1bb07c2c3fd..3b47651eea4 100644--- a/spec/support/components/projects/project_custom_fields/edit_dialog.rb+++ b/spec/support/components/projects/project_custom_fields/edit_dialog.rb@@ -103,377 +103,3 @@ module Componentsendendend--# def select_shares(*principals)-# within shares_list do-# principals.each do |principal|-# check principal.name-# end-# end-# end--# def deselect_shares(*principals)-# within shares_list do-# principals.each do |principal|-# uncheck principal.name-# end-# end-# end--# def expect_not_selectable(*principals)-# principals.each do |principal|-# within user_row(principal) do-# expect(page).to have_no_field(principal.name)-# end-# end-# end--# def toggle_select_all-# within shares_header do-# if page.find_field('toggle_all').checked?-# uncheck 'toggle_all'-# else-# check 'toggle_all'-# end-# end-# end--# def expect_selected(*principals)-# within shares_list do-# principals.each do |principal|-# expect(page).to have_checked_field(principal.name)-# end-# end-# end--# def expect_deselected(*principals)-# within shares_list do-# principals.each do |principal|-# expect(page).to have_unchecked_field(principal.name)-# end-# end-# end--# def expect_selected_count_of(count)-# expect(shares_header)-# .to have_text("#{count} selected")-# end--# def expect_select_all_available-# expect(shares_header)-# .to have_field('toggle_all')-# end--# def expect_select_all_not_available-# expect(shares_header)-# .to have_no_field('toggle_all', wait: 0)-# end--# def expect_select_all_toggled-# within shares_header do-# expect(page).to have_checked_field('toggle_all')-# end-# end--# def expect_select_all_untoggled-# within shares_header do-# expect(page).to have_unchecked_field('toggle_all')-# end-# end--# def expect_bulk_actions_available-# within shares_header do-# expect(page).to have_button 'Remove'-# expect(page).to have_test_selector('op-share-wp-bulk-update-role')-# end-# end--# def expect_bulk_actions_not_available-# within shares_header do-# expect(page).to have_no_button('Remove', wait: 0)-# expect(page).not_to have_test_selector('op-share-wp-bulk-update-role', wait: 0)-# end-# end--# def bulk_remove-# within shares_header do-# click_button 'Remove'-# end-# end--# def bulk_update(role_name)-# within shares_header do-# find('[data-test-selector="op-share-wp-bulk-update-role"]').click--# find('.ActionListContent', text: role_name).click-# end-# end--# def expect_bulk_update_label(label_text)-# within shares_header do-# expect(page)-# .to have_css('[data-test-selector="op-share-wp-bulk-update-role"] .Button-label',-# text: label_text)-# if label_text == 'Mixed'-# %w[View Comment Edit].each do |permission_name|-# within bulk_update_form(permission_name) do-# expect(page)-# .to have_css(unchecked_permission, visible: :all)-# end-# end-# else-# within bulk_update_form(label_text) do-# expect(page)-# .to have_css(checked_permission, visible: :all)-# end-# end-# end-# end--# def bulk_update_form(permission_name)-# find("[data-test-selector='op-share-wp-bulk-update-role-permission-#{permission_name}']", visible: :all)-# end--# def checked_permission-# 'button[type=submit][aria-checked=true]'-# end--# def unchecked_permission-# 'button[type=submit][aria-checked="false"]'-# end--# def expect_blankslate-# within_modal do-# expect(page).to have_text(I18n.t('work_package.sharing.text_empty_state_description'))-# end-# end--# def expect_empty_search_blankslate-# within_modal do-# expect(page).to have_text(I18n.t('work_package.sharing.text_empty_search_description'))-# end-# end--# def invite_user(users, role_name)-# Array(users).each do |user|-# case user-# when String-# select_not_existing_user_option(user)-# when Principal-# select_existing_user(user)-# end-# end--# select_invite_role(role_name)--# within_modal do-# click_button 'Share'-# end-# end--# alias_method :invite_users, :invite_user-# alias_method :invite_group, :invite_user--# # Augments +invite_user+ by asserting that the modifications to the-# # share have reflected in the modal's UI and we're able to continue-# # with our spec without any waits or network related assertions.-# #-# # As a side benefit, it just keeps the spec file cleaner.-# def invite_user!(user, role_name)-# invite_user(user, role_name)-# expect_shared_with(user, role_name)-# end--# def search_user(search_string)-# search_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),-# query: search_string,-# results_selector: 'body'-# end--# def remove_user(user)-# within user_row(user) do-# click_button 'Remove'-# end-# end--# def select_invite_role(role_name)-# within modal_element.find('[data-test-selector="op-share-wp-invite-role"]') do-# # Open the ActionMenu-# click_button 'View'--# find('.ActionListContent', text: role_name).click-# end-# end--# def change_role(user, role_name)-# within user_row(user) do-# find('[data-test-selector="op-share-wp-update-role"]').click--# within '.ActionListWrap' do-# click_button role_name-# end-# end-# end--# def filter(filter_name, value)-# within(shares_header) do-# retry_block do-# # The button's text changes dynamically based on the currently selected option-# # Hence the spec's readability is hindered by using something like-# # `click_button filter_name.capitalize`-# find("[data-test-selector='op-share-wp-filter-#{filter_name}-button']").click--# # Open the ActionMenu-# find('.ActionListContent', text: value).click-# end-# end--# wait_for_network_idle # Ensures filtering is done-# end--# def close-# within_modal do-# page.find("[data-test-selector='op-share-wp-modal--close-icon']").click-# end-# end--# def click_share-# within_modal do-# click_button 'Share'-# end-# end--# def expect_shared_with(user, role_name = nil, position: nil, editable: true)-# within_modal do-# within shares_list do-# expect(page).to have_list_item(text: user.name, position:)-# within(:list_item, text: user.name, position:) do-# if role_name-# expect(page).to have_button(role_name),-# "Expected share with #{user.name.inspect} to have button #{role_name}."-# end-# unless editable-# expect(page).not_to have_button,-# "Expected share with #{user.name.inspect} not to be editable (expected no buttons)."-# end-# end-# end-# end-# end--# def expect_not_shared_with(*principals)-# within shares_list do-# principals.each do |principal|-# expect(page)-# .to have_no_text(principal.name)-# end-# end-# end--# def expect_shared_count_of(count)-# expect(shares_header)-# .to have_text(I18n.t('work_package.sharing.count', count:))-# end--# def expect_no_invite_option-# within_modal do-# expect(page)-# .to have_text(I18n.t('work_package.sharing.permissions.denied'))-# end-# end--# def resend_invite(user)-# within user_row(user) do-# click_button I18n.t("work_package.sharing.user_details.resend_invite")-# end-# end--# def expect_invite_resent(user)-# within user_row(user) do-# expect(page)-# .to have_text(I18n.t("work_package.sharing.user_details.invite_resent"))-# end-# end--# def user_row(user)-# within_modal do-# find(:list_item, text: user.name)-# end-# end--# def active_list-# modal_element-# .find('[data-test-selector="op-share-wp-active-list"]')-# end--# def shares_header-# active_list.find('[data-test-selector="op-share-wp-header"]')-# end--# def shares_counter-# shares_header.find('[data-test-selector="op-share-wp-active-count"]')-# end--# def shares_list-# find_by_id('op-share-wp-active-shares')-# end--# def select_existing_user(user)-# select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),-# query: user.firstname,-# select_text: user.name,-# results_selector: 'body'-# end--# def select_not_existing_user_option(email)-# select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),-# query: email,-# select_text: "Send invite to\"#{email}\"",-# results_selector: 'body'-# end--# def expect_upsale_banner-# within_modal do-# expect(page)-# .to have_text(I18n.t(:label_enterprise_addon))-# end-# end--# def expect_no_user_limit_warning-# within modal_element do-# expect(page)-# .to have_no_text(I18n.t('work_package.sharing.warning_user_limit_reached'), wait: 0)-# end-# end--# def expect_user_limit_warning-# within modal_element do-# expect(page)-# .to have_text(I18n.t('work_package.sharing.warning_user_limit_reached'))-# end-# end--# def expect_error_message(text)-# within modal_element do-# expect(page)-# .to have_css('[data-test-selector="op-share-wp-error-message"]',-# text:)-# end-# end--# def expect_select_a_user_hint-# within modal_element do-# expect(page)-# .to have_text(I18n.t("work_package.sharing.warning_no_selected_user"))-# end-# end--# def expect_no_select_a_user_hint-# within modal_element do-# expect(page)-# .to have_no_text(I18n.t("work_package.sharing.warning_no_selected_user"), wait: 0)-# end-# end-# end-# end-# end