Skip to content

Commit

Permalink
Merge branch 'master' into feat/pick-relationship-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr authored Aug 31, 2024
2 parents e2e49d6 + fc36747 commit 3d1c861
Show file tree
Hide file tree
Showing 27 changed files with 289 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/budibase_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ jobs:
any_commit=$(git log --no-merges $base_commit_excluding_merges...$pro_commit)
if [ -n "$any_commit" ]; then
if [ -n "$any_commit" ] && [ "$base_commit" != "$pro_commit" ]; then
echo $any_commit
echo "An error occurred: <error_message>"
Expand Down
14 changes: 7 additions & 7 deletions examples/nextjs-api-sales/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"

braces@^3.0.1, braces@~3.0.2:
braces@^3.0.3, braces@~3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
Expand Down Expand Up @@ -1201,12 +1201,12 @@ merge2@^1.3.0, merge2@^1.4.1:
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==

micromatch@^4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9"
integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==
version "4.0.8"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202"
integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==
dependencies:
braces "^3.0.1"
picomatch "^2.2.3"
braces "^3.0.3"
picomatch "^2.3.1"

minimatch@^3.0.4, minimatch@^3.1.2:
version "3.1.2"
Expand Down Expand Up @@ -1422,7 +1422,7 @@ picocolors@^1.0.0:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3:
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,6 @@ export class FlagSet<V extends Flag<any>, T extends { [key: string]: V }> {
// default values set correctly and their types flow through the system.
export const flags = new FlagSet({
DEFAULT_VALUES: Flag.boolean(false),
SQS: Flag.boolean(false),
SQS: Flag.boolean(env.isDev()),
[FeatureFlag.ENRICHED_RELATIONSHIPS]: Flag.boolean(false),
})
14 changes: 11 additions & 3 deletions packages/backend-core/src/tenancy/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ export async function saveTenantInfo(tenantInfo: TenantInfo) {
})
}

