Class: NamespaceSettings::UpdateService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Allowable
Defined in:
app/services/namespace_settings/update_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(current_user, group, settings) ⇒ UpdateService

Returns a new instance of UpdateService.


9
10
11
12
13
# File 'app/services/namespace_settings/update_service.rb', line 9

def initialize(current_user, group, settings)
  @current_user = current_user
  @group = group
  @settings_params = settings
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.


7
8
9
# File 'app/services/namespace_settings/update_service.rb', line 7

def current_user
  @current_user
end

#groupObject (readonly)

Returns the value of attribute group.


7
8
9
# File 'app/services/namespace_settings/update_service.rb', line 7

def group
  @group
end

#settings_paramsObject (readonly)

Returns the value of attribute settings_params.


7
8
9
# File 'app/services/namespace_settings/update_service.rb', line 7

def settings_params
  @settings_params
end

Instance Method Details

#executeObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/namespace_settings/update_service.rb', line 15

def execute
  validate_resource_access_token_creation_allowed_param

  validate_settings_param_for_root_group(
    param_key: :prevent_sharing_groups_outside_hierarchy,
    user_policy: :change_prevent_sharing_groups_outside_hierarchy
  )
  validate_settings_param_for_root_group(
    param_key: :new_user_signups_cap,
    user_policy: :change_new_user_signups_cap
  )

  if group.namespace_settings
    group.namespace_settings.attributes = settings_params
  else
    group.build_namespace_settings(settings_params)
  end
end