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

Úpravy pro Obrok (přihlašování skupin) #1099

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
74 changes: 74 additions & 0 deletions .github/workflows/deploy-obrok-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: deploy-obrok-dev

on:
push:
branches: [obrok/master]

concurrency:
group: environment-dev

jobs:
deploy:
name: "Deploy to srs-obrok.skauting.cz"
environment: srs-obrok.skauting.cz
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
env:
CONFIG_DATABASE_HOST: ${{ secrets.CONFIG_DATABASE_HOST }}
CONFIG_DATABASE_NAME: ${{ secrets.CONFIG_DATABASE_NAME }}
CONFIG_DATABASE_PASSWORD: ${{ secrets.CONFIG_DATABASE_PASSWORD }}
CONFIG_DATABASE_USER: ${{ secrets.CONFIG_DATABASE_USER }}
CONFIG_MAIL_HOST:
CONFIG_MAIL_PASSWORD:
CONFIG_MAIL_PORT: 0
CONFIG_MAIL_SECURE:
CONFIG_MAIL_SMTP: false
CONFIG_MAIL_USERNAME:
CONFIG_MAILING_SENDER_EMAIL: ${{ secrets.CONFIG_MAILING_SENDER_EMAIL }}
CONFIG_SKAUTIS_APPLICATION_ID: ${{ secrets.CONFIG_SKAUTIS_APPLICATION_ID }}
CONFIG_SKAUTIS_TEST_MODE: ${{ secrets.CONFIG_SKAUTIS_TEST_MODE }}
CONFIG_RECAPTCHA_SITE_KEY: ${{ secrets.CONFIG_RECAPTCHA_SITE_KEY }}
CONFIG_RECAPTCHA_SECRET_KEY: ${{ secrets.CONFIG_RECAPTCHA_SECRET_KEY }}
DEPLOY_DIRECTORY: ${{ secrets.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ secrets.DEPLOY_LEBEDA }}
DEPLOY_SSH_HOST: ${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_SSH_IP: ${{ secrets.DEPLOY_SSH_IP }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
DEPLOY_SSH_PORT: ${{ secrets.DEPLOY_SSH_PORT }}
DEPLOY_SSH_USERNAME: ${{ secrets.DEPLOY_SSH_USERNAME }}
steps:
- uses: actions/checkout@v3
- run: git config --global --add safe.directory '*'
# Copy & paste from https://github.com/actions/cache/blob/master/examples.md#php---composer
- name: Get composer cache
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install yarn
run: |
apt-get update
apt-get install -y npm
npm install --global yarn
#Copy & paste from https://github.com/actions/cache/blob/master/examples.md#node---yarn
- name: Get yarn cache
id: yarn-cache
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup SSH key and deploy
run: |
mkdir -p /root/.ssh
ssh-keyscan -H "${DEPLOY_SSH_HOST}","${DEPLOY_SSH_IP}" >> /root/.ssh/known_hosts
eval `ssh-agent -s`
echo "${DEPLOY_SSH_KEY}" | tr -d '\r' | ssh-add -
phing deploy
119 changes: 119 additions & 0 deletions app/AdminModule/ConfigurationModule/Forms/GroupFormFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

declare(strict_types=1);

namespace App\AdminModule\ConfigurationModule\Forms;

use App\AdminModule\Forms\BaseFormFactory;
use App\Model\Settings\Commands\SetSettingDateValue;
use App\Model\Settings\Commands\SetSettingStringValue;
use App\Model\Settings\Queries\SettingDateValueQuery;
use App\Model\Settings\Queries\SettingStringValueQuery;
use App\Model\Settings\Settings;
use App\Services\CommandBus;
use App\Services\QueryBus;
use Nette;
use Nette\Application\UI\Form;
use Nette\Utils\DateTime;
use Nextras\FormComponents\Controls\DateControl;
use Nextras\FormsRendering\Renderers\Bs4FormRenderer;
use stdClass;
use Throwable;

use function assert;

/**
* Formulář pro nastavení semináře.
*/
class GroupFormFactory
{
use Nette\SmartObject;

public function __construct(
private BaseFormFactory $baseFormFactory,
private CommandBus $commandBus,
private QueryBus $queryBus,
) {
}

/**
* Vytvoří formulář.
*
* @throws Throwable
*/
public function create(): Form
{
$form = $this->baseFormFactory->create();

$renderer = $form->getRenderer();
assert($renderer instanceof Bs4FormRenderer);
$renderer->wrappers['control']['container'] = 'div class="col-7"';
$renderer->wrappers['label']['container'] = 'div class="col-5 col-form-label"';

$form->addText('groupMinMembers', 'admin.configuration.group_min_members')
->addRule(Form::FILLED, 'admin.configuration.group_min_members_empty');

$form->addText('groupMaxMembers', 'admin.configuration.group_max_members')
->addRule(Form::FILLED, 'admin.configuration.group_max_members_empty');

$groupFillTerm = new DateControl('admin.configuration.group_fill_term');
$groupFillTerm->addRule(Form::FILLED, 'admin.configuration.group_fill_term_empty');
$form->addComponent($groupFillTerm, 'groupFillTerm');



$form->addSubmit('submit', 'admin.common.save');

$form->setDefaults([
'groupMinMembers' => $this->queryBus->handle(new SettingStringValueQuery(Settings::GROUP_MIN_MEMBERS)),
'groupMaxMembers' => $this->queryBus->handle(new SettingStringValueQuery(Settings::GROUP_MAX_MEMBERS)),
'groupFillTerm' => $this->queryBus->handle(new SettingDateValueQuery(Settings::GROUP_FILL_TERM)),
]);

$form->onSuccess[] = [$this, 'processForm'];

return $form;
}

/**
* Zpracuje formulář.
*
* @throws Throwable
*/
public function processForm(Form $form, stdClass $values): void
{
$this->commandBus->handle(new SetSettingStringValue(Settings::GROUP_MIN_MEMBERS, $values->groupMinMembers));
$this->commandBus->handle(new SetSettingStringValue(Settings::GROUP_MAX_MEMBERS, $values->groupMaxMembers));
$this->commandBus->handle(new SetSettingDateValue(Settings::GROUP_FILL_TERM, $values->groupFillTerm));
}

/**
* Ověří, že datum začátku semináře je dříve než konce.
*
* @param DateTime[] $args
*/
public function validateSeminarFromDate(DateControl $field, array $args): bool
{
return $args[0] <= $args[1];
}

/**
* Ověří, že datum konce semináře je později než začátku.
*
* @param DateTime[] $args
*/
public function validateSeminarToDate(DateControl $field, array $args): bool
{
return $args[0] >= $args[1];
}

/**
* Ověří, že datum uzavření registrace je dříve než začátek semináře.
*
* @param DateTime[] $args
*/
public function validateEditRegistrationTo(DateControl $field, array $args): bool
{
return $args[0] < $args[1];
}
}
37 changes: 37 additions & 0 deletions app/AdminModule/ConfigurationModule/Presenters/GroupPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\AdminModule\ConfigurationModule\Presenters;

use App\AdminModule\ConfigurationModule\Forms\GroupFormFactory;
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
use Nette\Application\UI\Form;
use Nette\DI\Attributes\Inject;
use stdClass;
use Throwable;

/**
* Presenter obsluhující nastavení skupin.
*/
class GroupPresenter extends ConfigurationBasePresenter
{
#[Inject]
public GroupFormFactory $groupFormFactory;

/**
* @throws SettingsItemNotFoundException
* @throws Throwable
*/
protected function createComponentGroupForm(): Form
{
$form = $this->groupFormFactory->create();

$form->onSuccess[] = function (Form $form, stdClass $values): void {
$this->flashMessage('admin.configuration.configuration_saved', 'success');
$this->redirect('this');
};

return $form;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{block main}
<h2>{_admin.configuration.group_heading}</h2>
<div class="card card-body bg-light pb-1 mb-3">
{control groupForm}
</div>
{/block}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<a n:href="SkautIs:default" n:class="nav-link, $presenter->isLinkCurrent(':Admin:Configuration:SkautIs:*') ? active">
{_admin.configuration.menu.skautis}
</a>
<a n:href="Group:default" n:class="nav-link, $presenter->isLinkCurrent(':Admin:Configuration:Group:*') ? active">
{_admin.configuration.menu.group}
</a>
<a n:href="Web:default" n:class="nav-link, $presenter->isLinkCurrent(':Admin:Configuration:Web:*') ? active">
{_admin.configuration.menu.web}
</a>
Expand Down
Loading
Loading