summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension/fetch_user.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-07-14 15:49:31 +0200
committerAzul <azul@leap.se>2014-07-14 15:58:30 +0200
commit67f70b31bd16b05759e1f8393f077ee17f2c34be (patch)
treec269a2a342fdc6974cbf55586eb12832bb45e25e /app/controllers/controller_extension/fetch_user.rb
parentf07c952c870bfb8634ef0d80737b67a1eec760f6 (diff)
move fetch_user into module so it can be mixed in
We have an ApiController that wants to call #fetch_user. Since we can only inherit from one class i moved fetch_user into an extension.
Diffstat (limited to 'app/controllers/controller_extension/fetch_user.rb')
-rw-r--r--app/controllers/controller_extension/fetch_user.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/controllers/controller_extension/fetch_user.rb b/app/controllers/controller_extension/fetch_user.rb
new file mode 100644
index 0000000..695d723
--- /dev/null
+++ b/app/controllers/controller_extension/fetch_user.rb
@@ -0,0 +1,20 @@
+#
+# fetch the user taking into account permissions.
+# While normal users can only change settings for themselves
+# admins can change things for all users.
+#
+module ControllerExtension::FetchUser
+ extend ActiveSupport::Concern
+
+ protected
+
+ def fetch_user
+ @user = User.find(params[:user_id] || params[:id])
+ if !@user && admin?
+ redirect_to users_url, :alert => t(:no_such_thing, :thing => 'user')
+ elsif !admin? && @user != current_user
+ access_denied
+ end
+ end
+
+end