From 5a80487c77f331ddf054825fa0b04d4e32cec179 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 26 Oct 2023 17:54:26 +0100 Subject: [PATCH 1/4] Fix redirect loop when accessing a group as a global builder but not an admin. --- packages/pro | 2 +- .../api/routes/global/tests/groups.spec.ts | 37 ++++++++++++++++++- .../worker/src/tests/TestConfiguration.ts | 17 +++++++-- .../worker/src/tests/structures/groups.ts | 8 ++-- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/packages/pro b/packages/pro index d24c0dc3a3..1911442b93 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit d24c0dc3a30014cbe61860252aa48104cad36376 +Subproject commit 1911442b93670d71edb4d9e19b8e0677bbad6c47 diff --git a/packages/worker/src/api/routes/global/tests/groups.spec.ts b/packages/worker/src/api/routes/global/tests/groups.spec.ts index afeaae952c..8f0739a812 100644 --- a/packages/worker/src/api/routes/global/tests/groups.spec.ts +++ b/packages/worker/src/api/routes/global/tests/groups.spec.ts @@ -1,7 +1,7 @@ import { events } from "@budibase/backend-core" import { generator } from "@budibase/backend-core/tests" import { structures, TestConfiguration, mocks } from "../../../../tests" -import { UserGroup } from "@budibase/types" +import { User, UserGroup } from "@budibase/types" mocks.licenses.useGroups() @@ -231,4 +231,39 @@ describe("/api/global/groups", () => { }) }) }) + + describe("with global builder role", () => { + let builder: User + let group: UserGroup + + beforeAll(async () => { + builder = await config.createUser({ + builder: { global: true }, + admin: { global: false }, + }) + await config.createSession(builder) + + let resp = await config.api.groups.saveGroup( + structures.groups.UserGroup() + ) + group = resp.body as UserGroup + }) + + it("find should return 200", async () => { + await config.withUser(builder, async () => { + await config.api.groups.searchUsers(group._id!, { + emailSearch: `user1`, + }) + }) + }) + + it("update should return 200", async () => { + await config.withUser(builder, async () => { + await config.api.groups.updateGroupUsers(group._id!, { + add: [builder._id!], + remove: [], + }) + }) + }) + }) }) diff --git a/packages/worker/src/tests/TestConfiguration.ts b/packages/worker/src/tests/TestConfiguration.ts index 7e9792c9e3..d4fcbeebd6 100644 --- a/packages/worker/src/tests/TestConfiguration.ts +++ b/packages/worker/src/tests/TestConfiguration.ts @@ -190,6 +190,16 @@ class TestConfiguration { } } + async withUser(user: User, f: () => Promise) { + const oldUser = this.user + this.user = user + try { + await f() + } finally { + this.user = oldUser + } + } + authHeaders(user: User) { const authToken: AuthToken = { userId: user._id!, @@ -257,9 +267,10 @@ class TestConfiguration { }) } - async createUser(user?: User) { - if (!user) { - user = structures.users.user() + async createUser(opts?: Partial) { + let user = structures.users.user() + if (user) { + user = { ...user, ...opts } } const response = await this._req(user, null, controllers.users.save) const body = response as SaveUserResponse diff --git a/packages/worker/src/tests/structures/groups.ts b/packages/worker/src/tests/structures/groups.ts index b0d6bb8fc0..d39dd74eb8 100644 --- a/packages/worker/src/tests/structures/groups.ts +++ b/packages/worker/src/tests/structures/groups.ts @@ -1,8 +1,8 @@ import { generator } from "@budibase/backend-core/tests" import { db } from "@budibase/backend-core" -import { UserGroupRoles } from "@budibase/types" +import { UserGroup as UserGroupType, UserGroupRoles } from "@budibase/types" -export const UserGroup = () => { +export function UserGroup(): UserGroupType { const appsCount = generator.integer({ min: 0, max: 3 }) const roles = Array.from({ length: appsCount }).reduce( (p: UserGroupRoles, v) => { @@ -14,13 +14,11 @@ export const UserGroup = () => { {} ) - let group = { - apps: [], + return { color: generator.color(), icon: generator.word(), name: generator.word(), roles: roles, users: [], } - return group } From 8b9a8bf5f2ddaaa14b52c74aa00329958f7fca6a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 27 Oct 2023 10:46:00 +0100 Subject: [PATCH 2/4] Updating pro reference. --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index d24c0dc3a3..5ed0ee2aca 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit d24c0dc3a30014cbe61860252aa48104cad36376 +Subproject commit 5ed0ee2aca9d754d80cd46bae412b24621afa47e From 09052cb1a6bca50f18dec6578719247c06699dfc Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 27 Oct 2023 10:47:09 +0100 Subject: [PATCH 3/4] Revert "Updating pro reference." This reverts commit 8b9a8bf5f2ddaaa14b52c74aa00329958f7fca6a. --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index 5ed0ee2aca..d24c0dc3a3 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 5ed0ee2aca9d754d80cd46bae412b24621afa47e +Subproject commit d24c0dc3a30014cbe61860252aa48104cad36376 From ae69f9dd920a85a48fcc848bf4de1ee28eac2f6b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 27 Oct 2023 10:47:50 +0100 Subject: [PATCH 4/4] Update pro reference. --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index 1911442b93..5ed0ee2aca 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 1911442b93670d71edb4d9e19b8e0677bbad6c47 +Subproject commit 5ed0ee2aca9d754d80cd46bae412b24621afa47e