Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added user rake task set_admin_role #5587

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/tasks/user.rake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ 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.role = role
user.save!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this in one line user.update(role:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it and updated!

success "User role set to Administrator for email: #{email}"
end

private

def check_role!(user:)
Expand Down
Loading