mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-28 05:54:05 +02:00
Moved the "ENFORCE_CHANGE_COMMENTS_FOR" type to the HistorySettings class
This commit is contained in:
parent
6df7bc5f2a
commit
5ab6a63492
9 changed files with 147 additions and 16 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue