170 lines
7.6 KiB
PHP
170 lines
7.6 KiB
PHP
<?php
|
|
|
|
class UserEditController extends mfBaseController {
|
|
public User $user;
|
|
private $postData;
|
|
|
|
protected function init() {
|
|
$this->needlogin = true;
|
|
$this->user = new User();
|
|
$this->user->loadMe();
|
|
$this->layout()->set('me', $this->user);
|
|
|
|
if (!$this->user->isAdmin()) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
|
|
// if post then set postData
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$this->postData = json_decode(file_get_contents('php://input'), true);
|
|
}
|
|
}
|
|
|
|
protected function indexAction() {
|
|
$id = $this->request->id;
|
|
if (!is_numeric($id) || $id <= 0) throw new Exception("User ID is required.", 400);
|
|
|
|
$user = new User($id);
|
|
if (!$user->id) throw new Exception("User not found.", 404);
|
|
|
|
$preorderNetworks = $user->getFlag("preorder_networks")->value();
|
|
$consentProjects = $user->getFlag("constructionConsent_projects")->value();
|
|
|
|
$userData = $user->toArray();
|
|
$userData['permissions'] = (array)$user->permissions->data;
|
|
$userData['preorder_networks'] = $preorderNetworks ? json_decode($preorderNetworks, true) : [];
|
|
$userData['constructionconsent_projects'] = $consentProjects ? json_decode($consentProjects, true) : [];
|
|
$userData['employee_number'] = $user->getFlag("employee_number")->value();
|
|
$userData['project_api_key'] = $user->getFlag("project_api_key")->value();
|
|
$userData['vodia_identity_domain'] = $user->getFlag("vodia_identity_domain")->value();
|
|
$userData['vodia_identity_username'] = $user->getFlag("vodia_identity_username")->value();
|
|
$userData['vodia_identity_default'] = $user->getFlag("vodia_identity_default")->value();
|
|
|
|
|
|
$JS_VARIABLES = [
|
|
"USER_DATA" => $userData,
|
|
"LOOKUPS" => [
|
|
"addresses" => array_map(fn($addr) => ['value' => $addr->id, 'text' => ($addr->company) ? $addr->company : $addr->getFullName()], AddressModel::getAll()),
|
|
"networks" => array_map(fn($net) => ['value' => $net->id, 'text' => $net->name], NetworkModel::getAll()),
|
|
"consentProjects" => array_map(fn($proj) => ['value' => $proj->id, 'text' => $proj->name], ConstructionConsentProject::getAll()),
|
|
"permissionTemplates" => UserPermissionTemplateModel::getAll([], null, 0, ['key' => 'name', 'order' => 'asc']),
|
|
"users" => array_map(fn($u) => ['value' => $u->id, 'text' => $u->name], UserModel::search(['active' => 1])),
|
|
],
|
|
"PERMISSIONS_CONFIG" => $this->getPermissionsConfig(),
|
|
"SAVE_URL" => self::getUrl("User", "save"),
|
|
"API_KEY_URL" => self::getUrl("User", "generateApikey"),
|
|
];
|
|
|
|
Helper::renderVue($this, "UserEdit", "Benutzer bearbeiten: " . $user->name, $JS_VARIABLES);
|
|
}
|
|
|
|
protected function getUserDataForTemplateAction() {
|
|
$id = $this->request->id;
|
|
if (!$id) self::sendError("User ID is required.");
|
|
$user = new User($id);
|
|
if (!$user->id) self::sendError("User not found.");
|
|
|
|
$preorderNetworks = $user->getFlag("preorder_networks")->value();
|
|
$consentProjects = $user->getFlag("constructionConsent_projects")->value();
|
|
|
|
self::returnJson([
|
|
'permissions' => (array)$user->permissions->data,
|
|
'preorder_networks' => $preorderNetworks ? json_decode($preorderNetworks, true) : [],
|
|
'constructionconsent_projects' => $consentProjects ? json_decode($consentProjects, true) : [],
|
|
'vodia_identity_domain' => $user->getFlag("vodia_identity_domain")->value(),
|
|
'vodia_identity_default' => $user->getFlag("vodia_identity_default")->value(),
|
|
]);
|
|
}
|
|
|
|
protected function managePermissionTemplatesAction() {
|
|
Helper::renderVue($this, "UserPermissionTemplate", "Berechtigungsvorlagen", ["PERMISSIONS_CONFIG" => $this->getPermissionsConfig()]);
|
|
}
|
|
|
|
protected function getPermissionTemplatesAction() {
|
|
self::returnJson(array_map(
|
|
function ($perm) {
|
|
$perm = (array)$perm;
|
|
$perm['permissions'] = json_decode($perm['permissions'], true) ?: [];
|
|
return $perm;
|
|
}, UserPermissionTemplateModel::getAll([], null, 0, ['key' => 'name', 'order' => 'asc'])
|
|
));
|
|
}
|
|
|
|
protected function savePermissionTemplateAction() {
|
|
if (empty($this->postData['name'])) self::sendError("Template name is required.");
|
|
|
|
$data = [
|
|
'name' => $this->postData['name'],
|
|
'permissions' => json_encode($this->postData['permissions'] ?? []),
|
|
];
|
|
|
|
if (empty($this->postData['id'])) {
|
|
$data += ['createBy' => $this->user->id, 'create' => time()];
|
|
$id = UserPermissionTemplateModel::create($data);
|
|
self::returnJson(['success' => true, 'message' => 'Vorlage erstellt.', 'id' => $id]);
|
|
}
|
|
|
|
$template = UserPermissionTemplateModel::get($this->postData['id']);
|
|
$data += [
|
|
'id' => $this->postData['id'],
|
|
'create' => $template->create,
|
|
'createBy' => $template->createBy,
|
|
];
|
|
|
|
UserPermissionTemplateModel::update($data);
|
|
self::returnJson(['success' => true, 'message' => 'Vorlage gespeichert.']);
|
|
}
|
|
|
|
protected function deletePermissionTemplateAction() {
|
|
$post = json_decode(file_get_contents('php://input'), true);
|
|
if (empty($post['id'])) self::sendError("Template ID is required.");
|
|
UserPermissionTemplateModel::delete($post['id']);
|
|
self::returnJson(['success' => true, 'message' => 'Vorlage gelöscht.']);
|
|
}
|
|
|
|
private function getPermissionsConfig(): array {
|
|
return [
|
|
'Rollen' => [
|
|
'admin' => 'Administrator',
|
|
'employee' => TT_SYSOWNER_NAME_HTML . ' Mitarbeiter',
|
|
'technician' => 'Techniker',
|
|
],
|
|
'Preorder' => [
|
|
'preorderfront' => 'Frontdesk (Semi-Readonly)',
|
|
'preorderlogistics' => 'Logistikpartner',
|
|
'preorderaddressreporting' => 'Address Reporting API User',
|
|
'preorderreadonly' => 'Readonly',
|
|
'canPreorder' => 'Modul: Vorbestellung',
|
|
'canPreorderpricing' => 'Modul: Bepreisung',
|
|
'canPreorderpricingReadonly' => 'Modul: Bepreisung (Readonly)',
|
|
'canPreorderbilling' => 'Modul: Verrechnung',
|
|
'canPreorderbillingReadonly' => 'Modul: Verrechnung (Readonly)',
|
|
],
|
|
'Module' => [
|
|
'canBuilding' => 'Objekte & Anschlüsse',
|
|
'canPipework' => 'Tiefbau',
|
|
'canLinework' => 'Leitungsbau',
|
|
'canPatching' => 'Patching',
|
|
'canFilestore' => 'Filestore (Netzbau)',
|
|
'canCpeprovisioning' => 'CPE Provisioning',
|
|
'canCpeshipping' => 'CPE Versand',
|
|
'canVoipnumbering' => 'VOIP Nummernverwaltung',
|
|
'canOrder' => 'Bestellung',
|
|
'canBilling' => 'Verrechnung',
|
|
],
|
|
'Lager' => [
|
|
'canWarehouseAdmin' => 'Lager-Admin',
|
|
'canWarehouseUser' => 'Lager-User',
|
|
'canWarehouseEShop' => 'Energie Steiermark Shop',
|
|
],
|
|
'Zusatzberechtigungen' => [
|
|
'canFibu' => 'Buchhaltung',
|
|
'canStatistics' => 'Statistiken',
|
|
'canADBExtended' => 'Address-DB erweitert',
|
|
'canAssetAdmin' => 'Anlagen-Admin',
|
|
'canRMLAdmin' => 'RML-Workorder-Admin',
|
|
'canRMLCompany' => 'RML-Workorder-Firma',
|
|
]
|
|
];
|
|
}
|
|
} |