summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension/fetch_user.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-03-28 15:52:21 -0700
committerelijah <elijah@riseup.net>2016-03-28 16:03:54 -0700
commit67b5aa4198e0f6ab2cd29767aedcb4bf5b5dc4d9 (patch)
treecfea468d3d70363298490cc1ad7b8085688530b7 /app/controllers/controller_extension/fetch_user.rb
parentc63791c7ffacb7c6cfc685e2654ffe66f0a6b185 (diff)
api tokens - clarify terms: "monitors" are admins that authenticated via api token, "tmp" users are users that exist only in tmp db, "test" users are either tmp users or users named "test_user_x"
Diffstat (limited to 'app/controllers/controller_extension/fetch_user.rb')
-rw-r--r--app/controllers/controller_extension/fetch_user.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/app/controllers/controller_extension/fetch_user.rb b/app/controllers/controller_extension/fetch_user.rb
index 695d723..97f92fa 100644
--- a/app/controllers/controller_extension/fetch_user.rb
+++ b/app/controllers/controller_extension/fetch_user.rb
@@ -8,11 +8,25 @@ module ControllerExtension::FetchUser
protected
+ #
+ # fetch @user from params, but enforce permissions:
+ #
+ # * admins may fetch any user
+ # * monitors may fetch test users
+ # * users may fetch themselves
+ #
+ # these permissions matter, it is what protects
+ # users from being updated or deleted by other users.
+ #
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
+ if current_user.is_admin? || current_user.is_monitor?
+ if @user.nil?
+ not_found(t(:no_such_thing, :thing => 'user'), users_url)
+ elsif current_user.is_monitor?
+ access_denied unless @user.is_test?
+ end
+ elsif @user != current_user
access_denied
end
end