Browse Source

fix: update collaborator state issue

pull/7276/head
Ramesh Mane 12 months ago
parent
commit
ddd4117239
  1. 25
      packages/nc-gui/components/project/AccessSettings.vue
  2. 19
      packages/nc-gui/composables/useUserSorts.ts

25
packages/nc-gui/components/project/AccessSettings.vue

@ -7,7 +7,7 @@ import {
extractRolesObj,
timeAgo,
} from 'nocodb-sdk'
import type { WorkspaceUserRoles } from 'nocodb-sdk'
import type { Roles, WorkspaceUserRoles } from 'nocodb-sdk'
import InfiniteLoading from 'v3-infinite-loading'
import { isEeUI, storeToRefs, useUserSorts } from '#imports'
@ -26,6 +26,7 @@ interface Collaborators {
email: string
main_roles: OrgUserRoles
roles: ProjectRoles
base_roles: Roles
workspace_roles: WorkspaceUserRoles
created_at: string
}
@ -91,28 +92,32 @@ const loadListData = async ($state: any) => {
}
const updateCollaborator = async (collab: any, roles: ProjectRoles) => {
const currentCollaborator = collaborators.value.find((coll) => coll.id === collab.id)!
try {
if (
!roles ||
(roles === ProjectRoles.NO_ACCESS && !isEeUI) ||
(collab.workspace_roles && WorkspaceRolesToProjectRoles[collab.workspace_roles as WorkspaceUserRoles] === roles && isEeUI)
(currentCollaborator.workspace_roles &&
WorkspaceRolesToProjectRoles[currentCollaborator.workspace_roles as WorkspaceUserRoles] === roles &&
isEeUI)
) {
await removeProjectUser(activeProjectId.value!, collab)
if (
collab.workspace_roles &&
WorkspaceRolesToProjectRoles[collab.workspace_roles as WorkspaceUserRoles] === roles &&
currentCollaborator.workspace_roles &&
WorkspaceRolesToProjectRoles[currentCollaborator.workspace_roles as WorkspaceUserRoles] === roles &&
isEeUI
) {
collab.roles = WorkspaceRolesToProjectRoles[collab.workspace_roles as WorkspaceUserRoles]
currentCollaborator.roles = WorkspaceRolesToProjectRoles[currentCollaborator.workspace_roles as WorkspaceUserRoles]
} else {
collab.roles = ProjectRoles.NO_ACCESS
currentCollaborator.roles = ProjectRoles.NO_ACCESS
}
} else if (collab.base_roles) {
collab.roles = roles
} else if (currentCollaborator.base_roles) {
currentCollaborator.roles = roles
await updateProjectUser(activeProjectId.value!, collab)
} else {
collab.roles = roles
collab.base_roles = roles
currentCollaborator.roles = roles
currentCollaborator.base_roles = roles
await createProjectUser(activeProjectId.value!, collab)
}
} catch (e: any) {

19
packages/nc-gui/composables/useUserSorts.ts

@ -5,7 +5,9 @@ import { useGlobal } from '#imports'
/**
* Hook for managing user sorts and sort configurations.
* @returns An object containing reactive values and functions related to user sorts.
*
* @param {string} roleType - The type of role for which user sorts are managed ('Workspace', 'Org', or 'Project').
* @returns {object} An object containing reactive values and functions related to user sorts.
*/
export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') {
const clone = rfdc()
@ -107,10 +109,10 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') {
const superUserIndex = data.findIndex((user) => user?.roles?.includes('super'))
const superUser = superUserIndex !== -1 ? data.splice(superUserIndex, 1) : null
// console.log('super', superUser)
let sortedData = data.sort((a, b) => {
switch (sortsConfig.field) {
case 'roles':
case 'roles': {
const roleA = a?.roles?.split(',')[0]
const roleB = b?.roles?.split(',')[0]
@ -119,23 +121,24 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') {
} else {
return userRoleOrder.indexOf(roleB) - userRoleOrder.indexOf(roleA)
}
case 'email':
}
case 'email': {
if (sortsConfig.direction === 'asc') {
return a[sortsConfig.field]?.localeCompare(b[sortsConfig.field])
} else {
return b[sortsConfig.field]?.localeCompare(a[sortsConfig.field])
}
}
}
return 0
})
if (superUser && superUser.length) {
if (sortsConfig.direction === 'desc') {
sortedData = [...sortedData, superUser[0]]
} else {
if (sortsConfig.direction === 'asc') {
sortedData = [superUser[0], ...sortedData]
} else {
sortedData = [...sortedData, superUser[0]]
}
}

Loading…
Cancel
Save