0.12.12 : add mail templates as single type
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 6m55s

This commit is contained in:
2025-12-02 23:06:50 +01:00
parent ddf2ced098
commit 460560bb89
10 changed files with 925 additions and 9 deletions

View File

@@ -0,0 +1,30 @@
{
"kind": "singleType",
"collectionName": "mailss",
"info": {
"singularName": "mails",
"pluralName": "mailss",
"displayName": "Mails",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {
"i18n": {
"localized": true
}
},
"attributes": {
"onCreateUser": {
"type": "component",
"repeatable": false,
"pluginOptions": {
"i18n": {
"localized": true
}
},
"component": "mail.mail"
}
}
}

View File

@@ -0,0 +1,7 @@
/**
* mails controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::mails.mails');

View File

@@ -0,0 +1,7 @@
/**
* mails router
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreRouter('api::mails.mails');

View File

@@ -0,0 +1,7 @@
/**
* mails service
*/
import { factories } from '@strapi/strapi';
export default factories.createCoreService('api::mails.mails');

View File

@@ -0,0 +1,17 @@
{
"collectionName": "components_mail_mail",
"info": {
"displayName": "mail",
"icon": "paperPlane",
"description": ""
},
"options": {},
"attributes": {
"subject": {
"type": "string"
},
"message": {
"type": "text"
}
}
}

View File

@@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2025-11-30T20:43:11.125Z"
"x-generation-date": "2025-12-02T22:06:43.585Z"
},
"x-strapi-config": {
"plugins": [
@@ -11170,6 +11170,329 @@
"operationId": "delete/invites/{id}"
}
},
"/mails": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MailsResponse"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
},
"tags": [
"Mails"
],
"parameters": [
{
"name": "sort",
"in": "query",
"description": "Sort by attributes ascending (asc) or descending (desc)",
"deprecated": false,
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "pagination[withCount]",
"in": "query",
"description": "Return page/pageSize (default: true)",
"deprecated": false,
"required": false,
"schema": {
"type": "boolean"
}
},
{
"name": "pagination[page]",
"in": "query",
"description": "Page number (default: 0)",
"deprecated": false,
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "pagination[pageSize]",
"in": "query",
"description": "Page size (default: 25)",
"deprecated": false,
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "pagination[start]",
"in": "query",
"description": "Offset value (default: 0)",
"deprecated": false,
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "pagination[limit]",
"in": "query",
"description": "Number of entities to return (default: 25)",
"deprecated": false,
"required": false,
"schema": {
"type": "integer"
}
},
{
"name": "fields",
"in": "query",
"description": "Fields to return (ex: title,author)",
"deprecated": false,
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "populate",
"in": "query",
"description": "Relations to return",
"deprecated": false,
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "filters",
"in": "query",
"description": "Filters to apply",
"deprecated": false,
"required": false,
"schema": {
"type": "object",
"additionalProperties": true
},
"style": "deepObject"
},
{
"name": "locale",
"in": "query",
"description": "Locale to apply",
"deprecated": false,
"required": false,
"schema": {
"type": "string"
}
}
],
"operationId": "get/mails"
},
"put": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MailsResponse"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
},
"tags": [
"Mails"
],
"parameters": [],
"operationId": "put/mails",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MailsRequest"
}
}
}
}
},
"delete": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "integer",
"format": "int64"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
},
"tags": [
"Mails"
],
"parameters": [],
"operationId": "delete/mails"
}
},
"/messages": {
"get": {
"responses": {
@@ -102436,6 +102759,470 @@
}
}
},
"MailsRequest": {
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"type": "object",
"properties": {
"onCreateUser": {
"$ref": "#/components/schemas/MailMailComponent"
},
"locale": {
"type": "string"
},
"localizations": {
"type": "array",
"items": {
"oneOf": [
{
"type": "integer"
},
{
"type": "string"
}
],
"example": "string or id"
}
}
}
}
}
},
"MailsListResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Mails"
}
},
"meta": {
"type": "object",
"properties": {
"pagination": {
"type": "object",
"properties": {
"page": {
"type": "integer"
},
"pageSize": {
"type": "integer",
"minimum": 25
},
"pageCount": {
"type": "integer",
"maximum": 1
},
"total": {
"type": "integer"
}
}
}
}
}
}
},
"Mails": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
},
"onCreateUser": {
"$ref": "#/components/schemas/MailMailComponent"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
},
"publishedAt": {
"type": "string",
"format": "date-time"
},
"createdBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
},
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
},
"username": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"resetPasswordToken": {
"type": "string"
},
"registrationToken": {
"type": "string"
},
"isActive": {
"type": "boolean"
},
"roles": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
},
"name": {
"type": "string"
},
"code": {
"type": "string"
},
"description": {
"type": "string"
},
"users": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
}
},
"permissions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
},
"action": {
"type": "string"
},
"actionParameters": {},
"subject": {
"type": "string"
},
"properties": {},
"conditions": {},
"role": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
},
"publishedAt": {
"type": "string",
"format": "date-time"
},
"createdBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"updatedBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"locale": {
"type": "string"
},
"localizations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
}
}
}
}
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
},
"publishedAt": {
"type": "string",
"format": "date-time"
},
"createdBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"updatedBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"locale": {
"type": "string"
},
"localizations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
}
}
}
}
},
"blocked": {
"type": "boolean"
},
"preferedLanguage": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
},
"publishedAt": {
"type": "string",
"format": "date-time"
},
"createdBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"updatedBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"locale": {
"type": "string"
},
"localizations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
}
}
}
},
"updatedBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"locale": {
"type": "string"
},
"localizations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
},
"onCreateUser": {
"$ref": "#/components/schemas/MailMailComponent"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"updatedAt": {
"type": "string",
"format": "date-time"
},
"publishedAt": {
"type": "string",
"format": "date-time"
},
"createdBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"updatedBy": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
},
"locale": {
"type": "string"
},
"localizations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"documentId": {
"type": "string"
}
}
}
}
}
}
}
}
},
"MailsResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/components/schemas/Mails"
},
"meta": {
"type": "object"
}
}
},
"MailMailComponent": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"subject": {
"type": "string"
},
"message": {
"type": "string"
}
}
},
"MessageRequest": {
"type": "object",
"required": [

View File

@@ -46,6 +46,13 @@ module.exports = (plugin) => {
const sendConfirmationEmail = async (user) => {
// Génération du token de confirmation
const templates = await strapi
.documents("api::mails.mails")
.findFirst({ populate: "*" });
//const onCreateUser = templates.onCreateUser;
const onCreateUser = templates?.onCreateUser;
const confirmationToken = cryptoLib.randomBytes(20).toString("hex");
await edit(user.id, { confirmationToken });
@@ -54,7 +61,8 @@ module.exports = (plugin) => {
// Lecture du template HTML depuis le fichier
const htmlPath = path.join(process.cwd(), "public", "confirmation.html");
let html = await fs.readFile(htmlPath, "utf-8");
//let html = await fs.readFile(htmlPath, "utf-8");
let html = onCreateUser?.message;
// Remplacement des variables
html = html
@@ -63,12 +71,15 @@ module.exports = (plugin) => {
.replace(/{{YEAR}}/g, new Date().getFullYear().toString());
// Envoi de l'e-mail
await strapi.plugin("email").service("email").send({
to: user.email,
subject: "Confirme ton adresse e-mail",
html,
from: "ChoralSync <admin@harmonychoral.com>",
});
await strapi
.plugin("email")
.service("email")
.send({
to: user.email,
subject: onCreateUser?.subject ?? "Confirme ton adresse e-mail",
html,
from: "ChoralSync <admin@harmonychoral.com>",
});
return { ok: true };
};