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

Merge branch 'develop' into budi-6158/prevent_duplicated_group_names

# Conflicts:
#	packages/pro
This commit is contained in:
Adria Navarro 2023-05-10 10:34:27 +02:00
commit a80f00c954
5 changed files with 86 additions and 7 deletions

View file

@ -1,5 +1,5 @@
{
"version": "2.6.8-alpha.2",
"version": "2.6.8-alpha.4",
"npmClient": "yarn",
"packages": [
"packages/backend-core",

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>

View file

@ -15,7 +15,7 @@ import {
} from "@budibase/types"
import { OAuth2Client } from "google-auth-library"
import { buildExternalTableId, finaliseExternalTables } from "./utils"
import { GoogleSpreadsheet } from "google-spreadsheet"
import { GoogleSpreadsheet, GoogleSpreadsheetRow } from "google-spreadsheet"
import fetch from "node-fetch"
import { configs, HTTPError } from "@budibase/backend-core"
import { dataFilters } from "@budibase/shared-core"
@ -434,7 +434,20 @@ class GoogleSheetsIntegration implements DatasourcePlus {
try {
await this.connect()
const sheet = this.client.sheetsByTitle[query.sheet]
const rows = await sheet.getRows()
let rows: GoogleSpreadsheetRow[] = []
if (query.paginate) {
const limit = query.paginate.limit || 100
let page: number =
typeof query.paginate.page === "number"
? query.paginate.page
: parseInt(query.paginate.page || "1")
rows = await sheet.getRows({
limit,
offset: (page - 1) * limit,
})
} else {
rows = await sheet.getRows()
}
const filtered = dataFilters.runLuceneQuery(rows, query.filters)
const headerValues = sheet.headerValues
let response = []

View file

@ -13,6 +13,7 @@ describe("/api/global/groups", () => {
})
beforeEach(async () => {
jest.resetAllMocks()
mocks.licenses.useGroups()
})
@ -24,6 +25,63 @@ 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("name max length", () => {
const maxLength = 50
it(`should allow names shorter than ${maxLength} characters`, async () => {
const group = {
...structures.groups.UserGroup(),
name: structures.generator.word({ length: maxLength }),
}
await config.api.groups.saveGroup(group, { expect: 200 })
})
it(`should not allow names longer than ${maxLength} characters`, async () => {
const group = {
...structures.groups.UserGroup(),
name: structures.generator.word({ length: maxLength + 1 }),
}
const response = await config.api.groups.saveGroup(group, {
expect: 400,
})
expect(JSON.parse(response.text).message).toEqual(
'Invalid body - "name" length must be less than or equal to 50 characters long'
)
})
})
})
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) => {