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
user update service for update identifier action
ulfertsfc0e5bdfd213
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex f5fdebb7243..c535f692341 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -117,12 +117,14 @@ class ProjectsController < ApplicationControllerenddef update_identifier- @project.attributes = permitted_params.project+ service_call = Projects::UpdateService+ .new(user: current_user,+ model: @project)+ .call(permitted_params.project)- if @project.save+ if service_call.success?flash[:notice] = I18n.t(:notice_successful_update)redirect_to settings_project_path(@project)- OpenProject::Notifications.send('project_renamed', project: @project)elserender action: 'identifier'enddiff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rbindex 88f67a2048a..f48ffab1c38 100644--- a/app/services/projects/update_service.rb+++ b/app/services/projects/update_service.rb@@ -33,9 +33,20 @@ module Projectsprivatedef after_save+ touch_on_custom_values_update+ notify_on_identifier_renamed+ end++ def touch_on_custom_values_updatemodel.touch if only_custom_values_updated?end+ def notify_on_identifier_renamed+ return unless model.saved_change_to_identifier?++ OpenProject::Notifications.send('project_renamed', project: model)+ end+def only_custom_values_updated?!model.saved_changes? && model.custom_values.any?(&:saved_changes?)enddiff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rbindex 0b74856082d..b1694e32f05 100644--- a/spec/services/projects/update_service_spec.rb+++ b/spec/services/projects/update_service_spec.rb@@ -100,7 +100,25 @@ describe Projects::UpdateService, type: :model do.to eql projectend- context 'when the SetAttributeService is unsuccessful' do+ context 'if the identifier is altered' do+ let(:call_attributes) { { identifier: 'Some identifier' } }++ before do+ allow(project)+ .to receive(:saved_change_to_identifier?)+ .and_return(true)+ end++ it 'sends the notification' do+ expect(OpenProject::Notifications)+ .to receive(:send)+ .with('project_renamed', project: project)++ subject+ end+ end++ context 'if the SetAttributeService is unsuccessful' dolet(:set_attributes_success) { false }it 'is unsuccessful' do@@ -126,7 +144,7 @@ describe Projects::UpdateService, type: :model doendend- context 'when the project is invalid' do+ context 'if the project is invalid' dolet(:project_valid) { false }it 'is unsuccessful' do