-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(content-service): add registration notification
Also include a content type as reference.
- Loading branch information
Showing
13 changed files
with
206 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
apps/content-service/src/adsp-strapi/server/notifications.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Channel, NotificationType } from '@abgov/adsp-service-sdk'; | ||
import { UserRegisteredEventDefinition } from './events'; | ||
|
||
const CONTENT_EVENT_NAMESPACE = 'content-service'; | ||
export const UserRegistrationInvite: NotificationType = { | ||
name: 'user-registration-invite', | ||
displayName: 'User registration invite', | ||
description: 'Provides notification to user to complete their content manager registration.', | ||
publicSubscribe: false, | ||
subscriberRoles: [], | ||
channels: [Channel.email], | ||
addressPath: 'email', | ||
events: [ | ||
{ | ||
namespace: CONTENT_EVENT_NAMESPACE, | ||
name: UserRegisteredEventDefinition.name, | ||
templates: { | ||
email: { | ||
subject: 'Welcome to content service {{ event.payload.firstName }}!', | ||
body: ` | ||
<section> | ||
<p>You're invited to be an {{#if event.payload.isEditor}}editor{{else}}author{{/if}} in content service.</p> | ||
<p>Click on the following link to complete your registration: <a href="{{ event.payload.registrationUrl }}">{{ event.payload.registrationUrl }}</a></p> | ||
</section> | ||
`, | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |
48 changes: 48 additions & 0 deletions
48
apps/content-service/src/adsp-strapi/server/policies/apply-request-tenant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { Core, UID } from '@strapi/strapi'; | ||
import type { Request } from 'koa'; | ||
|
||
export async function applyRequestTenant( | ||
strapi: Core.Strapi, | ||
request: Request, | ||
tenantId: string, | ||
model: UID.ContentType, | ||
documentId: string, | ||
) { | ||
let documentTenant: string; | ||
if (tenantId) { | ||
switch (request.method) { | ||
case 'POST': { | ||
// This is a create request, so set the tenantId in the data. | ||
request.body.tenantId = tenantId; | ||
break; | ||
} | ||
case 'GET': { | ||
// This is a read request, so... | ||
if (documentId) { | ||
// for specific document read, check tenancy. | ||
const document = await strapi.documents(model).findOne({ documentId }); | ||
documentTenant = document?.['tenantId']; | ||
} else { | ||
// for collection reads, add a tenantId criteria to the filter. | ||
const filters: { $and: unknown[] } = { $and: [{ tenantId }] }; | ||
if (request.query.filters) { | ||
filters.$and.push(request.query.filters); | ||
} | ||
request.query.filters = filters; | ||
} | ||
break; | ||
} | ||
case 'PUT': | ||
case 'DELETE': { | ||
// This is an update or delete request, so we need to verify user access to the associated content. | ||
const document = await strapi.documents(model).findOne({ documentId }); | ||
documentTenant = document?.['tenantId']; | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
return documentTenant; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apps/content-service/src/api/service-release/content-types/service-release/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"kind": "collectionType", | ||
"collectionName": "service_releases", | ||
"info": { | ||
"singularName": "service-release", | ||
"pluralName": "service-releases", | ||
"displayName": "Service release", | ||
"description": "" | ||
}, | ||
"options": { | ||
"draftAndPublish": true | ||
}, | ||
"pluginOptions": {}, | ||
"attributes": { | ||
"tenantId": { | ||
"type": "string" | ||
}, | ||
"service": { | ||
"type": "string", | ||
"required": true | ||
}, | ||
"releasedOn": { | ||
"type": "date", | ||
"required": true | ||
}, | ||
"notes": { | ||
"type": "blocks", | ||
"required": true | ||
}, | ||
"version": { | ||
"type": "string", | ||
"required": true | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/content-service/src/api/service-release/controllers/service-release.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* service-release controller | ||
*/ | ||
|
||
import { factories } from '@strapi/strapi' | ||
|
||
export default factories.createCoreController('api::service-release.service-release'); |
16 changes: 16 additions & 0 deletions
16
apps/content-service/src/api/service-release/routes/service-release.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* service-release router | ||
*/ | ||
|
||
import { factories } from '@strapi/strapi'; | ||
|
||
const model = 'api::service-release.service-release'; | ||
export default factories.createCoreRouter(model, { | ||
config: { | ||
find: { policies: [{ name: 'plugin::adsp-strapi.isTenantUserWithRole', config: { model } }] }, | ||
findOne: { policies: [{ name: 'plugin::adsp-strapi.isTenantUserWithRole', config: { model } }] }, | ||
create: { policies: [{ name: 'plugin::adsp-strapi.isTenantUserWithRole', config: { model } }] }, | ||
update: { policies: [{ name: 'plugin::adsp-strapi.isTenantUserWithRole', config: { model } }] }, | ||
delete: { policies: [{ name: 'plugin::adsp-strapi.isTenantUserWithRole', config: { model } }] }, | ||
}, | ||
}); |
7 changes: 7 additions & 0 deletions
7
apps/content-service/src/api/service-release/services/service-release.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* service-release service | ||
*/ | ||
|
||
import { factories } from '@strapi/strapi'; | ||
|
||
export default factories.createCoreService('api::service-release.service-release'); |
Oops, something went wrong.