-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use different syntax * Remove * Use execute instead of invoke
- Loading branch information
1 parent
44f2dc8
commit bfd308c
Showing
2 changed files
with
11 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
namespace :users do | ||
desc "Promote an existing account to service account status, returning an access token" | ||
task promote_to_service_account: :environment do | ||
ActiveRecord::Base.transaction do | ||
user = User.find(ENV["id"]) | ||
puts "Found user #{user.id} with #{user.api_access_tokens.count} existing tokens" | ||
task :promote_to_service_account, [ :user_id ] => [ :environment ] do |_, user_id| | ||
user = User.find(user_id) | ||
|
||
if user && user.update(is_service_account: true) | ||
puts "Updated user to service account" | ||
user.api_access_tokens.create! | ||
puts "Created new token" | ||
if user && user.update(is_service_account: true) | ||
token = user.api_access_tokens.create | ||
|
||
puts "User #{ENV["id"]} (#{user.email}) is now a service account" | ||
puts "User now has #{user.api_access_tokens.count} tokens" | ||
end | ||
puts "User #{user_id} (#{user.email}) is now a service account: #{token.access_token}" | ||
end | ||
end | ||
|
||
desc "Demote an existing account, deleting all associated access tokens" | ||
task demote_service_account: :environment do | ||
user = User.find(ENV["id"]) | ||
task :demote_service_account, [ :user_id ] => [ :environment ] do |_, user_id| | ||
user = User.find(user_id) | ||
|
||
if user && user.update(is_service_account: false) | ||
user.api_access_tokens.update_all(deleted_at: Time.now) | ||
|
||
puts "User #{ENV["id"]} (#{user.email}) is no longer a service account." | ||
puts "User #{user_id} (#{user.email}) is no longer a service account." | ||
end | ||
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