debian-mirror-gitlab/app/services/base_container_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.3 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
2021-06-08 01:23:25 +05:30
# Base class, scoped by container (project or group).
#
2021-11-11 11:23:49 +05:30
# New or existing services which only require a project or group container
# should subclass BaseProjectService or BaseGroupService.
2021-06-08 01:23:25 +05:30
#
2021-11-11 11:23:49 +05:30
# If you require a different but specific, non-polymorphic container
# consider creating a new subclass, and update the related comment at
# the top of the original BaseService.
2020-05-24 23:13:21 +05:30
class BaseContainerService
include BaseServiceUtility
2023-05-27 22:25:52 +05:30
include ::Gitlab::Utils::StrongMemoize
2020-05-24 23:13:21 +05:30
2023-05-27 22:25:52 +05:30
attr_accessor :project, :group
2020-05-24 23:13:21 +05:30
attr_reader :container, :current_user, :params
def initialize(container:, current_user: nil, params: {})
2021-04-29 21:17:54 +05:30
@container = container
@current_user = current_user
@params = params.dup
2023-05-27 22:25:52 +05:30
handle_container_type(container)
2020-05-24 23:13:21 +05:30
end
2021-09-04 01:27:46 +05:30
def project_container?
container.is_a?(::Project)
end
def group_container?
container.is_a?(::Group)
end
2022-06-21 17:19:12 +05:30
def namespace_container?
container.is_a?(::Namespace)
end
2023-05-27 22:25:52 +05:30
def project_group
project&.group
end
strong_memoize_attr :project_group
private
def handle_container_type(container)
case container
when Project
@project = container
when Group
@group = container
when Namespaces::ProjectNamespace
@project = container.project
end
end
2020-05-24 23:13:21 +05:30
end