1
0
Fork 0
mirror of synced 2024-08-18 03:21:29 +12:00

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:
Adria Navarro 2023-05-10 10:23:06 +02:00 committed by GitHub
commit c288053641
4 changed files with 46 additions and 5 deletions

View file

@ -9,15 +9,23 @@
export let group
export let saveGroup
let nameError
</script>
<ModalContent
onConfirm={() => saveGroup(group)}
onConfirm={() => {
if (!group.name?.trim()) {
nameError = "Group name cannot be empty"
return false
}
saveGroup(group)
}}
size="M"
title={group?._rev ? "Edit group" : "Create group"}
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-inner">
<Body size="XS">Icon</Body>

@ -1 +1 @@
Subproject commit 79bc94b17baba885eb20e72f9abba3ac8b9c0eab
Subproject commit 124280d24ff60446c166a005e3cc09c986565bb3

View file

@ -13,6 +13,7 @@ describe("/api/global/groups", () => {
})
beforeEach(async () => {
jest.resetAllMocks()
mocks.licenses.useGroups()
})
@ -24,6 +25,38 @@ describe("/api/global/groups", () => {
expect(events.group.updated).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", () => {

View file

@ -7,13 +7,13 @@ export class GroupsAPI extends TestAPI {
super(config)
}
saveGroup = (group: UserGroup) => {
saveGroup = (group: UserGroup, { expect } = { expect: 200 }) => {
return this.request
.post(`/api/global/groups`)
.send(group)
.set(this.config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
.expect(expect)
}
deleteGroup = (id: string, rev: string) => {