GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

base_service.rb 1.32 KB
Newer Older
1
class BaseService
2 3
  include Gitlab::CurrentSettings

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4 5
  attr_accessor :project, :current_user, :params

6
  def initialize(project, user, params = {})
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
7 8
    @project, @current_user, @params = project, user, params.dup
  end
randx's avatar
randx committed
9 10

  def abilities
Ciro Santilli's avatar
Ciro Santilli committed
11
    Ability.abilities
randx's avatar
randx committed
12 13 14 15 16
  end

  def can?(object, action, subject)
    abilities.allowed?(object, action, subject)
  end
17 18 19 20 21 22 23 24 25

  def notification_service
    NotificationService.new
  end

  def event_service
    EventCreateService.new
  end

26 27
  def todo_service
    TodoService.new
28 29
  end

30
  def log_info(message)
31 32
    Gitlab::AppLogger.info message
  end
33 34 35 36

  def system_hook_service
    SystemHooksService.new
  end
37

38 39 40 41
  def repository
    project.repository
  end

42 43 44 45
  # 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

46
    level_name = Gitlab::VisibilityLevel.level_name(denied_visibility_level)
47 48 49 50 51 52 53

    model.errors.add(
      :visibility_level,
      "#{level_name} visibility has been restricted by your GitLab administrator"
    )
  end

54 55
  private

56 57
  def error(message, http_status = nil)
    result = {
58 59 60
      message: message,
      status: :error
    }
61 62 63

    result[:http_status] = http_status if http_status
    result
64 65 66 67 68 69 70
  end

  def success
    {
      status: :success
    }
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
71
end