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
Prevent rendering of delete buttons on global calendars page
Aaron Contrerasa78fb0569f8f
diff --git a/modules/calendar/app/components/calendar/row_component.rb b/modules/calendar/app/components/calendar/row_component.rbindex 269fb0a6452..17f7e5433c7 100644--- a/modules/calendar/app/components/calendar/row_component.rb+++ b/modules/calendar/app/components/calendar/row_component.rb@@ -51,7 +51,7 @@ module Calendarenddef delete_link- if table.current_user.allowed_to?(:manage_calendars, project)+ if render_delete_link?link_to('',project_calendar_path(project, query.id),@@ -65,5 +65,11 @@ module Calendar)endend++ private++ def render_delete_link?+ table.current_project && table.current_user.allowed_to?(:manage_calendars, project)+ endendenddiff --git a/modules/calendar/spec/features/calendars_index_spec.rb b/modules/calendar/spec/features/calendars_index_spec.rbindex c88bf26a91c..d11e9fbfe4d 100644--- a/modules/calendar/spec/features/calendars_index_spec.rb+++ b/modules/calendar/spec/features/calendars_index_spec.rb@@ -27,6 +27,7 @@#++require 'spec_helper'+require_relative '../support/pages/calendar'RSpec.describe 'Calendars', 'index', :js, :with_cuprite doshared_let(:project) do@@ -104,6 +105,7 @@ RSpec.describe 'Calendars', 'index', :js, :with_cuprite doendcontext 'when visiting from a global context', with_flag: { more_global_index_pages: true } do+ let(:calendars_page) { Pages::Calendar.new(nil) }let(:queries) { [query, other_query] }before do@@ -114,7 +116,7 @@ RSpec.describe 'Calendars', 'index', :js, :with_cuprite docontext 'with permissions to globally manage calendars' doit 'shows no create button' do- expect(page).not_to have_selector '.button', text: 'Calendar'+ calendars_page.expect_no_create_buttonendend@@ -122,15 +124,15 @@ RSpec.describe 'Calendars', 'index', :js, :with_cuprite dolet(:queries) { [] }it 'shows an empty index page' do- expect(page).to have_text 'There is currently nothing to display.'+ calendars_page.expect_no_views_visibleendendcontext 'with existing views' doit 'shows those views', :aggregate_failures doqueries.each do |q|- expect(page).to have_selector 'td', text: q.name- expect(page).to have_selector "[data-qa-selector='calendar-remove-#{q.id}']"+ calendars_page.expect_view_visible(q)+ calendars_page.expect_no_delete_button(q)endendend@@ -147,17 +149,18 @@ RSpec.describe 'Calendars', 'index', :js, :with_cuprite dolet(:query) { create(:query, user:, project:, public: false) }it 'does not show a non-public view' do- expect(page).to have_text 'There is currently nothing to display.'- expect(page).not_to have_selector 'td', text: query.name+ calendars_page.expect_no_views_visible+ calendars_page.expect_view_not_visible query- # Does not show the delete- expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ calendars_page.expect_no_delete_button queryendendendendcontext 'when visiting from a project-specific context' do+ let(:calendars_page) { Pages::Calendar.new(project) }+before dologin_as current_userquery@@ -168,15 +171,15 @@ RSpec.describe 'Calendars', 'index', :js, :with_cuprite dolet(:query) { nil }it 'shows an empty index page' do- expect(page).to have_text 'There is currently nothing to display.'- expect(page).to have_selector '.button', text: 'Calendar'+ calendars_page.expect_no_views_visible+ calendars_page.expect_create_buttonendendcontext 'with an existing view' doit 'shows that view' do- expect(page).to have_selector 'td', text: query.name- expect(page).to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"+ calendars_page.expect_view_visible query+ calendars_page.expect_delete_button queryendcontext 'with another user with limited access' do@@ -187,28 +190,21 @@ RSpec.describe 'Calendars', 'index', :js, :with_cuprite domember_with_permissions: %w[view_work_packages view_calendar])end- it 'does not show the create button' do- expect(page).to have_selector 'td', text: query.name+ it 'does not show the management buttons' do+ calendars_page.expect_view_visible query- # Does not show the delete- expect(page).not_to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"-- # Does not show the create button- expect(page).not_to have_selector '.button', text: 'Calendar'+ calendars_page.expect_no_delete_button query+ calendars_page.expect_no_create_buttonendcontext 'when the view is non-public' dolet(:query) { create(:query, user:, project:, public: false) }it 'does not show a non-public view' do- expect(page).to have_text 'There is currently nothing to display.'- expect(page).not_to have_selector 'td', text: query.name-- # Does not show the delete- expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"+ calendars_page.expect_no_views_visible+ calendars_page.expect_view_not_visible query- # Does not show the create button- expect(page).not_to have_selector '.button', text: 'Calendar'+ calendars_page.expect_no_create_buttonendendenddiff --git a/modules/calendar/spec/support/pages/calendar.rb b/modules/calendar/spec/support/pages/calendar.rbindex 658ed3c5006..18658dd1e6e 100644--- a/modules/calendar/spec/support/pages/calendar.rb+++ b/modules/calendar/spec/support/pages/calendar.rb@@ -111,5 +111,33 @@ module Pagesdef expect_wp_not_draggable(work_package)expect(page).to have_selector('.fc-event:not(.fc-event-draggable)', text: work_package.subject)end++ def expect_create_button+ expect(page).to have_selector '.button', text: 'Calendar'+ end++ def expect_no_create_button+ expect(page).not_to have_selector '.button', text: 'Calendar'+ end++ def expect_delete_button(query)+ expect(page).to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"+ end++ def expect_no_delete_button(query)+ expect(page).not_to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"+ end++ def expect_no_views_visible+ expect(page).to have_text 'There is currently nothing to display.'+ end++ def expect_view_visible(query)+ expect(page).to have_selector 'td', text: query.name+ end++ def expect_view_not_visible(query)+ expect(page).not_to have_selector 'td', text: query.name+ endendend