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

68 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 abilities
2015-04-26 12:48:37 +05:30
Ability.abilities
2014-09-02 18:07:02 +05:30
end
def can?(object, action, subject)
abilities.allowed?(object, action, subject)
end
def notification_service
NotificationService.new
end
def event_service
EventCreateService.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
level_name = Gitlab::VisibilityLevel.level_name(denied_visibility_level)
2015-04-26 12:48:37 +05:30
model.errors.add(
:visibility_level,
"#{level_name} visibility 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
{
status: :success
}
end
2014-09-02 18:07:02 +05:30
end