Closes https://github.com/twentyhq/core-team-issues/issues/868 We should not allow to grant any writing permission (update, soft delete, delete) on an object or at role-level without the reading permission at the same level. This has been implemented in the front-end at role level, and is yet to be done at object level (@Weiko)
40 lines
960 B
TypeScript
40 lines
960 B
TypeScript
import gql from 'graphql-tag';
|
|
|
|
export const createUpsertObjectPermissionsOperation = (
|
|
roleId: string,
|
|
objectPermissions: Array<{
|
|
objectMetadataId: string;
|
|
canReadObjectRecords?: boolean;
|
|
canUpdateObjectRecords?: boolean;
|
|
canSoftDeleteObjectRecords?: boolean;
|
|
canDestroyObjectRecords?: boolean;
|
|
}>,
|
|
selectedFields: string[] = [
|
|
'objectMetadataId',
|
|
'canReadObjectRecords',
|
|
'canUpdateObjectRecords',
|
|
'canSoftDeleteObjectRecords',
|
|
'canDestroyObjectRecords',
|
|
],
|
|
) => ({
|
|
query: gql`
|
|
mutation UpsertObjectPermissions(
|
|
$roleId: String!
|
|
$objectPermissions: [ObjectPermissionInput!]!
|
|
) {
|
|
upsertObjectPermissions(
|
|
upsertObjectPermissionsInput: {
|
|
roleId: $roleId
|
|
objectPermissions: $objectPermissions
|
|
}
|
|
) {
|
|
${selectedFields.join('\n')}
|
|
}
|
|
}
|
|
`,
|
|
variables: {
|
|
roleId,
|
|
objectPermissions,
|
|
},
|
|
});
|