Création d'une application - Restrict share-by-mail domains

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

Bonjour,
Cette Exception ne semble pas exister dans les classes Nextcloud. Vous devriez la crĂ©er dans l’environnement de votre application . Par ex : OCA\RestrictShareMailDomains\Exceptions\ShareNotAllowed