From a0d87c5a4bd9e78fa4eba1c9bd6e6757dcad4fda Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 14 Aug 2024 16:42:30 +0530 Subject: [PATCH] Nc feat/user management (#9219) * feat: api changes for user management * refactor: gift banner behaviour change * feat: user management api and ui changes * feat: introduce invited_by info * test: verify roles by checking datasource tab since access settings page will be available for all users now * feat: allow owner role update only if there is more than one owner exist * fix: role update behaviour correction * fix: base owner invite issue * fix: reload user roles state on changing roles of active user * refactor: show disabled button if not avail * refactor: hide dropdown and action menu options based on roles * refactor: migration file name * refactor: disable or hide option based on number of owners * refactor: hide user list in shared base * fix: review correction --- .../dashboard/Sidebar/TopSection.vue | 2 +- packages/nc-gui/components/dlg/InviteDlg.vue | 24 +++++-- packages/nc-gui/components/general/Gift.vue | 6 +- packages/nc-gui/components/nc/Badge.vue | 1 + .../components/project/AccessSettings.vue | 26 +++++--- packages/nc-gui/components/project/View.vue | 4 +- packages/nc-gui/components/roles/Badge.vue | 4 +- packages/nc-gui/components/roles/Selector.vue | 16 +++++ .../workspace/CollaboratorsList.vue | 51 ++++++++++----- packages/nc-gui/components/workspace/View.vue | 2 +- packages/nc-gui/lib/acl.ts | 2 +- packages/nc-gui/store/bases.ts | 11 ++++ packages/nocodb-sdk/src/lib/enums.ts | 2 +- .../meta/migrations/XcMigrationSourcev2.ts | 4 ++ .../meta/migrations/v2/nc_059_invited_by.ts | 16 +++++ packages/nocodb/src/models/BaseUser.ts | 13 ++-- packages/nocodb/src/models/Integration.ts | 1 - packages/nocodb/src/models/PresignedUrl.ts | 2 +- .../services/app-hooks/app-hooks.service.ts | 1 - .../services/base-users/base-users.service.ts | 65 +++++++++++++++---- .../src/services/integrations.service.ts | 2 +- .../pages/Dashboard/ProjectView/index.ts | 4 +- 22 files changed, 189 insertions(+), 70 deletions(-) create mode 100644 packages/nocodb/src/meta/migrations/v2/nc_059_invited_by.ts diff --git a/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue b/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue index 794d6c5f01..bf8e565ebf 100644 --- a/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue +++ b/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue @@ -57,7 +57,7 @@ const navigateToIntegrations = () => { { return props.type === 'base' ? ProjectRoles : WorkspaceUserRoles }) +const userRoles = computed(() => { + return props.type === 'base' ? baseRoles?.value : workspaceRoles?.value +}) const inviteData = reactive({ email: '', @@ -47,6 +52,8 @@ const emailBadges = ref>([]) const allowedRoles = ref<[]>([]) +const disabledRoles = ref<[]>([]) + const isLoading = ref(false) const organizationStore = useOrganization() @@ -77,13 +84,15 @@ const focusOnDiv = () => { watch(dialogShow, async (newVal) => { if (newVal) { try { - // todo: enable after discussing with anbu - // const currentRoleIndex = Object.values(orderedRoles.value).findIndex( - // (role) => userRoles.value && Object.keys(userRoles.value).includes(role), - // ) - // if (currentRoleIndex !== -1) { - allowedRoles.value = Object.values(orderedRoles.value) // .slice(currentRoleIndex + 1) - // } + const rolesArr = Object.values(orderedRoles.value) + const currentRoleIndex = rolesArr.findIndex((role) => userRoles.value && Object.keys(userRoles.value).includes(role)) + if (currentRoleIndex !== -1) { + allowedRoles.value = rolesArr.slice(currentRoleIndex) + disabledRoles.value = rolesArr.slice(0, currentRoleIndex) + } else { + allowedRoles.value = rolesArr + disabledRoles.value = [] + } } catch (e: any) { message.error(await extractSdkResponseErrorMsg(e)) } @@ -350,6 +359,7 @@ const onRoleChange = (role: keyof typeof RoleLabels) => (inviteData.roles = role :description="false" :on-role-change="onRoleChange" :role="inviteData.roles" + :disabled-roles="disabledRoles" :roles="allowedRoles" class="!min-w-[152px] nc-invite-role-selector" size="lg" diff --git a/packages/nc-gui/components/general/Gift.vue b/packages/nc-gui/components/general/Gift.vue index c14687c15b..516afc6f9b 100644 --- a/packages/nc-gui/components/general/Gift.vue +++ b/packages/nc-gui/components/general/Gift.vue @@ -1,8 +1,8 @@