Class: Subscriptions::Ci::Jobs::JobProcessed

Inherits:
BaseSubscription
  • Object
show all
Includes:
Gitlab::Graphql::Laziness
Defined in:
app/graphql/subscriptions/ci/jobs/job_processed.rb

Constant Summary

Constants inherited from BaseSubscription

BaseSubscription::UNAUTHORIZED_ERROR_MESSAGE

Instance Method Summary collapse

Methods included from Gitlab::Graphql::Laziness

#defer, #force

Methods inherited from BaseSubscription

#initialize, #subscribe

Constructor Details

This class inherits a constructor from Subscriptions::BaseSubscription

Instance Method Details

#authorized?(project_id:, **_kwargs) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'app/graphql/subscriptions/ci/jobs/job_processed.rb', line 21

def authorized?(project_id:, **_kwargs)
  project = force(GitlabSchema.find_by_gid(project_id))

  unauthorized! unless project
  unauthorized! unless Ability.allowed?(current_user, :read_build, project)

  true
end

#update(project_id:, with_artifacts: false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/graphql/subscriptions/ci/jobs/job_processed.rb', line 30

def update(project_id:, with_artifacts: false)
  processed_job = object

  return NO_UPDATE unless processed_job

  project = force(GitlabSchema.find_by_gid(project_id))

  return NO_UPDATE unless project && processed_job.project_id == project.id
  return NO_UPDATE unless Ability.allowed?(current_user, :read_build, processed_job)

  if processed_job.has_job_artifacts? && with_artifacts
    return processed_job
  elsif !processed_job.has_job_artifacts? && with_artifacts
    return NO_UPDATE
  end

  processed_job
end