From f1562c43070069067949916bae6bd16c872b816f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 8 Apr 2023 04:36:25 +0200 Subject: [PATCH] fix billing process --- .github/user_bug_report.md | 14 +- Admin/Install/Media.php | 56 ++++--- .../PdfDefaultTemplate/pdfTemplate.pdf.php | 144 +++++++++++------ .../defaultPdfListExporter.pdf.php | 5 +- Admin/Install/db.json | 6 +- Admin/Install/settings.php | 152 +++++++++--------- Admin/Installer.php | 17 +- Controller/ApiController.php | 102 ++++++------ Controller/BackendController.php | 4 +- Models/AccountExternalMapper.php | 2 +- Models/AccountPermission.php | 4 +- Models/AccountPermissionMapper.php | 2 +- Models/GroupPermission.php | 4 +- Models/GroupPermissionMapper.php | 2 +- tests/Controller/ApiControllerTest.php | 2 +- 15 files changed, 287 insertions(+), 229 deletions(-) diff --git a/.github/user_bug_report.md b/.github/user_bug_report.md index 9e5f2a5..4b92a8e 100755 --- a/.github/user_bug_report.md +++ b/.github/user_bug_report.md @@ -8,9 +8,11 @@ assignees: '' --- # Bug Description + A clear and concise description of what the bug is. # How to Reproduce + Steps to reproduce the behavior: 1. Go to '...' @@ -19,16 +21,20 @@ Steps to reproduce the behavior: 4. See error # Expected Behavior + A clear and concise description of what you expected to happen. # Screenshots + If applicable, add screenshots to help explain your problem. # System Information - - System: [e.g. PC or iPhone11, ...] - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - KarakaVersion [e.g. 22] + +- System: [e.g. PC or iPhone11, ...] +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- KarakaVersion [e.g. 22] # Additional Information + Add any other context about the problem here. diff --git a/Admin/Install/Media.php b/Admin/Install/Media.php index cd69acc..bffc618 100755 --- a/Admin/Install/Media.php +++ b/Admin/Install/Media.php @@ -45,32 +45,36 @@ class Media \Modules\Admin\Admin\Installer::installExternal($app, [ - 'type' => 'setting', - 'name' => SettingsEnum::DEFAULT_LIST_EXPORTS, - 'content' => (string) $media['collection'][4]['id'], - 'pattern' => '\\d+', - 'module' => 'Admin' - ], - [ - 'type' => 'setting', - 'name' => SettingsEnum::DEFAULT_LETTERS, - 'content' => (string) $media['collection'][5]['id'], - 'pattern' => '\\d+', - 'module' => 'Admin' - ], - [ - 'type' => 'setting', - 'name' => SettingsEnum::DEFAULT_ASSETS, - 'content' => (string) $media['upload'][0]['id'], - 'pattern' => '\\d+', - 'module' => 'Admin' - ], - [ - 'type' => 'setting', - 'name' => SettingsEnum::DEFAULT_TEMPLATES, - 'content' => (string) $media['upload'][1]['id'], - 'pattern' => '\\d+', - 'module' => 'Admin' + 'data' => [ + [ + 'type' => 'setting', + 'name' => SettingsEnum::DEFAULT_LIST_EXPORTS, + 'content' => (string) $media['collection'][4]['id'], + 'pattern' => '\\d+', + 'module' => 'Admin' + ], + [ + 'type' => 'setting', + 'name' => SettingsEnum::DEFAULT_LETTERS, + 'content' => (string) $media['collection'][5]['id'], + 'pattern' => '\\d+', + 'module' => 'Admin' + ], + [ + 'type' => 'setting', + 'name' => SettingsEnum::DEFAULT_ASSETS, + 'content' => (string) $media['upload'][0]['id'], + 'pattern' => '\\d+', + 'module' => 'Admin' + ], + [ + 'type' => 'setting', + 'name' => SettingsEnum::DEFAULT_TEMPLATES, + 'content' => (string) $media['upload'][1]['id'], + 'pattern' => '\\d+', + 'module' => 'Admin' + ] + ] ] ); } diff --git a/Admin/Install/Media/PdfDefaultTemplate/pdfTemplate.pdf.php b/Admin/Install/Media/PdfDefaultTemplate/pdfTemplate.pdf.php index b9b5fb0..80abf3f 100755 --- a/Admin/Install/Media/PdfDefaultTemplate/pdfTemplate.pdf.php +++ b/Admin/Install/Media/PdfDefaultTemplate/pdfTemplate.pdf.php @@ -19,6 +19,8 @@ declare(strict_types=1); * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 + * + * @phpstan-import-type TCPDF from ../../../../../Resources/tcpdf.php */ class DefaultPdf extends TCPDF { @@ -46,6 +48,43 @@ class DefaultPdf extends TCPDF */ public int $sideMargin = 15; + public string $language = 'en'; + + public array $lang = [ + 'en' => [ + 'Page' => 'Page', + 'CEO' => 'CEO', + 'TaxOffice' => 'Tax office', + 'TaxNumber' => 'Tax number', + 'Swift' => 'BIC', + 'BankAccount' => 'Account', + ], + 'de' => [ + 'Page' => 'Seite', + 'CEO' => 'Geschäftsführer', + 'TaxOffice' => 'Finanzamt', + 'TaxNumber' => 'Steuernummer', + 'Swift' => 'BIC', + 'BankAccount' => 'IBAN', + ] + ]; + + public array $attributes = [ + 'legal_name' => '', + 'address' => '', + 'city' => '', + 'country' => '', + 'ceo' => '', + 'tax_office' => '', + 'tax_number' => '', + 'bank_name' => '', + 'swift' => '', + 'bank_account' => '', + 'website' => '', + 'email' => '', + 'phone' => '', + ]; + /** * Constructor. * @@ -55,29 +94,24 @@ class DefaultPdf extends TCPDF { parent::__construct('P', 'mm', 'A4', true, 'UTF-8', false); - $this->SetCreator("Jingga"); - // set default header data - $this->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'Jingga', 'Business solutions made simple.'); + $this->setHeaderData('', 15, 'Jingga', 'Business solutions made simple.'); // set header and footer fonts - $this->SetHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); - $this->SetFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); + $this->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); + $this->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); // set default monospaced font - $this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); + $this->setDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins - $this->SetMargins(15, 30, 15); + $this->setMargins(15, 30, 15); // set auto page breaks - $this->SetAutoPageBreak(true, 25); + $this->setAutoPageBreak(true, 25); // set image scale factor - $this->SetImageScale(PDF_IMAGE_SCALE_RATIO); - - // add a page - $this->AddPage(); + $this->setImageScale(PDF_IMAGE_SCALE_RATIO); } /** @@ -93,15 +127,21 @@ class DefaultPdf extends TCPDF $this->header_xobjid = $this->startTemplate($this->w, 0); // Set Logo - $image_file = '/home/spl1nes/Orange-Management/Web/Backend/img/logo.png'; - $this->Image($image_file, 15, 15, 15, 15, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false); + if (!empty($this->header_logo)) { + $this->Image( + $this->header_logo, + 15, 15, + $this->header_logo_width, 0, + 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false + ); + } // Set Title - $this->SetFont('helvetica', 'B', 20); + $this->setFont('helvetica', 'B', 20); $this->setX(15 + 15 + 3); $this->Cell(0, 14, $this->header_title, 0, false, 'L', 0, '', 0, false, 'T', 'M'); - $this->SetFont('helvetica', '', 10); + $this->setFont('helvetica', '', 10); $this->setX(15 + 15 + 3); $this->Cell(0, 26, $this->header_string, 0, false, 'L', 0, '', 0, false, 'T', 'M'); @@ -138,50 +178,52 @@ class DefaultPdf extends TCPDF */ public function Footer() : void { - $this->SetY(-25); + $this->setY(-25); - $this->SetFont('helvetica', 'I', 7); - $this->Cell($this->getPageWidth() - 22, 0, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M'); + $this->setFont('helvetica', 'I', 7); + $this->Cell($this->getPageWidth() - 22, 0, $this->lang[$this->language]['Page'] . ' '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M'); $this->Ln(); $this->Ln(); $this->SetFillColor(245, 245, 245); - $this->SetX(0); + $this->setX(0); $this->Cell($this->getPageWidth(), 25, '', 0, 0, 'L', true, '', 0, false, 'T', 'T'); - $this->SetFont('helvetica', '', 7); - $this->SetXY(15 + 10, -15, true); - $this->MultiCell(30, 0, "Jingga e.K.\nGartenstr. 26\n61206 Woellstadt", 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B'); + $this->setFont('helvetica', '', 7); + $this->setXY(15 + 10, -15, true); + $this->MultiCell( + 30, 0, + $this->attributes['legal_name'] . "\n" + . $this->attributes['address'] . "\n" + . $this->attributes['city'], + 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' + ); - $this->SetXY(25 + 15 + 20, -15, true); - $this->MultiCell(40, 0, "Geschäftsführer: Dennis Eichhorn\nFinanzamt: HRB ???\nUSt Id: DE ??????????", 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B'); + $this->setXY(25 + 15 + 20, -15, true); + $this->MultiCell( + 40, 0, + $this->lang[$this->language]['CEO']. ': ' . $this->attributes['ceo'] . "\n" + . $this->lang[$this->language]['TaxOffice']. ': ' . $this->attributes['tax_office'] . "\n" + . $this->lang[$this->language]['TaxNumber']. ': ' . $this->attributes['tax_number'], + 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' + ); - $this->SetXY(25 + 45 + 15 + 30, -15, true); - $this->MultiCell(35, 0, "Volksbank Mittelhessen\nBIC: ??????????\nIBAN: ???????????", 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B'); + $this->setXY(25 + 45 + 15 + 30, -15, true); + $this->MultiCell( + 35, 0, + $this->attributes['bank_name'] . "\n" + . $this->lang[$this->language]['Swift']. ': ' . $this->attributes['swift'] . "\n" + . $this->lang[$this->language]['BankAccount']. ': ' . $this->attributes['bank_account'], + 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' + ); - $this->SetXY(25 + 45 + 35 + 15 + 40, -15, true); - $this->MultiCell(35, 0, "www.jingga.app\ninfo@jingga.app\n+49 0152 ???????", 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B'); + $this->setXY(25 + 45 + 35 + 15 + 40, -15, true); + $this->MultiCell( + 35, 0, + $this->attributes['website'] . "\n" + . $this->attributes['email'] . "\n" + . $this->attributes['phone'], + 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' + ); } } - -/* -[ - 'company' => '', - 'slogan' => '', - 'company_full' => '', - 'address' => '', - 'ciry' => '', - 'manager' => '', - 'tax_office' => '', - 'tax_id' => '', - 'tax_vat' => '', - 'bank_name' => '', - 'bank_bic' => '', - 'bank_iban' => '', - 'website' => '', - 'email' => '', - 'phone' => '', - 'creator' => '', - 'date' => '', -] -*/ diff --git a/Admin/Install/Media/PdfListExporter/defaultPdfListExporter.pdf.php b/Admin/Install/Media/PdfListExporter/defaultPdfListExporter.pdf.php index ee708b2..1d77018 100755 --- a/Admin/Install/Media/PdfListExporter/defaultPdfListExporter.pdf.php +++ b/Admin/Install/Media/PdfListExporter/defaultPdfListExporter.pdf.php @@ -22,7 +22,8 @@ $data = $this->getData('data') ?? []; include $media->getSourceByName('template.php')->getAbsolutePath(); -$excel = new DefaultPdf(); +/** @phpstan-import-type DefaultPdf from ../../../../Admin/Install/Media/PdfDefaultTemplate/pdfTemplate.pdf.php */ +$pdf = new DefaultPdf(); $topPos = $pdf->getY(); @@ -46,4 +47,4 @@ foreach ($data as $i => $row) { } $tbl .= ''; -$pdf->Output('list.pdf', 'I'); \ No newline at end of file +$pdf->Output('list.pdf', 'I'); diff --git a/Admin/Install/db.json b/Admin/Install/db.json index a7c5542..76f8f48 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -16,7 +16,7 @@ }, "country_code2": { "name": "country_code2", - "type": "VARCHAR(2)", + "type": "VARCHAR(3)", "null": false, "unique": true }, @@ -930,7 +930,7 @@ "group_permission_app": { "description": "@todo: consider to use int as value and create foreign key", "name": "group_permission_app", - "type": "VARCHAR(255)", + "type": "INT", "default": null, "null": true }, @@ -1308,7 +1308,7 @@ }, "account_permission_app": { "name": "account_permission_app", - "type": "VARCHAR(255)", + "type": "INT", "default": null, "null": true }, diff --git a/Admin/Install/settings.php b/Admin/Install/settings.php index 2f6d6ef..3a42780 100755 --- a/Admin/Install/settings.php +++ b/Admin/Install/settings.php @@ -7,164 +7,164 @@ use phpOMS\Message\Mail\SubmitType; return [ [ - 'type' => 'setting', - 'name' => SettingsEnum::PASSWORD_PATTERN, + 'type' => 'setting', + 'name' => SettingsEnum::PASSWORD_PATTERN, 'content' => '/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[.,\/\(\)\{\}\[\]#?!@$%^&*+=\':"-]).{8,}$/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::LOGIN_TRIES, + 'type' => 'setting', + 'name' => SettingsEnum::LOGIN_TRIES, 'content' => '3', 'pattern' => '/\\d+/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::PASSWORD_INTERVAL, + 'type' => 'setting', + 'name' => SettingsEnum::PASSWORD_INTERVAL, 'content' => '90', 'pattern' => '/\\d+/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::PASSWORD_HISTORY, + 'type' => 'setting', + 'name' => SettingsEnum::PASSWORD_HISTORY, 'content' => '3', 'pattern' => '/\\d+/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::LOGGING_STATUS, + 'type' => 'setting', + 'name' => SettingsEnum::LOGGING_STATUS, 'content' => '1', 'pattern' => '/[0-3]/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::LOGGING_PATH, + 'type' => 'setting', + 'name' => SettingsEnum::LOGGING_PATH, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::DEFAULT_UNIT, + 'type' => 'setting', + 'name' => SettingsEnum::DEFAULT_UNIT, 'content' => '1', 'pattern' => '/\\d+/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::LOGIN_STATUS, + 'type' => 'setting', + 'name' => SettingsEnum::LOGIN_STATUS, 'content' => '1', 'pattern' => '/[0-3]/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::LOGIN_MAIL_REGISTRATION_TEMPLATE, + 'type' => 'setting', + 'name' => SettingsEnum::LOGIN_MAIL_REGISTRATION_TEMPLATE, 'content' => '', 'pattern' => '/\\d*/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::LOGIN_MAIL_FORGOT_PASSWORD_TEMPLATE, + 'type' => 'setting', + 'name' => SettingsEnum::LOGIN_MAIL_FORGOT_PASSWORD_TEMPLATE, 'content' => '', 'pattern' => '/\\d*/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::LOGIN_MAIL_FAILED_TEMPLATE, + 'type' => 'setting', + 'name' => SettingsEnum::LOGIN_MAIL_FAILED_TEMPLATE, 'content' => '', 'pattern' => '/\\d*/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::DEFAULT_LOCALIZATION, + 'type' => 'setting', + 'name' => SettingsEnum::DEFAULT_LOCALIZATION, 'content' => '1', 'pattern' => '/\\d+/', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_OUT, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_OUT, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_PORT_OUT, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_PORT_OUT, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_IN, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_IN, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_PORT_IN, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_PORT_IN, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_ADDR, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_ADDR, 'content' => '', 'pattern' => "/(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/", - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_TYPE, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_TYPE, 'content' => SubmitType::MAIL, - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_USER, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_USER, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_PASS, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_PASS, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_CERT, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_CERT, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_KEY, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_KEY, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_KEYPASS, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_KEYPASS, 'content' => '', - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::MAIL_SERVER_TLS, + 'type' => 'setting', + 'name' => SettingsEnum::MAIL_SERVER_TLS, 'content' => (string) false, - 'module' => 'Admin', + 'module' => 'Admin', ], [ - 'type' => 'setting', - 'name' => SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_APP, + 'type' => 'setting', + 'name' => SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_APP, 'content' => (string) true, - 'module' => 'Admin', + 'module' => 'Admin', ], -]; \ No newline at end of file +]; diff --git a/Admin/Installer.php b/Admin/Installer.php index cf95526..8f8221f 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -239,16 +239,23 @@ final class Installer extends InstallerAbstract */ public static function installExternal(ApplicationAbstract $app, array $data) : array { - if (!\is_file($data['path'] ?? '')) { + if (!\is_file($data['path'] ?? '') && !isset($data['data'])) { throw new PathException($data['path'] ?? ''); } - $adminFile = \file_get_contents($data['path'] ?? ''); - if ($adminFile === false) { - throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore + $adminData = []; + + if (isset($data['path'])) { + $adminFile = \file_get_contents($data['path'] ?? ''); + if ($adminFile === false) { + throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore + } + + $adminData = \json_decode($adminFile, true) ?? []; + } elseif (isset($data['data'])) { + $adminData = $data['data']; } - $adminData = \json_decode($adminFile, true) ?? []; if (!\is_array($adminData)) { throw new \Exception(); // @codeCoverageIgnore } diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 0c3752d..1ac95f1 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -122,7 +122,6 @@ final class ApiController extends Controller if ($login > LoginReturnType::OK) { $this->app->sessionManager->set('UID', $login, true); - $this->app->sessionManager->save(); $response->set($request->uri->__toString(), new Reload()); } elseif ($login === LoginReturnType::NOT_ACTIVATED) { $response->header->status = RequestStatusCode::R_401; @@ -260,7 +259,7 @@ final class ApiController extends Controller public function apiForgot(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { /** @var \Modules\Admin\Models\Account $account */ - $account = !empty($request->getData('user')) + $account = $request->hasData('user') ? AccountMapper::get()->where('login', (string) $request->getData('user'))->execute() : AccountMapper::get()->where('email', (string) $request->getData('email'))->execute(); @@ -367,7 +366,7 @@ final class ApiController extends Controller $token = $forgotten[SettingsEnum::LOGIN_FORGOTTEN_TOKEN]->content; if ($date->getTimestamp() < \time() - 60 * 10 - || empty($request->getData('token')) + || !$request->hasData('token') || $request->getData('token') !== $token ) { $response->header->status = RequestStatusCode::R_405; @@ -626,7 +625,7 @@ final class ApiController extends Controller private function validateSettingsCreate(RequestAbstract $request) : array { $val = []; - if (($val['name'] = empty($request->getData('name')))) { + if (($val['name'] = !$request->hasData('name'))) { return $val; } @@ -751,9 +750,9 @@ final class ApiController extends Controller private function validatePasswordUpdate(RequestAbstract $request) : array { $val = []; - if (($val['oldpass'] = empty($request->getData('oldpass'))) - || ($val['newpass'] = empty($request->getData('newpass'))) - || ($val['reppass'] = empty($request->getData('reppass'))) + if (($val['oldpass'] = !$request->hasData('oldpass')) + || ($val['newpass'] = !$request->hasData('newpass')) + || ($val['reppass'] = !$request->hasData('reppass')) ) { return $val; } @@ -783,7 +782,7 @@ final class ApiController extends Controller && !$this->app->accountManager->get($accountId)->hasPermission( PermissionType::MODIFY, $this->app->unitId, - $this->app->appName, + $this->app->appId, self::NAME, PermissionCategory::ACCOUNT_SETTINGS, $accountId @@ -1030,7 +1029,7 @@ final class ApiController extends Controller private function validateApplicationCreate(RequestAbstract $request) : array { $val = []; - if (($val['name'] = empty($request->getData('name')))) { + if (($val['name'] = !$request->hasData('name'))) { return $val; } @@ -1211,7 +1210,7 @@ final class ApiController extends Controller private function validateGroupCreate(RequestAbstract $request) : array { $val = []; - if (($val['name'] = empty($request->getData('name'))) + if (($val['name'] = !$request->hasData('name')) || ($val['status'] = !GroupStatus::isValidValue((int) $request->getData('status'))) ) { return $val; @@ -1467,10 +1466,10 @@ final class ApiController extends Controller private function validateAccountCreate(RequestAbstract $request) : array { $val = []; - if (($val['name1'] = empty($request->getData('name1'))) + if (($val['name1'] = !$request->hasData('name1')) || ($val['type'] = !AccountType::isValidValue((int) $request->getData('type'))) || ($val['status'] = !AccountStatus::isValidValue((int) $request->getData('status'))) - || ($val['email'] = !empty($request->getData('email')) && !EmailValidator::isValid((string) $request->getData('email'))) + || ($val['email'] = $request->hasData('email') && !EmailValidator::isValid((string) $request->getData('email'))) ) { return $val; } @@ -1501,9 +1500,11 @@ final class ApiController extends Controller } $account = $this->createAccountFromRequest($request); - $this->createModel($request->header->account, $account, AccountCredentialMapper::class, 'account', $request->getOrigin()); - $this->createProfileForAccount($account, $request); + + if ($request->hasData('create_profile')) { + $this->createProfileForAccount($account, $request); + } $collection = $this->createMediaDirForAccount($account->getId(), $account->login ?? '', $request->header->account); $this->createModel($request->header->account, $collection, CollectionMapper::class, 'collection', $request->getOrigin()); @@ -1789,6 +1790,7 @@ final class ApiController extends Controller // New account $request->setData('status', AccountStatus::INACTIVE, true); $request->setData('type', AccountType::USER, true); + $request->setData('create_profile', (string) true); $request->setData('name1', !$request->hasData('name1') ? (!$request->hasData('user') ? \explode('@', $request->getDataString('email'))[0] @@ -1826,34 +1828,29 @@ final class ApiController extends Controller } // Create client - if ($request->hasData('client') && $account->getStatus() !== AccountStatus::ACTIVE) { - // @todo: only create if no client exists at the specified unit - // The check !== ACTIVE above is only a bad, wrong and specific solution to the problem + if ($request->hasData('client')) { + $client = $this->app->moduleManager->get('ClientManagement') + ->findClientForAccount($account->getId(), $request->getDataInt('unit')); - $internalRequest = new HttpRequest(); - $internalResponse = new HttpResponse(); + if ($client === null) { + $internalRequest = new HttpRequest(); + $internalResponse = new HttpResponse(); - $internalRequest->header->account = $account->getId(); - $internalRequest->setData('account', $account->getId()); - $internalRequest->setData('number', 100000 + $account->getId()); - $internalRequest->setData('address', $request->getDataString('address') ?? ''); - $internalRequest->setData('postal', $request->getDataString('postal') ?? ''); - $internalRequest->setData('city', $request->getDataString('city') ?? ''); - $internalRequest->setData('country', $request->getDataString('country') ?? ''); - $internalRequest->setData('state', $request->getDataString('state') ?? ''); - $internalRequest->setData('vat_id', $request->getDataString('vat_id') ?? ''); - $internalRequest->setData('unit', $request->getDataInt('unit')); + $internalRequest->header->account = $account->getId(); + $internalRequest->setData('account', $account->getId()); + $internalRequest->setData('number', 100000 + $account->getId()); + $internalRequest->setData('address', $request->getDataString('address') ?? ''); + $internalRequest->setData('postal', $request->getDataString('postal') ?? ''); + $internalRequest->setData('city', $request->getDataString('city') ?? ''); + $internalRequest->setData('country', $request->getDataString('country')); + $internalRequest->setData('state', $request->getDataString('state') ?? ''); + $internalRequest->setData('vat_id', $request->getDataString('vat_id') ?? ''); + $internalRequest->setData('unit', $request->getDataInt('unit')); - $this->app->moduleManager->get('ClientManagement')->apiClientCreate($internalRequest, $internalResponse); + $this->app->moduleManager->get('ClientManagement')->apiClientCreate($internalRequest, $internalResponse); + } } - // Create confirmation email - // @todo: adjust - // load base template for app - // load text content for login - // replace placeholders - // send email - $handler = $this->setUpServerMailHandler(); $emailSettings = $this->app->appSettings->get( @@ -1861,6 +1858,7 @@ final class ApiController extends Controller module: 'Admin' ); + /** @var \Modules\Messages\Models\Email $mail */ $mail = EmailMapper::get() ->where('id', (int) $emailSettings[SettingsEnum::LOGIN_MAIL_REGISTRATION_TEMPLATE]) ->execute(); @@ -1922,11 +1920,11 @@ final class ApiController extends Controller private function validateRegistration(RequestAbstract $request) : array { $val = []; - if (($val['email'] = !empty($request->getData('email')) + if (($val['email'] = $request->hasData('email') && !EmailValidator::isValid((string) $request->getData('email'))) - || ($val['unit'] = empty($request->getData('unit'))) - || ($val['app'] = empty($request->getData('app'))) - || ($val['password'] = empty($request->getData('password'))) + || ($val['unit'] = !$request->hasData('unit')) + || ($val['app'] = !$request->hasData('app')) + || ($val['password'] = !$request->hasData('password')) ) { return $val; } @@ -1993,7 +1991,7 @@ final class ApiController extends Controller private function validateDataChange(RequestAbstract $request) : array { $val = []; - if (($val['hash'] = empty($request->getData('hash')))) { + if (($val['hash'] = !$request->hasData('hash'))) { return $val; } @@ -2169,7 +2167,7 @@ final class ApiController extends Controller $account->setStatus($request->getDataInt('status') ?? $account->getStatus()); $account->setType($request->getDataInt('type') ?? $account->getType()); - if ($allowPassword && !empty($request->getData('password'))) { + if ($allowPassword && $request->hasData('password')) { $account->generatePassword((string) $request->getData('password')); } @@ -2656,7 +2654,7 @@ final class ApiController extends Controller : new AccountPermission((int) $request->getData('permissionref')); $permission->setUnit($request->getDataInt('permissionunit')); - $permission->setApp($request->getDataString('permissionapp')); + $permission->setApp($request->getDataInt('permissionapp')); $permission->setModule($request->getDataString('permissionmodule')); $permission->setCategory($request->getDataInt('permissioncategory')); $permission->setElement($request->getDataInt('permissionelement')); @@ -2764,12 +2762,12 @@ final class ApiController extends Controller */ private function updatePermissionFromRequest(RequestAbstract $request, PermissionAbstract $permission) : PermissionAbstract { - $permission->setUnit(empty($request->getData('permissionunit')) ? $permission->getUnit() : (int) $request->getData('permissionunit')); - $permission->setApp(empty($request->getData('permissionapp')) ? $permission->getApp() : (string) $request->getData('permissionapp')); - $permission->setModule(empty($request->getData('permissionmodule')) ? $permission->getModule() : (string) $request->getData('permissionmodule')); - $permission->setCategory(empty($request->getData('permissioncategory')) ? $permission->getCategory() : (int) $request->getData('permissioncategory')); - $permission->setElement(empty($request->getData('permissionelement')) ? $permission->getElement() : (int) $request->getData('permissionelement')); - $permission->setComponent(empty($request->getData('permissioncomponent')) ? $permission->getComponent() : (int) $request->getData('permissioncomponent')); + $permission->setUnit($request->getDataInt('permissionunit') ?? $permission->getUnit()); + $permission->setApp($request->getDataInt('permissionapp') ?? $permission->getApp()); + $permission->setModule($request->getDataString('permissionmodule') ?? $permission->getModule()); + $permission->setCategory($request->getDataInt('permissioncategory') ?? $permission->getCategory()); + $permission->setElement($request->getDataInt('permissionelement') ?? $permission->getElement()); + $permission->setComponent($request->getDataInt('permissioncomponent') ?? $permission->getComponent()); $permission->setPermission(($request->getDataInt('permissioncreate') ?? 0) | ($request->getDataInt('permissionread') ?? 0) | ($request->getDataInt('permissionupdate') ?? 0) @@ -3152,9 +3150,9 @@ final class ApiController extends Controller public function validateContactCreate(RequestAbstract $request) : array { $val = []; - if (($val['account'] = empty($request->getData('account'))) + if (($val['account'] = !$request->hasData('account')) || ($val['type'] = !\is_numeric($request->getData('type'))) - || ($val['content'] = empty($request->getData('content'))) + || ($val['content'] = !$request->hasData('content')) ) { return $val; } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 2df7730..c86dd8e 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -123,7 +123,7 @@ final class BackendController extends Controller $member = \prev($split); - if (!empty($request->getData('accountslist-f-' . $member . '-f1'))) { + if ($request->hasData('accountslist-f-' . $member . '-f1')) { $filterField[$member] = [ 'type' => $type, 'value1' => $request->getData('accountslist-f-' . $member . '-f1'), @@ -297,7 +297,7 @@ final class BackendController extends Controller $member = \prev($split); - if (!empty($request->getData('groupslist-f-' . $member . '-f1'))) { + if ($request->hasData('groupslist-f-' . $member . '-f1')) { $filterField[$member] = [ 'type' => $type, 'value1' => $request->getData('groupslist-f-' . $member . '-f1'), diff --git a/Models/AccountExternalMapper.php b/Models/AccountExternalMapper.php index f277d8f..6d01474 100755 --- a/Models/AccountExternalMapper.php +++ b/Models/AccountExternalMapper.php @@ -39,7 +39,7 @@ class AccountMapper extends DataMapperFactory 'account_external_id' => ['name' => 'account_external_id', 'type' => 'int', 'internal' => 'id'], 'account_external_status' => ['name' => 'account_external_status', 'type' => 'int', 'internal' => 'status'], 'account_external_type' => ['name' => 'account_external_type', 'type' => 'int', 'internal' => 'type'], - 'account_external_subtype' => ['name' => 'account_external_subtype', 'type' => 'int', 'internal' => 'subtype',], + 'account_external_subtype' => ['name' => 'account_external_subtype', 'type' => 'int', 'internal' => 'subtype'], 'account_external_key' => ['name' => 'account_external_key', 'type' => 'string', 'internal' => 'key'], 'account_external_name' => ['name' => 'account_external_name', 'type' => 'string', 'internal' => 'name'], 'account_external_auth' => ['name' => 'account_external_auth', 'type' => 'string', 'internal' => 'auth', ], diff --git a/Models/AccountPermission.php b/Models/AccountPermission.php index 0712a55..4312725 100755 --- a/Models/AccountPermission.php +++ b/Models/AccountPermission.php @@ -42,7 +42,7 @@ class AccountPermission extends PermissionAbstract * * @param int $account Group id * @param null|int $unit Unit Unit to check (null if all are acceptable) - * @param null|string $app App App to check (null if all are acceptable) + * @param null|int $app App App to check (null if all are acceptable) * @param null|string $module Module to check (null if all are acceptable) * @param null|string $from Module providing this permission * @param null|int $category Category (e.g. customer) (null if all are acceptable) @@ -55,7 +55,7 @@ class AccountPermission extends PermissionAbstract public function __construct( int $account = 0, int $unit = null, - string $app = null, + int $app = null, string $module = null, string $from = null, int $category = null, diff --git a/Models/AccountPermissionMapper.php b/Models/AccountPermissionMapper.php index e443375..9250dda 100755 --- a/Models/AccountPermissionMapper.php +++ b/Models/AccountPermissionMapper.php @@ -36,7 +36,7 @@ final class AccountPermissionMapper extends DataMapperFactory 'account_permission_id' => ['name' => 'account_permission_id', 'type' => 'int', 'internal' => 'id'], 'account_permission_account' => ['name' => 'account_permission_account', 'type' => 'int', 'internal' => 'account'], 'account_permission_unit' => ['name' => 'account_permission_unit', 'type' => 'int', 'internal' => 'unit'], - 'account_permission_app' => ['name' => 'account_permission_app', 'type' => 'string', 'internal' => 'app'], + 'account_permission_app' => ['name' => 'account_permission_app', 'type' => 'int', 'internal' => 'app'], 'account_permission_module' => ['name' => 'account_permission_module', 'type' => 'string', 'internal' => 'module'], 'account_permission_from' => ['name' => 'account_permission_from', 'type' => 'string', 'internal' => 'from'], 'account_permission_category' => ['name' => 'account_permission_category', 'type' => 'int', 'internal' => 'category'], diff --git a/Models/GroupPermission.php b/Models/GroupPermission.php index e387cdd..2b5ebe2 100755 --- a/Models/GroupPermission.php +++ b/Models/GroupPermission.php @@ -42,7 +42,7 @@ class GroupPermission extends PermissionAbstract * * @param int $group Group id * @param null|int $unit Unit to check (null if all are acceptable) - * @param null|string $app App to check (null if all are acceptable) + * @param null|int $app App to check (null if all are acceptable) * @param null|string $module Module to check (null if all are acceptable) * @param null|string $from Module providing this permission * @param null|int $category Category (e.g. customer) (null if all are acceptable) @@ -55,7 +55,7 @@ class GroupPermission extends PermissionAbstract public function __construct( int $group = 0, int $unit = null, - string $app = null, + int $app = null, string $module = null, string $from = null, int $category = null, diff --git a/Models/GroupPermissionMapper.php b/Models/GroupPermissionMapper.php index 48e1425..3dc5f17 100755 --- a/Models/GroupPermissionMapper.php +++ b/Models/GroupPermissionMapper.php @@ -36,7 +36,7 @@ final class GroupPermissionMapper extends DataMapperFactory 'group_permission_id' => ['name' => 'group_permission_id', 'type' => 'int', 'internal' => 'id'], 'group_permission_group' => ['name' => 'group_permission_group', 'type' => 'int', 'internal' => 'group'], 'group_permission_unit' => ['name' => 'group_permission_unit', 'type' => 'int', 'internal' => 'unit'], - 'group_permission_app' => ['name' => 'group_permission_app', 'type' => 'string', 'internal' => 'app'], + 'group_permission_app' => ['name' => 'group_permission_app', 'type' => 'int', 'internal' => 'app'], 'group_permission_module' => ['name' => 'group_permission_module', 'type' => 'string', 'internal' => 'module'], 'group_permission_from' => ['name' => 'group_permission_from', 'type' => 'string', 'internal' => 'from'], 'group_permission_category' => ['name' => 'group_permission_category', 'type' => 'int', 'internal' => 'category'], diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 24349d9..ad1ad8b 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -73,7 +73,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase $permission = new AccountPermission(); $permission->setUnit(1); - $permission->setApp('backend'); + $permission->setApp(2); $permission->setPermission( PermissionType::READ | PermissionType::CREATE