Browse Source

fix: restrict default values for user field with ws users

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/7202/head
mertmit 11 months ago
parent
commit
72f349a7d3
  1. 64
      packages/nocodb/src/services/columns.service.ts

64
packages/nocodb/src/services/columns.service.ts

@ -960,6 +960,36 @@ export class ColumnsService {
...colBody,
});
} else if (colBody.uidt === UITypes.User) {
// handle default value for user column
if (colBody.cdf) {
const baseUsers = await BaseUser.getUsersList({
base_id: source.base_id,
include_ws_deleted: false,
});
const emailOrIds = colBody.cdf.split(',');
const emailsNotPresent = emailOrIds.filter((el) => {
return !baseUsers.find((user) => user.id === el || user.email === el);
});
if (emailsNotPresent.length) {
NcError.badRequest(
`The following default users are not part of workspace: ${emailsNotPresent.join(
', ',
)}`,
);
}
const ids = emailOrIds.map((el) => {
const user = baseUsers.find(
(user) => user.id === el || user.email === el,
);
return user.id;
});
colBody.cdf = ids.join(',');
}
if (column.uidt === UITypes.User) {
// multi user to single user
if (
@ -1732,6 +1762,40 @@ export class ColumnsService {
}
}
if (colBody.uidt === UITypes.User) {
// handle default value for user column
if (colBody.cdf) {
const baseUsers = await BaseUser.getUsersList({
base_id: base.id,
include_ws_deleted: false,
});
const emailOrIds = colBody.cdf.split(',');
const emailsNotPresent = emailOrIds.filter((el) => {
return !baseUsers.find(
(user) => user.id === el || user.email === el,
);
});
if (emailsNotPresent.length) {
NcError.badRequest(
`The following default users are not part of workspace: ${emailsNotPresent.join(
', ',
)}`,
);
}
const ids = emailOrIds.map((el) => {
const user = baseUsers.find(
(user) => user.id === el || user.email === el,
);
return user.id;
});
colBody.cdf = ids.join(',');
}
}
const tableUpdateBody = {
...table,
tn: table.table_name,

Loading…
Cancel
Save