Compare commits

...

3 Commits

Author SHA1 Message Date
0648bf74bd 0.13.9 : change smartTags name
Some checks failed
Build release Docker image / Build Docker Images (push) Failing after 10m34s
2026-04-13 21:56:07 +02:00
d469fc41e8 0.13.8 : invite by mail or contact and change mail provider on local
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 10m42s
2026-04-07 22:15:59 +02:00
5af0f28b39 Fix controller to remove upload
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 5m43s
2026-04-06 16:42:54 +02:00
10 changed files with 465 additions and 80 deletions

View File

@@ -3,16 +3,18 @@ export default () => ({
config: {
provider: "nodemailer",
providerOptions: {
host: "mail.harmonychoral.com",
port: 465,
host: "smtp.zeptomail.eu",
port: 587,
auth: {
user: "admin@harmonychoral.com",
pass: "Apslxnap12bn23",
user: "emailapikey",
pass: "yA6KbHsJ4lrywWtTFUc+0pSC94lm/aE/2nzks3i2fpZ1LYXp3qE71RBvd4O4c2CLjdfT5a9UbIkVJoCwvIpbfpczPIBXJpTGTuv4P2uV48xh8ciEYNYjhJivALIWFqVOeBsnDyo4QfEjWA==",
},
debug: true,
logger: true,
},
settings: {
defaultFrom: "admin@harmonychoral.com",
defaultReplyTo: "admin@harmonychoral.com",
defaultFrom: "ChoralSync <noreply@choralsync.com>",
defaultReplyTo: "contact@choralsync.com",
},
},
},

View File

@@ -1,6 +1,6 @@
{
"name": "harmony-back",
"version": "0.13.7",
"version": "0.13.9",
"private": true,
"description": "A Strapi application",
"scripts": {

View File

@@ -51,6 +51,14 @@
"pending_admin_approval",
"decline"
]
},
"invite_email": {
"type": "email",
"private": true
},
"invite_token": {
"type": "string",
"private": true
}
}
}

View File

@@ -1,7 +1,97 @@
/**
* choral-membership controller
*/
import { factories } from "@strapi/strapi";
import crypto from "crypto";
import { factories } from '@strapi/strapi'
export default factories.createCoreController(
"api::choral-membership.choral-membership",
({ strapi }) => ({
async create(ctx) {
const { data } = ctx.request.body;
const inviter = ctx.state.user;
export default factories.createCoreController('api::choral-membership.choral-membership');
// 1. Déterminer le type d'invitation
const isExternalInvite = !!data.invite_email && !data.user;
const isInternalInvite = !!data.user;
let token = null;
let targetEmail = null;
// 2. Configuration commune
// On force le statut "en attente" peut importe le type d'invité
ctx.request.body.data.state = "pending_user_approval";
if (!data.role) {
ctx.request.body.data.role = "member";
}
// 3. Traitement spécifique selon le cas
if (isExternalInvite) {
// Cas A : Utilisateur externe (Token requis)
token = crypto.randomBytes(32).toString("hex");
ctx.request.body.data.invite_token = token;
ctx.request.body.data.invite_email = data.invite_email.toLowerCase();
targetEmail = data.invite_email.toLowerCase();
} else if (isInternalInvite) {
// Cas B : Utilisateur existant (Pas de token)
// On s'assure de nettoyer les champs d'invitation externe au cas où le front les enverrait par erreur
ctx.request.body.data.invite_token = null;
ctx.request.body.data.invite_email = null;
// On récupère l'email de l'utilisateur existant pour lui envoyer une notification
const invitedUser = await strapi
.documents("plugin::users-permissions.user")
.findMany({
filters: {
id: data.user,
},
});
if (invitedUser && invitedUser.length > 0) {
targetEmail = invitedUser[0].email;
}
}
// 4. Exécution de la création native par Strapi
const response = await super.create(ctx);
// 5. Post-traitement : Envoi de l'email
if (response && targetEmail) {
try {
const chorals = await strapi
.documents("api::choral.choral")
.findMany({
filters: {
id: data.choral,
},
});
const choral = chorals[0];
if (isExternalInvite) {
// Email d'invitation avec le lien tokenisé
await strapi
.service("api::mails.mails")
.sendInvitation(
targetEmail,
inviter?.username || "Un membre",
choral?.name || "votre chorale",
token,
);
} else if (isInternalInvite) {
// Email de notification pour un utilisateur existant
// Ici le token est 'null', on prévient le service que c'est un user interne
await strapi.service("api::mails.mails").sendInvitation(
targetEmail,
inviter?.username || "Un membre",
choral?.name || "votre chorale",
null, // On passe explicitement null
);
}
} catch (error) {
console.error(
"Erreur lors de l'envoi de l'email d'invitation :",
error,
);
}
}
return response;
},
}),
);

