Merge pull request #12187 from Budibase/bug/budi-7681-groups-list-infinite-reload-loop
Fix redirect loop when accessing a group as a global builder but not an admin.
This commit is contained in:
commit
a4f345de39
|
@ -1 +1 @@
|
||||||
Subproject commit d24c0dc3a30014cbe61860252aa48104cad36376
|
Subproject commit 5ed0ee2aca9d754d80cd46bae412b24621afa47e
|
|
@ -1,7 +1,7 @@
|
||||||
import { events } from "@budibase/backend-core"
|
import { events } from "@budibase/backend-core"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { structures, TestConfiguration, mocks } from "../../../../tests"
|
import { structures, TestConfiguration, mocks } from "../../../../tests"
|
||||||
import { UserGroup } from "@budibase/types"
|
import { User, UserGroup } from "@budibase/types"
|
||||||
|
|
||||||
mocks.licenses.useGroups()
|
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: [],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -190,6 +190,16 @@ class TestConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async withUser(user: User, f: () => Promise<void>) {
|
||||||
|
const oldUser = this.user
|
||||||
|
this.user = user
|
||||||
|
try {
|
||||||
|
await f()
|
||||||
|
} finally {
|
||||||
|
this.user = oldUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
authHeaders(user: User) {
|
authHeaders(user: User) {
|
||||||
const authToken: AuthToken = {
|
const authToken: AuthToken = {
|
||||||
userId: user._id!,
|
userId: user._id!,
|
||||||
|
@ -257,9 +267,10 @@ class TestConfiguration {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser(user?: User) {
|
async createUser(opts?: Partial<User>) {
|
||||||
if (!user) {
|
let user = structures.users.user()
|
||||||
user = structures.users.user()
|
if (user) {
|
||||||
|
user = { ...user, ...opts }
|
||||||
}
|
}
|
||||||
const response = await this._req(user, null, controllers.users.save)
|
const response = await this._req(user, null, controllers.users.save)
|
||||||
const body = response as SaveUserResponse
|
const body = response as SaveUserResponse
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { db } from "@budibase/backend-core"
|
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 appsCount = generator.integer({ min: 0, max: 3 })
|
||||||
const roles = Array.from({ length: appsCount }).reduce(
|
const roles = Array.from({ length: appsCount }).reduce(
|
||||||
(p: UserGroupRoles, v) => {
|
(p: UserGroupRoles, v) => {
|
||||||
|
@ -14,13 +14,11 @@ export const UserGroup = () => {
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
let group = {
|
return {
|
||||||
apps: [],
|
|
||||||
color: generator.color(),
|
color: generator.color(),
|
||||||
icon: generator.word(),
|
icon: generator.word(),
|
||||||
name: generator.word(),
|
name: generator.word(),
|
||||||
roles: roles,
|
roles: roles,
|
||||||
users: [],
|
users: [],
|
||||||
}
|
}
|
||||||
return group
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue