Extract authorization policy for viewing statuses (#3150)
This commit is contained in:
parent
9a81be0d37
commit
3a2003ba86
16 changed files with 155 additions and 80 deletions
22
app/controllers/concerns/authorization.rb
Normal file
22
app/controllers/concerns/authorization.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Authorization
|
||||
extend ActiveSupport::Concern
|
||||
include Pundit
|
||||
|
||||
def pundit_user
|
||||
current_account
|
||||
end
|
||||
|
||||
def authorize(*)
|
||||
super
|
||||
rescue Pundit::NotAuthorizedError
|
||||
raise Mastodon::NotPermittedError
|
||||
end
|
||||
|
||||
def authorize_with(user, record, query)
|
||||
Pundit.authorize(user, record, query)
|
||||
rescue Pundit::NotAuthorizedError
|
||||
raise Mastodon::NotPermittedError
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue