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

64 lines
1.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class BaseService
2015-04-26 12:48:37 +05:30
include Gitlab::CurrentSettings
2014-09-02 18:07:02 +05:30
attr_accessor :project, :current_user, :params
2015-04-26 12:48:37 +05:30
def initialize(project, user, params = {})
2014-09-02 18:07:02 +05:30
@project, @current_user, @params = project, user, params.dup
end
def can?(object, action, subject)
2016-09-29 09:46:39 +05:30
Ability.allowed?(object, action, subject)
2014-09-02 18:07:02 +05:30
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
def system_hook_service
SystemHooksService.new
end
2015-04-26 12:48:37 +05:30
2015-09-25 12:07:36 +05:30
def repository
project.repository
end
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
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