Repository navigation
[PAI-2149] feat: manage custom roles and permission schemes on the v2 client #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1d20d76
b0e2e6e
ff4ca9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| import { Page } from "../../models/v2/common"; | ||
| import { PermissionScheme } from "../../models/v2/PermissionScheme"; | ||
| import { | ||
| CreatePermissionScheme, | ||
| PermissionScheme, | ||
| PermissionSchemeImpact, | ||
| UpdatePermissionScheme, | ||
| } from "../../models/v2/PermissionScheme"; | ||
| import { FIELDS, ORDER_BY } from "./generated/constants"; | ||
| import { OperationId, V2Resource } from "./kernel/resource"; | ||
| import { AnyOperationId, V2Resource } from "./kernel/resource"; | ||
|
|
||
| export type PermissionSchemeField = (typeof FIELDS)["permission_schemes_list"][number]; | ||
| export type PermissionSchemeOrderBy = (typeof ORDER_BY)["permission_schemes_list"][number]; | ||
|
|
@@ -25,11 +30,15 @@ export interface PermissionSchemeFieldsParams { | |
| } | ||
|
|
||
| /** Workspace permission schemes. Read-only: no create/update/delete. */ | ||
| export class PermissionSchemes extends V2Resource<PermissionScheme, never, never> { | ||
| export class PermissionSchemes extends V2Resource<PermissionScheme, CreatePermissionScheme, UpdatePermissionScheme> { | ||
| protected path = "/workspaces/{slug}/permission-schemes/"; | ||
| protected operations: Record<string, OperationId> = { | ||
| protected operations: Record<string, AnyOperationId> = { | ||
| list: "permission_schemes_list", | ||
| retrieve: "permission_schemes_retrieve", | ||
| create: "permission_schemes_create", | ||
| update: "permission_schemes_partial_update", | ||
| delete: "permission_schemes_destroy", | ||
| impact: "permission_schemes_impact", | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -73,4 +82,46 @@ export class PermissionSchemes extends V2Resource<PermissionScheme, never, never | |
| retrieve(slug: string, scheme: string, params?: PermissionSchemeFieldsParams): Promise<PermissionScheme> { | ||
| return this.doRetrieve({ slug, pk: scheme }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| create<F extends Exclude<PermissionSchemeField, "all"> & keyof PermissionScheme>( | ||
| slug: string, | ||
| data: CreatePermissionScheme, | ||
| params: PermissionSchemeFieldsParams & { fields: readonly F[] } | ||
| ): Promise<Pick<PermissionScheme, F | "id">>; | ||
| /** Create a custom scheme; the stored `permissions` include what the given ones need. */ | ||
| create(slug: string, data: CreatePermissionScheme, params?: PermissionSchemeFieldsParams): Promise<PermissionScheme>; | ||
| create(slug: string, data: CreatePermissionScheme, params?: PermissionSchemeFieldsParams): Promise<PermissionScheme> { | ||
| return this.doCreate(data, { slug }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| update<F extends Exclude<PermissionSchemeField, "all"> & keyof PermissionScheme>( | ||
| slug: string, | ||
| scheme: string, | ||
| data: UpdatePermissionScheme, | ||
| params: PermissionSchemeFieldsParams & { fields: readonly F[] } | ||
| ): Promise<Pick<PermissionScheme, F | "id">>; | ||
| update( | ||
| slug: string, | ||
| scheme: string, | ||
| data: UpdatePermissionScheme, | ||
| params?: PermissionSchemeFieldsParams | ||
| ): Promise<PermissionScheme>; | ||
| update( | ||
| slug: string, | ||
| scheme: string, | ||
| data: UpdatePermissionScheme, | ||
| params?: PermissionSchemeFieldsParams | ||
| ): Promise<PermissionScheme> { | ||
| return this.doUpdate(data, { slug, pk: scheme }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| /** Refused (409) while a role composes the scheme. */ | ||
| delete(slug: string, scheme: string): Promise<void> { | ||
| return this.doDelete({ slug, pk: scheme }); | ||
| } | ||
|
|
||
| /** The roles, people and projects a change to this scheme reaches. */ | ||
| impact(slug: string, scheme: string): Promise<PermissionSchemeImpact> { | ||
| return this.doCustomAction<PermissionSchemeImpact>("impact", { method: "GET", pathParams: { slug }, pk: scheme }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject a missing scheme ID before sending the impact request. If a JavaScript caller calls
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| import { MultipleMatchesFoundError, NoMatchFoundError } from "../../errors/PlaneApiError"; | ||
| import { Page } from "../../models/v2/common"; | ||
| import { Role, RoleNamespace } from "../../models/v2/Role"; | ||
| import { FIELDS, ORDER_BY } from "./generated/constants"; | ||
| import { CreateRole, Role, RoleNamespace, UpdateRole } from "../../models/v2/Role"; | ||
| import { EXPAND, FIELDS, ORDER_BY } from "./generated/constants"; | ||
| import { OperationId, V2Resource } from "./kernel/resource"; | ||
|
|
||
| export type RoleField = (typeof FIELDS)["roles_list"][number]; | ||
| export type RoleOrderBy = (typeof ORDER_BY)["roles_list"][number]; | ||
| export type RoleExpand = (typeof EXPAND)["roles_list"][number]; | ||
|
|
||
| export interface ListRolesParams { | ||
| fields?: readonly RoleField[]; | ||
| expand?: readonly RoleExpand[]; | ||
| is_system?: boolean; | ||
| namespace?: RoleNamespace; | ||
| /** | ||
|
|
@@ -34,6 +36,7 @@ export interface ListRolesParams { | |
| /** `?fields=` on a single-row read. */ | ||
| export interface RoleFieldsParams { | ||
| fields?: readonly RoleField[]; | ||
| expand?: readonly RoleExpand[]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep field narrowing when
As per coding guidelines, “Any method that accepts
|
||
| } | ||
|
|
||
| /** `{ roleSlug: "admin" }` -> `{ slug: "admin" }`: the query key the golden declares. */ | ||
|
|
@@ -43,12 +46,18 @@ function withRoleSlug(params?: ListRolesParams): Record<string, unknown> | undef | |
| return roleSlug === undefined ? { ...rest } : { ...rest, slug: roleSlug }; | ||
| } | ||
|
|
||
| /** Workspace roles — system and custom. Read-only: no create/update/delete/upsert (full role CRUD lives only in the app UI). */ | ||
| export class Roles extends V2Resource<Role, never, never> { | ||
| /** | ||
| * Workspace roles — system and custom. Writes reach custom roles only (a system role takes | ||
| * `sort_order` alone), and nobody can grant permissions they don't hold. | ||
| */ | ||
| export class Roles extends V2Resource<Role, CreateRole, UpdateRole> { | ||
| protected path = "/workspaces/{slug}/roles/"; | ||
| protected operations: Record<string, OperationId> = { | ||
| list: "roles_list", | ||
| retrieve: "roles_retrieve", | ||
| create: "roles_create", | ||
| update: "roles_partial_update", | ||
| delete: "roles_destroy", | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -120,4 +129,32 @@ export class Roles extends V2Resource<Role, never, never> { | |
| slug, | ||
| }); | ||
| } | ||
|
|
||
| create<F extends Exclude<RoleField, "all"> & keyof Role>( | ||
| slug: string, | ||
| data: CreateRole, | ||
| params: RoleFieldsParams & { fields: readonly F[] } | ||
| ): Promise<Pick<Role, F | "id">>; | ||
| /** Create a custom role from permission schemes, or clone one with `based_on_slug`. */ | ||
| create(slug: string, data: CreateRole, params?: RoleFieldsParams): Promise<Role>; | ||
| create(slug: string, data: CreateRole, params?: RoleFieldsParams): Promise<Role> { | ||
| return this.doCreate(data, { slug }, params as Record<string, unknown>); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return loaded rows from role writes.
As per coding guidelines, “Every row-returning method routes through Also applies to: 153-153
|
||
| } | ||
|
|
||
| update<F extends Exclude<RoleField, "all"> & keyof Role>( | ||
| slug: string, | ||
| role: string, | ||
| data: UpdateRole, | ||
| params: RoleFieldsParams & { fields: readonly F[] } | ||
| ): Promise<Pick<Role, F | "id">>; | ||
| /** Disabling a role that people or invites hold needs `reassign_to`. */ | ||
| update(slug: string, role: string, data: UpdateRole, params?: RoleFieldsParams): Promise<Role>; | ||
| update(slug: string, role: string, data: UpdateRole, params?: RoleFieldsParams): Promise<Role> { | ||
| return this.doUpdate(data, { slug, pk: role }, params as Record<string, unknown>); | ||
| } | ||
|
|
||
| /** Delete a custom role; `reassignTo` is the role its people and pending invites move to. */ | ||
| delete(slug: string, role: string, reassignTo?: string): Promise<void> { | ||
| return this.doDelete({ slug, pk: role }, reassignTo ? { reassign_to: reassignTo } : undefined); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return loaded rows from permission-scheme writes.
createandupdatereturn the HTTP body directly. A successful response with{ id: "s1" }therefore has no$loadedmetadata. Route both write results throughLoadsNavigableRowsand keep the narrowedfieldsoverloads. Build$loaded.presentfrom the returned row so a projected response still records only the fields it contains.As per coding guidelines, “Every row-returning method routes through
LoadsNavigableRows” and returns a row with$loaded.Also applies to: 115-115
Source: Coding guidelines