Allow fields edit
This commit is contained in:
parent
baca156a17
commit
586275ed89
|
@ -1,2 +1,3 @@
|
||||||
export * from "./users"
|
export * from "./users"
|
||||||
export * from "./groups"
|
export * from "./groups"
|
||||||
|
export * from "./shared"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { ScimPatchOperation } from "scim-patch"
|
||||||
|
|
||||||
export interface ScimListResponse<T> {
|
export interface ScimListResponse<T> {
|
||||||
schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"]
|
schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"]
|
||||||
totalResults: number
|
totalResults: number
|
||||||
|
@ -5,3 +7,8 @@ export interface ScimListResponse<T> {
|
||||||
startIndex: number
|
startIndex: number
|
||||||
itemsPerPage: number
|
itemsPerPage: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ScimUpdateRequest {
|
||||||
|
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"]
|
||||||
|
Operations: ScimPatchOperation[]
|
||||||
|
}
|
||||||
|
|
|
@ -52,10 +52,5 @@ export interface ScimCreateUserRequest {
|
||||||
roles: []
|
roles: []
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScimUpdateRequest {
|
|
||||||
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"]
|
|
||||||
Operations: ScimPatchOperation[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ScimUserListResponse
|
export interface ScimUserListResponse
|
||||||
extends ScimListResponse<ScimUserResponse> {}
|
extends ScimListResponse<ScimUserResponse> {}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
import { mocks, structures } from "@budibase/backend-core/tests"
|
import { mocks, structures } from "@budibase/backend-core/tests"
|
||||||
import { ScimCreateGroupRequest, ScimGroupResponse } from "@budibase/types"
|
import {
|
||||||
|
ScimCreateGroupRequest,
|
||||||
|
ScimGroupResponse,
|
||||||
|
ScimUpdateRequest,
|
||||||
|
} from "@budibase/types"
|
||||||
import { TestConfiguration } from "../../../../../tests"
|
import { TestConfiguration } from "../../../../../tests"
|
||||||
|
|
||||||
mocks.licenses.useScimIntegration()
|
mocks.licenses.useScimIntegration()
|
||||||
|
@ -262,4 +266,58 @@ describe("/api/global/scim/v2/groups", () => {
|
||||||
await deleteScimGroup(structures.uuid(), { expect: 404 })
|
await deleteScimGroup(structures.uuid(), { expect: 404 })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("PATCH /api/global/scim/v2/groups/:id", () => {
|
||||||
|
const patchScimGroup = config.api.scimGroupsAPI.patch
|
||||||
|
|
||||||
|
let group: ScimGroupResponse
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const body = createScimCreateGroupRequest()
|
||||||
|
|
||||||
|
group = await config.api.scimGroupsAPI.post({ body })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("unauthorised calls are not allowed", async () => {
|
||||||
|
const response = await patchScimGroup({} as any, {
|
||||||
|
setHeaders: false,
|
||||||
|
expect: 403,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response).toEqual({ message: "Tenant id not set", status: 403 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("cannot be called when feature is disabled", async () => {
|
||||||
|
mocks.licenses.useCloudFree()
|
||||||
|
const response = await patchScimGroup({} as any, { expect: 400 })
|
||||||
|
|
||||||
|
expect(response).toEqual(featureDisabledResponse)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("an existing group can be updated", async () => {
|
||||||
|
const newDisplayName = structures.generator.word()
|
||||||
|
|
||||||
|
const body: ScimUpdateRequest = {
|
||||||
|
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
|
||||||
|
Operations: [
|
||||||
|
{
|
||||||
|
op: "Replace",
|
||||||
|
path: "displayName",
|
||||||
|
value: newDisplayName,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await patchScimGroup({ id: group.id, body })
|
||||||
|
|
||||||
|
const expectedScimGroup: ScimGroupResponse = {
|
||||||
|
...group,
|
||||||
|
displayName: newDisplayName,
|
||||||
|
}
|
||||||
|
expect(response).toEqual(expectedScimGroup)
|
||||||
|
|
||||||
|
const persistedGroup = await config.api.scimGroupsAPI.find(group.id)
|
||||||
|
expect(persistedGroup).toEqual(expectedScimGroup)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {
|
||||||
ScimCreateGroupRequest,
|
ScimCreateGroupRequest,
|
||||||
ScimGroupListResponse,
|
ScimGroupListResponse,
|
||||||
ScimGroupResponse,
|
ScimGroupResponse,
|
||||||
|
ScimUpdateRequest,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import TestConfiguration from "../../TestConfiguration"
|
import TestConfiguration from "../../TestConfiguration"
|
||||||
import { RequestSettings, ScimTestAPI } from "./shared"
|
import { RequestSettings, ScimTestAPI } from "./shared"
|
||||||
|
@ -70,4 +71,24 @@ export class ScimGroupsAPI extends ScimTestAPI {
|
||||||
)
|
)
|
||||||
return res.body as ScimGroupResponse
|
return res.body as ScimGroupResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patch = async (
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
body,
|
||||||
|
}: {
|
||||||
|
id: string
|
||||||
|
body: ScimUpdateRequest
|
||||||
|
},
|
||||||
|
requestSettings?: Partial<RequestSettings>
|
||||||
|
) => {
|
||||||
|
const res = await this.call(
|
||||||
|
`/api/global/scim/v2/groups/${id}`,
|
||||||
|
"patch",
|
||||||
|
requestSettings,
|
||||||
|
body
|
||||||
|
)
|
||||||
|
|
||||||
|
return res.body as ScimGroupResponse
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue