skill-assessment-app/app/policies/user_policy.rb

27 lines
513 B
Ruby
Raw Normal View History

2016-09-20 14:22:20 -05:00
# frozen_string_literal: true
class UserPolicy < ApplicationPolicy
2016-09-20 17:19:11 -05:00
# User Access Policy
#
# Only Admins can view, create, or update, users
2016-09-21 11:03:45 -05:00
# All other users can only access themselves (profile interface)
2016-09-20 17:19:11 -05:00
2016-09-20 14:22:20 -05:00
def view?
2016-09-21 11:03:45 -05:00
user.admin? || user == record
2016-09-20 14:22:20 -05:00
end
def create?
user.admin?
end
def update?
2016-09-21 11:03:45 -05:00
user.admin? || user == record
2016-09-20 14:22:20 -05:00
end
class Scope < Scope
def resolve
return scope if user.admin?
raise Pundit::NotAuthorizedError, "No access to resource."
end
end
end