Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions server/src/permissions/abilityBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import {
hasRole,
hasSameLocation,
isCreatedBySelf,
//isCreatedBySelf,
isSelf,
isToday
} from '@/permissions/utils';
Expand Down Expand Up @@ -138,13 +138,15 @@ function applyManagerPermissions(

// Survey actions
builder.can(ACTIONS.CASL.CREATE, SUBJECTS.SURVEY);
builder.can(ACTIONS.CASL.READ, SUBJECTS.SURVEY);
builder.can(ACTIONS.CUSTOM.CREATE_WITHOUT_REFERRAL, SUBJECTS.SURVEY);
// can only read/update surveys created by themselves at their own location today
builder.can([ACTIONS.CASL.READ, ACTIONS.CASL.UPDATE], SUBJECTS.SURVEY, {
...isCreatedBySelf(ctx.userObjectId),
...hasSameLocation(ctx.latestLocationObjectId),
...isToday('createdAt')
});
// NOTE: disabling because apply-referral page needs to read surveys created by others
// builder.can([ACTIONS.CASL.READ, ACTIONS.CASL.UPDATE], SUBJECTS.SURVEY, {
// ...isCreatedBySelf(ctx.userObjectId),
// ...hasSameLocation(ctx.latestLocationObjectId),
// ...isToday('createdAt')
// });
builder.cannot(ACTIONS.CASL.DELETE, SUBJECTS.SURVEY);

// admins can read all seeds
Expand All @@ -171,12 +173,14 @@ function applyVolunteerPermissions(
// Survey actions
builder.can(ACTIONS.CASL.CREATE, SUBJECTS.SURVEY);
builder.can(ACTIONS.CUSTOM.CREATE_WITHOUT_REFERRAL, SUBJECTS.SURVEY);
builder.can(ACTIONS.CASL.READ, SUBJECTS.SURVEY);
// can only read & update surveys created by themselves at their own location today
builder.can([ACTIONS.CASL.READ, ACTIONS.CASL.UPDATE], SUBJECTS.SURVEY, {
...isCreatedBySelf(ctx.userObjectId),
...hasSameLocation(ctx.latestLocationObjectId),
...isToday('createdAt')
});
// NOTE: disabling because apply-referral page needs to read surveys created by others
// builder.can([ACTIONS.CASL.READ, ACTIONS.CASL.UPDATE], SUBJECTS.SURVEY, {
// ...isCreatedBySelf(ctx.userObjectId),
// ...hasSameLocation(ctx.latestLocationObjectId),
// ...isToday('createdAt')
// });
builder.cannot(ACTIONS.CASL.DELETE, SUBJECTS.SURVEY);

// admins can read all seeds
Expand Down
Loading