Skip to content

Commit aa68734

Browse files
CopilotKnerio
andcommitted
Add roles field to NamespaceProject and assignedMembers field to NamespaceRole
Co-authored-by: Knerio <96529060+Knerio@users.noreply.github.com>
1 parent 8083526 commit aa68734

File tree

10 files changed

+19
-4
lines changed

10 files changed

+19
-4
lines changed

app/graphql/types/namespace_project_type.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class NamespaceProjectType < Types::BaseObject
1212

1313
field :runtimes, Types::RuntimeType.connection_type, null: false, description: 'Runtimes assigned to this project'
1414

15+
field :roles, Types::NamespaceRoleType.connection_type, null: false,
16+
description: 'Roles assigned to this project',
17+
method: :assigned_roles
18+
1519
field :namespace, Types::NamespaceType, null: false,
1620
description: 'The namespace where this project belongs to'
1721

app/graphql/types/namespace_role_type.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class NamespaceRoleType < BaseObject
1515
field :assigned_projects, Types::NamespaceProjectType.connection_type,
1616
description: 'The projects this role is assigned to'
1717

18+
field :members, Types::NamespaceMemberType.connection_type,
19+
description: 'The members this role is assigned to'
20+
1821
expose_abilities %i[
1922
assign_role_abilities
2023
assign_role_projects
@@ -28,5 +31,9 @@ class NamespaceRoleType < BaseObject
2831
def abilities
2932
object.abilities.map(&:ability)
3033
end
34+
35+
def assigned_members
36+
object.members
37+
end
3138
end
3239
end

app/models/namespace_project.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class NamespaceProject < ApplicationRecord
1111
inverse_of: :project
1212
has_many :assigned_roles, class_name: 'NamespaceRole', through: :role_assignments,
1313
inverse_of: :assigned_projects,
14-
source: :project
14+
source: :role
1515
has_many :flows, class_name: 'Flow', inverse_of: :project
1616

1717
validates :name, presence: true,

app/models/namespace_role.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class NamespaceRole < ApplicationRecord
1010
has_many :assigned_projects, class_name: 'NamespaceProject',
1111
through: :project_assignments,
1212
inverse_of: :assigned_roles,
13-
source: :role
13+
source: :project
1414

1515
scope :applicable_to_project, lambda { |project|
1616
left_joins(:project_assignments)

docs/graphql/object/namespaceproject.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Represents a namespace project
1515
| `name` | [`String!`](../scalar/string.md) | Name of the project |
1616
| `namespace` | [`Namespace!`](../object/namespace.md) | The namespace where this project belongs to |
1717
| `primaryRuntime` | [`Runtime`](../object/runtime.md) | The primary runtime for the project |
18+
| `roles` | [`NamespaceRoleConnection!`](../object/namespaceroleconnection.md) | Roles assigned to this project |
1819
| `runtimes` | [`RuntimeConnection!`](../object/runtimeconnection.md) | Runtimes assigned to this project |
1920
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this NamespaceProject was last updated |
2021
| `userAbilities` | [`NamespaceProjectUserAbilities!`](../object/namespaceprojectuserabilities.md) | Abilities for the current user on this NamespaceProject |

docs/graphql/object/namespacerole.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Represents a namespace role.
1212
| `assignedProjects` | [`NamespaceProjectConnection`](../object/namespaceprojectconnection.md) | The projects this role is assigned to |
1313
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this NamespaceRole was created |
1414
| `id` | [`NamespaceRoleID!`](../scalar/namespaceroleid.md) | Global ID of this NamespaceRole |
15+
| `members` | [`NamespaceMemberConnection`](../object/namespacememberconnection.md) | The members this role is assigned to |
1516
| `name` | [`String!`](../scalar/string.md) | The name of this role |
1617
| `namespace` | [`Namespace`](../object/namespace.md) | The namespace where this role belongs to |
1718
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this NamespaceRole was last updated |

spec/graphql/types/namespace_project_type_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace
1212
primary_runtime
1313
runtimes
14+
roles
1415
flows
1516
flow
1617
user_abilities

spec/graphql/types/namespace_role_type_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
name
1111
abilities
1212
assignedProjects
13+
members
1314
userAbilities
1415
createdAt
1516
updatedAt

spec/models/namespace_project_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
it do
2020
is_expected.to have_many(:assigned_roles).class_name('NamespaceRole')
2121
.through(:role_assignments)
22-
.source(:project)
22+
.source(:role)
2323
.inverse_of(:assigned_projects)
2424
is_expected.to have_many(:flows).class_name('Flow').inverse_of(:project)
2525
end

spec/models/namespace_role_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
it do
1515
is_expected.to have_many(:assigned_projects).class_name('NamespaceProject')
1616
.through(:project_assignments)
17-
.source(:role)
17+
.source(:project)
1818
.inverse_of(:assigned_roles)
1919
end
2020
end

0 commit comments

Comments
 (0)