2017-01-09 15:45:49 -05:00
|
|
|
module Gitlab
|
|
|
|
module View
|
|
|
|
module Presenter
|
2017-01-24 11:07:56 -05:00
|
|
|
CannotOverrideMethodError = Class.new(StandardError)
|
|
|
|
|
2017-01-09 15:45:49 -05:00
|
|
|
module Base
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
include Gitlab::Routing
|
|
|
|
include Gitlab::Allowable
|
|
|
|
|
|
|
|
attr_reader :subject
|
|
|
|
|
2017-01-10 17:41:04 -05:00
|
|
|
def can?(user, action, overriden_subject = nil)
|
|
|
|
super(user, action, overriden_subject || subject)
|
2017-01-09 15:45:49 -05:00
|
|
|
end
|
|
|
|
|
2017-06-22 14:08:40 -04:00
|
|
|
# delegate all #can? queries to the subject
|
|
|
|
def declarative_policy_delegate
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2017-01-09 15:45:49 -05:00
|
|
|
class_methods do
|
2017-01-10 17:41:04 -05:00
|
|
|
def presenter?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2017-01-09 15:45:49 -05:00
|
|
|
def presents(name)
|
|
|
|
define_method(name) { subject }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|