Commit 12b3e253 authored by Patrick Bajao's avatar Patrick Bajao

Merge branch '2256-add-organizations-to-graphql' into 'master'

Add group organizations query to GraphQL

See merge request gitlab-org/gitlab!69318
parents 522f7cd4 b0e0e336
# frozen_string_literal: true
module Types
module CustomerRelations
class OrganizationType < BaseObject
graphql_name 'CustomerRelationsOrganization'
authorize :read_organization
field :id,
GraphQL::Types::ID,
null: false,
description: 'Internal ID of the organization.'
field :name,
GraphQL::Types::String,
null: true,
description: 'Name of the organization.'
field :default_rate,
GraphQL::Types::Float,
null: true,
description: 'Standard billing rate for the organization.'
field :description,
GraphQL::Types::String,
null: true,
description: 'Description or notes for the organization.'
field :created_at,
Types::TimeType,
null: true,
description: 'Timestamp the organization was created.'
field :updated_at,
Types::TimeType,
null: true,
description: 'Timestamp the organization was last updated.'
end
end
end
......@@ -190,6 +190,10 @@ module Types
resolver: Resolvers::Ci::GroupRunnersResolver,
description: "Find runners visible to the current user."
field :organizations, Types::CustomerRelations::OrganizationType.connection_type,
null: true,
description: "Find organizations of this group."
def avatar_url
object.avatar_url(only_path: false)
end
......
......@@ -739,6 +739,10 @@ class Group < Namespace
Feature.enabled?(:cached_issues_state_count, self, default_enabled: :yaml)
end
def organizations
::CustomerRelations::Organization.where(group_id: self.id)
end
private
def max_member_access(user_ids)
......
# frozen_string_literal: true
module CustomerRelations
class OrganizationPolicy < BasePolicy
delegate { @subject.group }
end
end
......@@ -112,6 +112,7 @@ class GroupPolicy < BasePolicy
enable :read_group_member
enable :read_custom_emoji
enable :read_counts
enable :read_organization
end
rule { ~public_group & ~has_access }.prevent :read_counts
......
......@@ -5316,6 +5316,29 @@ The edge type for [`CustomEmoji`](#customemoji).
| <a id="customemojiedgecursor"></a>`cursor` | [`String!`](#string) | A cursor for use in pagination. |
| <a id="customemojiedgenode"></a>`node` | [`CustomEmoji`](#customemoji) | The item at the end of the edge. |
#### `CustomerRelationsOrganizationConnection`
The connection type for [`CustomerRelationsOrganization`](#customerrelationsorganization).
##### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="customerrelationsorganizationconnectionedges"></a>`edges` | [`[CustomerRelationsOrganizationEdge]`](#customerrelationsorganizationedge) | A list of edges. |
| <a id="customerrelationsorganizationconnectionnodes"></a>`nodes` | [`[CustomerRelationsOrganization]`](#customerrelationsorganization) | A list of nodes. |
| <a id="customerrelationsorganizationconnectionpageinfo"></a>`pageInfo` | [`PageInfo!`](#pageinfo) | Information to aid in pagination. |
#### `CustomerRelationsOrganizationEdge`
The edge type for [`CustomerRelationsOrganization`](#customerrelationsorganization).
##### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="customerrelationsorganizationedgecursor"></a>`cursor` | [`String!`](#string) | A cursor for use in pagination. |
| <a id="customerrelationsorganizationedgenode"></a>`node` | [`CustomerRelationsOrganization`](#customerrelationsorganization) | The item at the end of the edge. |
#### `DastProfileConnection`
The connection type for [`DastProfile`](#dastprofile).
......@@ -8519,6 +8542,19 @@ A custom emoji uploaded by user.
| <a id="customemojiname"></a>`name` | [`String!`](#string) | Name of the emoji. |
| <a id="customemojiurl"></a>`url` | [`String!`](#string) | Link to file of the emoji. |
### `CustomerRelationsOrganization`
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="customerrelationsorganizationcreatedat"></a>`createdAt` | [`Time`](#time) | Timestamp the organization was created. |
| <a id="customerrelationsorganizationdefaultrate"></a>`defaultRate` | [`Float`](#float) | Standard billing rate for the organization. |
| <a id="customerrelationsorganizationdescription"></a>`description` | [`String`](#string) | Description or notes for the organization. |
| <a id="customerrelationsorganizationid"></a>`id` | [`ID!`](#id) | Internal ID of the organization. |
| <a id="customerrelationsorganizationname"></a>`name` | [`String`](#string) | Name of the organization. |
| <a id="customerrelationsorganizationupdatedat"></a>`updatedAt` | [`Time`](#time) | Timestamp the organization was last updated. |
### `DastProfile`
Represents a DAST Profile.
......@@ -9738,6 +9774,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="grouplfsenabled"></a>`lfsEnabled` | [`Boolean`](#boolean) | Indicates if Large File Storage (LFS) is enabled for namespace. |
| <a id="groupmentionsdisabled"></a>`mentionsDisabled` | [`Boolean`](#boolean) | Indicates if a group is disabled from getting mentioned. |
| <a id="groupname"></a>`name` | [`String!`](#string) | Name of the namespace. |
| <a id="grouporganizations"></a>`organizations` | [`CustomerRelationsOrganizationConnection`](#customerrelationsorganizationconnection) | Find organizations of this group. (see [Connections](#connections)) |
| <a id="grouppackagesettings"></a>`packageSettings` | [`PackageSettings`](#packagesettings) | Package settings for the namespace. |
| <a id="groupparent"></a>`parent` | [`Group`](#group) | Parent group. |
| <a id="grouppath"></a>`path` | [`String!`](#string) | Path of the namespace. |
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['CustomerRelationsOrganization'] do
let(:fields) { %i[id name default_rate description created_at updated_at] }
it { expect(described_class.graphql_name).to eq('CustomerRelationsOrganization') }
it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class).to require_graphql_authorizations(:read_organization) }
end
......@@ -21,7 +21,7 @@ RSpec.describe GitlabSchema.types['Group'] do
packages dependency_proxy_setting dependency_proxy_manifests
dependency_proxy_blobs dependency_proxy_image_count
dependency_proxy_blob_count dependency_proxy_total_size
shared_runners_setting timelogs
shared_runners_setting timelogs organizations
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
......@@ -2628,6 +2628,16 @@ RSpec.describe Group do
end
end
describe '.organizations' do
it 'returns organizations belonging to the group' do
organization1 = create(:organization, group: group)
create(:organization)
organization3 = create(:organization, group: group)
expect(group.organizations).to contain_exactly(organization1, organization3)
end
end
describe '#to_ability_name' do
it 'returns group' do
group = build(:group)
......
......@@ -11,6 +11,7 @@ RSpec.describe GroupPolicy do
it do
expect_allowed(:read_group)
expect_allowed(:read_organization)
expect_allowed(:read_counts)
expect_allowed(*read_group_permissions)
expect_disallowed(:upload_file)
......@@ -31,6 +32,7 @@ RSpec.describe GroupPolicy do
end
it { expect_disallowed(:read_group) }
it { expect_disallowed(:read_organization) }
it { expect_disallowed(:read_counts) }
it { expect_disallowed(*read_group_permissions) }
end
......@@ -44,6 +46,7 @@ RSpec.describe GroupPolicy do
end
it { expect_disallowed(:read_group) }
it { expect_disallowed(:read_organization) }
it { expect_disallowed(:read_counts) }
it { expect_disallowed(*read_group_permissions) }
end
......@@ -899,6 +902,7 @@ RSpec.describe GroupPolicy do
it { is_expected.to be_allowed(:read_package) }
it { is_expected.to be_allowed(:read_group) }
it { is_expected.to be_allowed(:read_organization) }
it { is_expected.to be_disallowed(:create_package) }
end
......@@ -908,6 +912,7 @@ RSpec.describe GroupPolicy do
it { is_expected.to be_allowed(:create_package) }
it { is_expected.to be_allowed(:read_package) }
it { is_expected.to be_allowed(:read_group) }
it { is_expected.to be_allowed(:read_organization) }
it { is_expected.to be_disallowed(:destroy_package) }
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment