Last active
February 11, 2022 09:59
-
-
Save theareba/8d70d767059ea81a2b4aad3913ba7373 to your computer and use it in GitHub Desktop.
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
user = User.find 151778 | |
stakeholder = user.stakeholder | |
em_subscription = EnterpriseManager::Subscription.find 2 | |
# Add user as manager of all EM gaggles | |
em_subscription.organizations.each do |organization| | |
organization.managers.find_or_create_by(user: user, role: "admin") | |
end | |
# Add user as member of all EM gaggles | |
em_subscription.organizations.each do |organization| | |
organization.affiliations.find_or_create_by(stakeholder: stakeholder, membership_status: "approved") | |
end | |
# Find the BitlyAuthentication's template, this is the one we'll copy to the other Gaggles | |
auth = BitlyAuthentication.find 132775 | |
# set Kyle as the bitly auth owner | |
auth.manager.user.managers.each do |m| | |
next unless m.authentications.where(type: "BitlyAuthentication").any? | |
mm = user.managers.find_by(organization_id: m.organization_id) | |
m.authentications.where(type: "BitlyAuthentication").update_all(attachable_id: mm.id) | |
end | |
# add bitly to missing organizations | |
user.managers.each do |m| | |
next if m.authentications.where(type: "BitlyAuthentication").any? | |
a = auth.dup | |
a.attachable = m | |
a.save! | |
# Make sure this is the domain they wanted. | |
m.organization.update! bitly_custom_domain: "tmsnrt.rs" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment