Add moderator role and add pundit policies for admin actions (#5635)
* Add moderator role and add pundit policies for admin actions * Add rake task for turning user into mod and revoking it again * Fix handling of unauthorized exception * Deliver new report e-mails to staff, not just admins * Add promote/demote to admin UI, hide some actions conditionally * Fix unused i18n
This commit is contained in:
parent
2b1190065c
commit
7bb8b0b2fc
44 changed files with 539 additions and 91 deletions
|
@ -10,14 +10,41 @@ namespace :mastodon do
|
|||
desc 'Turn a user into an admin, identified by the USERNAME environment variable'
|
||||
task make_admin: :environment do
|
||||
include RoutingHelper
|
||||
|
||||
account_username = ENV.fetch('USERNAME')
|
||||
user = User.joins(:account).where(accounts: { username: account_username })
|
||||
user = User.joins(:account).where(accounts: { username: account_username })
|
||||
|
||||
if user.present?
|
||||
user.update(admin: true)
|
||||
puts "Congrats! #{account_username} is now an admin. \\o/\nNavigate to #{edit_admin_settings_url} to get started"
|
||||
else
|
||||
puts "User could not be found; please make sure an Account with the `#{account_username}` username exists."
|
||||
puts "User could not be found; please make sure an account with the `#{account_username}` username exists."
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Turn a user into a moderator, identified by the USERNAME environment variable'
|
||||
task make_mod: :environment do
|
||||
account_username = ENV.fetch('USERNAME')
|
||||
user = User.joins(:account).where(accounts: { username: account_username })
|
||||
|
||||
if user.present?
|
||||
user.update(moderator: true)
|
||||
puts "Congrats! #{account_username} is now a moderator \\o/"
|
||||
else
|
||||
puts "User could not be found; please make sure an account with the `#{account_username}` username exists."
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Remove admin and moderator privileges from user identified by the USERNAME environment variable'
|
||||
task revoke_staff: :environment do
|
||||
account_username = ENV.fetch('USERNAME')
|
||||
user = User.joins(:account).where(accounts: { username: account_username })
|
||||
|
||||
if user.present?
|
||||
user.update(moderator: false, admin: false)
|
||||
puts "#{account_username} is no longer admin or moderator."
|
||||
else
|
||||
puts "User could not be found; please make sure an account with the `#{account_username}` username exists."
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue