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
Introduce ProjectQueryRole
Klaus Zanders5cde7451b64d
diff --git a/app/models/project_query_role.rb b/app/models/project_query_role.rbnew file mode 100644index 00000000000..dc29a9905b1--- /dev/null+++ b/app/models/project_query_role.rb@@ -0,0 +1,41 @@+# frozen_string_literal: true++#+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 ProjectQueryRole < Role+ def self.givable+ super+ .where(type: "ProjectQueryRole")+ end++ def member?+ true+ end+enddiff --git a/app/models/role.rb b/app/models/role.rbindex fb460ae868c..8dc6ba329a6 100644--- a/app/models/role.rb+++ b/app/models/role.rb@@ -34,6 +34,13 @@ class Role < ApplicationRecordBUILTIN_WORK_PACKAGE_VIEWER = 3BUILTIN_WORK_PACKAGE_COMMENTER = 4BUILTIN_WORK_PACKAGE_EDITOR = 5+ BUILTIN_PROJECT_QUERY_VIEW = 6+ BUILTIN_PROJECT_QUERY_EDIT = 7++ HIDDEN_ROLE_TYPES = [+ "WorkPackageRole",+ "ProjectQueryRole"+ ]scope :builtin, ->(*args) {compare = "not" if args.first == true@@ -41,7 +48,7 @@ class Role < ApplicationRecord}# Work Package Roles are intentionally visually hidden from users temporarily- scope :visible, -> { where.not(type: "WorkPackageRole") }+ scope :visible, -> { where.not(type: HIDDEN_ROLE_TYPES) }scope :ordered_by_builtin_and_position, -> { order(Arel.sql("builtin, position")) }before_destroy(prepend: true) do@@ -84,7 +91,9 @@ class Role < ApplicationRecordRole::BUILTIN_ANONYMOUS,Role::BUILTIN_WORK_PACKAGE_VIEWER,Role::BUILTIN_WORK_PACKAGE_COMMENTER,- Role::BUILTIN_WORK_PACKAGE_EDITOR+ Role::BUILTIN_WORK_PACKAGE_EDITOR,+ Role::BUILTIN_PROJECT_QUERY_VIEW,+ Role::BUILTIN_PROJECT_QUERY_EDIT]).order(Arel.sql("position"))diff --git a/app/seeders/common.yml b/app/seeders/common.ymlindex a491e884d5b..c75e9c9c766 100644--- a/app/seeders/common.yml+++ b/app/seeders/common.yml@@ -239,6 +239,22 @@ open_color_palette:- "#e8590c"- "#d9480f"+project_query_roles:+ - reference: :default_role_project_query_view+ t_name: Project query viewer+ position: 10+ builtin: :project_query_view+ permissions:+ - :view_project_query++ - reference: :default_role_project_query_edit+ t_name: Project query editor+ position: 11+ builtin: :project_query_edit+ permissions:+ - :view_project_query+ - :edit_project_query+work_package_roles:- reference: :default_role_work_package_editort_name: Work package editordiff --git a/db/migrate/20240527070439_add_project_query_roles.rb b/db/migrate/20240527070439_add_project_query_roles.rbnew file mode 100644index 00000000000..0913d438ba5--- /dev/null+++ b/db/migrate/20240527070439_add_project_query_roles.rb@@ -0,0 +1,21 @@+class AddProjectQueryRoles < ActiveRecord::Migration[7.1]+ def up+ view_role ||= ProjectQueryRole.find_or_initialize_by(builtin: Role::BUILTIN_PROJECT_QUERY_VIEW)++ view_role.update!(+ name: I18n.t("seeds.common.project_query_roles.item_0.name", default: "Project query viewer"),+ permissions: %i[+ view_project_query+ ]+ )++ edit_role ||= ProjectQueryRole.find_or_initialize_by(builtin: Role::BUILTIN_PROJECT_QUERY_EDIT)+ edit_role.update!(+ name: I18n.t("seeds.common.project_query_roles.item_1.name", default: "Project query editor"),+ permissions: %i[+ view_project_query+ edit_project_query+ ]+ )+ end+end