Moved the "ENFORCE_CHANGE_COMMENTS_FOR" type to the HistorySettings class

This commit is contained in:
Jan Böhmer 2024-06-25 22:59:22 +02:00
parent 6df7bc5f2a
commit 5ab6a63492
9 changed files with 147 additions and 16 deletions

View file

@ -22,14 +22,16 @@ declare(strict_types=1);
*/
namespace App\Services\LogSystem;
use App\Settings\SystemSettings\HistorySettings;
/**
* This service is used to check if a log change comment is needed for a given operation type.
* It is configured using the "enforce_change_comments_for" config parameter.
* @see \App\Tests\Services\LogSystem\EventCommentNeededHelperTest
*/
class EventCommentNeededHelper
final class EventCommentNeededHelper
{
public function __construct(protected array $enforce_change_comments_for)
public function __construct(private readonly HistorySettings $settings)
{
}
@ -39,6 +41,6 @@ class EventCommentNeededHelper
*/
public function isCommentNeeded(EventCommentType $comment_type): bool
{
return in_array($comment_type, $this->enforce_change_comments_for, true);
return in_array($comment_type, $this->settings->enforceComments, true);
}
}

View file

@ -23,11 +23,14 @@ declare(strict_types=1);
namespace App\Services\LogSystem;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* This enum represents the different types of event comments that could be required, by the system.
* They are almost only useful when working with the EventCommentNeededHelper service.
*/
enum EventCommentType: string
enum EventCommentType: string implements TranslatableInterface
{
case PART_EDIT = 'part_edit';
case PART_CREATE = 'part_create';
@ -36,4 +39,9 @@ enum EventCommentType: string
case DATASTRUCTURE_EDIT = 'datastructure_edit';
case DATASTRUCTURE_CREATE = 'datastructure_create';
case DATASTRUCTURE_DELETE = 'datastructure_delete';
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return $translator->trans('settings.system.history.enforceComments.type.' . $this->value, locale: $locale);
}
}