Merge pull request #10512 from Budibase/budi-6158/handle_empty_group_names
Do not allow empty group names on builder
This commit is contained in:
commit
c288053641
|
@ -9,15 +9,23 @@
|
||||||
|
|
||||||
export let group
|
export let group
|
||||||
export let saveGroup
|
export let saveGroup
|
||||||
|
|
||||||
|
let nameError
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModalContent
|
<ModalContent
|
||||||
onConfirm={() => saveGroup(group)}
|
onConfirm={() => {
|
||||||
|
if (!group.name?.trim()) {
|
||||||
|
nameError = "Group name cannot be empty"
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
saveGroup(group)
|
||||||
|
}}
|
||||||
size="M"
|
size="M"
|
||||||
title={group?._rev ? "Edit group" : "Create group"}
|
title={group?._rev ? "Edit group" : "Create group"}
|
||||||
confirmText="Save"
|
confirmText="Save"
|
||||||
>
|
>
|
||||||
<Input bind:value={group.name} label="Name" />
|
<Input bind:value={group.name} label="Name" error={nameError} />
|
||||||
<div class="modal-format">
|
<div class="modal-format">
|
||||||
<div class="modal-inner">
|
<div class="modal-inner">
|
||||||
<Body size="XS">Icon</Body>
|
<Body size="XS">Icon</Body>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 79bc94b17baba885eb20e72f9abba3ac8b9c0eab
|
Subproject commit 124280d24ff60446c166a005e3cc09c986565bb3
|
|
@ -13,6 +13,7 @@ describe("/api/global/groups", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
jest.resetAllMocks()
|
||||||
mocks.licenses.useGroups()
|
mocks.licenses.useGroups()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -24,6 +25,38 @@ describe("/api/global/groups", () => {
|
||||||
expect(events.group.updated).not.toBeCalled()
|
expect(events.group.updated).not.toBeCalled()
|
||||||
expect(events.group.permissionsEdited).not.toBeCalled()
|
expect(events.group.permissionsEdited).not.toBeCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should not allow undefined names", async () => {
|
||||||
|
const group = { ...structures.groups.UserGroup(), name: undefined } as any
|
||||||
|
const response = await config.api.groups.saveGroup(group, { expect: 400 })
|
||||||
|
expect(JSON.parse(response.text).message).toEqual(
|
||||||
|
'Invalid body - "name" is required'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not allow empty names", async () => {
|
||||||
|
const group = { ...structures.groups.UserGroup(), name: "" }
|
||||||
|
const response = await config.api.groups.saveGroup(group, { expect: 400 })
|
||||||
|
expect(JSON.parse(response.text).message).toEqual(
|
||||||
|
'Invalid body - "name" is not allowed to be empty'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not allow whitespace names", async () => {
|
||||||
|
const group = { ...structures.groups.UserGroup(), name: " " }
|
||||||
|
const response = await config.api.groups.saveGroup(group, { expect: 400 })
|
||||||
|
expect(JSON.parse(response.text).message).toEqual(
|
||||||
|
'Invalid body - "name" is not allowed to be empty'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should trim names", async () => {
|
||||||
|
const group = { ...structures.groups.UserGroup(), name: " group name " }
|
||||||
|
await config.api.groups.saveGroup(group)
|
||||||
|
expect(events.group.created).toBeCalledWith(
|
||||||
|
expect.objectContaining({ name: "group name" })
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
|
|
|
@ -7,13 +7,13 @@ export class GroupsAPI extends TestAPI {
|
||||||
super(config)
|
super(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
saveGroup = (group: UserGroup) => {
|
saveGroup = (group: UserGroup, { expect } = { expect: 200 }) => {
|
||||||
return this.request
|
return this.request
|
||||||
.post(`/api/global/groups`)
|
.post(`/api/global/groups`)
|
||||||
.send(group)
|
.send(group)
|
||||||
.set(this.config.defaultHeaders())
|
.set(this.config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteGroup = (id: string, rev: string) => {
|
deleteGroup = (id: string, rev: string) => {
|
||||||
|
|
Loading…
Reference in New Issue