OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/db/migrate/20200625133727_fix_inherite...

22 lines
683 B

class FixInheritedGroupMemberRoles < ActiveRecord::Migration[6.0]
def up
# Delete all member roles that should be inherited by groups
MemberRole.where.not(inherited_from: nil).delete_all
# For all group memberships, recreate the member_roles for all users
# which will auto-create members for the users if necessary
MemberRole
.joins(member: [:principal])
.includes(member: %i[principal member_roles])
.where("#{Principal.table_name}.type" => 'Group')
.find_each do |member_role|
# Recreate member_roles for all group members
member_role.send :add_role_to_group_users
end
end
def down
# Nothing to do
end
end