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