Skip to content

Commit

Permalink
Vypínatelná registrace (#958)
Browse files Browse the repository at this point in the history
* disable registration

* config property
  • Loading branch information
jan-stanek authored Mar 3, 2023
1 parent e18216c commit 22cacb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,13 +73,16 @@ 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([
'seminarName' => $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)),
'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'];
Expand All @@ -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));
}

/**
Expand Down
5 changes: 5 additions & 0 deletions app/Model/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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í.
*/
Expand Down
3 changes: 3 additions & 0 deletions app/WebModule/Components/TroopApplicationContentControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,8 @@ public function render(?ContentDto $content = null): void
$dbuser = $this->userRepository->findById($user->id);
$template->dbuser = $dbuser;

$template->registrationAllowed = $this->queryBus->handle(new SettingBoolValueQuery(Settings::GROUP_REGISTRATION_ALLOWED));

$skautIsUserId = $dbuser->getSkautISUserId();
$skautIsRoles = $this->skautIsService->getUserRoles($skautIsUserId, self::$ALLOWED_ROLE_TYPES);
$template->skautIsRoles = $skautIsRoles;
Expand Down
10 changes: 10 additions & 0 deletions app/WebModule/Components/templates/troop_application_content.latte
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
</div>
</div>

{if $registrationAllowed || $troop->getState() !== 'draft'}
<div class="form-group row">
<div class="col-3 col-form-label">
Pracuješ v roli
Expand Down Expand Up @@ -220,5 +221,14 @@
{control troopConfirmForm}
</div>
</div>
{else}
<div class="row">
<div class="col">
<div class="alert alert-info alert-forever">
Registrace nové skupiny není v tuto chvíli povolena.
</div>
</div>
</div>
{/if}
{/if}
</div>

0 comments on commit 22cacb7

Please sign in to comment.