Class: BaseService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::CurrentSettings
Defined in:
app/services/base_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

#initialize(project, user, params = {}) ⇒ BaseService

Returns a new instance of BaseService


6
7
8
# File 'app/services/base_service.rb', line 6

def initialize(project, user, params = {})
  @project, @current_user, @params = project, user, params.dup
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user


4
5
6
# File 'app/services/base_service.rb', line 4

def current_user
  @current_user
end

#paramsObject

Returns the value of attribute params


4
5
6
# File 'app/services/base_service.rb', line 4

def params
  @params
end

#projectObject

Returns the value of attribute project


4
5
6
# File 'app/services/base_service.rb', line 4

def project
  @project
end

Instance Method Details

#abilitiesObject


10
11
12
# File 'app/services/base_service.rb', line 10

def abilities
  Ability.abilities
end

#can?(object, action, subject) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
# File 'app/services/base_service.rb', line 14

def can?(object, action, subject)
  abilities.allowed?(object, action, subject)
end

#deny_visibility_level(model, denied_visibility_level = nil) ⇒ Object

Add an error to the specified model for restricted visibility levels


43
44
45
46
47
48
49
# File 'app/services/base_service.rb', line 43

def deny_visibility_level(model, denied_visibility_level = nil)
  denied_visibility_level ||= model.visibility_level

  level_name = Gitlab::VisibilityLevel.level_name(denied_visibility_level).downcase

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

#event_serviceObject


22
23
24
# File 'app/services/base_service.rb', line 22

def event_service
  EventCreateService.new
end

#log_info(message) ⇒ Object


30
31
32
# File 'app/services/base_service.rb', line 30

def log_info(message)
  Gitlab::AppLogger.info message
end

#notification_serviceObject


18
19
20
# File 'app/services/base_service.rb', line 18

def notification_service
  NotificationService.new
end

#repositoryObject


38
39
40
# File 'app/services/base_service.rb', line 38

def repository
  project.repository
end

#system_hook_serviceObject


34
35
36
# File 'app/services/base_service.rb', line 34

def system_hook_service
  SystemHooksService.new
end

#todo_serviceObject


26
27
28
# File 'app/services/base_service.rb', line 26

def todo_service
  TodoService.new
end