Browse Source

Merge pull request #9599 from nocodb/nc-fix/add-to-fav-bug-followup

Nc fix/add to fav bug followup
pull/9604/head
Pranav C 2 months ago committed by GitHub
parent
commit
5a98a2f8a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 32
      packages/nocodb/src/models/BaseUser.ts
  2. 16
      packages/nocodb/src/services/base-users/base-users.service.ts

32
packages/nocodb/src/models/BaseUser.ts

@ -133,7 +133,7 @@ export default class BaseUser {
baseId: string,
userId: string,
ncMeta = Noco.ncMeta,
) {
): Promise<BaseUser & { is_mapped?: boolean }> {
let baseUser =
baseId &&
userId &&
@ -178,32 +178,14 @@ export default class BaseUser {
);
}
}
return this.castType(baseUser);
// decide if user is mapped to base by checking if base_id is present
// base_id will be null if base_user entry is not present
if (baseUser) {
baseUser.is_mapped = !!baseUser.base_id;
}
/**
* Check if user entry exists in BaseUser table
* @param context
* @param baseId
* @param userId
* @param ncMeta
*/
public static async getBaseUserFromDb(
context: NcContext,
baseId: string,
userId: string,
ncMeta = Noco.ncMeta,
): Promise<BaseUser> {
const baseUser = await ncMeta.metaGet2(
context.workspace_id,
context.base_id,
MetaTable.PROJECT_USERS,
{
base_id: baseId,
fk_user_id: userId,
},
)
return baseUser && this.castType(baseUser);
return this.castType(baseUser);
}
public static async getUsersList(

16
packages/nocodb/src/services/base-users/base-users.service.ts

@ -105,11 +105,7 @@ export class BaseUsersService {
if (user) {
// check if this user has been added to this base
const baseUser = await BaseUser.getBaseUserFromDb(
context,
param.baseId,
user.id,
);
const baseUser = await BaseUser.get(context, param.baseId, user.id);
const base = await Base.get(context, param.baseId);
@ -118,13 +114,13 @@ export class BaseUsersService {
}
// if already exists and has a role then throw error
if (baseUser?.roles) {
if (baseUser?.is_mapped && baseUser?.roles) {
NcError.badRequest(
`${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
else if (baseUser) {
else if (baseUser?.is_mapped) {
await BaseUser.updateRoles(
context,
param.baseId,
@ -476,11 +472,7 @@ export class BaseUsersService {
if (Object.keys(baseUserData).length) {
// create new base user if it doesn't exist
if (
!(await BaseUser.getBaseUserFromDb(
context,
param.baseId,
param.user?.id,
))
!(await BaseUser.get(context, param.baseId, param.user?.id))?.is_mapped
) {
await BaseUser.insert(context, {
...baseUserData,

Loading…
Cancel
Save