|
|
@ -105,7 +105,11 @@ export class BaseUsersService { |
|
|
|
|
|
|
|
|
|
|
|
if (user) { |
|
|
|
if (user) { |
|
|
|
// check if this user has been added to this base
|
|
|
|
// check if this user has been added to this base
|
|
|
|
const baseUser = await BaseUser.get(context, param.baseId, user.id); |
|
|
|
const baseUser = await BaseUser.getBaseUserFromDb( |
|
|
|
|
|
|
|
context, |
|
|
|
|
|
|
|
param.baseId, |
|
|
|
|
|
|
|
user.id, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const base = await Base.get(context, param.baseId); |
|
|
|
const base = await Base.get(context, param.baseId); |
|
|
|
|
|
|
|
|
|
|
@ -113,18 +117,28 @@ export class BaseUsersService { |
|
|
|
return NcError.baseNotFound(param.baseId); |
|
|
|
return NcError.baseNotFound(param.baseId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (baseUser && baseUser.roles) { |
|
|
|
// if already exists and has a role then throw error
|
|
|
|
|
|
|
|
if (baseUser?.roles) { |
|
|
|
NcError.badRequest( |
|
|
|
NcError.badRequest( |
|
|
|
`${user.email} with role ${baseUser.roles} already exists in this base`, |
|
|
|
`${user.email} with role ${baseUser.roles} already exists in this base`, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// if user exist and role is not assigned then assign role by updating base user
|
|
|
|
await BaseUser.insert(context, { |
|
|
|
else if (baseUser) { |
|
|
|
base_id: param.baseId, |
|
|
|
await BaseUser.updateRoles( |
|
|
|
fk_user_id: user.id, |
|
|
|
context, |
|
|
|
roles: param.baseUser.roles || 'editor', |
|
|
|
param.baseId, |
|
|
|
invited_by: param.req?.user?.id, |
|
|
|
user.id, |
|
|
|
}); |
|
|
|
param.baseUser.roles, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await BaseUser.insert(context, { |
|
|
|
|
|
|
|
base_id: param.baseId, |
|
|
|
|
|
|
|
fk_user_id: user.id, |
|
|
|
|
|
|
|
roles: param.baseUser.roles || 'editor', |
|
|
|
|
|
|
|
invited_by: param.req?.user?.id, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.appHooksService.emit(AppEvents.PROJECT_INVITE, { |
|
|
|
this.appHooksService.emit(AppEvents.PROJECT_INVITE, { |
|
|
|
base, |
|
|
|
base, |
|
|
@ -461,7 +475,13 @@ export class BaseUsersService { |
|
|
|
|
|
|
|
|
|
|
|
if (Object.keys(baseUserData).length) { |
|
|
|
if (Object.keys(baseUserData).length) { |
|
|
|
// create new base user if it doesn't exist
|
|
|
|
// create new base user if it doesn't exist
|
|
|
|
if (!(await BaseUser.get(context, param.baseId, param.user?.id))) { |
|
|
|
if ( |
|
|
|
|
|
|
|
!(await BaseUser.getBaseUserFromDb( |
|
|
|
|
|
|
|
context, |
|
|
|
|
|
|
|
param.baseId, |
|
|
|
|
|
|
|
param.user?.id, |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
) { |
|
|
|
await BaseUser.insert(context, { |
|
|
|
await BaseUser.insert(context, { |
|
|
|
...baseUserData, |
|
|
|
...baseUserData, |
|
|
|
base_id: param.baseId, |
|
|
|
base_id: param.baseId, |
|
|
|