-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8473 from opf/fix/inherited-member-roles
[33659] Fix inserting on group MEMBER id not MEMBER ROLE id
- Loading branch information
Showing
3 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
db/migrate/20200625133727_fix_inherited_group_member_roles.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters