Skip to content

Commit

Permalink
fix(authz): fixed bug causing accountId to not be properly added to l…
Browse files Browse the repository at this point in the history
…istPublication result (#80)

The listPublications function was adding the accountId improperly, causing authz logic to not allow
any publications to be viewed, even by the owner. Additionally, added the Account entity as a
required attribute for Publication in the cedar schema

fix #79
  • Loading branch information
flamingquaks authored Jun 4, 2024
1 parent 9f52f1b commit 408adac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 6 additions & 7 deletions lib/api/functions/pipeline/listPublications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type DynamoDBQueryRequest
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { filterForDuplicatesById } from '../../resolver-helper'
import { addAccountToItem, filterForDuplicatesById } from '../../resolver-helper'

export function request (ctx: Context): DynamoDBQueryRequest {
const { nextToken, limit = 250 } = ctx.args
Expand Down Expand Up @@ -51,16 +51,15 @@ export const response = (ctx: Context): any => {
filePath = '/' + filePath
}
}

items.push({
let itemToPush = {
newsletterId,
accountId,
id: publicationId,
account: {
id: accountId
},
createdAt,
filePath
})
}
itemToPush = addAccountToItem(itemToPush)
items.push(itemToPush)
}
}
let result = {
Expand Down
13 changes: 9 additions & 4 deletions lib/authorization/cedarschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"GenAINewsletter": {
"entityTypes": {
"Publication": {
"memberOfTypes": [
"Newsletter"
],
"shape": {
"type": "Record",
"attributes": {
Expand All @@ -13,12 +16,14 @@
"id": {
"required": true,
"type": "String"
},
"Account": {
"required": true,
"type": "Entity",
"name": "Account"
}
}
},
"memberOfTypes": [
"Newsletter"
]
}
},
"Account": {
"memberOfTypes": [],
Expand Down

0 comments on commit 408adac

Please sign in to comment.