updating license check to search for feature

This commit is contained in:
Peter Clement 2022-07-21 09:52:01 +01:00
parent 2c16089258
commit ea061e6ab1
13 changed files with 58 additions and 31 deletions

View File

@ -8,7 +8,7 @@
"editor.defaultFormatter": "vscode.json-language-features" "editor.defaultFormatter": "vscode.json-language-features"
}, },
"[javascript]": { "[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features" "editor.defaultFormatter": "esbenp.prettier-vscode"
}, },
"debug.javascript.terminalOptions": { "debug.javascript.terminalOptions": {
"skipFiles": [ "skipFiles": [
@ -16,7 +16,4 @@
"<node_internals>/**" "<node_internals>/**"
] ]
}, },
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
} }

View File

@ -69,7 +69,9 @@
$: unlocked = lockedApps?.length === 0 $: unlocked = lockedApps?.length === 0
$: automationErrors = getAutomationErrors(enrichedApps) $: automationErrors = getAutomationErrors(enrichedApps)
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
const enrichApps = (apps, user, sortBy) => { const enrichApps = (apps, user, sortBy) => {
const enrichedApps = apps.map(app => ({ const enrichedApps = apps.map(app => ({
@ -358,7 +360,7 @@
</Button> </Button>
{/if} {/if}
<div class="filter"> <div class="filter">
{#if isProPlan && $groups.length} {#if hasGroupsLicense && $groups.length}
<AccessFilter on:change={accessFilterAction} /> <AccessFilter on:change={accessFilterAction} />
{/if} {/if}
<Select <Select

View File

@ -31,7 +31,7 @@
$: page = $pageInfo.page $: page = $pageInfo.page
$: fetchUsers(page, search) $: fetchUsers(page, search)
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)
$: console.log(group.users)
async function addAll() { async function addAll() {
group.users = selectedUsers group.users = selectedUsers
await groups.actions.save(group) await groups.actions.save(group)

View File

@ -15,7 +15,9 @@
import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte" import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte"
import UserGroupsRow from "./_components/UserGroupsRow.svelte" import UserGroupsRow from "./_components/UserGroupsRow.svelte"
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
let modal let modal
let group = { let group = {
@ -45,7 +47,9 @@
onMount(async () => { onMount(async () => {
try { try {
await groups.actions.init() if (hasGroupsLicense) {
await groups.actions.init()
}
} catch (error) { } catch (error) {
notifications.error("Error getting User groups") notifications.error("Error getting User groups")
} }
@ -56,7 +60,7 @@
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<div style="display: flex;"> <div style="display: flex;">
<Heading size="M">User groups</Heading> <Heading size="M">User groups</Heading>
{#if !isProPlan} {#if !hasGroupsLicense}
<Tags> <Tags>
<div class="tags"> <div class="tags">
<div class="tag"> <div class="tag">
@ -71,14 +75,14 @@
<div class="align-buttons"> <div class="align-buttons">
<Button <Button
newStyles newStyles
icon={isProPlan ? "UserGroup" : ""} icon={hasGroupsLicense ? "UserGroup" : ""}
cta={isProPlan} cta={hasGroupsLicense}
on:click={isProPlan on:click={hasGroupsLicense
? () => modal.show() ? () => modal.show()
: window.open("https://budibase.com/pricing/", "_blank")} : window.open("https://budibase.com/pricing/", "_blank")}
>{isProPlan ? "Create user group" : "Upgrade Account"}</Button >{hasGroupsLicense ? "Create user group" : "Upgrade Account"}</Button
> >
{#if !isProPlan} {#if !hasGroupsLicense}
<Button <Button
newStyles newStyles
secondary secondary
@ -89,7 +93,7 @@
{/if} {/if}
</div> </div>
{#if isProPlan} {#if hasGroupsLicense}
<div class="groupTable"> <div class="groupTable">
{#each $groups as group} {#each $groups as group}
<div> <div>

View File

@ -41,7 +41,9 @@
let allAppList = [] let allAppList = []
$: user = users.get(userId) $: user = users.get(userId)
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
$: allAppList = $apps $: allAppList = $apps
.filter(x => { .filter(x => {
@ -70,7 +72,6 @@
selectedGroups && selectedGroups &&
group?.name?.toLowerCase().includes(searchTerm.toLowerCase()) group?.name?.toLowerCase().includes(searchTerm.toLowerCase())
) )
$: console.log($groups)
$: userGroups = $groups.filter(x => { $: userGroups = $groups.filter(x => {
return x.users?.find(y => { return x.users?.find(y => {
return y._id === userId return y._id === userId
@ -236,7 +237,7 @@
</div> </div>
</Layout> </Layout>
{#if isProPlan} {#if hasGroupsLicense}
<!-- User groups --> <!-- User groups -->
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<div class="tableTitle"> <div class="tableTitle">

View File

@ -15,7 +15,9 @@
let disabled let disabled
let userGroups = [] let userGroups = []
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
$: userData = [ $: userData = [
{ {
@ -65,7 +67,7 @@
</div> </div>
</Layout> </Layout>
{#if isProPlan} {#if hasGroupsLicense}
<Multiselect <Multiselect
bind:value={userGroups} bind:value={userGroups}
placeholder="Select User Groups" placeholder="Select User Groups"

View File

@ -22,7 +22,9 @@
let usersRole = null let usersRole = null
$: invalidEmails = [] $: invalidEmails = []
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
const validEmails = userEmails => { const validEmails = userEmails => {
for (const email of userEmails) { for (const email of userEmails) {
@ -87,7 +89,7 @@
options={Constants.BuilderRoleDescriptions} options={Constants.BuilderRoleDescriptions}
/> />
{#if isProPlan} {#if hasGroupsLicense}
<Multiselect <Multiselect
bind:value={userGroups} bind:value={userGroups}
placeholder="Select User Groups" placeholder="Select User Groups"

View File

@ -64,7 +64,9 @@
{ column: "role", component: RoleTableRenderer }, { column: "role", component: RoleTableRenderer },
] ]
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
$: schema = { $: schema = {
name: {}, name: {},
@ -73,7 +75,7 @@
noPropagation: true, noPropagation: true,
sortable: false, sortable: false,
}, },
...(isProPlan && { ...(hasGroupsLicense && {
userGroups: { sortable: false, displayName: "User groups" }, userGroups: { sortable: false, displayName: "User groups" },
}), }),
apps: { width: "120px" }, apps: { width: "120px" },

View File

@ -31,7 +31,9 @@
$: page = $pageInfo.page $: page = $pageInfo.page
$: fetchUsers(page, search) $: fetchUsers(page, search)
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
$: appUsers = $: appUsers =
$users.data?.filter(x => { $users.data?.filter(x => {
@ -158,7 +160,7 @@
> >
</div> </div>
</div> </div>
{#if isProPlan && appGroups.length} {#if hasGroupsLicense && appGroups.length}
<List title="User Groups"> <List title="User Groups">
{#each appGroups as group} {#each appGroups as group}
<ListItem <ListItem

View File

@ -1,5 +1,7 @@
import { writable } from "svelte/store" import { writable, get } from "svelte/store"
import { API } from "api" import { API } from "api"
import { auth } from "stores/portal"
import { Constants } from "@budibase/frontend-core"
export function createGroupsStore() { export function createGroupsStore() {
const DEFAULT_CONFIG = { const DEFAULT_CONFIG = {
@ -15,8 +17,14 @@ export function createGroupsStore() {
const actions = { const actions = {
init: async () => { init: async () => {
const users = await API.getGroups() // only init if these is a groups license, just to be sure but the feature will be blocked
store.set(users) // on the backend anyway
if (
get(auth).user.license.features.includes(Constants.Features.USER_GROUPS)
) {
const users = await API.getGroups()
store.set(users)
}
}, },
save: async group => { save: async group => {

View File

@ -99,6 +99,10 @@ export const PlanType = {
*/ */
export const ApiVersion = "1" export const ApiVersion = "1"
export const Features = {
USER_GROUPS: "userGroups",
}
// Role IDs // Role IDs
export const Roles = { export const Roles = {
ADMIN: "ADMIN", ADMIN: "ADMIN",

View File

@ -33,6 +33,7 @@ describe("/users", () => {
.expect(200) .expect(200)
expect(res.body.length).toBe(3) expect(res.body.length).toBe(3)
console.debug('test: ' + JSON.stringify(res.body))
expect(res.body.find(u => u._id === `ro_ta_users_us_uuidx`)).toBeDefined() expect(res.body.find(u => u._id === `ro_ta_users_us_uuidx`)).toBeDefined()
expect(res.body.find(u => u._id === `ro_ta_users_us_uuidy`)).toBeDefined() expect(res.body.find(u => u._id === `ro_ta_users_us_uuidy`)).toBeDefined()
}) })

View File

@ -11,7 +11,9 @@ const tenantsRoutes = require("./system/tenants")
const statusRoutes = require("./system/status") const statusRoutes = require("./system/status")
const selfRoutes = require("./global/self") const selfRoutes = require("./global/self")
const licenseRoutes = require("./global/license") const licenseRoutes = require("./global/license")
const userGroupRoutes = require("./global/groups") const { api } = require("@budibase/pro")
let userGroupRoutes = api.groups
exports.routes = [ exports.routes = [
configRoutes, configRoutes,
userRoutes, userRoutes,