Browse Source

fix: project collabs issues

pull/6378/head
mertmit 1 year ago
parent
commit
db939d8bff
  1. 16
      packages/nc-gui/components/project/AccessSettings.vue
  2. 22
      packages/nc-gui/components/project/InviteProjectCollabSection.vue
  3. 2
      packages/nc-gui/components/roles/Badge.vue
  4. 4
      packages/nocodb/src/services/project-users/project-users.service.ts
  5. 2
      packages/nocodb/src/utils/roleHelper.ts

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

@ -75,6 +75,12 @@ const loadListData = async ($state: any) => {
$state.loaded()
}
const reloadCollabs = async () => {
currentPage.value = 0
collaborators.value = []
await loadCollaborators()
}
const updateCollaborator = async (collab: any, roles: ProjectRoles) => {
try {
if (
@ -90,7 +96,7 @@ const updateCollaborator = async (collab: any, roles: ProjectRoles) => {
) {
collab.roles = WorkspaceRolesToProjectRoles[collab.workspace_roles as WorkspaceUserRoles]
} else {
collab.roles = null
collab.roles = ProjectRoles.NO_ACCESS
}
} else if (collab.project_roles) {
collab.roles = roles
@ -101,6 +107,8 @@ const updateCollaborator = async (collab: any, roles: ProjectRoles) => {
}
} catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e))
} finally {
reloadCollabs()
}
}
@ -127,12 +135,6 @@ watchDebounced(
},
)
const reloadCollabs = async () => {
currentPage.value = 0
collaborators.value = []
await loadCollaborators()
}
onMounted(async () => {
isLoading.value = true
try {

22
packages/nc-gui/components/project/InviteProjectCollabSection.vue

@ -1,5 +1,5 @@
<script lang="ts" setup>
import { ProjectRoles } from 'nocodb-sdk'
import { OrderedProjectRoles, ProjectRoles } from 'nocodb-sdk'
import { extractSdkResponseErrorMsg, useDashboard, useManageUsers } from '#imports'
const emit = defineEmits(['invited'])
@ -15,6 +15,8 @@ const { inviteUser } = useManageUsers()
const { $e } = useNuxtApp()
const { projectRoles } = useRoles()
const usersData = ref<{
invite_token?: string
email?: string
@ -47,6 +49,22 @@ const inviteUrl = computed(() =>
usersData.value?.invite_token ? `${dashboardUrl.value}#/signup/${usersData.value.invite_token}` : null,
)
// allow only lower roles to be assigned
const allowedRoles = ref<ProjectRoles[]>([])
onMounted(async () => {
try {
const currentRoleIndex = OrderedProjectRoles.findIndex(
(role) => projectRoles.value && Object.keys(projectRoles.value).includes(role),
)
if (currentRoleIndex !== -1) {
allowedRoles.value = OrderedProjectRoles.slice(currentRoleIndex).filter((r) => r && r !== ProjectRoles.OWNER)
}
} catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e))
}
})
const { copy } = useCopy(true)
const { t } = useI18n()
@ -120,7 +138,7 @@ const copyUrl = async () => {
<RolesSelector
class="px-1"
:role="inviteData.roles"
:roles="ProjectRoles"
:roles="allowedRoles"
:on-role-change="(role: ProjectRoles) => (inviteData.roles = role)"
:description="true"
/>

2
packages/nc-gui/components/roles/Badge.vue

@ -34,8 +34,6 @@ const roleProperties = computed(() => {
label,
}
})
console.log('dummy')
</script>
<template>

4
packages/nocodb/src/services/project-users/project-users.service.ts

@ -290,7 +290,7 @@ export class ProjectUsersService {
NcError.badRequest("Admin can't delete themselves!");
}
if (!param.req.user?.roles?.owner) {
if (!param.req.user?.project_roles?.owner) {
const user = await User.get(param.userId);
if (user.roles?.split(',').includes('super'))
NcError.forbidden(
@ -298,7 +298,7 @@ export class ProjectUsersService {
);
const projectUser = await ProjectUser.get(project_id, param.userId);
if (projectUser?.roles?.split(',').includes('super'))
if (projectUser?.roles?.split(',').includes('owner'))
NcError.forbidden('Insufficient privilege to delete a owner user.');
}

2
packages/nocodb/src/utils/roleHelper.ts

@ -6,7 +6,7 @@ export function getProjectRolePower(user: any) {
const reverseOrderedProjectRoles = [...OrderedProjectRoles].reverse();
if (!user.project_roles) {
NcError.badRequest('Role not found');
return -1;
}
// get most powerful role of user (TODO moving forward we will confirm that user has only one role)

Loading…
Cancel
Save