Skip to content

Commit

Permalink
Fix issue with permissions to allow a PB creator to view his own non-…
Browse files Browse the repository at this point in the history
…public record
  • Loading branch information
big213 committed Dec 28, 2021
1 parent b27c776 commit b18a981
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 13 additions & 3 deletions backend/functions/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// Query builder (Typescript version >= 4.1.3 required)
/* const queryResult = executeGiraffeql({
const queryResult = executeGiraffeql({
// Start typing here to get hints
}); */
getUser: {
id: true,
name: true,
createdBy: {
id: true,
name: true,
},
__args: {
id: 9,
},
},
});

export function executeGiraffeql<Key extends keyof Root>(
query: GetQuery<Key>
Expand Down
10 changes: 7 additions & 3 deletions backend/functions/src/schema/models/personalBest/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ export class PersonalBestService extends PaginatedService {
groupByFieldsMap = {};

accessControl: AccessControlMap = {
get: async ({ args, fieldPath }) => {
get: async ({ req, args, fieldPath }) => {
// check the createdBy.isPublic to see if true
// OR if createdBy is current user
const result = await this.lookupRecord(
["createdBy.isPublic"],
["createdBy.isPublic", "createdBy.id"],
args,
fieldPath
);
return result["createdBy.isPublic"] === true;
return (
result["createdBy.isPublic"] === true ||
result["createdBy.id"] === req.user?.id
);
},

getMultiple: ({ req, args, query }) => {
Expand Down

0 comments on commit b18a981

Please sign in to comment.