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

67 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
# 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
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