2014-01-16 12:03:42 -05:00
|
|
|
class BaseService
|
2015-01-08 12:53:35 -05:00
|
|
|
include Gitlab::CurrentSettings
|
|
|
|
|
2012-07-20 01:39:34 -04:00
|
|
|
attr_accessor :project, :current_user, :params
|
|
|
|
|
2014-09-21 04:29:52 -04:00
|
|
|
def initialize(project, user, 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
|
|
|
|
|
|
|
def abilities
|
2014-10-19 04:50:23 -04:00
|
|
|
Ability.abilities
|
2012-07-27 20:35:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def can?(object, action, subject)
|
|
|
|
abilities.allowed?(object, action, subject)
|
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
|
|
|
|
def notification_service
|
|
|
|
NotificationService.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_service
|
|
|
|
EventCreateService.new
|
|
|
|
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
|
|
|
|
|
|
|
def system_hook_service
|
|
|
|
SystemHooksService.new
|
|
|
|
end
|
2014-09-21 04:29:52 -04:00
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
def repository
|
|
|
|
project.repository
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
|
level_name = 'Unknown'
|
|
|
|
Gitlab::VisibilityLevel.options.each do |name, level|
|
|
|
|
level_name = name if level == denied_visibility_level
|
|
|
|
end
|
|
|
|
|
|
|
|
model.errors.add(
|
|
|
|
:visibility_level,
|
|
|
|
"#{level_name} visibility has been restricted by your GitLab administrator"
|
|
|
|
)
|
|
|
|
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
|
|
|
|
|
|
|
|
def success
|
|
|
|
{
|
|
|
|
status: :success
|
|
|
|
}
|
|
|
|
end
|
2012-07-20 01:39:34 -04:00
|
|
|
end
|