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
Replace meetings update with services
Oliver Güntherabec97e1e408
diff --git a/modules/meeting/app/contracts/meeting_contents/base_contract.rb b/modules/meeting/app/contracts/meeting_contents/base_contract.rbnew file mode 100644index 00000000000..ed749bf2624--- /dev/null+++ b/modules/meeting/app/contracts/meeting_contents/base_contract.rb@@ -0,0 +1,55 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module MeetingContents+ class BaseContract < ::ModelContract+ include Attachments::ValidateReplacements++ def self.model+ MeetingContent+ end++ attribute :meeting+ attribute :text+ attribute :lock_version+ attribute :locked+ attribute :type++ validate :type_in_allowed++ private++ def type_in_allowed+ unless [MeetingAgenda.name, MeetingMinutes.name].include?(model.type)+ errors.add(:type, :inclusion)+ end+ end+ end+enddiff --git a/modules/meeting/app/contracts/meeting_contents/update_contract.rb b/modules/meeting/app/contracts/meeting_contents/update_contract.rbnew file mode 100644index 00000000000..605d58ff160--- /dev/null+++ b/modules/meeting/app/contracts/meeting_contents/update_contract.rb@@ -0,0 +1,43 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module MeetingContents+ class UpdateContract < BaseContract+ validate :validate_editable++ private++ def validate_editable+ unless model.editable?+ errors.add :base, :error_readonly+ end+ end+ end+enddiff --git a/modules/meeting/app/controllers/meeting_contents_controller.rb b/modules/meeting/app/controllers/meeting_contents_controller.rbindex dd89619493a..9ff36aca032 100644--- a/modules/meeting/app/controllers/meeting_contents_controller.rb+++ b/modules/meeting/app/controllers/meeting_contents_controller.rb@@ -27,6 +27,7 @@#++class MeetingContentsController < ApplicationController+ include AttachableServiceCallinclude PaginationHelpermenu_item :meetings@@ -60,26 +61,26 @@ class MeetingContentsController < ApplicationControllerenddef update- (render_403; return) unless @content.editable? # TODO: not tested!- @content.attributes = content_params.merge(author: User.current)- @content.attach_files(permitted_params.attachments.to_h)-- if [email protected]_version_changed?- if @content.save- flash[:notice] = I18n.t(:notice_successful_update)- redirect_back_or_default controller: '/meetings', action: 'show', id: @meeting- end+ call = attachable_update_call ::MeetingContents::UpdateService,+ model: @content,+ args: content_params++ if call.success?+ flash[:notice] = I18n.t(:notice_successful_update)+ redirect_back_or_default controller: '/meetings', action: 'show', id: @meetingelse- render_conflict+ flash.now[:error] = call.message+ params[:tab] ||= 'minutes' if @meeting.agenda.present? && @meeting.agenda.locked?+ render 'meetings/show'endenddef history# don't load text@content_versions = @content.journals.select('id, user_id, notes, created_at, version')- .order(Arel.sql('version DESC'))- .page(page_param)- .per_page(per_page_param)+ .order(Arel.sql('version DESC'))+ .page(page_param)+ .per_page(per_page_param)render 'meeting_contents/history', layout: !request.xhr?end@@ -129,19 +130,13 @@ class MeetingContentsController < ApplicationControllerdef find_meeting@meeting = Meeting.includes(:project, :author, :participants, :agenda, :minutes)- .find(params[:meeting_id])+ .find(params[:meeting_id])@project = @meeting.project@author = User.currentrescue ActiveRecord::RecordNotFoundrender_404end- def render_conflict- flash.now[:error] = I18n.t(:notice_locking_conflict)- params[:tab] ||= 'minutes' if @meeting.agenda.present? && @meeting.agenda.locked?- render 'meetings/show'- end-def content_paramsparams.require(@content_type).permit(:text, :lock_version, :comment)enddiff --git a/modules/meeting/app/services/meeting_contents/set_attributes_service.rb b/modules/meeting/app/services/meeting_contents/set_attributes_service.rbnew file mode 100644index 00000000000..321ea665fda--- /dev/null+++ b/modules/meeting/app/services/meeting_contents/set_attributes_service.rb@@ -0,0 +1,42 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module MeetingContents+ class SetAttributesService < ::BaseServices::SetAttributes+ include Attachments::SetReplacements+++ def set_default_attributes(_params)+ model.change_by_system do+ model.author = user if model.author.nil?+ end+ end+ end+enddiff --git a/modules/meeting/app/services/meeting_contents/update_service.rb b/modules/meeting/app/services/meeting_contents/update_service.rbnew file mode 100644index 00000000000..8eb13957337--- /dev/null+++ b/modules/meeting/app/services/meeting_contents/update_service.rb@@ -0,0 +1,47 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module MeetingContents+ class UpdateService < ::BaseServices::Update+ include Attachments::ReplaceAttachments++ def persist(call)+ content = call.result++ if content.lock_version_changed?+ call.errors.add(:base, I18n.t(:notice_locking_conflict))+ call.success = false+ return call+ end++ super+ end+ end+enddiff --git a/modules/meeting/spec/contracts/meeting_contents/update_contract_spec.rb b/modules/meeting/spec/contracts/meeting_contents/update_contract_spec.rbnew file mode 100644index 00000000000..3ebddead893--- /dev/null+++ b/modules/meeting/spec/contracts/meeting_contents/update_contract_spec.rb@@ -0,0 +1,55 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'+require 'contracts/shared/model_contract_shared_context'++describe MeetingContents::UpdateContract do+ include_context 'ModelContract shared context'+ let(:agenda) { FactoryBot.build_stubbed(:meeting_agenda) }+ let(:current_user) { FactoryBot.build_stubbed(:user) }+ let(:contract) { described_class.new(agenda, current_user) }++ context 'when not editable' do+ before do+ allow(agenda).to receive(:editable?).and_return false+ end++ it_behaves_like 'contract is invalid', base: :error_readonly+ end++ context 'when editable' do+ before do+ allow(agenda).to receive(:editable?).and_return true+ end++ it_behaves_like 'contract is valid'+ end+enddiff --git a/modules/meeting/spec/services/meeting_contents/update_service_spec.rb b/modules/meeting/spec/services/meeting_contents/update_service_spec.rbnew file mode 100644index 00000000000..11dc41cc59d--- /dev/null+++ b/modules/meeting/spec/services/meeting_contents/update_service_spec.rb@@ -0,0 +1,38 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'+require 'services/base_services/behaves_like_update_service'++describe MeetingContents::UpdateService, type: :model do+ it_behaves_like 'BaseServices update service' do+ let(:factory) { :meeting_agenda }+ end+end