pundit: add initial application policy.

This commit is contained in:
evazion
2020-03-15 13:48:34 -05:00
parent 15ba2f6cd7
commit 1d16034144
4 changed files with 83 additions and 1 deletions

View File

@@ -1,4 +1,6 @@
class ApplicationController < ActionController::Base
include Pundit
class ApiLimitError < StandardError; end
self.responder = ApplicationResponder
@@ -92,7 +94,7 @@ class ApplicationController < ActionController::Base
render_error_page(401, exception, template: "sessions/new")
when ActionController::InvalidAuthenticityToken, ActionController::UnpermittedParameters, ActionController::InvalidCrossOriginRequest
render_error_page(403, exception)
when User::PrivilegeError
when User::PrivilegeError, Pundit::NotAuthorizedError
render_error_page(403, exception, template: "static/access_denied", message: "Access denied")
when ActiveRecord::RecordNotFound
render_error_page(404, exception, message: "That record was not found.")
@@ -174,6 +176,14 @@ class ApplicationController < ActionController::Base
end
end
def pundit_user
[CurrentUser.user, request]
end
def pundit_params_for(record)
params.fetch(PolicyFinder.new(record).param_key, {})
end
# Remove blank `search` params from the url.
#
# /tags?search[name]=touhou&search[category]=&search[order]=