Skip to content

Instantly share code, notes, and snippets.

@theareba
Last active February 11, 2022 09:59
Show Gist options
  • Save theareba/8d70d767059ea81a2b4aad3913ba7373 to your computer and use it in GitHub Desktop.
Save theareba/8d70d767059ea81a2b4aad3913ba7373 to your computer and use it in GitHub Desktop.
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