View File

@@ -33,34 +33,5 @@ export default factories.createCoreController(
const result = await super.create(ctx);
return result;
},
async update(ctx) {
const data = ctx.request.body.data
? JSON.parse(ctx.request.body.data)
: {};
if (ctx.request.files && ctx.request.files.coverImage) {
const files = Array.isArray(ctx.request.files.coverImage)
? ctx.request.files.coverImage[0]
: ctx.request.files.coverImage;
const extension = files.originalFilename.match(/\.[0-9a-z]+$/i);
const payload = {
fileInfo: {
caption: "undefined",
alternativeText: data.name || "",
name: `${data.name}_cover${extension}`,
},
};
const asset = await strapi.services["plugin::upload.upload"].upload({
data: payload,
files,
});
data.cover = asset[0].id;
}
ctx.request.body = { data };
const result = await super.update(ctx);
return result;
},
})
}),
);

View File

@@ -25,6 +25,16 @@
}
},
"component": "mail.mail"
},
"onInviteUser": {
"type": "component",
"repeatable": true,
"pluginOptions": {
"i18n": {
"localized": true
}
},
"component": "mail.mail"
}
}
}

View File

@@ -1,7 +1,61 @@
/**
* mails service
*/
import { factories } from "@strapi/strapi";
import { factories } from '@strapi/strapi';
export default factories.createCoreService(
"api::mails.mails",
({ strapi }) => ({
// Notre méthode personnalisée
async sendInvitation(
emailAddress: string,
inviterName: string,
choirName: string,
inviteToken: string | null,
) {
// 1. Définir le lien de redirection selon le type d'utilisateur
// S'il y a un token, c'est un nouvel utilisateur. Sinon, c'est un membre existant.
const inviteLink = inviteToken
? `https://www.choralsync.com/invite?token=${inviteToken}`
: `https://www.choralsync.com/app`; // Lien vers l'app pour accepter l'invitation interne
export default factories.createCoreService('api::mails.mails');
// 2. Récupérer le single-type "mails" avec l'API Document
const mailsConfig = await strapi.documents("api::mails.mails").findFirst({
populate: ["onInviteUser"],
});
if (!mailsConfig || !mailsConfig.onInviteUser) {
throw new Error(
"Le template d'email d'invitation n'est pas configuré dans le CMS.",
);
}
const templateConfig = mailsConfig.onInviteUser[0];
try {
// 3. Envoyer l'email via le moteur de template natif
await strapi.plugin("email").service("email").sendTemplatedEmail(
{
to: emailAddress,
from: "ChoralSync <contact@choralsync.com>",
},
{
subject: templateConfig.subject,
html: templateConfig.message,
text: `Bonjour, Vous avez été invité(e) par <%= inviter_name %> à rejoindre <%= choir_name %>. Acceptez l'invitation en cliquant sur ce lien : <%= invite_link %>`,
},
{
// Variables injectées dans le template (<%= variable %>)
inviter_name: inviterName,
choir_name: choirName,
invite_link: inviteLink,
},
);
return { success: true };
} catch (error) {
console.error("Erreur lors de l'envoi de l'email :", error);
// On throw l'erreur pour que le contrôleur puisse la logger,
// mais idéalement sans bloquer la création en base.
throw error;
}
},
}),
);

View File

