Bonjour,
Lâapplication empĂȘche la crĂ©ation de partages dâe-mails lorsque le domaine du destinataire nâest pas autorisĂ©.
Lâapplication fonctionne, elle bloque le partage vers les domaines que je nâautorise pas.
Cependant jâai une erreur que je ne comprend pas: Exception Class âOCP\Share\Exceptions\ShareNotAllowedâ not found in file â/var/www/html/custom_apps/restrict_share_mail_domains/lib/Listener/BeforeShareCreatedListener.phpâ line 62
Si je retire lâExceptions ShareNoAllowed, le blocage ne fonctionne plus
<?php
declare(strict_types=1);
namespace OCA\RestrictShareMailDomains\Listener;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\Share\Events\BeforeShareCreatedEvent;
use OCP\Share\IShare;
use OCP\Share\Exceptions\ShareNotAllowed;
class BeforeShareCreatedListener implements IEventListener {
public function __construct(
private IConfig $config,
) {}
public function handle(Event $event): void {
// preuve dâexĂ©cution
error_log('DEBUG RSM: handle() called');
if (!($event instanceof BeforeShareCreatedEvent)) {
return;
}
$share = $event->getShare();
// uniquement les partages e-mail
if ($share->getShareType() !== IShare::TYPE_EMAIL) {
return;
}
$recipient = trim((string) $share->getSharedWith());
error_log('DEBUG RSM: shareType=' . $share->getShareType() . ' rawRecipient=' . $recipient);
if ($recipient === '' || strpos($recipient, '@') === false) {
throw new ShareNotAllowed('Partage e-mail refusé : adresse invalide.');
}
$domain = strtolower(substr(strrchr($recipient, '@'), 1));
$allowed = $this->config->getSystemValue('restrict_share_mail_domains', []);
$allowed = array_map(
static fn ($d) => strtolower(trim((string) $d)),
is_array($allowed) ? $allowed : []
);
error_log('DEBUG RSM: allowedRaw=' . json_encode($allowed));
error_log('DEBUG RSM: parsedDomain=' . $domain);
if ($domain === '' || !in_array($domain, $allowed, true)) {
error_log(
'DEBUG RSM: domain NOT allowed -> BLOCK. domain=' .
$domain .
' allowed=' .
json_encode($allowed)
);
// CETTE EXCEPTION BLOQUE RĂELLEMENT LE SHARE
throw new ShareNotAllowed('Partage e-mail refusé : domaine non autorisé.');
}
}
}
Si vous avez une idée, je suis preneur.
Merci dâavance