Skip to content

Commit

Permalink
🔒 Allow moderators to manage communication templates (#2364)
Browse files Browse the repository at this point in the history
* 🔒 Allow moderators to manage communication templates

* ✅ Adjust test to check errors properly
  • Loading branch information
foysalit authored Apr 15, 2024
1 parent a2d5658 commit 0f915a6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/ozone/src/api/communication/createTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default function (server: Server, ctx: AppContext) {
const db = ctx.db
const { createdBy, ...template } = input.body

if (!access.isAdmin) {
if (!access.isModerator) {
throw new AuthRequiredError(
'Must be an admin to create a communication template',
'Must be a moderator to create a communication template',
)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ozone/src/api/communication/deleteTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default function (server: Server, ctx: AppContext) {
const db = ctx.db
const { id } = input.body

if (!access.isAdmin) {
if (!access.isModerator) {
throw new AuthRequiredError(
'Must be an admin to delete a communication template',
'Must be a moderator to delete a communication template',
)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ozone/src/api/communication/updateTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default function (server: Server, ctx: AppContext) {
const db = ctx.db
const { id, updatedBy, ...template } = input.body

if (!access.isAdmin) {
if (!access.isModerator) {
throw new AuthRequiredError(
'Must be an admin to update a communication template',
'Must be a moderator to update a communication template',
)
}

Expand Down
10 changes: 5 additions & 5 deletions packages/ozone/tests/communication-templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe('communication-templates', () => {
{ ...templateOne, createdBy: sc.dids.bob },
{
encoding: 'application/json',
headers: await network.ozone.modHeaders('moderator'),
headers: await network.ozone.modHeaders('triage'),
},
)
await expect(moderatorReq).rejects.toThrow(
'Must be an admin to create a communication template',
'Must be a moderator to create a communication template',
)
const modReq = await agent.api.tools.ozone.communication.createTemplate(
{ ...templateOne, createdBy: sc.dids.bob },
Expand Down Expand Up @@ -105,19 +105,19 @@ describe('communication-templates', () => {
{ id: '1' },
{
encoding: 'application/json',
headers: await network.ozone.modHeaders('moderator'),
headers: await network.ozone.modHeaders('triage'),
},
)

await expect(modReq).rejects.toThrow(
'Must be an admin to delete a communication template',
'Must be a moderator to delete a communication template',
)

await agent.api.tools.ozone.communication.deleteTemplate(
{ id: '1' },
{
encoding: 'application/json',
headers: await network.ozone.modHeaders('admin'),
headers: await network.ozone.modHeaders('moderator'),
},
)
const list = await listTemplates()
Expand Down

0 comments on commit 0f915a6

Please sign in to comment.