2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-05-02 13:15:17 +08:00
|
|
|
require_dependency 'current_user'
|
|
|
|
|
2013-05-02 15:22:27 +08:00
|
|
|
class StaffConstraint
|
2013-05-02 13:15:17 +08:00
|
|
|
|
|
|
|
def matches?(request)
|
2018-09-04 14:17:05 +08:00
|
|
|
provider = Discourse.current_user_provider.new(request.env)
|
2018-03-29 02:48:14 +08:00
|
|
|
provider.current_user &&
|
|
|
|
provider.current_user.staff? &&
|
|
|
|
custom_staff_check(request)
|
2019-01-21 13:49:08 +08:00
|
|
|
rescue Discourse::InvalidAccess, Discourse::ReadOnly
|
2017-08-10 17:27:01 +08:00
|
|
|
false
|
2013-05-02 13:15:17 +08:00
|
|
|
end
|
|
|
|
|
2018-03-29 02:48:14 +08:00
|
|
|
# Extensibility point: plugins can overwrite this to add additional checks
|
|
|
|
# if they require.
|
|
|
|
def custom_staff_check(request)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-05-02 13:15:17 +08:00
|
|
|
end
|