about summary refs log tree commit diff
path: root/app/controllers/concerns/authorization.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/concerns/authorization.rb')
-rw-r--r--app/controllers/concerns/authorization.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/controllers/concerns/authorization.rb b/app/controllers/concerns/authorization.rb
new file mode 100644
index 000000000..7828fe48d
--- /dev/null
+++ b/app/controllers/concerns/authorization.rb
@@ -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