debian-mirror-gitlab/app/graphql/types/group_type.rb

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

284 lines
9.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
module Types
class GroupType < NamespaceType
graphql_name 'Group'
authorize :read_group
expose_permissions Types::PermissionTypes::Group
2021-04-29 21:17:54 +05:30
field :web_url,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::String,
2021-04-29 21:17:54 +05:30
null: false,
2021-03-11 19:13:27 +05:30
description: 'Web URL of the group.'
2019-07-31 22:56:46 +05:30
2021-04-29 21:17:54 +05:30
field :avatar_url,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::String,
2021-04-29 21:17:54 +05:30
null: true,
2021-03-11 19:13:27 +05:30
description: 'Avatar URL of the group.'
2019-07-31 22:56:46 +05:30
2021-04-29 21:17:54 +05:30
field :custom_emoji,
type: Types::CustomEmojiType.connection_type,
null: true,
2021-03-11 19:13:27 +05:30
description: 'Custom emoji within this namespace.',
2022-08-27 11:52:29 +05:30
_deprecated_feature_flag: :custom_emoji
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
field :share_with_group_lock,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Boolean,
2021-04-29 21:17:54 +05:30
null: true,
2021-03-11 19:13:27 +05:30
description: 'Indicates if sharing a project with another group within this group is prevented.'
2020-03-13 15:44:24 +05:30
2021-04-29 21:17:54 +05:30
field :project_creation_level,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::String,
2021-04-29 21:17:54 +05:30
null: true,
method: :project_creation_level_str,
2021-11-11 11:23:49 +05:30
description: 'Permission level required to create projects in the group.'
2021-12-11 22:18:48 +05:30
2021-04-29 21:17:54 +05:30
field :subgroup_creation_level,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::String,
2021-04-29 21:17:54 +05:30
null: true,
method: :subgroup_creation_level_str,
2021-11-11 11:23:49 +05:30
description: 'Permission level required to create subgroups within the group.'
2020-03-13 15:44:24 +05:30
2021-04-29 21:17:54 +05:30
field :require_two_factor_authentication,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Boolean,
2021-04-29 21:17:54 +05:30
null: true,
2021-03-11 19:13:27 +05:30
description: 'Indicates if all users in this group are required to set up two-factor authentication.'
2021-12-11 22:18:48 +05:30
2021-04-29 21:17:54 +05:30
field :two_factor_grace_period,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Int,
2021-04-29 21:17:54 +05:30
null: true,
2021-03-11 19:13:27 +05:30
description: 'Time before two-factor authentication is enforced.'
2020-03-13 15:44:24 +05:30
2021-04-29 21:17:54 +05:30
field :auto_devops_enabled,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Boolean,
2021-04-29 21:17:54 +05:30
null: true,
2021-03-11 19:13:27 +05:30
description: 'Indicates whether Auto DevOps is enabled for all projects within this group.'
2020-03-13 15:44:24 +05:30
2021-04-29 21:17:54 +05:30
field :emails_disabled,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Boolean,
2021-04-29 21:17:54 +05:30
null: true,
2021-03-11 19:13:27 +05:30
description: 'Indicates if a group has email notifications disabled.'
2020-03-13 15:44:24 +05:30
2021-04-29 21:17:54 +05:30
field :mentions_disabled,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Boolean,
2021-04-29 21:17:54 +05:30
null: true,
2021-03-11 19:13:27 +05:30
description: 'Indicates if a group is disabled from getting mentioned.'
2020-03-13 15:44:24 +05:30
2021-04-29 21:17:54 +05:30
field :parent,
type: GroupType,
null: true,
2021-03-11 19:13:27 +05:30
description: 'Parent group.'
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
field :issues,
Types::IssueType.connection_type,
null: true,
2021-03-11 19:13:27 +05:30
description: 'Issues for projects in this group.',
2020-10-24 23:57:45 +05:30
resolver: Resolvers::GroupIssuesResolver
2020-04-22 19:07:51 +05:30
2021-01-03 14:25:43 +05:30
field :merge_requests,
Types::MergeRequestType.connection_type,
null: true,
2021-03-11 19:13:27 +05:30
description: 'Merge requests for projects in this group.',
2021-01-03 14:25:43 +05:30
resolver: Resolvers::GroupMergeRequestsResolver
2021-04-29 21:17:54 +05:30
field :milestones,
2021-03-11 19:13:27 +05:30
description: 'Milestones of the group.',
2022-08-27 11:52:29 +05:30
extras: [:lookahead],
2020-10-24 23:57:45 +05:30
resolver: Resolvers::GroupMilestonesResolver
2020-04-08 14:13:33 +05:30
field :boards,
Types::BoardType.connection_type,
null: true,
2021-03-11 19:13:27 +05:30
description: 'Boards of the group.',
2020-04-08 14:13:33 +05:30
max_page_size: 2000,
resolver: Resolvers::BoardsResolver
2022-04-04 11:22:00 +05:30
field :recent_issue_boards,
Types::BoardType.connection_type,
null: true,
description: 'List of recently visited boards of the group. Maximum size is 4.',
resolver: Resolvers::RecentBoardsResolver
2020-04-08 14:13:33 +05:30
field :board,
Types::BoardType,
null: true,
2021-03-11 19:13:27 +05:30
description: 'A single board of the group.',
2021-01-03 14:25:43 +05:30
resolver: Resolvers::BoardResolver
2020-06-23 00:09:42 +05:30
field :label,
Types::LabelType,
null: true,
2021-11-11 11:23:49 +05:30
description: 'Label available on this group.' do
2021-04-29 21:17:54 +05:30
argument :title,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::String,
2021-04-29 21:17:54 +05:30
required: true,
description: 'Title of the label.'
2020-06-23 00:09:42 +05:30
end
2020-11-24 15:15:51 +05:30
field :group_members,
2021-03-11 19:13:27 +05:30
description: 'A membership of a user within this group.',
2020-11-24 15:15:51 +05:30
resolver: Resolvers::GroupMembersResolver
2021-01-29 00:20:46 +05:30
field :container_repositories,
Types::ContainerRepositoryType.connection_type,
null: true,
2021-03-11 19:13:27 +05:30
description: 'Container repositories of the group.',
2021-01-29 00:20:46 +05:30
resolver: Resolvers::ContainerRepositoriesResolver,
authorize: :read_container_image
2021-04-29 21:17:54 +05:30
field :container_repositories_count,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::Int,
2021-04-29 21:17:54 +05:30
null: false,
2021-03-11 19:13:27 +05:30
description: 'Number of container repositories in the group.'
2021-02-22 17:27:13 +05:30
2021-04-17 20:07:23 +05:30
field :packages,
description: 'Packages of the group.',
resolver: Resolvers::GroupPackagesResolver
2021-11-11 11:23:49 +05:30
field :dependency_proxy_setting,
Types::DependencyProxy::GroupSettingType,
null: true,
description: 'Dependency Proxy settings for the group.'
field :dependency_proxy_manifests,
Types::DependencyProxy::ManifestType.connection_type,
null: true,
description: 'Dependency Proxy manifests.'
field :dependency_proxy_blobs,
Types::DependencyProxy::BlobType.connection_type,
null: true,
description: 'Dependency Proxy blobs.'
field :dependency_proxy_image_count,
GraphQL::Types::Int,
null: false,
description: 'Number of dependency proxy images cached in the group.'
field :dependency_proxy_blob_count,
GraphQL::Types::Int,
null: false,
description: 'Number of dependency proxy blobs cached in the group.'
field :dependency_proxy_total_size,
GraphQL::Types::String,
null: false,
description: 'Total size of the dependency proxy cached images.'
field :dependency_proxy_image_prefix,
GraphQL::Types::String,
null: false,
description: 'Prefix for pulling images when using the dependency proxy.'
field :dependency_proxy_image_ttl_policy,
Types::DependencyProxy::ImageTtlGroupPolicyType,
null: true,
description: 'Dependency proxy TTL policy for the group.'
2020-06-23 00:09:42 +05:30
field :labels,
Types::LabelType.connection_type,
null: true,
2021-03-11 19:13:27 +05:30
description: 'Labels available on this group.',
resolver: Resolvers::GroupLabelsResolver
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
field :timelogs, ::Types::TimelogType.connection_type, null: false,
2022-08-27 11:52:29 +05:30
description: 'Time logged on issues and merge requests in the group and its subgroups.',
extras: [:lookahead],
complexity: 5,
resolver: ::Resolvers::TimelogResolver
2021-04-29 21:17:54 +05:30
2021-10-27 15:23:28 +05:30
field :descendant_groups, Types::GroupType.connection_type,
null: true,
description: 'List of descendant groups of this group.',
complexity: 5,
resolver: Resolvers::GroupsResolver
2022-08-13 15:12:31 +05:30
field :ci_variables,
2022-08-27 11:52:29 +05:30
Types::Ci::GroupVariableType.connection_type,
2022-08-13 15:12:31 +05:30
null: true,
description: "List of the group's CI/CD variables.",
authorize: :admin_group,
method: :variables
2021-11-11 11:23:49 +05:30
field :runners, Types::Ci::RunnerType.connection_type,
null: true,
resolver: Resolvers::Ci::GroupRunnersResolver,
description: "Find runners visible to the current user."
field :organizations, Types::CustomerRelations::OrganizationType.connection_type,
null: true,
2022-07-23 23:45:48 +05:30
description: "Find organizations of this group.",
resolver: Resolvers::Crm::OrganizationsResolver
2021-11-11 11:23:49 +05:30
field :contacts, Types::CustomerRelations::ContactType.connection_type,
null: true,
2022-07-23 23:45:48 +05:30
description: "Find contacts of this group.",
resolver: Resolvers::Crm::ContactsResolver
2021-11-11 11:23:49 +05:30
2022-08-27 11:52:29 +05:30
field :contact_state_counts,
Types::CustomerRelations::ContactStateCountsType,
null: true,
description: 'Counts of contacts by state for the group.',
resolver: Resolvers::Crm::ContactStateCountsResolver
2022-03-02 08:16:31 +05:30
field :work_item_types, Types::WorkItems::TypeType.connection_type,
resolver: Resolvers::WorkItems::TypesResolver,
2022-05-07 20:08:51 +05:30
description: 'Work item types available to the group.' \
' Returns `null` if `work_items` feature flag is disabled.' \
' This flag is disabled by default, because the feature is experimental and is subject to change without notice.'
2022-03-02 08:16:31 +05:30
2022-04-04 11:22:00 +05:30
def label(title:)
BatchLoader::GraphQL.for(title).batch(key: group) do |titles, loader, args|
LabelsFinder
.new(current_user, group: args[:key], title: titles)
.execute
.each { |label| loader.call(label.title, label) }
end
end
2021-02-22 17:27:13 +05:30
def avatar_url
object.avatar_url(only_path: false)
end
def parent
Gitlab::Graphql::Loaders::BatchModelLoader.new(Group, object.parent_id).find
end
def container_repositories_count
group.container_repositories.size
end
2021-12-11 22:18:48 +05:30
def dependency_proxy_manifests
group.dependency_proxy_manifests.order_id_desc
end
2021-11-11 11:23:49 +05:30
def dependency_proxy_image_count
2021-12-11 22:18:48 +05:30
group.dependency_proxy_manifests.size
2021-11-11 11:23:49 +05:30
end
def dependency_proxy_blob_count
2021-12-11 22:18:48 +05:30
group.dependency_proxy_blobs.size
2021-11-11 11:23:49 +05:30
end
def dependency_proxy_total_size
ActiveSupport::NumberHelper.number_to_human_size(
group.dependency_proxy_manifests.sum(:size) + group.dependency_proxy_blobs.sum(:size)
)
end
2021-11-18 22:05:49 +05:30
def dependency_proxy_setting
group.dependency_proxy_setting || group.create_dependency_proxy_setting
end
2020-06-23 00:09:42 +05:30
private
def group
object.respond_to?(:sync) ? object.sync : object
end
2019-07-31 22:56:46 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Types::GroupType.prepend_mod_with('Types::GroupType')