export async function getTenantInfo(tenantId: string): Promise<TenantInfo> {
const db = getTenantDB(tenantId)
return db.get("tenant_info")
export async function getTenantInfo(
tenantId: string
): Promise<TenantInfo | undefined> {
try {
const db = getTenantDB(tenantId)
const tenantInfo = (await db.get("tenant_info")) as TenantInfo
delete tenantInfo.owner.password
return tenantInfo
} catch {
return undefined
}
}
3 changes: 2 additions & 1 deletion packages/bbui/src/Table/SelectEditRenderer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
export let onEdit
export let allowSelectRows = false
export let allowEditRows = false
export let data
</script>

<div>
{#if allowSelectRows}
{#if allowSelectRows && data.__selectable !== false}
<Checkbox value={selected} />
{/if}
{#if allowEditRows}
Expand Down
12 changes: 11 additions & 1 deletion packages/bbui/src/Table/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
export let showHeaderBorder = true
export let placeholderText = "No rows found"
export let snippets = []
export let defaultSortColumn
export let defaultSortOrder = "Ascending"
const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -162,6 +164,8 @@
}
const sortRows = (rows, sortColumn, sortOrder) => {
sortColumn = sortColumn ?? defaultSortColumn
sortOrder = sortOrder ?? defaultSortOrder
if (!sortColumn || !sortOrder || disableSorting) {
return rows
}
Expand Down Expand Up @@ -259,7 +263,10 @@
if (select) {
// Add any rows which are not already in selected rows
rows.forEach(row => {
if (selectedRows.findIndex(x => x._id === row._id) === -1) {
if (
row.__selectable !== false &&
selectedRows.findIndex(x => x._id === row._id) === -1
) {
selectedRows.push(row)
}
})
Expand Down Expand Up @@ -396,6 +403,9 @@
class:noBorderCheckbox={!showHeaderBorder}
class="spectrum-Table-cell spectrum-Table-cell--divider spectrum-Table-cell--edit"
on:click={e => {
if (row.__selectable === false) {
return
}
toggleSelectRow(row)
e.stopPropagation()
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
let popoverAnchor
let searchTerm = ""
let popover
let user
let user, tenantOwner
let loaded = false
$: internalGroups = $groups?.filter(g => !g?.scimInfo?.isSync)
Expand All @@ -104,6 +104,7 @@
})
})
$: globalRole = users.getUserRole(user)
$: isTenantOwner = tenantOwner?.email && tenantOwner.email === user?.email
const getAvailableApps = (appList, privileged, roles) => {
let availableApps = appList.slice()
Expand Down Expand Up @@ -205,6 +206,7 @@
if (!user?._id) {
$goto("./")
}
tenantOwner = await users.tenantOwner($auth.tenantId)
}
async function toggleFlags(detail) {
Expand Down Expand Up @@ -268,9 +270,11 @@
Force password reset
</MenuItem>
{/if}
<MenuItem on:click={deleteModal.show} icon="Delete">
Delete
</MenuItem>
{#if !isTenantOwner}
<MenuItem on:click={deleteModal.show} icon="Delete">
Delete
</MenuItem>
{/if}
</ActionMenu>
</div>
{/if}
Expand Down Expand Up @@ -310,9 +314,11 @@
<Label size="L">Role</Label>
<Select
placeholder={null}
disabled={!sdk.users.isAdmin($auth.user)}
value={globalRole}
options={Constants.BudibaseRoleOptions}
disabled={!sdk.users.isAdmin($auth.user) || isTenantOwner}
value={isTenantOwner ? "owner" : globalRole}
options={isTenantOwner
? Constants.ExtendedBudibaseRoleOptions
: Constants.BudibaseRoleOptions}
on:change={updateUserRole}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export let row
$: role = Constants.BudibaseRoleOptions.find(
$: role = Constants.ExtendedBudibaseRoleOptions.find(
x => x.value === users.getUserRole(row)
)
$: value = role?.label || "Not available"
Expand Down
23 changes: 20 additions & 3 deletions packages/builder/src/pages/builder/portal/users/users/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
let groupsLoaded = !$licensing.groupsEnabled || $groups?.length
let enrichedUsers = []
let tenantOwner
let createUserModal,
inviteConfirmationModal,
onboardingTypeModal,
Expand All @@ -70,6 +71,7 @@
]
let userData = []
let invitesLoaded = false
let tenantOwnerLoaded = false
let pendingInvites = []
let parsedInvites = []
Expand Down Expand Up @@ -98,8 +100,14 @@
$: pendingSchema = getPendingSchema(schema)
$: userData = []
$: inviteUsersResponse = { successful: [], unsuccessful: [] }
$: {
enrichedUsers = $fetch.rows?.map(user => {
$: setEnrichedUsers($fetch.rows, tenantOwnerLoaded)
const setEnrichedUsers = async rows => {
if (!tenantOwnerLoaded) {
enrichedUsers = []
return
}
enrichedUsers = rows?.map(user => {
let userGroups = []
$groups.forEach(group => {
if (group.users) {
Expand All @@ -110,15 +118,21 @@
})
}
})
user.tenantOwnerEmail = tenantOwner?.email
const role = Constants.ExtendedBudibaseRoleOptions.find(
x => x.value === users.getUserRole(user)
)
return {
...user,
name: user.firstName ? user.firstName + " " + user.lastName : "",
userGroups,
__selectable:
role.value === Constants.BudibaseRoles.Owner ? false : undefined,
apps: [...new Set(Object.keys(user.roles))],
access: role.sortOrder,
}
})
}
const getPendingSchema = tblSchema => {
if (!tblSchema) {
return {}
Expand Down Expand Up @@ -302,6 +316,8 @@
groupsLoaded = true
pendingInvites = await users.getInvites()
invitesLoaded = true
tenantOwner = await users.tenantOwner($auth.tenantId)
tenantOwnerLoaded = true
} catch (error) {
notifications.error("Error fetching user group data")
}
Expand Down Expand Up @@ -376,6 +392,7 @@
allowSelectRows={!readonly}
{customRenderers}
loading={!$fetch.loaded || !groupsLoaded}
defaultSortColumn={"access"}
/>
<div class="pagination">
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/stores/portal/licensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const createLicensingStore = () => {
}, {})
}
const monthlyMetrics = getMetrics(
["dayPasses", "queries", "automations"],
["queries", "automations"],
license.quotas.usage.monthly,
usage.monthly.current
)
Expand Down
10 changes: 9 additions & 1 deletion packages/builder/src/stores/portal/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ export function createUsersStore() {
return await API.removeAppBuilder({ userId, appId })
}

async function getTenantOwner(tenantId) {
const tenantInfo = await API.getTenantInfo({ tenantId })
return tenantInfo?.owner
}

const getUserRole = user => {
if (sdk.users.isAdmin(user)) {
if (user && user.email === user.tenantOwnerEmail) {
return Constants.BudibaseRoles.Owner
} else if (sdk.users.isAdmin(user)) {
return Constants.BudibaseRoles.Admin
} else if (sdk.users.isBuilder(user)) {
return Constants.BudibaseRoles.Developer
Expand Down Expand Up @@ -169,6 +176,7 @@ export function createUsersStore() {
save: refreshUsage(save),
bulkDelete: refreshUsage(bulkDelete),
delete: refreshUsage(del),
tenantOwner: getTenantOwner,
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/frontend-core/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,10 @@ export const buildUserEndpoints = API => ({
url: `/api/global/users/${userId}/app/${appId}/builder`,
})
},

getTenantInfo: async ({ tenantId }) => {
return await API.get({
url: `/api/global/tenant/${tenantId}`,
})
},
})
11 changes: 11 additions & 0 deletions packages/frontend-core/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const BudibaseRoles = {
Developer: "developer",
Creator: "creator",
Admin: "admin",
Owner: "owner",
}

export const BudibaseRoleOptionsOld = [
Expand All @@ -54,18 +55,28 @@ export const BudibaseRoleOptions = [
label: "Account admin",
value: BudibaseRoles.Admin,
subtitle: "Has full access to all apps and settings in your account",
sortOrder: 1,
},
{
label: "Creator",
value: BudibaseRoles.Creator,
subtitle: "Can create and edit apps they have access to",
sortOrder: 2,
},
{
label: "App user",
value: BudibaseRoles.AppUser,
subtitle: "Can only use published apps they have access to",
sortOrder: 3,
},
]
export const ExtendedBudibaseRoleOptions = [
{
label: "Account holder",
value: BudibaseRoles.Owner,
sortOrder: 0,
},
].concat(BudibaseRoleOptions)

export const PlanType = {
FREE: "free",
Expand Down
1 change: 0 additions & 1 deletion packages/server/scripts/dev/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ async function init() {
HTTP_LOGGING: "0",
VERSION: "0.0.0+local",
PASSWORD_MIN_LENGTH: "1",
TENANT_FEATURE_FLAGS: "*:SQS",
}

config = { ...config, ...existingConfig }
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/routes/tests/misc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe("run misc tests", () => {
const rowThree = rows.find(row => row.e === 3)
expect(rowThree.a).toEqual("9")
expect(rowThree.f).toEqual(["Two", "Four"])
expect(rowThree.g).toEqual(null)
expect(rowThree.g).toEqual(undefined)

const rowFour = rows.find(row => row.e === 4)
expect(rowFour.a).toEqual("13")
Expand Down
8 changes: 5 additions & 3 deletions packages/server/src/api/routes/tests/row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ describe.each([
let envCleanup: (() => void) | undefined

beforeAll(async () => {
await withCoreEnv({ TENANT_FEATURE_FLAGS: "*SQS" }, () => config.init())
if (isSqs) {
envCleanup = setCoreEnv({ TENANT_FEATURE_FLAGS: "*SQS" })
await withCoreEnv({ TENANT_FEATURE_FLAGS: "*:SQS" }, () => config.init())
if (isLucene) {
envCleanup = setCoreEnv({ TENANT_FEATURE_FLAGS: "*:!SQS" })
} else if (isSqs) {
envCleanup = setCoreEnv({ TENANT_FEATURE_FLAGS: "*:SQS" })
}

if (dsProvider) {
Expand Down
6 changes: 5 additions & 1 deletion packages/server/src/api/routes/tests/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ describe.each([

beforeAll(async () => {
await withCoreEnv({ TENANT_FEATURE_FLAGS: "*:SQS" }, () => config.init())
if (isSqs) {
if (isLucene) {
envCleanup = setCoreEnv({
TENANT_FEATURE_FLAGS: "*:!SQS",
})
} else if (isSqs) {
envCleanup = setCoreEnv({
TENANT_FEATURE_FLAGS: "*:SQS",
})
Expand Down
Loading

0 comments on commit 3d1c861

Please sign in to comment.