From 81e45a2a9dc46fca7a4243fb2b21fb2b1e8e37a1 Mon Sep 17 00:00:00 2001 From: ulferts Date: Fri, 29 Oct 2021 09:08:24 +0200 Subject: [PATCH] move time entry activities to nested settings --- .../project_settings/activities_controller.rb | 37 ---------- app/helpers/project_settings_helper.rb | 4 +- .../form/_project_attributes.html.erb | 70 ------------------- .../projects/form/_select_template.html.erb | 39 ----------- config/routes.rb | 6 +- .../time_entry_activities_controller.rb | 7 +- .../_activities.html.erb | 8 +-- .../time_entry_activities/show.html.erb | 6 +- modules/costs/lib/costs/engine.rb | 2 +- .../spec/features/time_entry/activity_spec.rb | 18 +++++ spec/routing/project_settings_routing_spec.rb | 4 +- .../projects/time_entry_activities_spec.rb | 38 ---------- 12 files changed, 34 insertions(+), 205 deletions(-) delete mode 100644 app/controllers/project_settings/activities_controller.rb delete mode 100644 app/views/projects/form/_project_attributes.html.erb delete mode 100644 app/views/projects/form/_select_template.html.erb rename modules/costs/app/controllers/projects/{ => settings}/time_entry_activities_controller.rb (89%) rename {app/views/projects/form => modules/costs/app/views/projects/settings/time_entry_activities}/_activities.html.erb (90%) rename app/views/project_settings/activities.html.erb => modules/costs/app/views/projects/settings/time_entry_activities/show.html.erb (86%) delete mode 100644 spec/routing/projects/time_entry_activities_spec.rb diff --git a/app/controllers/project_settings/activities_controller.rb b/app/controllers/project_settings/activities_controller.rb deleted file mode 100644 index 7efce9b8cf..0000000000 --- a/app/controllers/project_settings/activities_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -#-- 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 COPYRIGHT and LICENSE files for more details. -#++ - -class ProjectSettings::ActivitiesController < ProjectSettingsController - menu_item :settings_activities - - def show - render template: 'project_settings/activities' - end -end diff --git a/app/helpers/project_settings_helper.rb b/app/helpers/project_settings_helper.rb index 88a9ccbe1c..178b3ec188 100644 --- a/app/helpers/project_settings_helper.rb +++ b/app/helpers/project_settings_helper.rb @@ -69,8 +69,8 @@ module ProjectSettingsHelper label: :label_repository }, { - name: 'activities', - action: { controller: '/project_settings/activities', action: 'show' }, + name: 'time_entry_activities', + action: { controller: '/projects/settings/time_entry_activities', action: 'show' }, label: :enumeration_activities }, { diff --git a/app/views/projects/form/_project_attributes.html.erb b/app/views/projects/form/_project_attributes.html.erb deleted file mode 100644 index 085655b19d..0000000000 --- a/app/views/projects/form/_project_attributes.html.erb +++ /dev/null @@ -1,70 +0,0 @@ -<%#-- 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 COPYRIGHT and LICENSE files for more details. - -++#%> -<% all_fields = (render_advanced) ? false : true %> - -<%= render partial: "projects/form/attributes/name", - locals: { form: form } %> - -<% if project.new_record? && !is_copy %> - <%= render partial: "projects/form/select_template", - locals: { project: project, form: form } %> -<% end %> - -<%= render partial: "customizable/form", - locals: { form: form, help_text: { 'attribute-scope': :Project }, all_fields: all_fields, only_required: render_advanced } %> -<% if render_advanced %> - -<% end %> - -<% unless form.object.errors[:identifier].blank? %> - <%= nonced_javascript_tag do %> - jQuery('#advanced-project-settings > .advanced-settings-inner').show(); - <% end %> -<% end %> diff --git a/app/views/projects/form/_select_template.html.erb b/app/views/projects/form/_select_template.html.erb deleted file mode 100644 index ada2d0d9d8..0000000000 --- a/app/views/projects/form/_select_template.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -<%#-- 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 COPYRIGHT and LICENSE files for more details. - -++#%> - -
- <%= styled_label_tag 'from_template', t('project.template.use_template') %> -
- <%= styled_select_tag :from_template, - options_for_select(project_options_for_templated, @template_project&.id), - id: 'project-select-template', - prompt: "(#{t(:label_none)})", - container_class: '-wide' %> -
-
diff --git a/config/routes.rb b/config/routes.rb index fb7392a7b2..26e634cc84 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -184,7 +184,7 @@ OpenProject::Application.routes.draw do namespace 'settings' do ProjectSettingsHelper .project_settings_tabs - .select { |s| %w[modules general types custom_fields versions categories repository].include?(s[:name]) } + .select { |s| %w[modules general types custom_fields versions categories repository time_entry_activities].include?(s[:name]) } .each do |tab| get tab[:name], controller: tab[:name], @@ -198,7 +198,7 @@ OpenProject::Application.routes.draw do ProjectSettingsHelper .project_settings_tabs - .reject { |s| %w[modules general types custom_fields versions categories repository].include?(s[:name]) } + .reject { |s| %w[modules general types custom_fields versions categories repository time_entry_activities].include?(s[:name]) } .each do |tab| get "settings/#{tab[:name]}", controller: "project_settings/#{tab[:name]}", @@ -228,8 +228,6 @@ OpenProject::Application.routes.draw do get :level_list end - resource :time_entry_activities, controller: 'projects/time_entry_activities', only: %i[update] - resources :versions, only: %i[new create] do collection do put :close_completed diff --git a/modules/costs/app/controllers/projects/time_entry_activities_controller.rb b/modules/costs/app/controllers/projects/settings/time_entry_activities_controller.rb similarity index 89% rename from modules/costs/app/controllers/projects/time_entry_activities_controller.rb rename to modules/costs/app/controllers/projects/settings/time_entry_activities_controller.rb index 0829fc80c2..e9c536e15c 100644 --- a/modules/costs/app/controllers/projects/time_entry_activities_controller.rb +++ b/modules/costs/app/controllers/projects/settings/time_entry_activities_controller.rb @@ -28,15 +28,14 @@ # See COPYRIGHT and LICENSE files for more details. #++ -class Projects::TimeEntryActivitiesController < ApplicationController - before_action :find_project_by_project_id - before_action :authorize +class Projects::Settings::TimeEntryActivitiesController < ProjectSettingsController + menu_item :settings_time_entry_activities def update TimeEntryActivitiesProject.upsert_all(update_params, unique_by: %i[project_id activity_id]) flash[:notice] = t(:notice_successful_update) - redirect_to settings_activities_project_path(@project) + redirect_to time_entry_activities_settings_project_path(@project) end private diff --git a/app/views/projects/form/_activities.html.erb b/modules/costs/app/views/projects/settings/time_entry_activities/_activities.html.erb similarity index 90% rename from app/views/projects/form/_activities.html.erb rename to modules/costs/app/views/projects/settings/time_entry_activities/_activities.html.erb index c2a4dac662..e78b5b392f 100644 --- a/app/views/projects/form/_activities.html.erb +++ b/modules/costs/app/views/projects/settings/time_entry_activities/_activities.html.erb @@ -44,8 +44,6 @@ See COPYRIGHT and LICENSE files for more details. <% end %> -<% if withControlls == true %> -
- <%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %> -
-<% end %> +
+ <%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %> +
diff --git a/app/views/project_settings/activities.html.erb b/modules/costs/app/views/projects/settings/time_entry_activities/show.html.erb similarity index 86% rename from app/views/project_settings/activities.html.erb rename to modules/costs/app/views/projects/settings/time_entry_activities/show.html.erb index a040a4d939..49b169e480 100644 --- a/app/views/project_settings/activities.html.erb +++ b/modules/costs/app/views/projects/settings/time_entry_activities/show.html.erb @@ -32,10 +32,10 @@ See COPYRIGHT and LICENSE files for more details. <% if TimeEntryActivity.any? %> <%= labelled_tabular_form_for @project, - url: project_time_entry_activities_path(@project), - method: :put do %> + url: time_entry_activities_settings_project_path(@project) do %> - <%= render partial: 'projects/form/activities', locals: { project: @project, withControlls: true } %> + <%= render partial: '/projects/settings/time_entry_activities/activities', + locals: { project: @project } %> <% end %>
diff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rb index 8bec7e61bf..e4d62577e0 100644 --- a/modules/costs/lib/costs/engine.rb +++ b/modules/costs/lib/costs/engine.rb @@ -60,7 +60,7 @@ module Costs require: :loggedin permission :manage_project_activities, - { 'projects/time_entry_activities': %i[update] }, + { 'projects/settings/time_entry_activities': %i[show update] }, require: :member permission :view_own_hourly_rate, {} permission :view_hourly_rates, {} diff --git a/modules/costs/spec/features/time_entry/activity_spec.rb b/modules/costs/spec/features/time_entry/activity_spec.rb index 94c33afd79..1734376a5c 100644 --- a/modules/costs/spec/features/time_entry/activity_spec.rb +++ b/modules/costs/spec/features/time_entry/activity_spec.rb @@ -30,6 +30,7 @@ require 'spec_helper' describe 'Time entry activity', type: :feature do shared_let(:admin) { FactoryBot.create :admin } + let(:project) { FactoryBot.create(:project) } before do login_as(admin) @@ -48,5 +49,22 @@ describe 'Time entry activity', type: :feature do expect(page) .to have_content('A new activity') + + visit general_settings_project_path(project) + + click_on "Time tracking activities" + + expect(page) + .to have_field('A new activity', checked: true) + + uncheck 'A new activity' + + click_on 'Save' + + expect(page) + .to have_content "Successful update." + + expect(page) + .to have_field('A new activity', checked: false) end end diff --git a/spec/routing/project_settings_routing_spec.rb b/spec/routing/project_settings_routing_spec.rb index a3c8a412e8..09925901bf 100644 --- a/spec/routing/project_settings_routing_spec.rb +++ b/spec/routing/project_settings_routing_spec.rb @@ -87,9 +87,9 @@ describe ProjectSettingsController, type: :routing do end it do - expect(get('/projects/123/settings/activities')) + expect(get('/projects/123/settings/time_entry_activities')) .to route_to( - controller: 'project_settings/activities', action: 'show', id: '123' + controller: 'projects/settings/time_entry_activities', action: 'show', id: '123' ) end diff --git a/spec/routing/projects/time_entry_activities_spec.rb b/spec/routing/projects/time_entry_activities_spec.rb deleted file mode 100644 index 263e864c09..0000000000 --- a/spec/routing/projects/time_entry_activities_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -#-- 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 COPYRIGHT and LICENSE files for more details. -#++ - -require 'spec_helper' - -describe 'project/time_entry_activities routes', type: :routing do - describe 'update' do - it 'links PUT /projects/:project_id/time_entry_activities' do - expect(put('/projects/64/time_entry_activities')) - .to route_to('projects/time_entry_activities#update', project_id: '64') - end - end -end