You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add configurable user requirements for community creation (#841)
* feat: add configurable user requirements for community creation
* fix: fail-closed on invalid COMMUNITY_CREATION_* env var values
* fix: reject negative values for COMMUNITY_CREATION_* thresholds
* harden the check on community creation configuration
* Code formatting
* Refactored threshold validation to helper functions, enforced fail-closed configuration checks, improved error logging levels, added explicit user date validation, and updated all locales to provide detailed feedback to the user on unmet requirements.
* Improve community creation requirement gating by:
- Renaming COMMUNITY_CREATION_MIN_VOLUME to COMMUNITY_CREATION_MIN_VOLUME_SATS and documenting the sats unit in .env-sample.
- Extracting validation logic to a new module with high test coverage.
- Implementing startup logging for misconfigurations.
- Dynamically constructing requirement messages to show only active thresholds.
- Splitting localization keys for granular control across all locales.
---------
Co-authored-by: Maxi Vila <matovi98@gmail.com>
`Community creation is failing due to a misconfiguration in initialization time: ${invalidEnvVars.join(', ')}`,
32
+
);
33
+
returnctx.reply(ctx.i18n.t('generic_error'));
34
+
}
35
+
36
+
const{ meets, daysUsing, hasInvalidDate }=
37
+
meetsCommunityCreationRequirements(
38
+
{
39
+
tg_id: user.tg_id,
40
+
trades_completed: user.trades_completed,
41
+
volume_traded: user.volume_traded,
42
+
total_rating: user.total_rating,
43
+
created_at: user.created_at,
44
+
},
45
+
{
46
+
minOrders,
47
+
minVolume,
48
+
minDays,
49
+
minReputation,
50
+
},
51
+
);
52
+
53
+
if(hasInvalidDate){
54
+
logger.error(
55
+
`User ${user.tg_id} has invalid created_at timestamp: ${user.created_at}`,
56
+
);
57
+
returnctx.reply(ctx.i18n.t('generic_error'));
58
+
}
59
+
60
+
if(!meets){
61
+
logger.warning(
62
+
`User ${user.tg_id} tried to create a community but does not meet the requirements - orders: ${user.trades_completed}, volume: ${user.volume_traded}, days: ${daysUsing}, reputation: ${user.total_rating}`,
63
+
);
64
+
65
+
// Build the message dynamically based on active thresholds
Copy file name to clipboardExpand all lines: locales/fr.yaml
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -721,6 +721,11 @@ payment_methods_reset: "Méthodes de paiement supprimées. Les utilisateurs peuv
721
721
payment_methods_wizard_commands: "/reset — supprimer toutes les méthodes de paiement et restaurer le comportement par défaut\n/exit — quitter sans enregistrer"
722
722
community_disabled_by_admin: Un administrateur a désactivé votre communauté ${communityName}
723
723
community_enabled_by_admin: Un administrateur a réactivé votre communauté ${communityName}
724
+
community_creation_requirements_not_met_header: "Vous ne remplissez pas les conditions pour créer une communauté :"
Copy file name to clipboardExpand all lines: locales/it.yaml
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -719,6 +719,11 @@ payment_methods_reset: "Metodi di pagamento rimossi. Gli utenti possono ora inse
719
719
payment_methods_wizard_commands: "/reset — rimuovere tutti i metodi di pagamento e ripristinare il comportamento predefinito\n/exit — uscire senza salvare"
720
720
community_disabled_by_admin: Un amministratore ha disabilitato la tua comunità ${communityName}
721
721
community_enabled_by_admin: Un amministratore ha riabilitato la tua comunità ${communityName}
722
+
community_creation_requirements_not_met_header: "Non soddisfi i requisiti per creare una comunità:"
0 commit comments