discourse/lib/staff_constraint.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

23 lines
502 B
Ruby

# frozen_string_literal: true
require_dependency 'current_user'
class StaffConstraint
def matches?(request)
provider = Discourse.current_user_provider.new(request.env)
provider.current_user &&
provider.current_user.staff? &&
custom_staff_check(request)
rescue Discourse::InvalidAccess, Discourse::ReadOnly
false
end
# Extensibility point: plugins can overwrite this to add additional checks
# if they require.
def custom_staff_check(request)
true
end
end