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 PermissionRenamer for renaming permissions
Oliver Güntherf71f6538ae1d
diff --git a/db/migrate/20250324161229_merge_lifecycle_steps.rb b/db/migrate/20250324161229_merge_lifecycle_steps.rbindex 9d2e870911c..30f747d1d37 100644--- a/db/migrate/20250324161229_merge_lifecycle_steps.rb+++ b/db/migrate/20250324161229_merge_lifecycle_steps.rb@@ -27,6 +27,7 @@## See COPYRIGHT and LICENSE files for more details.#+++require Rails.root.join("db/migrate/migration_utils/permission_renamer")class MergeLifecycleSteps < ActiveRecord::Migration[8.0]def change@@ -35,14 +36,14 @@ class MergeLifecycleSteps < ActiveRecord::Migration[8.0]delete_life_cycle_project_queriesdelete_life_cycles- rename_permissions("view_project_stages_and_gates", "view_project_phases")- rename_permissions("select_project_life_cycle", "select_project_phases")- rename_permissions("edit_project_stages_and_gates", "edit_project_phases")+ ::Migration::MigrationUtils::PermissionRenamer.rename("view_project_stages_and_gates", "view_project_phases")+ ::Migration::MigrationUtils::PermissionRenamer.rename("select_project_life_cycle", "select_project_phases")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_project_stages_and_gates", "edit_project_phases")enddirection.down do- rename_permissions("view_project_phases", "view_project_stages_and_gates")- rename_permissions("select_project_phases", "select_project_life_cycle")- rename_permissions("edit_project_phases", "edit_project_stages_and_gates")+ ::Migration::MigrationUtils::PermissionRenamer.rename("view_project_phases", "view_project_stages_and_gates")+ ::Migration::MigrationUtils::PermissionRenamer.rename("select_project_phases", "select_project_life_cycle")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_project_phases", "edit_project_stages_and_gates")endend@@ -123,12 +124,4 @@ class MergeLifecycleSteps < ActiveRecord::Migration[8.0]rename_table :project_life_cycle_steps, :project_phasesrename_table :project_life_cycle_step_journals, :project_phase_journalsend-- def rename_permissions(old, new)- execute <<-SQL.squish- UPDATE role_permissions- SET permission = '#{new}'- WHERE permission = '#{old}'- SQL- endenddiff --git a/db/migrate/20250422072119_rename_comment_permissions.rb b/db/migrate/20250422072119_rename_comment_permissions.rbindex 45cc152c0f0..efbe5231b93 100644--- a/db/migrate/20250422072119_rename_comment_permissions.rb+++ b/db/migrate/20250422072119_rename_comment_permissions.rb@@ -27,24 +27,28 @@## See COPYRIGHT and LICENSE files for more details.#+++require Rails.root.join("db/migrate/migration_utils/permission_renamer")class RenameCommentPermissions < ActiveRecord::Migration[8.0]- def change- rename_permissions("add_work_package_notes", "add_work_package_comments")- rename_permissions("edit_own_work_package_notes", "edit_own_work_package_comments")- rename_permissions("edit_work_package_notes", "edit_work_package_comments")+ def up+ ::Migration::MigrationUtils::PermissionRenamer.rename("add_work_package_notes", "add_work_package_comments")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_own_work_package_notes", "edit_own_work_package_comments")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_work_package_notes", "edit_work_package_comments")- rename_permissions("view_comments_with_restricted_visibility", "view_internal_comments")- rename_permissions("add_comments_with_restricted_visibility", "add_internal_comments")- rename_permissions("edit_own_comments_with_restricted_visibility", "edit_own_internal_comments")- rename_permissions("edit_others_comments_with_restricted_visibility", "edit_others_internal_comments")+ ::Migration::MigrationUtils::PermissionRenamer.rename("view_comments_with_restricted_visibility", "view_internal_comments")+ ::Migration::MigrationUtils::PermissionRenamer.rename("add_comments_with_restricted_visibility", "add_internal_comments")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_own_comments_with_restricted_visibility", "edit_own_internal_comments")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_others_comments_with_restricted_visibility", "edit_others_internal_comments")end- def rename_permissions(old, new)- execute <<-SQL.squish- UPDATE role_permissions- SET permission = '#{new}'- WHERE permission = '#{old}'- SQL+ def down+ ::Migration::MigrationUtils::PermissionRenamer.rename("add_work_package_comments", "add_work_package_notes")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_own_work_package_comments", "edit_own_work_package_notes")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_work_package_comments", "edit_work_package_notes")++ ::Migration::MigrationUtils::PermissionRenamer.rename("view_internal_comments", "view_comments_with_restricted_visibility")+ ::Migration::MigrationUtils::PermissionRenamer.rename("add_internal_comments", "add_comments_with_restricted_visibility")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_own_internal_comments", "edit_own_comments_with_restricted_visibility")+ ::Migration::MigrationUtils::PermissionRenamer.rename("edit_others_internal_comments", "edit_others_comments_with_restricted_visibility")endenddiff --git a/db/migrate/migration_utils/permission_renamer.rb b/db/migrate/migration_utils/permission_renamer.rbnew file mode 100644index 00000000000..a3a202f9060--- /dev/null+++ b/db/migrate/migration_utils/permission_renamer.rb@@ -0,0 +1,55 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++module Migration+ module MigrationUtils+ class PermissionRenamer+ class << self+ def rename(from, to)+ ActiveRecord::Base.connection.execute <<-SQL.squish+ UPDATE #{role_permissions_table}+ SET permission = #{quote_value(to)}+ WHERE permission = #{quote_value(from)}+ SQL+ end++ private++ def role_permissions_table+ @role_permissions_table ||= ActiveRecord::Base.connection.quote_table_name("role_permissions")+ end++ def quote_value(s)+ ActiveRecord::Base.connection.quote(s)+ end+ end+ end+ end+end