From 69ca36e75a1d03e1c750dfe44ba12401ed3bb0bb Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 1 Jul 2011 15:10:13 -0400 Subject: [PATCH] rake task to add/remove image mode access for given users --- lib/tasks/users.rake | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/tasks/users.rake diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake new file mode 100644 index 00000000..019089fc --- /dev/null +++ b/lib/tasks/users.rake @@ -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 +