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
add project status to project settings page
ulferts573367929153
diff --git a/app/contracts/projects/base_contract.rb b/app/contracts/projects/base_contract.rbindex 1b1145e1684..26e3a9e16ba 100644--- a/app/contracts/projects/base_contract.rb+++ b/app/contracts/projects/base_contract.rb@@ -71,6 +71,10 @@ module Projectsmodel.assignable_versionsend+ def assignable_status_codes+ Project::Status.codes.keys+ end+privatedef validate_parent_assignablediff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rbindex 2cb5d8df28e..452b9bf171b 100644--- a/app/helpers/projects_helper.rb+++ b/app/helpers/projects_helper.rb@@ -207,6 +207,21 @@ module ProjectsHelperendend+ def project_options_for_status(project)+ contract = if project.new_record?+ Projects::CreateContract+ else+ Projects::UpdateContract+ end++ contract+ .new(project, current_user)+ .assignable_status_codes+ .map do |code|+ [I18n.t("activerecord.attributes.project/status.codes.#{code}"), code]+ end+ end+def shorten_text(text, length)text.to_s.gsub(/\A(.{#{length}[^\n\r]*).*\z/m, '\1...').stripenddiff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex 828bbd4e470..d32e6abb519 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -162,19 +162,6 @@ class PermittedParamspend- def calendar_filter- keys = Query.registered_filters.map(&:key)- op_keys = keys_whitelisted_by_list(params["op"], keys)- v_keys = keys_whitelisted_by_list(params["v"], keys).map { |f| { f => [] } }-- params.permit(:project_id,- :month,- :year,- f: [],- op: op_keys,- v: v_keys)- end-def roleparams.require(:role).permit(*self.class.permitted_attributes[:role])end@@ -299,11 +286,16 @@ class PermittedParams:identifier,:project_type_id,:parent_id,+ status: %i(code explanation),custom_fields: [],work_package_custom_field_ids: [],type_ids: [],enabled_module_names: [])+ if whitelist[:status] && whitelist[:status][:code] && whitelist[:status][:code].blank?+ whitelist[:status][:code] = nil+ end+whitelist.merge(custom_field_values(:project))enddiff --git a/app/views/customizable/_form.html.erb b/app/views/customizable/_form.html.erbindex 2fba4bd6566..a7a76b01e45 100644--- a/app/views/customizable/_form.html.erb+++ b/app/views/customizable/_form.html.erb@@ -32,11 +32,11 @@ See docs/COPYRIGHT.rdoc for more details.<% form.object.custom_field_values.each do |value| %><%= form.fields_for_custom_fields :custom_field_values, value do |value_form| %><% required = value.custom_field.is_required? %>- <div class="form--field custom_field_<%= value.custom_field.id %> <%= required ? '-required' : '' %>">- <%# display all fields OR only display required fields OR only display optional fields #%>- <% if all_fields || (only_required && required) || (!only_required && !required) %>+ <%# display all fields OR only display required fields OR only display optional fields #%>+ <% if all_fields || (only_required && required) || (!only_required && !required) %>+ <div class="form--field custom_field_<%= value.custom_field.id %> <%= required ? '-required' : '' %>"><%= value_form.custom_field(container_class: '-wide', required: required) %>- <% end %>- </div>+ </div>+ <% end %><% end %><% end %>diff --git a/app/views/projects/form/_project_attributes.html.erb b/app/views/projects/form/_project_attributes.html.erbindex db989b7d7f2..5d212d24a29 100644--- a/app/views/projects/form/_project_attributes.html.erb+++ b/app/views/projects/form/_project_attributes.html.erb@@ -48,6 +48,8 @@ See docs/COPYRIGHT.rdoc for more details.locals: { form: form } %><%= render partial: "projects/form/attributes/public",locals: { form: form } %>+ <%= render partial: "projects/form/attributes/status",+ locals: { form: form } %><% unless all_fields %><%= render partial: "customizable/form",locals: { form: form, all_fields: false, only_required: false } %>diff --git a/app/views/projects/form/attributes/_status.html.erb b/app/views/projects/form/attributes/_status.html.erbnew file mode 100644index 00000000000..87c781c720f--- /dev/null+++ b/app/views/projects/form/attributes/_status.html.erb@@ -0,0 +1,48 @@+<%#-- copyright+OpenProject is a project management system.+Copyright (C) 2012-2018 the OpenProject Foundation (OPF)++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-2017 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.++++#%>++<%+ project = form.object+ project.build_status unless project.status+%>++<%= form.fields_for :status, project.status do |status_form| %>+ <div class="form--field">+ <%= status_form.select :code,+ project_options_for_status(project),+ include_blank: true,+ container_class: '-wide' %>+ </div>+ <div class="form--field">+ <%= status_form.text_area :explanation,+ with_text_formatting: true,+ preview_context: project_preview_context(project.status, project),+ container_class: '-xxwide' %>+ </div>+<% end %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex f7725863d84..96452d56e68 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -397,6 +397,13 @@ en:types: "Types"versions: "Versions"work_packages: "Work Packages"+ project/status:+ code: 'Status'+ explanation: 'Status description'+ codes:+ on_track: 'On track'+ at_risk: 'At risk'+ off_track: 'Off track'query:column_names: "Columns"relations_to_type_column: "Relations to %{type}"diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rbindex ce3d1a6bbe0..a258467e6a7 100644--- a/lib/api/v3/projects/project_representer.rb+++ b/lib/api/v3/projects/project_representer.rb@@ -166,8 +166,12 @@ module APIsetter: ->(fragment:, **) {status = fragment.with_indifferent_access.slice(:explanation)- if fragment['code']- status[:code] = fragment['code'].strip.tr(' ', '_').underscore.to_sym+ if fragment.key?('code')+ status[:code] = if fragment['code'].nil?+ nil+ else+ fragment['code'].strip.tr(' ', '_').underscore.to_sym+ endendrepresented.status = statusdiff --git a/spec/features/projects/project_status_administration_spec.rb b/spec/features/projects/project_status_administration_spec.rbnew file mode 100644index 00000000000..a0c90d3b64d--- /dev/null+++ b/spec/features/projects/project_status_administration_spec.rb@@ -0,0 +1,98 @@+#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# 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-2017 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'++describe 'Projects status administration', type: :feature, js: true do+ let(:current_user) do+ FactoryBot.create(:user).tap do |user|+ FactoryBot.create(:principal_role,+ principal: user,+ role: FactoryBot.create(:global_role, permissions: global_permissions))+ end+ end+ let(:global_permissions) { [:add_project] }+ let(:project_permissions) { [:edit_project] }+ let!(:project_role) do+ FactoryBot.create(:role, permissions: project_permissions).tap do |r|+ allow(Setting)+ .to receive(:new_project_user_role_id)+ .and_return(r.id.to_s)+ end+ end+ let(:create_status_description) { Components::WysiwygEditor.new('.form--field:nth-of-type(5)') }+ let(:edit_status_description) { Components::WysiwygEditor.new('.form--field:nth-of-type(6)') }++ before do+ login_as current_user+ end++ it 'allows setting the status on project creation' do+ visit new_project_path++ # Create the project with status+ click_link 'Advanced settings'++ fill_in 'Name', with: 'New project'+ select 'On track', from: 'Status'+ create_status_description.set_markdown 'Everything is fine at the start'++ click_button 'Create'++ expect(page)+ .to have_content('Successful creation.')++ # Check that the status has been set correctly+ visit settings_project_path(Project.last)++ expect(page)+ .to have_select('Status', selected: 'On track')++ edit_status_description.expect_value 'Everything is fine at the start'++ select '', from: 'Status'+ edit_status_description.set_markdown 'Now we do not know'++ click_button 'Save'++ expect(page)+ .to have_select('Status', selected: '')++ edit_status_description.expect_value 'Now we do not know'++ select 'Off track', from: 'Status'+ edit_status_description.set_markdown 'Oh no'++ click_button 'Save'++ expect(page)+ .to have_select('Status', selected: 'Off track')++ edit_status_description.expect_value 'Oh no'+ end+enddiff --git a/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb b/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rbindex e1edc112b52..a2f538ff7c7 100644--- a/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb+++ b/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb@@ -93,7 +93,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do}end- it 'does not set code' do+ it 'does set code' doproject = representer.from_hash(hash)expect(project.status[:code]).to eql :off_track@@ -105,6 +105,29 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do.to be_nilendend++ context 'with null for a scope' do+ let(:hash) do+ {+ "status" => {+ "code" => nil+ }+ }+ end++ it 'does set code to nil' do+ project = representer.from_hash(hash).to_h++ expect(project)+ .to be_key(:status)++ expect(project[:status])+ .to be_key(:code)++ expect(project[:status][:code])+ .to eql nil+ end+ endendendenddiff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rbindex 3fcde75aa61..95be056b30f 100644--- a/spec/models/permitted_params_spec.rb+++ b/spec/models/permitted_params_spec.rb@@ -990,47 +990,6 @@ describe PermittedParams, type: :model doendend- describe 'calendar_filter' do- let(:attribute) { :calendar_filter }- let(:flat) { true }-- describe 'project_id' do- let(:hash) { { 'project_id' => 'some_identifier' } }-- it_behaves_like 'allows params'- end-- describe 'f' do- let(:hash) { { 'f' => ['assigned_to_id', 'subject'] } }-- it_behaves_like 'allows params'- end-- describe 'op' do- let(:hash) { { 'op' => { 'assigned_to_id' => '=', 'subject' => '~', 'cf_0815' => '=' } } }-- it_behaves_like 'allows params'- end-- describe 'v' do- let(:hash) { { 'v' => { 'assigned_to_id' => ['1'], 'subject' => ['blubs'], 'cf_0815' => ['a', 'b', 'c'] } } }-- it_behaves_like 'allows params'- end-- describe 'month' do- let(:hash) { { 'month' => '3' } }-- it_behaves_like 'allows params'- end-- describe 'year' do- let(:hash) { { 'year' => '3' } }-- it_behaves_like 'allows params'- end- end-describe '.add_permitted_attributes' dobefore do@original_permitted_attributes = PermittedParams.permitted_attributes.clone