Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zapomenutá migrace #959

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
27 changes: 27 additions & 0 deletions migrations/Version20230303221015.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20230303221015 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->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
{
}
}