Class: Organizations::UpdateService

Inherits:
BaseService show all
Defined in:
app/services/organizations/update_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(organization, current_user:, params: {}) ⇒ UpdateService

Returns a new instance of UpdateService.



7
8
9
10
11
12
13
14
15
# File 'app/services/organizations/update_service.rb', line 7

def initialize(organization, current_user:, params: {})
  @organization = organization
  @current_user = current_user
  @params = params.dup

  build_organization_detail_attributes
  # TODO: Remove explicit passing of id once https://github.com/rails/rails/issues/48714 is resolved.
  @params[:organization_detail_attributes][:id] = organization.id
end

Instance Attribute Details

#organizationObject (readonly)

Returns the value of attribute organization.



5
6
7
# File 'app/services/organizations/update_service.rb', line 5

def organization
  @organization
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/organizations/update_service.rb', line 17

def execute
  return error_no_permissions unless allowed?

  if params[:organization_detail_attributes].key?(:avatar) && params[:organization_detail_attributes][:avatar].nil?
    organization.remove_avatar!
  end

  if organization.update(params)
    ServiceResponse.success(payload: { organization: organization })
  else
    error_updating
  end
end