Skip to content

Commit

Permalink
Merge branch 'master' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-stanek authored Dec 20, 2024
2 parents 2ecd818 + b266189 commit b4c2cae
Show file tree
Hide file tree
Showing 31 changed files with 1,138 additions and 824 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
environment: test-srs.skauting.cz
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
env:
CONFIG_DATABASE_HOST: ${{ secrets.CONFIG_DATABASE_HOST }}
CONFIG_DATABASE_NAME: ${{ secrets.CONFIG_DATABASE_NAME }}
Expand All @@ -28,11 +28,11 @@ jobs:
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_SKAUTIS_TEST_MODE: ${{ vars.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_DIRECTORY: ${{ vars.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ vars.DEPLOY_LEBEDA }}
DEPLOY_SSH_HOST: ${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_SSH_IP: ${{ secrets.DEPLOY_SSH_IP }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
Expand Down Expand Up @@ -66,10 +66,13 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup SSH key and deploy
- name: Setup SSH2
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
apt-get -y install libssh2-1-dev
pecl install pecl.php.net/ssh2-1.4.1
echo extension=ssh2.so > /usr/local/etc/php/conf.d/ssh2.ini
echo "${{ secrets.DEPLOY_SSH_KEY }}" | tr -d '\r' > id_rsa
chmod 600 id_rsa
ssh-keygen -f id_rsa -y > id_rsa.pub
- name: Deploy
run: phing deploy
25 changes: 14 additions & 11 deletions .github/workflows/deploy-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
environment: ${{ github.event.inputs.environment }}
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
env:
CONFIG_DATABASE_HOST: ${{ secrets.CONFIG_DATABASE_HOST }}
CONFIG_DATABASE_NAME: ${{ secrets.CONFIG_DATABASE_NAME }}
Expand All @@ -26,16 +26,16 @@ jobs:
CONFIG_MAIL_HOST: ${{ secrets.CONFIG_MAIL_HOST }}
CONFIG_MAIL_PASSWORD: ${{ secrets.CONFIG_MAIL_PASSWORD }}
CONFIG_MAIL_PORT: ${{ secrets.CONFIG_MAIL_PORT }}
CONFIG_MAIL_SECURE: ${{ secrets.CONFIG_MAIL_SECURE }}
CONFIG_MAIL_SECURE: ${{ vars.CONFIG_MAIL_SECURE }}
CONFIG_MAIL_SMTP: ${{ secrets.CONFIG_MAIL_SMTP }}
CONFIG_MAIL_USERNAME: ${{ secrets.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_SKAUTIS_TEST_MODE: ${{ vars.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_DIRECTORY: ${{ vars.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ vars.DEPLOY_LEBEDA }}
DEPLOY_SSH_HOST: ${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_SSH_IP: ${{ secrets.DEPLOY_SSH_IP }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
Expand Down Expand Up @@ -69,10 +69,13 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup SSH key and deploy
- name: Setup SSH2
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
apt-get -y install libssh2-1-dev
pecl install pecl.php.net/ssh2-1.4.1
echo extension=ssh2.so > /usr/local/etc/php/conf.d/ssh2.ini
echo "${{ secrets.DEPLOY_SSH_KEY }}" | tr -d '\r' > id_rsa
chmod 600 id_rsa
ssh-keygen -f id_rsa -y > id_rsa.pub
- name: Deploy
run: phing deploy
23 changes: 13 additions & 10 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
environment: srs.skauting.cz
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
env:
CONFIG_DATABASE_HOST: ${{ secrets.CONFIG_DATABASE_HOST }}
CONFIG_DATABASE_NAME: ${{ secrets.CONFIG_DATABASE_NAME }}
Expand All @@ -27,11 +27,11 @@ jobs:
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_SKAUTIS_TEST_MODE: ${{ vars.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_DIRECTORY: ${{ vars.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ vars.DEPLOY_LEBEDA }}
DEPLOY_SSH_HOST: ${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_SSH_IP: ${{ secrets.DEPLOY_SSH_IP }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
Expand Down Expand Up @@ -65,10 +65,13 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup SSH key and deploy
- name: Setup SSH2
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
apt-get -y install libssh2-1-dev
pecl install pecl.php.net/ssh2-1.4.1
echo extension=ssh2.so > /usr/local/etc/php/conf.d/ssh2.ini
echo "${{ secrets.DEPLOY_SSH_KEY }}" | tr -d '\r' > id_rsa
chmod 600 id_rsa
ssh-keygen -f id_rsa -y > id_rsa.pub
- name: Deploy
run: phing deploy
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: "Create release package"
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
steps:
- uses: actions/checkout@v4
# Copy & paste from https://github.com/actions/cache/blob/master/examples.md#php---composer
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: "Build"
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
steps:
- uses: actions/checkout@v4
# Copy & paste from https://github.com/actions/cache/blob/master/examples.md#php---composer
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
name: "Unit tests"
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
needs: workdir
steps:
- name: Download workdir
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
name: "PHPStan analysis"
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
needs: workdir
steps:
- name: Download workdir
Expand All @@ -131,7 +131,7 @@ jobs:
name: "Coding standard"
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
needs: workdir
steps:
- name: Download workdir
Expand All @@ -147,7 +147,7 @@ jobs:
name: "Doctrine checks"
runs-on: ubuntu-22.04
container:
image: skaut/lebeda:8.1
image: skaut/lebeda:8.3
services:
mysql-test:
image: mysql:8.0
Expand Down
2 changes: 1 addition & 1 deletion app/AdminModule/Components/UsersGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function createComponentUsersGrid(string $name): DataGrid
->andWhere('uA.validTo IS NULL')
->andWhere('uA.state IN (:states)')
->setParameter('sids', (array) $values)
->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::WAITING_FOR_PAYMENT]);
->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::PAID_TRANSFERED, ApplicationState::WAITING_FOR_PAYMENT]);
});

$columnApproved = $grid->addColumnStatus('approved', 'admin.users.users_approved');
Expand Down
79 changes: 79 additions & 0 deletions app/AdminModule/Forms/EditUserTransferFormFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace App\AdminModule\Forms;

use App\AdminModule\Presenters\AdminBasePresenter;
use App\Model\User\Repositories\UserRepository;
use App\Model\User\User;
use App\Services\ApplicationService;
use Contributte\Translation\Translator;
use Nette;
use Nette\Application\UI\Form;
use Nette\Utils\ImageException;
use stdClass;

use function assert;

/**
* Formulář pro předání registrace jinému uživateli.
*/
class EditUserTransferFormFactory
{
use Nette\SmartObject;

/**
* Upravovaný uživatel.
*/
private User|null $user = null;

public function __construct(
private readonly BaseFormFactory $baseFormFactory,
private readonly UserRepository $userRepository,
private readonly ApplicationService $applicationService,
private readonly Translator $translator,
) {
}

public function create(int $id): Form
{
$this->user = $this->userRepository->findById($id);

$form = $this->baseFormFactory->create();

$form->addSelect('targetUser', 'admin.users.users_target_user', $this->userRepository->getUsersOptions(true))
->addRule(Form::NOT_EQUAL, 'admin.users.users_target_user_empty', 0)
->addRule(Form::NOT_EQUAL, 'admin.users.users_target_user_same', $this->user->getId())
->setHtmlAttribute('data-live-search', 'true');

$form->addSubmit('submit', 'admin.users.users_transfer')
->setDisabled(! $this->user->isRegistered() || ! $this->user->hasPaidAnyApplication())
->setHtmlAttribute('class', 'btn btn-danger')
->setHtmlAttribute('data-toggle', 'confirmation')
->setHtmlAttribute('data-content', $this->translator->translate('admin.users.users_transfer_confirm'))
->setHtmlAttribute('data-html', 'true');

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

return $form;
}

/**
* Zpracuje formulář.
*
* @throws Nette\Utils\UnknownImageFileException
* @throws ImageException
*/
public function processForm(Form $form, stdClass $values): void
{
$presenter = $form->getPresenter();
assert($presenter instanceof AdminBasePresenter);

$loggedUser = $presenter->getDbUser();

$targetUser = $this->userRepository->findById($values->targetUser);

$this->applicationService->transferRegistration($this->user, $targetUser, $loggedUser);
}
}
34 changes: 17 additions & 17 deletions app/AdminModule/Presenters/UsersPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\AdminModule\Forms\AddLectorFormFactory;
use App\AdminModule\Forms\EditUserPersonalDetailsFormFactory;
use App\AdminModule\Forms\EditUserSeminarFormFactory;
use App\AdminModule\Forms\EditUserTransferFormFactory;
use App\Model\Acl\Permission;
use App\Model\Acl\Role;
use App\Model\Acl\SrsResource;
Expand Down Expand Up @@ -48,6 +49,9 @@ class UsersPresenter extends AdminBasePresenter
#[Inject]
public EditUserSeminarFormFactory $editUserSeminarFormFactory;

#[Inject]
public EditUserTransferFormFactory $editUserTransferFormFactory;

#[Inject]
public IApplicationsGridControlFactory $applicationsGridControlFactory;

Expand All @@ -73,7 +77,6 @@ public function startup(): void
$this->template->results = [];
$this->template->editPersonalDetails = false;
$this->template->editSeminar = false;
$this->template->editPayment = false;
}

public function renderDetail(int $id): void
Expand Down Expand Up @@ -137,22 +140,6 @@ public function handleEditSeminar(): void
}
}

/**
* Zobrazí formulář pro editaci údajů o platbě uživatele.
*
* @throws AbortException
*/
public function handleEditPayment(): void
{
$this->template->editPayment = true;

if ($this->isAjax()) {
$this->redrawControl('userDetail');
} else {
$this->redirect('this');
}
}

/** @throws Throwable */
public function handleCancelRegistration(): void
{
Expand Down Expand Up @@ -235,6 +222,19 @@ protected function createComponentEditUserSeminarForm(): Form
return $form;
}

/** @throws JsonException */
protected function createComponentEditUserTransferForm(): Form
{
$form = $this->editUserTransferFormFactory->create((int) $this->getParameter('id'));

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

return $form;
}

protected function createComponentApplicationsGrid(): ApplicationsGridControl
{
return $this->applicationsGridControlFactory->create();
Expand Down
5 changes: 5 additions & 0 deletions app/AdminModule/Presenters/templates/Users/detail.latte
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@
{/if}
</div>

<h3>{_admin.users.users_detail_transfer}</h3>
<div class="card card-body bg-light pb-1 mb-3">
{control editUserTransferForm}
</div>

<h3>{_admin.users.users_detail_schedule}</h3>
<table class="table table-sm table-bordered table-striped">
<thead>
Expand Down
2 changes: 1 addition & 1 deletion app/ApiModule/Presenters/TicketsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function actionCheckTicket(int $userId, int $subeventId): void
$subevents = [];
$hasSubevent = false;

foreach ($user->getPaidAndFreeApplications() as $application) {
foreach ($user->getPaidAndTransferedAndFreeApplications() as $application) {
if ($application instanceof RolesApplication) {
foreach ($application->getRoles() as $r) {
$roles[] = $r->getName();
Expand Down
4 changes: 2 additions & 2 deletions app/Model/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ public function isValid(): bool

public function isCanceled(): bool
{
return $this->state === ApplicationState::CANCELED || $this->state === ApplicationState::CANCELED_NOT_PAID;
return $this->state === ApplicationState::CANCELED || $this->state === ApplicationState::CANCELED_NOT_PAID || $this->state === ApplicationState::CANCELED_TRANSFERED;
}

public function isPaid(): bool
{
return $this->state === ApplicationState::PAID || $this->getState() === ApplicationState::PAID_FREE;
return $this->state === ApplicationState::PAID || $this->getState() === ApplicationState::PAID_FREE || $this->getState() === ApplicationState::PAID_TRANSFERED;
}

public function isWaitingForPayment(): bool
Expand Down
Loading

0 comments on commit b4c2cae

Please sign in to comment.