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

implement project status updating

ulfertsfbb6c9dc8f06
diff --git a/app/services/projects/set_attributes_service.rb b/app/services/projects/set_attributes_service.rb
index 1d3ab77f052..f462098a567 100644
--- a/app/services/projects/set_attributes_service.rb
+++ b/app/services/projects/set_attributes_service.rb
@@ -99,7 +99,7 @@ module Projects
end
def faulty_code?(attributes)
- attributes && attributes[:code] && !Project::Status.codes.keys.include?(attributes[:code])
+ attributes && attributes[:code] && !Project::Status.codes.keys.include?(attributes[:code].to_s)
end
def first_not_set_code
diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb
index ac4afbd4574..b2e942ab381 100644
--- a/app/services/projects/update_service.rb
+++ b/app/services/projects/update_service.rb
@@ -49,6 +49,7 @@ module Projects
notify_on_identifier_renamed
send_update_notification
update_wp_versions_on_parent_change
+ persist_status
service_call
end
@@ -76,5 +77,9 @@ module Projects
WorkPackage.update_versions_from_hierarchy_change(model)
end
+
+ def persist_status
+ model.status.save if model.status.changed?
+ end
end
end
diff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rb
index 65df801d30a..954e50deca6 100644
--- a/spec/requests/api/v3/project_resource_spec.rb
+++ b/spec/requests/api/v3/project_resource_spec.rb
@@ -484,7 +484,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
end
end
- context 'without permission to create projects' do
+ context 'without permission to patch projects' do
let(:permissions) { [] }
it 'responds with 403' do
@@ -499,7 +499,43 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
end
end
- context 'with faulty params' do
+ context 'with a status' do
+ let(:body) do
+ {
+ status: {
+ "code": "off track",
+ "explanation": "Some explanation."
+ }
+ }
+ end
+
+ it 'alters the status' do
+ expect(last_response.body)
+ .to be_json_eql(
+ {
+ "code": "off track",
+ "explanation": {
+ "format": "markdown",
+ "html": "<p>Some explanation.</p>",
+ "raw": "Some explanation."
+ }
+ }.to_json
+ )
+ .at_path("status")
+ end
+
+ it 'persists the altered status' do
+ project_status.reload
+
+ expect(project_status.code)
+ .to eql('off_track')
+
+ expect(project_status.explanation)
+ .to eql('Some explanation.')
+ end
+ end
+
+ context 'with faulty name' do
let(:body) do
{
name: nil
@@ -527,6 +563,37 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
.at_path('message')
end
end
+
+ context 'with a faulty status' do
+ let(:body) do
+ {
+ status: {
+ "code": "bogus"
+ }
+ }
+ end
+
+ it 'responds with 422' do
+ expect(last_response.status).to eq(422)
+ end
+
+ it 'does not change the project status' do
+ code_before = project_status.code
+
+ expect(project_status.reload.code)
+ .to eql(code_before)
+ end
+
+ it 'denotes the error' do
+ expect(last_response.body)
+ .to be_json_eql('Error'.to_json)
+ .at_path('_type')
+
+ expect(last_response.body)
+ .to be_json_eql("Status is not set to one of the allowed values.".to_json)
+ .at_path('message')
+ end
+ end
end
describe '#delete /api/v3/projects/:id' do
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index c5e97a89a97..29a130b8c45 100644
--- a/spec/services/projects/update_service_spec.rb
+++ b/spec/services/projects/update_service_spec.rb
@@ -54,12 +54,17 @@ describe Projects::UpdateService, type: :model do
errors: set_attributes_errors
end
let!(:project) do
- FactoryBot.build_stubbed(:project).tap do |p|
+ FactoryBot.build_stubbed(:project, status: project_status).tap do |p|
allow(p)
.to receive(:save)
.and_return(project_valid)
+
+ project_status.clear_changes_information
end
end
+ let(:project_status) do
+ FactoryBot.build_stubbed(:project_status)
+ end
let!(:set_attributes_service) do
service = double('set_attributes_service_instance')
@@ -145,6 +150,21 @@ describe Projects::UpdateService, type: :model do
end
end
+ context 'if the project status is altered' do
+ before do
+ allow(project_status)
+ .to receive(:changed?)
+ .and_return(true)
+ end
+
+ it 'persists the changes' do
+ expect(project_status)
+ .to receive(:save)
+
+ subject
+ end
+ end
+
context 'if the SetAttributeService is unsuccessful' do
let(:set_attributes_success) { false }