Extract authorization policy for viewing statuses (#3150)
This commit is contained in:
committed by
Eugen Rochko
parent
9a81be0d37
commit
3a2003ba86
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
|
Reference in New Issue
Block a user