Skip to content
Open
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
28 changes: 21 additions & 7 deletions app/presenters/SpravaSmluvPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ class SpravaSmluvPresenter extends BasePresenter

protected $smlouva;
protected $podpis;
protected $logger;

public function __construct(Model\Smlouva $smlouva, Model\PodpisSmlouvy $podpis) {
public function __construct(Model\Smlouva $smlouva,
Model\PodpisSmlouvy $podpis, Model\Log $logger) {
$this->smlouva = $smlouva;
$this->podpis = $podpis;
$this->logger = $logger;
}

// Zkontroluje ze jsme dostali ID a existuje smlouva s timto ID
Expand Down Expand Up @@ -85,8 +88,6 @@ public function parseDate(string $timestamp): DateTime {
}

public function actionCancelContract() {
// TODO: Logování změn

$contract_id = $this->getParameter('id');
$this->idAndContractExists($contract_id);
$this->userCanChange($contract_id);
Expand All @@ -97,21 +98,26 @@ public function actionCancelContract() {
$this->redirect('SpravaSmluv:show');
}

$now = new DateTime();
$updated_row = $current_contract->update([
'kdy_ukonceno' => new DateTime()
'kdy_ukonceno' => $now
]);

if ($updated_row) {
$this->flashMessage('Smlouva č. ' . $contract_id . ' vypovězena!');
$log = [];
$this->logger->logujUpdate(
['kdy_ukonceno' => null], ['kdy_ukonceno' => $now],
'Smlouva', $log
);
$this->logger->loguj('Smlouva', $current_contract->id, $log);
} else {
$this->flashMessage('Chyba ve vypovezení smlouvy.', 'danger');
}
$this->redirect('SpravaSmluv:show');
}

public function actionUpdateNote() {
// TODO: Logování změn

$request = $this->getHttpRequest();
$contract_id = $this->getParameter('id');

Expand All @@ -123,12 +129,20 @@ public function actionUpdateNote() {
$this->idAndContractExists($contract_id);
$this->userCanChange($contract_id);

$updated_row = $this->smlouva->find($contract_id)->update([
$current_contract = $this->smlouva->find($contract_id);
$old_note = $current_contract->poznamka;
$updated_row = $current_contract->update([
'poznamka' => $request->getPost('interni-poznamka')
]);

if ($updated_row) {
$this->flashMessage('Poznámka uložena');
$log = [];
$this->logger->logujUpdate(
['poznamka' => $old_note], ['poznamka' => $request->getPost('interni-poznamka')],
'Smlouva', $log
);
$this->logger->loguj('Smlouva', $current_contract->id, $log);
} else {
$this->flashMessage('Chyba při update poznámky.', 'danger');
}
Expand Down
9 changes: 3 additions & 6 deletions app/presenters/UzivatelActionsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Services;
use DateInterval;
use DateTime;
use Tracy\Debugger;

/**
* Uzivatel actions presenter.
Expand All @@ -20,7 +19,6 @@ class UzivatelActionsPresenter extends UzivatelPresenter
private $pdfGenerator;
private $mailService;
private $smlouva;

private Services\RequestDruzstvoContract $requestDruzstvoContract;
private Services\Stitkovac $stitkovac;

Expand All @@ -33,7 +31,7 @@ public function __construct(
Model\Smlouva $smlouva,
Services\RequestDruzstvoContract $requestDruzstvoContract,
Services\Stitkovac $stitkovac,
Services\CryptoSluzba $cryptosvc
Services\CryptoSluzba $cryptosvc,
) {
$this->parameters = $parameters;
$this->pdfGenerator = $pdf;
Expand Down Expand Up @@ -172,8 +170,6 @@ public function actionHandleSubscriberContractPreview() {
}

public function actionHandleSubscriberContract() {
// TODO: Logování změn

if (!$this->getParameter('id')) {
$this->flashMessage('Žádné id.');
$this->redirect('UzivatelList:listall');
Expand All @@ -188,11 +184,12 @@ public function actionHandleSubscriberContract() {
}

// Kontrola, že od poslední generace uběhlo aspoň 5 minut...
// $this->checkTimeSinceLastGenerateContract();
$this->checkTimeSinceLastGenerateContract();

$newId = $this->requestDruzstvoContract->execute($user_id);

$this->flashMessage(sprintf('Nová smlouva číslo %u bude odeslána na e-mail %s.', $newId, $current_user->email));

// Tady call na generaci nove smlouvy a odeslani
$this->redirect('Uzivatel:show', array('id' => $user_id));
}
Expand Down
1 change: 0 additions & 1 deletion app/presenters/UzivatelPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ public function renderShow() {
$seznamUzivatelu = array_merge($seznamUzivatelu, $this->uzivatel->findUsersIdsFromOtherAreasByAreaId($ap->id, $subnety));
}
}
// \Tracy\Debugger::barDump($seznamUzivatelu);

$this->template->canViewOrEdit = $this->getUser()->isInRole('EXTSUPPORT')
|| $this->ap->canViewOrEditAP($uzivatel->Ap_id, $this->getUser())
Expand Down
27 changes: 23 additions & 4 deletions app/services/RequestDruzstvoContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
namespace App\Services;

use Nette;
use App\Model;
use DateTime;

class RequestDruzstvoContract
{
private $connection;
public function __construct(Nette\Database\Connection $connection) {
private Model\Log $logger;

public function __construct(
Nette\Database\Connection $connection,
Model\Log $logger,
) {
$this->connection = $connection;
$this->logger = $logger;
}

public function execute(int $userId): int {
$now = new DateTime();

$this->connection->query('INSERT INTO Smlouva ?', [
'Uzivatel_id' => $userId,
'typ' => 'ucastnicka',
'kdy_vygenerovano' => new \Nette\Utils\DateTime()
'kdy_vygenerovano' => $now
]);
$newId = $this->connection->getInsertId();

Expand All @@ -24,7 +34,16 @@ public function execute(int $userId): int {
error_log("RUN: [$cmd2]", );
proc_close(proc_open($cmd2, array(), $foo));

return $newId;
}
$log = [];
$new_data = [
'id' => $newId,
'Uzivatel_id' => $userId,
'typ' => 'ucastnicka',
'kdy_vygenerovano' => $now
];
$this->logger->logujInsert($new_data, 'Smlouva', $log);
$this->logger->loguj('Smlouva', $newId, $log);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tady to funguje - do logu zapisuje


return (int) $newId;
}
}
31 changes: 31 additions & 0 deletions www/digisign-webhook/WebhookReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ function process_digisign_webhook($hook) {

$UzivatelModel = $container->getByType(\App\Model\Uzivatel::class);
$SmlouvaModel = $container->getByType(\App\Model\Smlouva::class);
$Logger = $container->getByType(\App\Model\Log::class);
$PodpisSmlouvyModel = $container->getByType(\App\Model\PodpisSmlouvy::class);
$Stitkovac = $container->getByType(\App\Services\Stitkovac::class);
$log = [];

$FILE_STORAGE_PATH = getenv('FILE_STORAGE_PATH') ?: '/tmp';
$FILE_STORAGE_PATH .= '/ucastnickeSmlouvy';
Expand Down Expand Up @@ -87,6 +89,7 @@ function process_digisign_webhook($hook) {
$podpis = $PodpisSmlouvyModel->findOneBy(['smlouva_id' => $smlouva->id, 'smluvni_strana' => 'ucastnik']);
$podpis->update(['kdy_podepsano' => $hook->time]);
print_and_log(sprintf("smlouva #%u podpis ucastnika \"%s\" datum/cas: %s", $smlouva->id, $podpis->jmeno, $hook->time));

// 2. stáhnout podepsaný PDF a uložit
$fileResponse = $ENVELOPES->download($envelope->id);
$documentFullName = "{$FILE_STORAGE_PATH}/{$envelope->documents[0]->name}";
Expand All @@ -95,14 +98,17 @@ function process_digisign_webhook($hook) {
$smlouva->update(['podepsany_dokument_nazev' => $envelope->documents[0]->name]);
$smlouva->update(['podepsany_dokument_content_type' => 'application/pdf']);
$smlouva->update(['podepsany_dokument_path' => $documentFullName]);

// 3. pokud nemáme datum narození, zkusíme parsovat vyplněný ze smlouvy
$uzivatel = $UzivatelModel->find($smlouva->uzivatel);
if (!$uzivatel->datum_narozeni) {
$recipient1 = $ENVELOPES->recipients($envelope)->get($envelope->recipients[0]->id);
$tags = $recipient1->tags->toArray();

foreach ($tags as $tag) {
if ($tag['recipientClaim'] == 'birthdate') {
$birthdate_dirty = $tag['value'];

try {
$d = new DateTime(preg_replace('/\s+/', '', $birthdate_dirty) . " 00:00:00");
print_and_log(sprintf('datum narozeni [%s] parsovano jako %s', $birthdate_dirty, $d->format('Y-m-d')));
Expand All @@ -122,10 +128,12 @@ function process_digisign_webhook($hook) {
}
}
}

// 4. zrušit členství ve spolku (pokud existuje)
if ($uzivatel->spolek) {
$uzivatel->update(['TypClenstvi_id' => 1]); // zrušeno
}

// 5. nastavit "vztah" s družstvem
$uzivatel->update(['druzstvo' => 1]);

Expand All @@ -135,6 +143,10 @@ function process_digisign_webhook($hook) {
// 7. Odstranit oneclick_auth (odkaz v e-mailu už nebude fungovat) /* migrace 2025 temporary */
$uzivatel->update(['oneclick_auth' => null]);

// 8. zalogovat, že smlouva byla podepsána

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zatím nemergovat. Tyhle 2 řádky vyhazujou 500 Internal Server Error a nejde to snadno debuggovat.

$Logger->logujInsert(['kdy_podepsano' => $hook->time], 'Smlouva', $log);
$Logger->loguj('Smlouva', $smlouva->id, $log);

break;
case 'envelopeDeclined': // obálka byla odmítnuta
/**
Expand All @@ -150,6 +162,7 @@ function process_digisign_webhook($hook) {
$podpis = $PodpisSmlouvyModel->findOneBy(['smlouva_id' => $smlouva->id, 'smluvni_strana' => 'ucastnik']);
$podpis->update(['kdy_odmitnuto' => $hook->time]);
print_and_log(sprintf("smlouva #%u podpis \"%s\" odmitnut, datum/cas: %s", $smlouva->id, $podpis->jmeno, $hook->time));

// 2. důvod odmítnutí uložit do poznámky
if (!empty($envelope->recipients[0]->declineReason)) {
$novaPoznamka = sprintf(
Expand All @@ -161,6 +174,15 @@ function process_digisign_webhook($hook) {
);
$smlouva->update(['poznamka' => $novaPoznamka]);
}

// 3. zalogovat, že smlouva byla odmítnnuta
$new_data = [
'kdy_odmitnuto' => $hook->time,
'poznamka' => $novaPoznamka
];
$Logger->logujInsert($new_data, 'Smlouva', $log);
$Logger->loguj('Smlouva', $smlouva->id, $log);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tohle je taky potřeba odzkoušet, viz 500 error vejš.


break;
case 'envelopeExpired': // obálka expirovala
// ověřit skutečný stav
Expand All @@ -177,6 +199,15 @@ function process_digisign_webhook($hook) {
empty($smlouva->poznamka) ? '' : "\n",
$envelope->recipients[0]->declinedAt->format('d.m.Y H:i'),
);

// 2. zalogovat že smlouva vypršela
$Logger->logujUpdate(
['poznamka' => $smlouva->poznamka],
['poznamka' => $novaPoznamka],
'Smlouva',
$log
);
$Logger->loguj('Smlouva', $smlouva->id, $log);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tady taky

$smlouva->update(['poznamka' => $novaPoznamka]);
break;
case 'envelopeCancelled': // obálka byla zrušena
Expand Down
4 changes: 3 additions & 1 deletion www/digisign-webhook/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
return;
}

print_and_log(sprintf("%s %s %s", $hook->event, $hook->entityName, $hook->entityId));
print_and_log(sprintf("%s (%s %s) START", $hook->event, $hook->entityName, $hook->entityId));

process_digisign_webhook($hook);

print_and_log(sprintf("%s (%s %s) DONE", $hook->event, $hook->entityName, $hook->entityId));

http_response_code(200);