Browse Source

Merge branch 'develop' into fix/gui-v2-misc

pull/3051/head
Wing-Kam Wong 2 years ago
parent
commit
a8b194ab33
  1. 26
      packages/nc-gui-v2/components/tabs/auth/UserManagement.vue
  2. 24
      packages/nc-gui-v2/components/tabs/auth/user-management/ShareBase.vue
  3. 39
      packages/nc-gui-v2/components/tabs/auth/user-management/UsersModal.vue
  4. 1
      packages/nc-gui-v2/composables/useUIPermission/rolePermissions.ts
  5. 1
      packages/nc-gui-v2/lang/en.json
  6. 5
      packages/nc-gui-v2/lib/enums.ts
  7. 4
      packages/nc-gui-v2/utils/urlUtils.ts
  8. 7
      packages/nc-gui-v2/utils/userUtils.ts

26
packages/nc-gui-v2/components/tabs/auth/UserManagement.vue

@ -21,6 +21,8 @@ import type { User } from '~/lib/types'
const { $api, $e } = useNuxtApp()
const { project } = useProject()
const { copy } = useClipboard()
const { isUIAllowed } = useUIPermission()
const { dashboardUrl } = $(useDashboard())
let users = $ref<null | User[]>(null)
let selectedUser = $ref<null | User>(null)
@ -88,6 +90,8 @@ const deleteUser = async () => {
notification.error({
message: await extractSdkResponseErrorMsg(e),
})
} finally {
showUserDeleteModal = false
}
$e('a:user:delete')
@ -129,7 +133,7 @@ const resendInvite = async (user: User) => {
const copyInviteUrl = (user: User) => {
if (!user.invite_token) return
const getInviteUrl = (token: string) => `${location.origin}${location.pathname}#/user/authentication/signup/${token}`
const getInviteUrl = (token: string) => `${dashboardUrl}/user/authentication/signup/${token}`
copy(getInviteUrl(user.invite_token))
notification.success({
@ -169,8 +173,8 @@ watchDebounced(searchText, () => loadUsers(), { debounce: 300, maxWait: 600 })
This action will remove this user from this project
</div>
<div class="flex mt-6 justify-center space-x-2">
<a-button @click="showUserDeleteModal = false"> Cancel </a-button>
<a-button type="primary" danger @click="deleteUser"> Confirm </a-button>
<a-button @click="showUserDeleteModal = false"> {{ $t('general.cancel') }} </a-button>
<a-button type="primary" danger @click="deleteUser"> {{ $t('general.confirm') }} </a-button>
</div>
</div>
</a-modal>
@ -190,10 +194,10 @@ watchDebounced(searchText, () => loadUsers(), { debounce: 300, maxWait: 600 })
<div class="text-gray-500">Reload</div>
</div>
</a-button>
<a-button size="middle" @click="onInvite">
<a-button v-if="isUIAllowed('newUser')" size="middle" @click="onInvite">
<div class="flex flex-row justify-center items-center caption capitalize space-x-1">
<MidAccountIcon />
<div>Invite Team</div>
<div>{{ $t('activity.inviteTeam') }}</div>
</div>
</a-button>
</div>
@ -203,15 +207,15 @@ watchDebounced(searchText, () => loadUsers(), { debounce: 300, maxWait: 600 })
<div class="flex flex-row w-4/6 space-x-1 items-center pl-1">
<EmailIcon class="flex text-gray-500 -mt-0.5" />
<div class="text-gray-600 text-xs space-x-1">E-mail</div>
<div class="text-gray-600 text-xs space-x-1">{{ $t('labels.email') }}</div>
</div>
<div class="flex flex-row justify-center w-1/6 space-x-1 items-center pl-1">
<RolesIcon class="flex text-gray-500 -mt-0.5" />
<div class="text-gray-600 text-xs">Role</div>
<div class="text-gray-600 text-xs">{{ $t('objects.role') }}</div>
</div>
<div class="flex flex-row w-1/6 justify-end items-center pl-1">
<div class="text-gray-600 text-xs">Actions</div>
<div class="text-gray-600 text-xs">{{ $t('labels.actions') }}</div>
</div>
</div>
@ -220,14 +224,14 @@ watchDebounced(searchText, () => loadUsers(), { debounce: 300, maxWait: 600 })
{{ user.email }}
</div>
<div class="flex w-1/6 justify-center flex-wrap ml-4">
<div :class="`rounded-full px-2 py-1 bg-[${projectRoleTagColors[user.roles]}]`">
<div class="rounded-full px-2 py-1" :style="{ backgroundColor: projectRoleTagColors[user.roles as String] }">
{{ user.roles }}
</div>
</div>
<div class="flex w-1/6 flex-wrap justify-end">
<a-tooltip v-if="user.project_id" placement="bottom">
<template #title>
<span>Edit user</span>
<span>{{ $t('activity.editUser') }}</span>
</template>
<a-button type="text" class="!rounded-md" @click="onEdit(user)">
<template #icon>
@ -276,7 +280,7 @@ watchDebounced(searchText, () => loadUsers(), { debounce: 300, maxWait: 600 })
<a-menu-item>
<div class="flex flex-row items-center py-1" @click="copyInviteUrl(user)">
<MdiContentCopyIcon class="flex h-[1rem]" />
<div class="text-xs pl-2">Copy invite URL</div>
<div class="text-xs pl-2">{{ $t('activity.copyInviteURL') }}</div>
</div>
</a-menu-item>
</a-menu>

24
packages/nc-gui-v2/components/tabs/auth/user-management/ShareBase.vue

@ -1,7 +1,7 @@
<script setup lang="ts">
import { notification } from 'ant-design-vue'
import { onMounted, useClipboard, useNuxtApp, useProject } from '#imports'
import { dashboardUrl, extractSdkResponseErrorMsg } from '~/utils'
import { extractSdkResponseErrorMsg } from '~/utils'
interface ShareBase {
uuid?: string
@ -14,6 +14,8 @@ enum ShareBaseRole {
Viewer = 'viewer',
}
const { dashboardUrl } = $(useDashboard())
const { $api, $e } = useNuxtApp()
let base = $ref<null | ShareBase>(null)
@ -24,7 +26,7 @@ const { project } = useProject()
const { copy } = useClipboard()
const url = $computed(() => (base && base.uuid ? `${dashboardUrl()}#/nc/base/${base.uuid}` : null))
const url = $computed(() => (base && base.uuid ? `${dashboardUrl}/nc/base/${base.uuid}` : null))
const loadBase = async () => {
try {
@ -147,14 +149,14 @@ onMounted(() => {
<div class="flex flex-row items-center space-x-0.5 pl-2 h-[0.8rem]">
<MdiOpenInNew />
<div class="text-xs">Shared Base Link</div>
<div class="text-xs">{{ $t('activity.shareBase.link') }}</div>
</div>
<div v-if="base?.uuid" class="flex flex-row mt-2 bg-red-50 py-4 mx-1 px-2 items-center rounded-sm w-full justify-between">
<span class="flex text-xs overflow-x-hidden overflow-ellipsis text-gray-700 pl-2">{{ url }}</span>
<div class="flex border-l-1 pt-1 pl-1">
<a-tooltip placement="bottom">
<template #title>
<span>Reload</span>
<span>{{ $t('general.reload') }}</span>
</template>
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="recreate">
<template #icon>
@ -164,7 +166,7 @@ onMounted(() => {
</a-tooltip>
<a-tooltip placement="bottom">
<template #title>
<span>Copy URL</span>
<span>{{ $t('activity.copyUrl') }}</span>
</template>
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="copyUrl">
<template #icon>
@ -174,7 +176,7 @@ onMounted(() => {
</a-tooltip>
<a-tooltip placement="bottom">
<template #title>
<span>Open new tab</span>
<span>{{ $t('activity.openTab') }}</span>
</template>
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="navigateToSharedBase">
<template #icon>
@ -184,7 +186,7 @@ onMounted(() => {
</a-tooltip>
<a-tooltip placement="bottom">
<template #title>
<span>Copy embeddable HTML code</span>
<span>{{ $t('activity.iFrame') }}</span>
</template>
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="generateEmbeddableIframe">
<template #icon>
@ -199,8 +201,8 @@ onMounted(() => {
<a-dropdown v-model="showEditBaseDropdown" class="flex">
<a-button>
<div class="flex flex-row items-center space-x-2">
<div v-if="base?.uuid">Anyone with the link</div>
<div v-else>Disable shared base</div>
<div v-if="base?.uuid">{{ $t('activity.shareBase.enable') }}</div>
<div v-else>{{ $t('activity.shareBase.disable') }}</div>
<IcRoundKeyboardArrowDown class="h-[1rem]" />
</div>
</a-button>
@ -208,8 +210,8 @@ onMounted(() => {
<template #overlay>
<a-menu>
<a-menu-item>
<div v-if="base?.uuid" @click="disableSharedBase">Disable shared base</div>
<div v-else @click="createShareBase(ShareBaseRole.Viewer)">Anyone with the link</div>
<div v-if="base?.uuid" @click="disableSharedBase">{{ $t('activity.shareBase.disable') }}</div>
<div v-else @click="createShareBase(ShareBaseRole.Viewer)">{{ $t('activity.shareBase.enable') }}</div>
</a-menu-item>
</a-menu>
</template>

39
packages/nc-gui-v2/components/tabs/auth/user-management/UsersModal.vue

@ -8,7 +8,7 @@ import MidAccountIcon from '~icons/mdi/account-outline'
import ContentCopyIcon from '~icons/mdi/content-copy'
import type { User } from '~/lib/types'
import { ProjectRole } from '~/lib/enums'
import { extractSdkResponseErrorMsg, isEmail, projectRoleTagColors } from '~/utils'
import { extractSdkResponseErrorMsg, projectRoles, isEmail, projectRoleTagColors } from '~/utils'
interface Props {
show: boolean
@ -27,8 +27,9 @@ const emit = defineEmits(['closed', 'reload'])
const { project } = useProject()
const { $api, $e } = useNuxtApp()
const { copy } = useClipboard()
const { dashboardUrl } = $(useDashboard())
const usersData = $ref<Users>({ emails: undefined, role: ProjectRole.Guest, invitationToken: undefined })
const usersData = $ref<Users>({ emails: undefined, role: ProjectRole.Viewer, invitationToken: undefined })
const formRef = ref()
const useForm = Form.useForm
@ -100,9 +101,7 @@ const saveUser = async () => {
}
const inviteUrl = $computed(() =>
usersData.invitationToken
? `${location.origin}${location.pathname}#/user/authentication/signup/${usersData.invitationToken}`
: null,
usersData.invitationToken ? `${dashboardUrl}/user/authentication/signup/${usersData.invitationToken}` : null,
)
const copyUrl = async () => {
@ -119,7 +118,7 @@ const copyUrl = async () => {
const clickInviteMore = () => {
$e('c:user:invite-more')
usersData.invitationToken = undefined
usersData.role = ProjectRole.Guest
usersData.role = ProjectRole.Viewer
usersData.emails = undefined
}
</script>
@ -128,7 +127,7 @@ const clickInviteMore = () => {
<a-modal :footer="null" centered :visible="show" :closable="false" width="max(50vw, 44rem)" @cancel="emit('closed')">
<div class="flex flex-col">
<div class="flex flex-row justify-between items-center pb-1.5 mb-2 border-b-1 w-full">
<a-typography-title class="select-none" :level="4"> Share: {{ project.title }} </a-typography-title>
<a-typography-title class="select-none" :level="4"> {{ $t('activity.share') }}: {{ project.title }} </a-typography-title>
<a-button type="text" class="!rounded-md mr-1 -mt-1.5" @click="emit('closed')">
<template #icon>
<CloseIcon class="flex mx-auto" />
@ -146,11 +145,11 @@ const clickInviteMore = () => {
<a-alert class="mt-1" type="success" show-icon>
<template #message>
<div class="flex flex-row w-full justify-between items-center">
<div class="flex pl-2 text-green-700">
<div class="flex flex-row justify-between items-center py-1">
<div class="flex pl-2 text-green-700 text-xs">
{{ inviteUrl }}
</div>
<a-button type="text" class="!rounded-md mr-1" @click="copyUrl">
<a-button type="text" class="!rounded-md -mt-0.5" @click="copyUrl">
<template #icon>
<ContentCopyIcon class="flex mx-auto text-green-700 h-[1rem]" />
</template>
@ -158,15 +157,16 @@ const clickInviteMore = () => {
</div>
</template>
</a-alert>
<div class="flex text-xs text-gray-500 mt-2 justify-start ml-2">
Looks like you have not configured mailer yet! Please copy above invite link and send it to
{{ $t('msg.info.userInviteNoSMTP') }}
{{ usersData.invitationToken && usersData.emails }}
</div>
<div class="flex flex-row justify-start mt-4 ml-2">
<a-button size="small" outlined @click="clickInviteMore">
<div class="flex flex-row justify-center items-center space-x-0.5">
<SendIcon class="flex mx-auto text-gray-600 h-[0.8rem]" />
<div class="text-xs text-gray-600">Invite more</div>
<div class="text-xs text-gray-600">{{ $t('activity.inviteMore') }}</div>
</div>
</a-button>
</div>
@ -197,18 +197,21 @@ const clickInviteMore = () => {
<a-input
v-model:value="usersData.emails"
validate-trigger="onBlur"
placeholder="Email"
:placeholder="$t('labels.email')"
:disabled="!!selectedUser"
/>
</a-form-item>
</div>
<div class="flex flex-col w-1/4">
<a-form-item name="role" :rules="[{ required: true, message: 'Role required' }]">
<div class="ml-1 mb-1 text-xs text-gray-500">Select User Role:</div>
<div class="ml-1 mb-1 text-xs text-gray-500">{{ $t('labels.selectUserRole') }}</div>
<a-select v-model:value="usersData.role">
<a-select-option v-for="(role, index) in Object.keys(projectRoleTagColors)" :key="index" :value="role">
<a-select-option v-for="(role, index) in projectRoles" :key="index" :value="role">
<div class="flex flex-row h-full justify-start items-center">
<div :class="`px-2 py-1 flex rounded-full text-xs bg-[${projectRoleTagColors[role]}]`">
<div
class="px-2 py-1 flex rounded-full text-xs"
:style="{ backgroundColor: projectRoleTagColors[role] }"
>
{{ role }}
</div>
</div>
@ -219,10 +222,10 @@ const clickInviteMore = () => {
</div>
<div class="flex flex-row justify-center">
<a-button type="primary" html-type="submit">
<div v-if="selectedUser">Save</div>
<div v-if="selectedUser">{{ $t('general.save') }}</div>
<div v-else class="flex flex-row justify-center items-center space-x-1.5">
<SendIcon class="flex h-[0.8rem]" />
<div>Invite</div>
<div>{{ $t('activity.invite') }}</div>
</div>
</a-button>
</div>

1
packages/nc-gui-v2/composables/useUIPermission/rolePermissions.ts

@ -17,6 +17,7 @@ const rolePermissions = {
csvImport: true,
apiDocs: true,
projectSettings: true,
newUser: false,
},
commenter: {
smartSheet: true,

1
packages/nc-gui-v2/lang/en.json

@ -13,6 +13,7 @@
"edit": "Edit",
"remove": "Remove",
"save": "Save",
"confirm": "Confirm",
"cancel": "Cancel",
"submit": "Submit",
"create": "Create",

5
packages/nc-gui-v2/lib/enums.ts

@ -6,9 +6,10 @@ export enum Role {
export enum ProjectRole {
Owner = 'owner',
Creator = 'creator',
Editor = 'editor',
User = 'user',
Guest = 'guest',
Commenter = 'commenter',
Viewer = 'viewer',
}
export enum ClientType {

4
packages/nc-gui-v2/utils/urlUtils.ts

@ -17,10 +17,6 @@ export const replaceUrlsWithLink = (text: string): boolean | string => {
return found && out
}
export const dashboardUrl = () => {
return `${location.origin}${location.pathname || ''}`
}
// ref : https://stackoverflow.com/a/5717133
export const isValidURL = (str: string) => {
const pattern =

7
packages/nc-gui-v2/utils/userUtils.ts

@ -2,7 +2,10 @@ import { ProjectRole } from '~/lib/enums'
export const projectRoleTagColors = {
[ProjectRole.Owner]: '#cfdffe',
[ProjectRole.Creator]: '#d0f1fd',
[ProjectRole.Editor]: '#c2f5e8',
[ProjectRole.User]: '#4caf50',
[ProjectRole.Guest]: '#9e9e9e',
[ProjectRole.Commenter]: '#ffdaf6',
[ProjectRole.Viewer]: '#ffdce5',
}
export const projectRoles = [ProjectRole.Creator, ProjectRole.Editor, ProjectRole.Commenter, ProjectRole.Viewer]

Loading…
Cancel
Save