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

adjust urls and permissions

Bruno Pagnoc5a5d5260b31
diff --git a/app/components/settings/project_work_packages/header_component.html.erb b/app/components/settings/project_work_packages/header_component.html.erb
index ac9cce34495..bce39e7a1b4 100644
--- a/app/components/settings/project_work_packages/header_component.html.erb
+++ b/app/components/settings/project_work_packages/header_component.html.erb
@@ -32,17 +32,17 @@ See COPYRIGHT and LICENSE files for more details.
header.with_breadcrumbs(breadcrumbs_items)
header.with_tab_nav(label: nil) do |tab_nav|
if show_types?
- tab_nav.with_tab(selected: selected?(:types), href: project_settings_types_path) do |tab|
+ tab_nav.with_tab(selected: selected?(:types), href: project_settings_work_packages_types_path) do |tab|
tab.with_text { t("settings.work_packages.types_tab") }
end
end
if show_categories?
- tab_nav.with_tab(selected: selected?(:categories), href: project_settings_categories_path) do |tab|
+ tab_nav.with_tab(selected: selected?(:categories), href: project_settings_work_packages_categories_path) do |tab|
tab.with_text { t("settings.work_packages.categories_tab") }
end
end
if show_custom_fields?
- tab_nav.with_tab(selected: selected?(:custom_fields), href: project_settings_custom_fields_path) do |tab|
+ tab_nav.with_tab(selected: selected?(:custom_fields), href: project_settings_work_packages_custom_fields_path) do |tab|
tab.with_text { t("settings.work_packages.custom_fields_tab") }
end
end
diff --git a/app/controllers/projects/settings/categories_controller.rb b/app/controllers/projects/settings/work_packages/categories_controller.rb
similarity index 93%
rename from app/controllers/projects/settings/categories_controller.rb
rename to app/controllers/projects/settings/work_packages/categories_controller.rb
index 7ae2f8100fc..54686d26bfc 100644
--- a/app/controllers/projects/settings/categories_controller.rb
+++ b/app/controllers/projects/settings/work_packages/categories_controller.rb
@@ -26,6 +26,6 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Projects::Settings::CategoriesController < Projects::SettingsController
+class Projects::Settings::WorkPackages::CategoriesController < Projects::SettingsController
menu_item :settings_work_packages
end
diff --git a/app/controllers/projects/settings/custom_fields_controller.rb b/app/controllers/projects/settings/work_packages/custom_fields_controller.rb
similarity index 95%
rename from app/controllers/projects/settings/custom_fields_controller.rb
rename to app/controllers/projects/settings/work_packages/custom_fields_controller.rb
index 91f652d6725..018d26c80fb 100644
--- a/app/controllers/projects/settings/custom_fields_controller.rb
+++ b/app/controllers/projects/settings/work_packages/custom_fields_controller.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Projects::Settings::CustomFieldsController < Projects::SettingsController
+class Projects::Settings::WorkPackages::CustomFieldsController < Projects::SettingsController
menu_item :settings_work_packages
def show
diff --git a/app/controllers/projects/settings/types_controller.rb b/app/controllers/projects/settings/work_packages/types_controller.rb
similarity index 95%
rename from app/controllers/projects/settings/types_controller.rb
rename to app/controllers/projects/settings/work_packages/types_controller.rb
index 7f4f115e666..6df0f8d0292 100644
--- a/app/controllers/projects/settings/types_controller.rb
+++ b/app/controllers/projects/settings/work_packages/types_controller.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Projects::Settings::TypesController < Projects::SettingsController
+class Projects::Settings::WorkPackages::TypesController < Projects::SettingsController
menu_item :settings_work_packages
def show
diff --git a/app/controllers/projects/settings/work_packages_controller.rb b/app/controllers/projects/settings/work_packages_controller.rb
index 921ad5166b6..69ef4f49f6c 100644
--- a/app/controllers/projects/settings/work_packages_controller.rb
+++ b/app/controllers/projects/settings/work_packages_controller.rb
@@ -33,11 +33,11 @@ class Projects::Settings::WorkPackagesController < Projects::SettingsController
def show
if User.current.allowed_in_project?(:manage_types, @project)
- redirect_to project_settings_types_path
+ redirect_to project_settings_work_packages_types_path
elsif User.current.allowed_in_project?(:manage_categories, @project)
- redirect_to project_settings_categories_path
+ redirect_to project_settings_work_packages_categories_path
elsif User.current.allowed_in_project?(:select_custom_fields, @project)
- redirect_to project_settings_custom_fields_path
+ redirect_to project_settings_work_packages_custom_fields_path
end
end
end
diff --git a/app/views/projects/settings/categories/show.html.erb b/app/views/projects/settings/work_packages/categories/show.html.erb
similarity index 100%
rename from app/views/projects/settings/categories/show.html.erb
rename to app/views/projects/settings/work_packages/categories/show.html.erb
diff --git a/app/views/projects/settings/custom_fields/_form.html.erb b/app/views/projects/settings/work_packages/custom_fields/_form.html.erb
similarity index 96%
rename from app/views/projects/settings/custom_fields/_form.html.erb
rename to app/views/projects/settings/work_packages/custom_fields/_form.html.erb
index d1b19307c88..c6a5312042e 100644
--- a/app/views/projects/settings/custom_fields/_form.html.erb
+++ b/app/views/projects/settings/work_packages/custom_fields/_form.html.erb
@@ -68,7 +68,7 @@ See COPYRIGHT and LICENSE files for more details.
</thead>
<tbody>
<% all_custom_fields = @project.all_work_package_custom_fields.pluck(:id) %>
- <% work_package_custom_fields.includes(:types).each do |custom_field| %>
+ <% work_package_custom_fields.includes(:types).find_each do |custom_field| %>
<%
options = {
lang: custom_field.name_locale,
@@ -97,7 +97,7 @@ See COPYRIGHT and LICENSE files for more details.
<td>
<% if current_user.admin? %>
<% type_links = custom_field.types.map { |t| link_to(t.name, edit_tab_type_path(id: t.id, tab: "form_configuration")) } %>
- <%= safe_join type_links, ", ".html_safe %>
+ <%= safe_join type_links, ", " %>
<% else %>
<%= custom_field.types.map(&:name).join(", ") %>
<% end %>
diff --git a/app/views/projects/settings/custom_fields/show.html.erb b/app/views/projects/settings/work_packages/custom_fields/show.html.erb
similarity index 96%
rename from app/views/projects/settings/custom_fields/show.html.erb
rename to app/views/projects/settings/work_packages/custom_fields/show.html.erb
index ba793a83dcc..8ac3bc13fe4 100644
--- a/app/views/projects/settings/custom_fields/show.html.erb
+++ b/app/views/projects/settings/work_packages/custom_fields/show.html.erb
@@ -48,7 +48,7 @@ See COPYRIGHT and LICENSE files for more details.
<% if @wp_custom_fields.any? %>
<%= labelled_tabular_form_for @project,
- url: project_settings_custom_fields_path(@project),
+ url: project_settings_work_packages_custom_fields_path(@project),
html: { id: "modules-form" } do |form| %>
<%= render partial: "form",
diff --git a/app/views/projects/settings/types/_form.html.erb b/app/views/projects/settings/work_packages/types/_form.html.erb
similarity index 95%
rename from app/views/projects/settings/types/_form.html.erb
rename to app/views/projects/settings/work_packages/types/_form.html.erb
index 86aae5b6d5e..015ab9102f7 100644
--- a/app/views/projects/settings/types/_form.html.erb
+++ b/app/views/projects/settings/work_packages/types/_form.html.erb
@@ -79,11 +79,11 @@ See COPYRIGHT and LICENSE files for more details.
</thead>
<tbody>
<% projects_types_id = project.types.pluck(:id) %>
- <% Type.includes(:color).each do |type| %>
+ <% Type.includes(:color).find_each do |type| %>
<tr>
<td class='center'>
<% type_id = "project_planning_element_type_ids_#{type.id}" %>
- <%= label_tag type_id, t(".enable_type_in_project", type: type.name), class: "hidden-for-sighted" %>
+ <%= label_tag type_id, t("projects.settings.types.form.enable_type_in_project", type: type.name), class: "hidden-for-sighted" %>
<%= check_box_tag "project[type_ids][]",
type.id,
projects_types_id.include?(type.id),
diff --git a/app/views/projects/settings/types/show.html.erb b/app/views/projects/settings/work_packages/types/show.html.erb
similarity index 95%
rename from app/views/projects/settings/types/show.html.erb
rename to app/views/projects/settings/work_packages/types/show.html.erb
index 277a2212478..bcfde42c2c2 100644
--- a/app/views/projects/settings/types/show.html.erb
+++ b/app/views/projects/settings/work_packages/types/show.html.erb
@@ -31,7 +31,7 @@ See COPYRIGHT and LICENSE files for more details.
<% if Type.any? %>
<%= form_for @project,
- url: project_settings_types_path(@project),
+ url: project_settings_work_packages_types_path(@project),
method: :patch,
html: { id: "types-form" } do |f| %>
<%= render partial: "form",
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index 48114234abb..cfa5291483f 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -650,7 +650,14 @@ Redmine::MenuManager.map :project_menu do |menu|
},
project_custom_fields: { caption: :label_project_attributes_plural },
modules: { caption: :label_module_plural },
- work_packages: { caption: :label_work_package_plural },
+ work_packages: {
+ caption: :label_work_package_plural,
+ if: ->(project) {
+ User.current.allowed_in_project?(:manage_types, project) ||
+ User.current.allowed_in_project?(:manage_categories, project) ||
+ User.current.allowed_in_project?(:select_custom_fields, project)
+ }
+ },
versions: { caption: :label_version_plural },
repository: { caption: :label_repository },
time_entry_activities: { caption: :enumeration_activities },
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 090934435ba..d42e5216801 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -184,14 +184,14 @@ Rails.application.reloader.to_prepare do
map.permission :manage_types,
{
- "projects/settings/types": %i[show update]
+ "projects/settings/work_packages/types": %i[show update]
},
permissible_on: :project,
require: :member
map.permission :select_custom_fields,
{
- "projects/settings/custom_fields": %i[show update]
+ "projects/settings/work_packages/custom_fields": %i[show update]
},
permissible_on: :project,
require: :member
@@ -319,7 +319,7 @@ Rails.application.reloader.to_prepare do
# WorkPackage categories
wpt.permission :manage_categories,
{
- "projects/settings/categories": [:show],
+ "projects/settings/work_packages/categories": [:show],
categories: %i[new create edit update destroy]
},
permissible_on: :project,
diff --git a/config/routes.rb b/config/routes.rb
index 3978760b73c..9d448e89d0c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -254,7 +254,6 @@ Rails.application.routes.draw do
namespace "settings" do
resource :general, only: %i[show], controller: "general"
resource :modules, only: %i[show update]
- resource :types, only: %i[show update]
resource :project_custom_fields, only: %i[show] do
member do
post :toggle
@@ -273,12 +272,18 @@ Rails.application.routes.draw do
post :disable_all
end
end
- resource :custom_fields, only: %i[show update]
resource :repository, only: %i[show], controller: "repository"
resource :versions, only: %i[show]
- resource :categories, only: %i[show update]
resource :storage, only: %i[show], controller: "storage"
+ get :types, to: redirect("projects/%{project_id}/settings/work_packages/types")
+ get :custom_fields, to: redirect("projects/%{project_id}/settings/work_packages/custom_fields")
+ get :categories, to: redirect("projects/%{project_id}/settings/work_packages/categories")
resource :work_packages, only: %i[show]
+ namespace :work_packages do
+ resource :types, only: %i[show update]
+ resource :custom_fields, only: %i[show update]
+ resource :categories, only: %i[show update]
+ end
end
resource :templated, only: %i[create destroy], controller: "templated"
diff --git a/spec/features/projects/work_packages_settings_spec.rb b/spec/features/projects/work_packages_settings_spec.rb
index b46f37a4a48..0ae018563de 100644
--- a/spec/features/projects/work_packages_settings_spec.rb
+++ b/spec/features/projects/work_packages_settings_spec.rb
@@ -33,6 +33,7 @@ require "spec_helper"
RSpec.describe "Projects", "work packages settings menu", :js do
let!(:project) { create(:project) }
let(:work_packages_settings_page) { Pages::Projects::Settings::WorkPackages.new(project) }
+ let(:general_settings_page) { Pages::Projects::Settings::General.new(project) }
describe "view settings page" do
context "when the user has access to types tab" do
@@ -42,7 +43,7 @@ RSpec.describe "Projects", "work packages settings menu", :js do
it "displays the types tab" do
work_packages_settings_page.visit!
- expect(page).to have_css(".tabnav-tab", text: I18n.t("settings.work_packages.types_tab"))
+ expect(page).to have_css(".tabnav-tab", text: "Types")
expect(page).to have_css("#types-form")
end
end
@@ -54,8 +55,8 @@ RSpec.describe "Projects", "work packages settings menu", :js do
it "displays the categories tab" do
work_packages_settings_page.visit!
- expect(page).to have_css(".tabnav-tab", text: I18n.t("settings.work_packages.categories_tab"))
- expect(page).to have_css("span", text: I18n.t("projects.settings.categories.no_results_title_text"))
+ expect(page).to have_css(".tabnav-tab", text: "Categories")
+ expect(page).to have_css("span", text: "There are currently no work package categories.")
end
end
@@ -66,8 +67,8 @@ RSpec.describe "Projects", "work packages settings menu", :js do
it "displays the custom fields tab" do
work_packages_settings_page.visit!
- expect(page).to have_css(".tabnav-tab", text: I18n.t("settings.work_packages.custom_fields_tab"))
- expect(page).to have_css("span", text: I18n.t("projects.settings.custom_fields.no_results_title_text"))
+ expect(page).to have_css(".tabnav-tab", text: "Custom Fields")
+ expect(page).to have_css("span", text: "There are currently no custom fields available.")
end
end
@@ -76,10 +77,9 @@ RSpec.describe "Projects", "work packages settings menu", :js do
current_user { create(:user, member_with_permissions: { project => permissions }) }
- it "does not display any tabs" do
- work_packages_settings_page.visit!
- expect(page).to have_no_css(".tabnav-tab")
- expect(page).to have_css("span", text: I18n.t("settings.work_packages.not_allowed_text"))
+ it "does not display the menu entry" do
+ general_settings_page.visit!
+ expect(page).to have_no_css(".op-menu--item-title", text: "Work packages")
end
end
end
diff --git a/spec/routing/project_settings_routing_spec.rb b/spec/routing/project_settings_routing_spec.rb
index ed6e3d5d7b7..a2587c92c29 100644
--- a/spec/routing/project_settings_routing_spec.rb
+++ b/spec/routing/project_settings_routing_spec.rb
@@ -52,16 +52,16 @@ RSpec.describe Projects::SettingsController do
end
it do
- expect(get("/projects/123/settings/custom_fields"))
+ expect(get("/projects/123/settings/work_packages/custom_fields"))
.to route_to(
- controller: "projects/settings/custom_fields", action: "show", project_id: "123"
+ controller: "projects/settings/work_packages/custom_fields", action: "show", project_id: "123"
)
end
it do
- expect(patch("/projects/123/settings/custom_fields"))
+ expect(patch("/projects/123/settings/work_packages/custom_fields"))
.to route_to(
- controller: "projects/settings/custom_fields", action: "update", project_id: "123"
+ controller: "projects/settings/work_packages/custom_fields", action: "update", project_id: "123"
)
end
@@ -73,9 +73,9 @@ RSpec.describe Projects::SettingsController do
end
it do
- expect(get("/projects/123/settings/categories"))
+ expect(get("/projects/123/settings/work_packages/categories"))
.to route_to(
- controller: "projects/settings/categories", action: "show", project_id: "123"
+ controller: "projects/settings/work_packages/categories", action: "show", project_id: "123"
)
end
@@ -94,16 +94,16 @@ RSpec.describe Projects::SettingsController do
end
it do
- expect(get("/projects/123/settings/types"))
+ expect(get("/projects/123/settings/work_packages/types"))
.to route_to(
- controller: "projects/settings/types", action: "show", project_id: "123"
+ controller: "projects/settings/work_packages/types", action: "show", project_id: "123"
)
end
it do
- expect(patch("/projects/123/settings/types"))
+ expect(patch("/projects/123/settings/work_packages/types"))
.to route_to(
- controller: "projects/settings/types", action: "update", project_id: "123"
+ controller: "projects/settings/work_packages/types", action: "update", project_id: "123"
)
end
end