@@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2026-04-05T22:52:10.996Z"
"x-generation-date": "2026-04-13T19:55:11.976Z"
},
"x-strapi-config": {
"plugins": [
@@ -20365,6 +20365,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -23161,7 +23168,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -26724,6 +26731,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -28549,7 +28563,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -32414,6 +32428,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -34239,7 +34260,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -37495,6 +37516,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -39320,7 +39348,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -43178,6 +43206,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -45003,7 +45038,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -49217,6 +49252,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -51042,7 +51084,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -54739,6 +54781,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -57535,7 +57584,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -60708,6 +60757,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -63504,7 +63560,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -66793,6 +66849,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -69589,7 +69652,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -73090,6 +73153,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -75886,7 +75956,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -76462,6 +76532,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"locale": {
"type": "string"
},
@@ -78977,6 +79054,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -81773,7 +81857,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -81893,6 +81977,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -84537,6 +84628,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -87333,7 +87431,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -90064,6 +90162,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -92860,7 +92965,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -95641,6 +95746,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -98437,7 +98549,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -101225,6 +101337,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -103871,7 +103990,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -106749,6 +106868,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -109545,7 +109671,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -112545,6 +112671,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -115341,7 +115474,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -118404,6 +118537,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -120229,7 +120369,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -123946,6 +124086,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -126742,7 +126889,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -129866,6 +130013,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -131691,7 +131845,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -135897,6 +136051,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -138275,7 +138436,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -141410,6 +141571,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -144206,7 +144374,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -146962,6 +147130,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -149758,7 +149933,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -150698,6 +150873,12 @@
"onCreateUser": {
"$ref": "#/components/schemas/MailMailComponent"
},
"onInviteUser": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MailMailComponent"
}
},
"locale": {
"type": "string"
},
@@ -150773,6 +150954,12 @@
"onCreateUser": {
"$ref": "#/components/schemas/MailMailComponent"
},
"onInviteUser": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MailMailComponent"
}
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -151188,6 +151375,12 @@
"onCreateUser": {
"$ref": "#/components/schemas/MailMailComponent"
},
"onInviteUser": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MailMailComponent"
}
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -153866,6 +154059,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -156662,7 +156862,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -159433,6 +159633,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -162229,7 +162436,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -165078,6 +165285,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -167874,7 +168088,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -171231,6 +171445,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -173056,7 +173277,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -176956,6 +177177,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -179752,7 +179980,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -182570,6 +182798,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -185366,7 +185601,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -188130,6 +188365,13 @@
"decline"
]
},
"invite_email": {
"type": "string",
"format": "email"
},
"invite_token": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
@@ -190926,7 +191168,7 @@
}
}
},
"admin_tags": {},
"smartTags": {},
"createdAt": {
"type": "string",
"format": "date-time"

View File

@@ -265,7 +265,7 @@
"target": "api::order.order",
"mappedBy": "user"
},
"admin_tags": {
"smartTags": {
"type": "json"
}
}

View File

@@ -723,6 +723,8 @@ export interface ApiChoralMembershipChoralMembership
createdAt: Schema.Attribute.DateTime;
createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
Schema.Attribute.Private;
invite_email: Schema.Attribute.Email & Schema.Attribute.Private;
invite_token: Schema.Attribute.String & Schema.Attribute.Private;
locale: Schema.Attribute.String & Schema.Attribute.Private;
localizations: Schema.Attribute.Relation<
'oneToMany',
@@ -1369,6 +1371,12 @@ export interface ApiMailsMails extends Struct.SingleTypeSchema {
localized: true;
};
}>;
onInviteUser: Schema.Attribute.Component<'mail.mail', true> &
Schema.Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
publishedAt: Schema.Attribute.DateTime;
updatedAt: Schema.Attribute.DateTime;
updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
@@ -2132,7 +2140,6 @@ export interface PluginUsersPermissionsUser
attributes: {
activities: Schema.Attribute.Component<'group.activity', true>;
address: Schema.Attribute.Text;
admin_tags: Schema.Attribute.JSON;
announcements: Schema.Attribute.Relation<
'oneToMany',
'api::announcement.announcement'
@@ -2226,6 +2233,7 @@ export interface PluginUsersPermissionsUser
'plugin::users-permissions.role'
>;
saved_posts: Schema.Attribute.Relation<'oneToMany', 'api::post.post'>;
smartTags: Schema.Attribute.JSON;
subscriptionPlan: Schema.Attribute.Enumeration<['free', 'pro', 'premium']> &
Schema.Attribute.DefaultTo<'free'>;
surname: Schema.Attribute.String;