forked from OpenNeo/impress
rake task to add/remove image mode access for given users
This commit is contained in:
parent
868dd003fd
commit
69ca36e75a
1 changed files with 32 additions and 0 deletions
32
lib/tasks/users.rake
Normal file
32
lib/tasks/users.rake
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
namespace :users do
|
||||||
|
namespace :image_mode do
|
||||||
|
|
||||||
|
desc "Grants given username access to image mode"
|
||||||
|
task :add, :username, :needs => :environment do |t, args|
|
||||||
|
user = toggle_user_image_mode(args, true)
|
||||||
|
puts "#{user.name} has gained access to image mode"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Removes given username's access to image mode"
|
||||||
|
task :remove, :username, :needs => :environment do |t, args|
|
||||||
|
user = toggle_user_image_mode(args, false)
|
||||||
|
puts "#{user.name} has lost access to image mode"
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_user(args)
|
||||||
|
name = args[:username]
|
||||||
|
user = User.find_by_name(name)
|
||||||
|
raise RuntimeError, "Could not find user with name #{name.inspect}" unless user
|
||||||
|
user
|
||||||
|
end
|
||||||
|
|
||||||
|
def toggle_user_image_mode(args, image_mode)
|
||||||
|
user = find_user(args)
|
||||||
|
user.image_mode_tester = image_mode
|
||||||
|
user.save!
|
||||||
|
user
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue