debian-mirror-gitlab/app/services/base_service.rb

68 lines
1.4 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
class BaseService
2017-08-17 22:00:37 +05:30
include Gitlab::Allowable
2015-04-26 12:48:37 +05:30
2014-09-02 18:07:02 +05:30
attr_accessor :project, :current_user, :params
2018-11-08 19:23:39 +05:30
def initialize(project, user = nil, params = {})
2014-09-02 18:07:02 +05:30
@project, @current_user, @params = project, user, params.dup
end
def notification_service
NotificationService.new
end
def event_service
EventCreateService.new
end
2016-04-02 18:10:28 +05:30
def todo_service
TodoService.new
end
2015-04-26 12:48:37 +05:30
def log_info(message)
2014-09-02 18:07:02 +05:30
Gitlab::AppLogger.info message
end
2017-08-17 22:00:37 +05:30
def log_error(message)
Gitlab::AppLogger.error message
end
2014-09-02 18:07:02 +05:30
def system_hook_service
SystemHooksService.new
end
2015-04-26 12:48:37 +05:30
2017-08-17 22:00:37 +05:30
delegate :repository, to: :project
2015-09-25 12:07:36 +05:30
2015-04-26 12:48:37 +05:30
# 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-06-02 11:05:42 +05:30
level_name = Gitlab::VisibilityLevel.level_name(denied_visibility_level).downcase
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
model.errors.add(:visibility_level, "#{level_name} has been restricted by your GitLab administrator")
2015-04-26 12:48:37 +05:30
end
2019-10-12 21:52:04 +05:30
def visibility_level
params[:visibility].is_a?(String) ? Gitlab::VisibilityLevel.level_value(params[:visibility]) : params[:visibility_level]
end
2015-04-26 12:48:37 +05:30
private
def error(message, http_status = nil)
result = {
message: message,
status: :error
}
result[:http_status] = http_status if http_status
result
end
2016-11-03 12:29:30 +05:30
def success(pass_back = {})
pass_back[:status] = :success
pass_back
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end