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

[#43231] Migration::MigrationUtils::PermissionAdder.add not idempotent

Frank Bergmann6e89a6f4c830
diff --git a/db/migrate/migration_utils/permission_adder.rb b/db/migrate/migration_utils/permission_adder.rb
index 858302e9d29..cb610647fe3 100644
--- a/db/migrate/migration_utils/permission_adder.rb
+++ b/db/migrate/migration_utils/permission_adder.rb
@@ -35,7 +35,14 @@ module Migration
.where(role_permissions: { permission: having.to_s })
.references(:role_permissions)
.find_each do |role|
- role.add_permission! add
+ # Check if the add-permission already exists before adding
+ already_exists = Role
+ .joins(:role_permissions)
+ .where(role_permissions: { permission: add.to_s })
+ .exists?(roles: { id: role.id })
+ unless already_exists
+ role.add_permission! add
+ end
end
end
end