2018-07-05 10:18:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-01-16 17:03:42 +00:00
|
|
|
class BaseService
|
2017-02-14 10:28:30 +00:00
|
|
|
include Gitlab::Allowable
|
2015-01-08 17:53:35 +00:00
|
|
|
|
2012-07-20 05:39:34 +00:00
|
|
|
attr_accessor :project, :current_user, :params
|
|
|
|
|
2018-06-06 16:42:18 +00:00
|
|
|
def initialize(project, user = nil, params = {})
|
2012-07-20 05:39:34 +00:00
|
|
|
@project, @current_user, @params = project, user, params.dup
|
|
|
|
end
|
2012-07-28 00:35:24 +00:00
|
|
|
|
2014-04-02 10:38:35 +00:00
|
|
|
def notification_service
|
|
|
|
NotificationService.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_service
|
|
|
|
EventCreateService.new
|
|
|
|
end
|
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
def todo_service
|
|
|
|
TodoService.new
|
2016-02-15 18:13:52 +00:00
|
|
|
end
|
|
|
|
|
2014-09-25 22:07:40 +00:00
|
|
|
def log_info(message)
|
2014-04-02 10:38:35 +00:00
|
|
|
Gitlab::AppLogger.info message
|
|
|
|
end
|
2014-06-17 19:20:10 +00:00
|
|
|
|
2017-03-30 12:39:17 +00:00
|
|
|
def log_error(message)
|
|
|
|
Gitlab::AppLogger.error message
|
|
|
|
end
|
|
|
|
|
2014-06-17 19:20:10 +00:00
|
|
|
def system_hook_service
|
|
|
|
SystemHooksService.new
|
|
|
|
end
|
2014-09-21 08:29:52 +00:00
|
|
|
|
2017-02-22 17:51:46 +00:00
|
|
|
delegate :repository, to: :project
|
2015-08-11 12:33:31 +00:00
|
|
|
|
2015-03-07 19:47:06 +00:00
|
|
|
# Add an error to the specified model for restricted visibility levels
|
|
|
|
def deny_visibility_level(model, denied_visibility_level = nil)
|
|
|
|
denied_visibility_level ||= model.visibility_level
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
level_name = Gitlab::VisibilityLevel.level_name(denied_visibility_level).downcase
|
2015-03-07 19:47:06 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
model.errors.add(:visibility_level, "#{level_name} has been restricted by your GitLab administrator")
|
2015-03-07 19:47:06 +00:00
|
|
|
end
|
|
|
|
|
2014-09-21 08:29:52 +00:00
|
|
|
private
|
|
|
|
|
2015-02-22 23:01:49 +00:00
|
|
|
def error(message, http_status = nil)
|
|
|
|
result = {
|
2014-09-21 08:29:52 +00:00
|
|
|
message: message,
|
|
|
|
status: :error
|
|
|
|
}
|
2015-02-22 23:01:49 +00:00
|
|
|
|
|
|
|
result[:http_status] = http_status if http_status
|
|
|
|
result
|
2014-09-21 08:29:52 +00:00
|
|
|
end
|
|
|
|
|
2016-08-29 23:58:32 +00:00
|
|
|
def success(pass_back = {})
|
|
|
|
pass_back[:status] = :success
|
|
|
|
pass_back
|
2014-09-21 08:29:52 +00:00
|
|
|
end
|
2012-07-20 05:39:34 +00:00
|
|
|
end
|