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