Class: Clusters::Management::ValidateManagementProjectPermissionsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/clusters/management/validate_management_project_permissions_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user = nil) ⇒ ValidateManagementProjectPermissionsService

Returns a new instance of ValidateManagementProjectPermissionsService.


8
9
10
# File 'app/services/clusters/management/validate_management_project_permissions_service.rb', line 8

def initialize(user = nil)
  @current_user = user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


6
7
8
# File 'app/services/clusters/management/validate_management_project_permissions_service.rb', line 6

def current_user
  @current_user
end

Instance Method Details

#execute(cluster, management_project_id) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/clusters/management/validate_management_project_permissions_service.rb', line 12

def execute(cluster, management_project_id)
  if management_project_id.present?
    management_project = management_project_scope(cluster).find_by_id(management_project_id)

    unless management_project && can_admin_pipeline_for_project?(management_project)
      cluster.errors.add(:management_project_id, _('Project does not exist or you don\'t have permission to perform this action'))

      return false
    end
  end

  true
end