mirror of https://github.com/Budibase/budibase.git
17 changed files with 425 additions and 207 deletions
@ -0,0 +1,58 @@ |
|||
<script> |
|||
import { |
|||
ColorPicker, |
|||
Body, |
|||
ModalContent, |
|||
Input, |
|||
IconPicker, |
|||
} from "@budibase/bbui" |
|||
|
|||
export let group |
|||
export let saveGroup |
|||
</script> |
|||
|
|||
<ModalContent |
|||
onConfirm={() => saveGroup(group)} |
|||
size="M" |
|||
title="Create User Group" |
|||
confirmText="Save" |
|||
> |
|||
<Input bind:value={group.name} label="Team name" /> |
|||
<div class="modal-format"> |
|||
<div class="modal-inner"> |
|||
<Body size="XS">Icon</Body> |
|||
<div class="modal-spacing"> |
|||
<IconPicker |
|||
on:change={e => (group.icon = e.detail)} |
|||
bind:value={group.icon} |
|||
/> |
|||
</div> |
|||
</div> |
|||
<div class="modal-inner"> |
|||
<Body size="XS">Color</Body> |
|||
<div class="modal-spacing"> |
|||
<ColorPicker |
|||
bind:value={group.color} |
|||
on:change={e => (group.color = e.detail)} |
|||
/> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</ModalContent> |
|||
|
|||
<style> |
|||
.modal-format { |
|||
display: flex; |
|||
justify-content: space-between; |
|||
width: 40%; |
|||
} |
|||
|
|||
.modal-inner { |
|||
display: flex; |
|||
align-items: center; |
|||
} |
|||
|
|||
.modal-spacing { |
|||
margin-left: var(--spacing-l); |
|||
} |
|||
</style> |
|||
@ -0,0 +1,58 @@ |
|||
<script> |
|||
import { Icon, Body, StatusLight } from "@budibase/bbui" |
|||
|
|||
export let app |
|||
</script> |
|||
|
|||
<div class="title"> |
|||
<div class="name" style="display: flex; margin-left: var(--spacing-xl)"> |
|||
<div class="app-icon" style="color: {app.icon?.color || ''}"> |
|||
<Icon size="XL" name={app.icon?.name || "Apps"} /> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="desktop"> |
|||
<div style="display: flex; align-items: center;"> |
|||
<Body size="M">{app.name}</Body> |
|||
<div style="opacity: 0.5; margin: var(--spacing-xs) 0 0 var(--spacing-m)"> |
|||
<Body size="XS">{app.access}</Body> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div class="desktop" /> |
|||
<div |
|||
style="display: flex; align-items: baseline; margin-right: var(--spacing-xl);" |
|||
> |
|||
<StatusLight purple /> |
|||
<Body size="XS">{app.access}</Body> |
|||
</div> |
|||
|
|||
<style> |
|||
.name { |
|||
grid-gap: var(--spacing-xl); |
|||
grid-template-columns: 75px 75px; |
|||
align-items: center; |
|||
} |
|||
|
|||
.name { |
|||
text-decoration: none; |
|||
overflow: hidden; |
|||
} |
|||
.name :global(.spectrum-Heading) { |
|||
overflow: hidden; |
|||
white-space: nowrap; |
|||
text-overflow: ellipsis; |
|||
margin-left: calc(1.5 * var(--spacing-xl)); |
|||
} |
|||
.title :global(h1:hover) { |
|||
color: var(--spectrum-global-color-blue-600); |
|||
cursor: pointer; |
|||
transition: color 130ms ease; |
|||
} |
|||
|
|||
@media (max-width: 640px) { |
|||
.desktop { |
|||
display: none !important; |
|||
} |
|||
} |
|||
</style> |
|||
@ -1,24 +1,46 @@ |
|||
import { writable } from "svelte/store" |
|||
import { API } from "api" |
|||
import { update } from "lodash" |
|||
|
|||
export function createGroupsStore() { |
|||
const { subscribe, set } = writable([]) |
|||
const store = writable([]) |
|||
|
|||
async function init() { |
|||
const users = await API.getGroups() |
|||
set(users) |
|||
} |
|||
const actions = { |
|||
init: async () => { |
|||
const users = await API.getGroups() |
|||
store.set(users) |
|||
}, |
|||
|
|||
async function save(data) { |
|||
await API.saveGroup(data) |
|||
} |
|||
save: async group => { |
|||
const response = await API.saveGroup(group) |
|||
group._id = response._id |
|||
group._rev = response._rev |
|||
store.update(state => { |
|||
const currentIdx = state.findIndex(gr => gr._id === response._id) |
|||
if (currentIdx >= 0) { |
|||
state.splice(currentIdx, 1, group) |
|||
} else { |
|||
state.push(group) |
|||
} |
|||
return state |
|||
}) |
|||
}, |
|||
|
|||
return { |
|||
subscribe, |
|||
init, |
|||
save, |
|||
} |
|||
delete: async group => { |
|||
await API.deleteGroup({ |
|||
id: group._id, |
|||
rev: group._rev, |
|||
}) |
|||
store.update(state => { |
|||
state = state.filter(state => state._id !== group._id) |
|||
return state |
|||
}) |
|||
}, |
|||
} |
|||
|
|||
return { |
|||
subscribe: store.subscribe, |
|||
actions, |
|||
} |
|||
} |
|||
|
|||
export const groups = createGroupsStore() |
|||
|
|||
@ -1,18 +1,40 @@ |
|||
export const buildGroupsEndpoints = API => ({ |
|||
/** |
|||
* Creates or updates a user in the current tenant. |
|||
* @param user the new user to create |
|||
*/ |
|||
saveGroup: async group => { |
|||
return await API.post({ |
|||
url: "/api/global/groups", |
|||
body: group, |
|||
}) |
|||
}, |
|||
getGroups: async () => { |
|||
return await API.get({ |
|||
url: "/api/global/groups", |
|||
}) |
|||
/** |
|||
* Creates a user group. |
|||
* @param user the new group to create |
|||
*/ |
|||
saveGroup: async group => { |
|||
return await API.post({ |
|||
url: "/api/global/groups", |
|||
body: group, |
|||
}) |
|||
}, |
|||
/** |
|||
* Gets all of the user groups |
|||
*/ |
|||
getGroups: async () => { |
|||
return await API.get({ |
|||
url: "/api/global/groups", |
|||
}) |
|||
}, |
|||
|
|||
} |
|||
/** |
|||
* Gets a group by ID |
|||
*/ |
|||
getGroup: async id => { |
|||
return await API.get({ |
|||
url: `/api/global/groups/${id}`, |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* Deletes a user group |
|||
* @param id the id of the config to delete |
|||
* @param rev the revision of the config to delete |
|||
*/ |
|||
deleteGroup: async ({ id, rev }) => { |
|||
return await API.delete({ |
|||
url: `/api/global/groups/${id}/${rev}`, |
|||
}) |
|||
}, |
|||
}) |
|||
|
|||
@ -1,58 +0,0 @@ |
|||
const { |
|||
generateUserGroupID, |
|||
getUserGroupsParams |
|||
} = require("@budibase/backend-core/db") |
|||
const { Configs } = require("../../../constants") |
|||
const email = require("../../../utilities/email") |
|||
const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy") |
|||
const env = require("../../../environment") |
|||
const { |
|||
withCache, |
|||
CacheKeys, |
|||
bustCache, |
|||
} = require("@budibase/backend-core/cache") |
|||
|
|||
|
|||
exports.save = async function (ctx) { |
|||
const db = getGlobalDB() |
|||
|
|||
// Config does not exist yet
|
|||
if (!ctx.request.body._id) { |
|||
ctx.request.body._id = generateUserGroupID(ctx.request.body.name) |
|||
} |
|||
|
|||
try { |
|||
const response = await db.put(ctx.request.body) |
|||
ctx.body = { |
|||
_id: response.id, |
|||
_rev: response.rev, |
|||
} |
|||
} catch (err) { |
|||
ctx.throw(400, err) |
|||
} |
|||
} |
|||
|
|||
exports.fetch = async function (ctx) { |
|||
const db = getGlobalDB() |
|||
console.log('in here') |
|||
const response = await db.allDocs( |
|||
getUserGroupsParams(null, { |
|||
include_docs: true, |
|||
}) |
|||
) |
|||
ctx.body = response.rows.map(row => row.doc) |
|||
|
|||
} |
|||
|
|||
|
|||
exports.destroy = async function (ctx) { |
|||
const db = getGlobalDB() |
|||
const { id, rev } = ctx.params |
|||
|
|||
try { |
|||
await db.remove(id, rev) |
|||
ctx.body = { message: "Group deleted successfully" } |
|||
} catch (err) { |
|||
ctx.throw(err.status, err) |
|||
} |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
const { |
|||
generateUserGroupID, |
|||
getUserGroupsParams, |
|||
} = require("@budibase/backend-core/db") |
|||
const { Configs } = require("../../../constants") |
|||
const email = require("../../../utilities/email") |
|||
const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy") |
|||
const env = require("../../../environment") |
|||
const { |
|||
withCache, |
|||
CacheKeys, |
|||
bustCache, |
|||
} = require("@budibase/backend-core/cache") |
|||
|
|||
exports.save = async function (ctx: any) { |
|||
const db = getGlobalDB() |
|||
|
|||
// Config does not exist yet
|
|||
if (!ctx.request.body._id) { |
|||
ctx.request.body._id = generateUserGroupID(ctx.request.body.name) |
|||
} |
|||
|
|||
try { |
|||
const response = await db.put(ctx.request.body) |
|||
ctx.body = { |
|||
_id: response.id, |
|||
_rev: response.rev, |
|||
} |
|||
} catch (err) { |
|||
ctx.throw(400, err) |
|||
} |
|||
} |
|||
|
|||
exports.fetch = async function (ctx: any) { |
|||
const db = getGlobalDB() |
|||
const response = await db.allDocs( |
|||
getUserGroupsParams(null, { |
|||
include_docs: true, |
|||
}) |
|||
) |
|||
ctx.body = response.rows.map((row: any) => row.doc) |
|||
} |
|||
|
|||
exports.destroy = async function (ctx: any) { |
|||
const db = getGlobalDB() |
|||
const { id, rev } = ctx.params |
|||
|
|||
try { |
|||
await db.remove(id, rev) |
|||
ctx.body = { message: "Group deleted successfully" } |
|||
} catch (err: any) { |
|||
ctx.throw(err.status, err) |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Gets a group by ID from the global database. |
|||
*/ |
|||
exports.find = async function (ctx: any) { |
|||
const db = getGlobalDB() |
|||
try { |
|||
ctx.body = await db.get(ctx.params.id) |
|||
} catch (err: any) { |
|||
ctx.throw(err.status, err) |
|||
} |
|||
} |
|||
Loading…
Reference in new issue