Merge branch 'develop' into budi-6158/paginage-group-users

This commit is contained in:
Adria Navarro 2023-05-10 10:37:38 +02:00
commit ad257366cf
6 changed files with 87 additions and 8 deletions

View File

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

View File

@ -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 64ff0f044f8d80f2feb24331ca4fc0f51197c813 Subproject commit 4d640bfa74945d2e8675af0022fba42c738679f0

View File

@ -15,7 +15,7 @@ import {
} from "@budibase/types" } from "@budibase/types"
import { OAuth2Client } from "google-auth-library" import { OAuth2Client } from "google-auth-library"
import { buildExternalTableId, finaliseExternalTables } from "./utils" import { buildExternalTableId, finaliseExternalTables } from "./utils"
import { GoogleSpreadsheet } from "google-spreadsheet" import { GoogleSpreadsheet, GoogleSpreadsheetRow } from "google-spreadsheet"
import fetch from "node-fetch" import fetch from "node-fetch"
import { configs, HTTPError } from "@budibase/backend-core" import { configs, HTTPError } from "@budibase/backend-core"
import { dataFilters } from "@budibase/shared-core" import { dataFilters } from "@budibase/shared-core"
@ -434,7 +434,20 @@ class GoogleSheetsIntegration implements DatasourcePlus {
try { try {
await this.connect() await this.connect()
const sheet = this.client.sheetsByTitle[query.sheet] 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 filtered = dataFilters.runLuceneQuery(rows, query.filters)
const headerValues = sheet.headerValues const headerValues = sheet.headerValues
let response = [] let response = []

View File

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

View File

@ -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) => {