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

Add a migration to add create_user permission to all roles with manage_user permission

Klaus Zandersf9e18057970e
diff --git a/db/migrate/20230718084649_add_create_user_permission_to_roles.rb b/db/migrate/20230718084649_add_create_user_permission_to_roles.rb
new file mode 100644
index 00000000000..0819c3d03b3
--- /dev/null
+++ b/db/migrate/20230718084649_add_create_user_permission_to_roles.rb
@@ -0,0 +1,17 @@
+class AddCreateUserPermissionToRoles < ActiveRecord::Migration[7.0]
+ class MigrationRolePermission < ApplicationRecord
+ self.table_name = 'role_permissions'
+ end
+
+ def up
+ role_ids = MigrationRolePermission.where(permission: 'manage_user').pluck(:role_id)
+
+ role_ids.each do |role_id|
+ MigrationRolePermission.create(permission: 'create_user', role_id:)
+ end
+ end
+
+ def down
+ MigrationRolePermission.where(permission: 'create_user').delete_all
+ end
+end