From 2c75a512856f887cef594cfc47fb9abc219fb5d0 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 22 May 2023 11:30:36 -0700 Subject: [PATCH] Schema: Move TeamDTO properties out of the resource (#68155) --- .../kinds/core/team/schema-reference.md | 13 ++---- kinds/team/team_kind.cue | 14 ------- packages/grafana-schema/src/index.gen.ts | 3 -- .../src/raw/team/x/team_types.gen.ts | 27 ------------ pkg/kinds/team/team_spec_gen.go | 24 ----------- public/app/types/acl.ts | 16 +++---- public/app/types/teams.ts | 42 ++++++++++++++++--- 7 files changed, 50 insertions(+), 89 deletions(-) diff --git a/docs/sources/developers/kinds/core/team/schema-reference.md b/docs/sources/developers/kinds/core/team/schema-reference.md index f2e9b55bb57..04eab625850 100644 --- a/docs/sources/developers/kinds/core/team/schema-reference.md +++ b/docs/sources/developers/kinds/core/team/schema-reference.md @@ -64,15 +64,10 @@ extraFields is reserved for any fields that are pulled from the API server metad ### Spec -| Property | Type | Required | Default | Description | -|-----------------|--------------------|----------|---------|----------------------------------------------------------| -| `memberCount` | integer | **Yes** | | MemberCount is the number of the team members. | -| `name` | string | **Yes** | | Name of the team. | -| `orgId` | integer | **Yes** | | OrgId is the ID of an organisation the team belongs to. | -| `permission` | integer | **Yes** | | Possible values are: `0`, `1`, `2`, `4`. | -| `accessControl` | map[string]boolean | No | | AccessControl metadata associated with a given resource. | -| `avatarUrl` | string | No | | AvatarUrl is the team's avatar URL. | -| `email` | string | No | | Email of the team. | +| Property | Type | Required | Default | Description | +|----------|--------|----------|---------|--------------------| +| `name` | string | **Yes** | | Name of the team. | +| `email` | string | No | | Email of the team. | ### Status diff --git a/kinds/team/team_kind.cue b/kinds/team/team_kind.cue index d692dac8173..59cbc85c843 100644 --- a/kinds/team/team_kind.cue +++ b/kinds/team/team_kind.cue @@ -10,25 +10,11 @@ lineage: seqs: [ // v0.0 { spec: { - // OrgId is the ID of an organisation the team belongs to. - orgId: int64 @grafanamaturity(ToMetadata="sys") // Name of the team. name: string // Email of the team. email?: string - // AvatarUrl is the team's avatar URL. - avatarUrl?: string @grafanamaturity(MaybeRemove) - // MemberCount is the number of the team members. - memberCount: int64 @grafanamaturity(ToMetadata="kind") - // TODO - it seems it's a team_member.permission, unlikely it should belong to the team kind - permission: #Permission @grafanamaturity(ToMetadata="kind", MaybeRemove) - // AccessControl metadata associated with a given resource. - accessControl?: { - [string]: bool @grafanamaturity(ToMetadata="sys") - } } @cuetsy(kind="interface") - - #Permission: 0 | 1 | 2 | 4 @cuetsy(kind="enum",memberNames="Member|Viewer|Editor|Admin") }, ] }, diff --git a/packages/grafana-schema/src/index.gen.ts b/packages/grafana-schema/src/index.gen.ts index aa647f38e81..8f3939960e5 100644 --- a/packages/grafana-schema/src/index.gen.ts +++ b/packages/grafana-schema/src/index.gen.ts @@ -140,6 +140,3 @@ export { defaultServiceAccount } from './raw/serviceaccount/x/serviceaccount_typ // Raw generated types from Team kind. export type { Team } from './raw/team/x/team_types.gen'; - -// Raw generated enums and default consts from team kind. -export { Permission } from './raw/team/x/team_types.gen'; diff --git a/packages/grafana-schema/src/raw/team/x/team_types.gen.ts b/packages/grafana-schema/src/raw/team/x/team_types.gen.ts index 938d69c4455..fef0a47a874 100644 --- a/packages/grafana-schema/src/raw/team/x/team_types.gen.ts +++ b/packages/grafana-schema/src/raw/team/x/team_types.gen.ts @@ -8,40 +8,13 @@ // // Run 'make gen-cue' from repository root to regenerate. -export enum Permission { - Admin = 4, - Editor = 2, - Member = 0, - Viewer = 1, -} - export interface Team { - /** - * AccessControl metadata associated with a given resource. - */ - accessControl?: Record; - /** - * AvatarUrl is the team's avatar URL. - */ - avatarUrl?: string; /** * Email of the team. */ email?: string; - /** - * MemberCount is the number of the team members. - */ - memberCount: number; /** * Name of the team. */ name: string; - /** - * OrgId is the ID of an organisation the team belongs to. - */ - orgId: number; - /** - * TODO - it seems it's a team_member.permission, unlikely it should belong to the team kind - */ - permission: Permission; } diff --git a/pkg/kinds/team/team_spec_gen.go b/pkg/kinds/team/team_spec_gen.go index 7fc36635200..cfb7e648321 100644 --- a/pkg/kinds/team/team_spec_gen.go +++ b/pkg/kinds/team/team_spec_gen.go @@ -9,35 +9,11 @@ package team -// Defines values for Permission. -const ( - PermissionN0 Permission = 0 - PermissionN1 Permission = 1 - PermissionN2 Permission = 2 - PermissionN4 Permission = 4 -) - -// Permission defines model for Permission. -type Permission int - // Spec defines model for Spec. type Spec struct { - // AccessControl metadata associated with a given resource. - AccessControl map[string]bool `json:"accessControl,omitempty"` - - // AvatarUrl is the team's avatar URL. - AvatarUrl *string `json:"avatarUrl,omitempty"` - // Email of the team. Email *string `json:"email,omitempty"` - // MemberCount is the number of the team members. - MemberCount int64 `json:"memberCount"` - // Name of the team. Name string `json:"name"` - - // OrgId is the ID of an organisation the team belongs to. - OrgId int64 `json:"orgId"` - Permission Permission `json:"permission"` } diff --git a/public/app/types/acl.ts b/public/app/types/acl.ts index 7643349df33..54d8ab4b1d4 100644 --- a/public/app/types/acl.ts +++ b/public/app/types/acl.ts @@ -1,7 +1,9 @@ -import { Permission } from '@grafana/schema'; - -// Alias to an existing type to reduce the number of changes -export { Permission as TeamPermissionLevel }; +export enum TeamPermissionLevel { + Admin = 4, + Editor = 2, + Member = 0, + Viewer = 1, +} export enum OrgRole { Viewer = 'Viewer', @@ -123,15 +125,15 @@ export const dashboardPermissionLevels: DashboardPermissionInfo[] = [ ]; export interface TeamPermissionInfo { - value: Permission; + value: TeamPermissionLevel; label: string; description: string; } export const teamsPermissionLevels: TeamPermissionInfo[] = [ - { value: Permission.Member, label: 'Member', description: 'Is team member' }, + { value: TeamPermissionLevel.Member, label: 'Member', description: 'Is team member' }, { - value: Permission.Admin, + value: TeamPermissionLevel.Admin, label: 'Admin', description: 'Can add/remove permissions, members and delete team.', }, diff --git a/public/app/types/teams.ts b/public/app/types/teams.ts index 2df78c6e231..015f685f093 100644 --- a/public/app/types/teams.ts +++ b/public/app/types/teams.ts @@ -1,11 +1,43 @@ -import { Team as TeamBase } from '@grafana/schema'; +import { Team as TeamDTO } from '@grafana/schema/src/raw/team/x/team_types.gen'; -export interface Team extends TeamBase { +import { TeamPermissionLevel } from './acl'; + +// The team resource +export { TeamDTO }; + +// This is the team resource with permissions and metadata expanded +export interface Team { id: number; // TODO switch to UUID -} -// Represents the data sent via an API to create a team -export interface TeamDTO extends Pick {} + /** + * AccessControl metadata associated with a given resource. + */ + accessControl?: Record; + /** + * AvatarUrl is the team's avatar URL. + */ + avatarUrl?: string; + /** + * Email of the team. + */ + email?: string; + /** + * MemberCount is the number of the team members. + */ + memberCount: number; + /** + * Name of the team. + */ + name: string; + /** + * OrgId is the ID of an organisation the team belongs to. + */ + orgId: number; + /** + * TODO - it seems it's a team_member.permission, unlikely it should belong to the team kind + */ + permission: TeamPermissionLevel; +} export interface TeamMember { userId: number;