From b6d80c5ea782699bcc663f3bd1e33a739a751697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Fri, 3 Mar 2023 22:58:43 +0100 Subject: [PATCH 1/3] disable registration --- .../Components/TroopApplicationContentControl.php | 5 +++++ .../templates/troop_application_content.latte | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/WebModule/Components/TroopApplicationContentControl.php b/app/WebModule/Components/TroopApplicationContentControl.php index 9d2482a73..a96e6bd7a 100644 --- a/app/WebModule/Components/TroopApplicationContentControl.php +++ b/app/WebModule/Components/TroopApplicationContentControl.php @@ -79,6 +79,11 @@ public function render(?ContentDto $content = null): void $dbuser = $this->userRepository->findById($user->id); $template->dbuser = $dbuser; + $template->registrationAllowed = $this->roleRepository->findBySystemName(Role::ATTENDEE)->isRegisterableNow() + && $this->roleRepository->findBySystemName(Role::PATROL_LEADER)->isRegisterableNow() + && $this->roleRepository->findBySystemName(Role::LEADER)->isRegisterableNow() + && $this->roleRepository->findBySystemName(Role::ESCORT)->isRegisterableNow(); + $skautIsUserId = $dbuser->getSkautISUserId(); $skautIsRoles = $this->skautIsService->getUserRoles($skautIsUserId, self::$ALLOWED_ROLE_TYPES); $template->skautIsRoles = $skautIsRoles; diff --git a/app/WebModule/Components/templates/troop_application_content.latte b/app/WebModule/Components/templates/troop_application_content.latte index f273ab25e..7b0a7d94d 100644 --- a/app/WebModule/Components/templates/troop_application_content.latte +++ b/app/WebModule/Components/templates/troop_application_content.latte @@ -46,6 +46,7 @@ + {if $registrationAllowed || $troop->getState() !== 'draft'}
Pracuješ v roli @@ -220,5 +221,14 @@ {control troopConfirmForm}
+ {else} +
+
+
+ Registrace nové skupiny není v tuto chvíli povolena. +
+
+
+ {/if} {/if} From e82ade836bcfab95575d44cb92328587b5beff2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Fri, 3 Mar 2023 23:16:07 +0100 Subject: [PATCH 2/3] config property --- .../ConfigurationModule/Forms/SeminarFormFactory.php | 6 ++++++ app/Model/Settings/Settings.php | 5 +++++ app/WebModule/Components/TroopApplicationContentControl.php | 6 ++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/AdminModule/ConfigurationModule/Forms/SeminarFormFactory.php b/app/AdminModule/ConfigurationModule/Forms/SeminarFormFactory.php index 28c8957b1..0ebf16d1a 100644 --- a/app/AdminModule/ConfigurationModule/Forms/SeminarFormFactory.php +++ b/app/AdminModule/ConfigurationModule/Forms/SeminarFormFactory.php @@ -5,8 +5,10 @@ namespace App\AdminModule\ConfigurationModule\Forms; use App\AdminModule\Forms\BaseFormFactory; +use App\Model\Settings\Commands\SetSettingBoolValue; use App\Model\Settings\Commands\SetSettingDateValue; use App\Model\Settings\Commands\SetSettingStringValue; +use App\Model\Settings\Queries\SettingBoolValueQuery; use App\Model\Settings\Queries\SettingDateValueQuery; use App\Model\Settings\Queries\SettingStringValueQuery; use App\Model\Settings\Settings; @@ -71,6 +73,8 @@ public function create(): Form $seminarToDate->addRule([$this, 'validateSeminarToDate'], 'admin.configuration.seminar_to_date_before_from', [$seminarToDate, $seminarFromDate]); $editRegistrationTo->addRule([$this, 'validateEditRegistrationTo'], 'admin.configuration.edit_registration_to_after_from', [$editRegistrationTo, $seminarFromDate]); + $form->addCheckbox('groupRegistrationAllowed', 'povolit registraci nových skupin'); + $form->addSubmit('submit', 'admin.common.save'); $form->setDefaults([ @@ -78,6 +82,7 @@ public function create(): Form 'seminarFromDate' => $this->queryBus->handle(new SettingDateValueQuery(Settings::SEMINAR_FROM_DATE)), 'seminarToDate' => $this->queryBus->handle(new SettingDateValueQuery(Settings::SEMINAR_TO_DATE)), 'editRegistrationTo' => $this->queryBus->handle(new SettingDateValueQuery(Settings::EDIT_REGISTRATION_TO)), + 'groupRegistrationAllowed' => $this->queryBus->handle(new SettingBoolValueQuery(Settings::GROUP_REGISTRATION_ALLOWED)), ]); $form->onSuccess[] = [$this, 'processForm']; @@ -100,6 +105,7 @@ public function processForm(Form $form, stdClass $values): void $this->commandBus->handle(new SetSettingDateValue(Settings::SEMINAR_FROM_DATE, $values->seminarFromDate)); $this->commandBus->handle(new SetSettingDateValue(Settings::SEMINAR_TO_DATE, $values->seminarToDate)); $this->commandBus->handle(new SetSettingDateValue(Settings::EDIT_REGISTRATION_TO, $values->editRegistrationTo)); + $this->commandBus->handle(new SetSettingBoolValue(Settings::GROUP_REGISTRATION_ALLOWED, $values->groupRegistrationAllowed)); } /** diff --git a/app/Model/Settings/Settings.php b/app/Model/Settings/Settings.php index 255cde18f..de5e9771d 100644 --- a/app/Model/Settings/Settings.php +++ b/app/Model/Settings/Settings.php @@ -234,6 +234,11 @@ class Settings */ public const CONTACT_FORM_GUESTS_ALLOWED = 'contact_form_guests_allowed'; + /** + * Povolit registraci skupiny. + */ + public const GROUP_REGISTRATION_ALLOWED = 'group_registration_allowed'; + /** * Název položky nastavení. */ diff --git a/app/WebModule/Components/TroopApplicationContentControl.php b/app/WebModule/Components/TroopApplicationContentControl.php index a96e6bd7a..7b5c3e228 100644 --- a/app/WebModule/Components/TroopApplicationContentControl.php +++ b/app/WebModule/Components/TroopApplicationContentControl.php @@ -7,6 +7,7 @@ use App\Model\Acl\Repositories\RoleRepository; use App\Model\Acl\Role; use App\Model\Cms\Dto\ContentDto; +use App\Model\Settings\Queries\SettingBoolValueQuery; use App\Model\Settings\Queries\SettingStringValueQuery; use App\Model\Settings\Settings; use App\Model\User\Commands\RegisterTroop; @@ -79,10 +80,7 @@ public function render(?ContentDto $content = null): void $dbuser = $this->userRepository->findById($user->id); $template->dbuser = $dbuser; - $template->registrationAllowed = $this->roleRepository->findBySystemName(Role::ATTENDEE)->isRegisterableNow() - && $this->roleRepository->findBySystemName(Role::PATROL_LEADER)->isRegisterableNow() - && $this->roleRepository->findBySystemName(Role::LEADER)->isRegisterableNow() - && $this->roleRepository->findBySystemName(Role::ESCORT)->isRegisterableNow(); + $template->registrationAllowed = $this->queryBus->handle(new SettingBoolValueQuery(Settings::GROUP_REGISTRATION_ALLOWED)); $skautIsUserId = $dbuser->getSkautISUserId(); $skautIsRoles = $this->skautIsService->getUserRoles($skautIsUserId, self::$ALLOWED_ROLE_TYPES); From 033b7f237db100b52b6f55112cf96f28e97d6099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Sat, 4 Mar 2023 00:20:30 +0100 Subject: [PATCH 3/3] migration added --- migrations/Version20230303221015.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 migrations/Version20230303221015.php diff --git a/migrations/Version20230303221015.php b/migrations/Version20230303221015.php new file mode 100644 index 000000000..540369ff8 --- /dev/null +++ b/migrations/Version20230303221015.php @@ -0,0 +1,27 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('INSERT INTO `settings` (`item`, `value`) VALUES (\'group_registration_allowed\', \'0\')'); + } + + public function down(Schema $schema): void + { + } +}