gitlab-org--gitlab-foss/app/services/base_service.rb

62 lines
1.3 KiB
Ruby
Raw Normal View History

class BaseService
include Gitlab::Allowable
attr_accessor :project, :current_user, :params
def initialize(project, user = nil, params = {})
@project, @current_user, @params = project, user, params.dup
end
2012-07-27 20:35:24 -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
end
def log_info(message)
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
2017-02-22 12:51:46 -05:00
delegate :repository, to: :project
# 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
2016-03-20 16:03:53 -04:00
model.errors.add(:visibility_level, "#{level_name} has been restricted by your GitLab administrator")
end
private
def error(message, http_status = nil)
result = {
message: message,
status: :error
}
result[:http_status] = http_status if http_status
result
end
def success(pass_back = {})
pass_back[:status] = :success
pass_back
end
end