Skip to content

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

user update service for update identifier action

ulfertsfc0e5bdfd213
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index f5fdebb7243..c535f692341 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -117,12 +117,14 @@ class ProjectsController < ApplicationController
end
def 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)
else
render action: 'identifier'
end
diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb
index 88f67a2048a..f48ffab1c38 100644
--- a/app/services/projects/update_service.rb
+++ b/app/services/projects/update_service.rb
@@ -33,9 +33,20 @@ module Projects
private
def after_save
+ touch_on_custom_values_update
+ notify_on_identifier_renamed
+ end
+
+ def touch_on_custom_values_update
model.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?)
end
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index 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 project
end
- 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' do
let(:set_attributes_success) { false }
it 'is unsuccessful' do
@@ -126,7 +144,7 @@ describe Projects::UpdateService, type: :model do
end
end
- context 'when the project is invalid' do
+ context 'if the project is invalid' do
let(:project_valid) { false }
it 'is unsuccessful' do