From fce2fb2d682775fb3921bbc54f4a42c06b8e2360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 23 Nov 2023 16:06:43 +0100 Subject: [PATCH] Fix copying meetings between types, allow empty copy of structured meetings --- .../meetings/header_component.html.erb | 11 +++++++- .../app/controllers/meetings_controller.rb | 2 +- .../meeting/app/views/meetings/_form.html.erb | 4 +++ .../meeting/app/views/meetings/new.html.erb | 3 ++- modules/meeting/config/locales/en.yml | 1 + .../structured_meeting_crud_spec.rb | 27 ++++++++++++++++++- 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/modules/meeting/app/components/meetings/header_component.html.erb b/modules/meeting/app/components/meetings/header_component.html.erb index a85d5b23f7d5..7b1374d8592b 100644 --- a/modules/meeting/app/components/meetings/header_component.html.erb +++ b/modules/meeting/app/components/meetings/header_component.html.erb @@ -21,12 +21,21 @@ item.with_leading_visual_icon(icon: :pencil) end if @meeting.editable? + menu.with_item(label: t(:button_copy), + href: copy_meeting_path(@meeting), + content_arguments: { + data: { turbo: false } + }) do |item| + item.with_leading_visual_icon(icon: :copy) + end + menu.with_item(label: t(:label_icalendar_download), href: download_ics_meeting_path(@meeting)) do |item| item.with_leading_visual_icon(icon: :download) end - if User.current.allowed_to?(:send_meeting_agendas_notification, @meeting.project) + if User.current.allowed_in_project?(:send_meeting_agendas_notification, @meeting.project + ) menu.with_item(label: t('meeting.label_mail_all_participants'), href: notify_meeting_path(@meeting), form_arguments: { method: :post, data: { turbo: 'false' } }) do |item| diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb index 41ef478cd641..386c36167fb9 100644 --- a/modules/meeting/app/controllers/meetings_controller.rb +++ b/modules/meeting/app/controllers/meetings_controller.rb @@ -102,7 +102,7 @@ def copy params[:copied_from_meeting_id] = @meeting.id params[:copied_meeting_agenda_text] = @meeting.agenda.text if @meeting.agenda.present? @meeting = @meeting.copy(author: User.current) - render action: 'new', project_id: @project + render action: 'new', project_id: @project, locals: { copy: true } end def destroy diff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erb index 26cac65acb06..87d9e388f3fd 100644 --- a/modules/meeting/app/views/meetings/_form.html.erb +++ b/modules/meeting/app/views/meetings/_form.html.erb @@ -55,6 +55,10 @@ See COPYRIGHT and LICENSE files for more details.

<%= t('meeting.types.structured_text') %> + <% if local_assigns[:copy] %> +
+ <%= t('meeting.types.structured_text_copy') %> + <% end %>

diff --git a/modules/meeting/app/views/meetings/new.html.erb b/modules/meeting/app/views/meetings/new.html.erb index a11f9539fed1..79706a160fb0 100644 --- a/modules/meeting/app/views/meetings/new.html.erb +++ b/modules/meeting/app/views/meetings/new.html.erb @@ -30,12 +30,13 @@ See COPYRIGHT and LICENSE files for more details. <% html_title t(:label_meeting_new) %> <%= toolbar title: t(:label_meeting_new) %> <%= labelled_tabular_form_for @meeting, + as: :meeting, url: {:controller => '/meetings', :action => 'create', :project_id => @project}, :html => {:id => 'meeting-form', :data => { :controller => 'refresh-on-form-changes', 'refresh-on-form-changes-target': 'form', 'refresh-on-form-changes-turbo-stream-url-value': new_meeting_url }} do |f| -%> - <%= render :partial => 'form', :locals => {:f => f} %> + <%= render :partial => 'form', :locals => { f:, copy: local_assigns[:copy] } %> <%= styled_button_tag t(:button_create), class: '-highlight' %> <%= link_to t(:button_cancel), { :action => 'index', :project_id => @project }, class: 'button' %> diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.yml index 331132c93add..ab3485306e00 100644 --- a/modules/meeting/config/locales/en.yml +++ b/modules/meeting/config/locales/en.yml @@ -125,6 +125,7 @@ en: classic_text: 'Organize your meeting in a formattable text agenda and protocol.' structured: 'Dynamic' structured_text: 'Organize your meeting as a list of agenda items, optionally linking them to a work package.' + structured_text_copy: 'Copying a meeting will currently not copy the associated meeting agenda items, just the details' copied: "Copied from Meeting #%{id}" notice_successful_notification: "Notification sent successfully" diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb index 6e60f5751165..81b01efdf6df 100644 --- a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb +++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb @@ -62,7 +62,8 @@ let(:current_user) { user } let(:new_page) { Pages::Meetings::New.new(project) } - let(:show_page) { Pages::StructuredMeeting::Show.new(StructuredMeeting.order(id: :asc).last) } + let(:meeting) { StructuredMeeting.order(id: :asc).last } + let(:show_page) { Pages::StructuredMeeting::Show.new(meeting) } before do login_as current_user @@ -250,6 +251,30 @@ expect(page).to have_css('.flash', text: I18n.t('activerecord.errors.messages.error_conflict')) end + it 'can copy the meeting (empty)' do + show_page.expect_toast(message: 'Successful creation') + + # Can add and edit a single item + show_page.add_agenda_item do + fill_in 'Title', with: 'My agenda item' + fill_in 'Duration (min)', with: '25' + end + + show_page.expect_agenda_item title: 'My agenda item' + show_page.cancel_add_form + + click_button('op-meetings-header-action-trigger') + click_link 'Copy' + + expect(page).to have_current_path "/meetings/#{meeting.id}/copy" + + click_button 'Create' + + expect(page).to have_text 'Your meeting is empty' + new_meeting = StructuredMeeting.order(id: :asc).last + expect(page).to have_current_path "/meetings/#{new_meeting.id}" + end + context 'with a work package reference to another' do let!(:meeting) { create(:structured_meeting, project:, author: current_user) } let!(:other_project) { create(:project) }