chore: convert string to constants

This will make more easy to add new activities.

Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
Vitor Mattos 2025-05-16 13:17:57 -03:00
parent 0fa24fe615
commit 279e26ab95
No known key found for this signature in database
GPG key ID: B7AB4B76A7CA7318
8 changed files with 19 additions and 12 deletions

View file

@ -9,11 +9,17 @@ declare(strict_types=1);
namespace OCA\Libresign\Activity;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Events\SendSignNotificationEvent;
use OCA\Libresign\Events\SignedEvent;
use OCP\Activity\IFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
class Filter implements IFilter {
private const ALLOWED_TYPES = [
SendSignNotificationEvent::FILE_TO_SIGN,
SignedEvent::FILE_SIGNED,
];
public function __construct(
protected IL10N $l,
protected IURLGenerator $url,
@ -39,10 +45,7 @@ class Filter implements IFilter {
}
public function filterTypes(array $types) {
return array_intersect([
'file_to_sign',
'file_signed',
], $types);
return array_intersect(self::ALLOWED_TYPES, $types);
}
public function allowedApps() {

View file

@ -78,7 +78,7 @@ class Listener implements IEventListener {
try {
$event
->setApp(Application::APP_ID)
->setType('file_to_sign')
->setType(SendSignNotificationEvent::FILE_TO_SIGN)
->setAuthor($actorId)
->setObject('signRequest', $signRequest->getId())
->setTimestamp($this->timeFactory->getTime())
@ -129,7 +129,7 @@ class Listener implements IEventListener {
try {
$activityEvent
->setApp(Application::APP_ID)
->setType('file_signed')
->setType(SignedEvent::FILE_SIGNED)
->setAuthor($actorId)
->setObject('signedFile', 10)
->setTimestamp($this->timeFactory->getTime())

View file

@ -8,6 +8,7 @@ declare(strict_types=1);
namespace OCA\Libresign\Activity\Settings;
use OCA\Libresign\Events\SignedEvent;
use OCP\IL10N;
class FileSigned extends LibresignActivitySettings {
@ -20,7 +21,7 @@ class FileSigned extends LibresignActivitySettings {
* {@inheritdoc}
*/
public function getIdentifier(): string {
return 'file_signed';
return SignedEvent::FILE_SIGNED;
}
/**

View file

@ -8,6 +8,7 @@ declare(strict_types=1);
namespace OCA\Libresign\Activity\Settings;
use OCA\Libresign\Events\SendSignNotificationEvent;
use OCP\IL10N;
class FileToSign extends LibresignActivitySettings {
@ -21,7 +22,7 @@ class FileToSign extends LibresignActivitySettings {
* @since 20.0.0
*/
public function getIdentifier(): string {
return 'file_to_sign';
return SendSignNotificationEvent::FILE_TO_SIGN;
}
/**

View file

@ -14,6 +14,7 @@ use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
use OCP\EventDispatcher\Event;
class SendSignNotificationEvent extends Event {
public const FILE_TO_SIGN = 'libresign_file_to_sign';
public function __construct(
private SignRequest $signRequest,
private FileEntity $libreSignFile,

View file

@ -15,6 +15,7 @@ use OCP\EventDispatcher\Event;
use OCP\IUser;
class SignedEvent extends Event {
public const FILE_SIGNED = 'libresign_file_signed';
public function __construct(
private SignRequest $signRequest,
private FileEntity $libreSignFile,

View file

@ -56,7 +56,7 @@ class MailNotifyListener implements IEventListener {
IIdentifyMethod $identifyMethod,
): void {
try {
if ($this->isNotificationDisabledAtActivity($identifyMethod, 'file_to_sign')) {
if ($this->isNotificationDisabledAtActivity($identifyMethod, SendSignNotificationEvent::FILE_TO_SIGN)) {
return;
}
$email = '';
@ -89,7 +89,7 @@ class MailNotifyListener implements IEventListener {
IUser $user,
): void {
try {
if ($this->isNotificationDisabledAtActivity($identifyMethod, 'file_signed')) {
if ($this->isNotificationDisabledAtActivity($identifyMethod, SignedEvent::FILE_SIGNED)) {
return;
}

View file

@ -61,7 +61,7 @@ class NotificationListener implements IEventListener {
if (!$actor instanceof IUser) {
return;
}
if ($this->isNotificationDisabledAtActivity($identifyMethod, 'file_to_sign')) {
if ($this->isNotificationDisabledAtActivity($identifyMethod, SendSignNotificationEvent::FILE_TO_SIGN)) {
return;
}
$notification = $this->notificationManager->createNotification();
@ -99,7 +99,7 @@ class NotificationListener implements IEventListener {
$actorId = $libreSignFile->getUserId();
if ($this->isNotificationDisabledAtActivity($identifyMethod, 'file_signed')) {
if ($this->isNotificationDisabledAtActivity($identifyMethod, SignedEvent::FILE_SIGNED)) {
return;
}