Skip to content

Commit

Permalink
added user rake task set_admin_role (#5587)
Browse files Browse the repository at this point in the history
* added user rake task set_admin_role

* fixed rubocop offenses

* added guard clauses to user:set_admin_role rake task

* minor refactor user.update rake task
  • Loading branch information
SilentFlameCR authored Dec 13, 2023
1 parent 4554909 commit 7422a46
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/tasks/user.rake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ namespace :user do
exit 0
end

desc 'Set user role to Administrator'
task :set_admin_role, %i[email] => :environment do |_task, args|
email = args[:email]

# return err if no user email provided
err 'Please provide an email address of the user you wish to set to Administrator role.' if email.blank?

user = User.find_by(email:, provider: 'greenlight')

# return err if user not found
err "User with email: #{email} not found" if user.blank?

role = Role.find_by(name: 'Administrator', provider: 'greenlight')

# return err if Administrator role not found
err "Role 'Administrator' not found for provider 'greenlight'" if role.blank?

user.update(role:)
success "User role set to Administrator for email: #{email}"
end

private

def check_role!(user:)
Expand Down

0 comments on commit 7422a46

Please sign in to comment.