OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

user.php

9 KB
<?php $this->layout('layouts/admin', [
    'page_title'         => 'Berechtigungen: ' . ($user['display_name'] ?: $user['email']),
    'current_admin_page' => 'permissions',
    'breadcrumbs'        => [
        ['label' => 'Berechtigungen', 'url' => '/admin/permissions'],
        ['label' => $user['display_name'] ?: $user['email']],
    ],
]); ?>

<?php
    // Wirksame Rechte nach Geltungsbereich bündeln – dieselbe Capability kann aus
    // mehreren Rollen stammen.
    $nachGebiet = [];
    foreach ($effective_capabilities as $eintrag) {
        $schluessel = $eintrag['scope_key'];
        if (!isset($nachGebiet[$schluessel])) {
            $nachGebiet[$schluessel] = ['bereich' => $eintrag, 'rechte' => []];
        }
        $nachGebiet[$schluessel]['rechte'][] = $eintrag;
    }
    ksort($nachGebiet);
?>

<div class="kpi-row">
    <div class="kpi-col">
        <div class="small-box bg-info">
            <div class="inner">
                <h3><?= count($permissions) ?></h3>
                <p><?= $this->te('Zuweisungen') ?></p>
            </div>
            <div class="icon"><i class="fas fa-key"></i></div>
        </div>
    </div>
    <div class="kpi-col">
        <div class="small-box bg-primary">
            <div class="inner">
                <h3><?= count($nachGebiet) ?></h3>
                <p><?= $this->te('Geltungsbereiche') ?></p>
            </div>
            <div class="icon"><i class="fas fa-sitemap"></i></div>
        </div>
    </div>
    <div class="kpi-col">
        <div class="small-box bg-success">
            <div class="inner">
                <h3><?= count($effective_capabilities) ?></h3>
                <p><?= $this->te('wirksame Rechte') ?></p>
            </div>
            <div class="icon"><i class="fas fa-user-shield"></i></div>
        </div>
    </div>
</div>

<div class="card">
    <div class="card-header">
        <h3 class="card-title"><?= $this->te('Weitere Rolle vergeben') ?></h3>
    </div>
    <div class="card-body">
        <form method="POST" action="/admin/permissions/grant" class="filter-card-body">
            <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
            <input type="hidden" name="user_id" value="<?= (int)$user['id'] ?>">
            <input type="hidden" name="return_to" value="/admin/permissions/user/<?= (int)$user['id'] ?>">
            <div class="form-group">
                <label for="pu-topic"><?= $this->te('Themengebiet') ?> <span class="text-danger">*</span></label>
                <select name="topic_id" id="pu-topic" class="form-control form-control-sm" required>
                    <option value=""><?= $this->te('Bitte wählen') ?></option>
                    <?php foreach ($topics as $t): ?>
                        <option value="<?= (int)$t['id'] ?>">
                            <?= str_repeat('— ', max(0, (int)($t['depth'] ?? 0))) ?><?= $this->e($t['name']) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <label for="pu-role"><?= $this->te('Rolle') ?> <span class="text-danger">*</span></label>
                <select name="role_id" id="pu-role" class="form-control form-control-sm" required>
                    <option value=""><?= $this->te('Bitte wählen') ?></option>
                    <?php foreach ($roles as $r): ?>
                        <option value="<?= (int)$r['id'] ?>"><?= $this->e($r['name']) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <label>&nbsp;</label>
                <button type="submit" class="btn btn-primary btn-sm">
                    <i class="fas fa-plus"></i> <?= $this->te('Zuweisen') ?>
                </button>
            </div>
        </form>
    </div>
</div>

<div class="detail-card">
    <div class="detail-card-header">
        <span class="detail-card-title"><?= $this->te('Vergebene Rollen') ?></span>
    </div>
    <div class="detail-card-body">
        <?php if (!empty($permissions)): ?>
        <div class="table-wrapper">
            <table class="data-table">
                <thead>
                    <tr>
                        <th scope="col"><?= $this->te('Geltungsbereich') ?></th>
                        <th scope="col"><?= $this->te('Rolle') ?></th>
                        <th scope="col"><?= $this->te('Vergeben am') ?></th>
                        <th scope="col"><?= $this->te('Vergeben von') ?></th>
                        <th scope="col"></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($permissions as $p): ?>
                    <tr>
                        <td><?= $this->partial('permission-scope', [
                                'scope_type'    => $p['scope_type'] ?? '',
                                'topic_id'      => $p['topic_id'] ?? null,
                                'topic_name'    => $p['topic_name'] ?? '',
                                'location_id'   => $p['location_id'] ?? null,
                                'location_name' => $p['location_name'] ?? '',
                            ]) ?></td>
                        <td>
                            <span class="badge badge-info"><?= $this->e($p['role_name']) ?></span>
                            <?php if (!empty($p['role_description'])): ?>
                                <div style="font-size:.76rem;color:var(--gray-500);">
                                    <?= $this->e($p['role_description']) ?>
                                </div>
                            <?php endif; ?>
                        </td>
                        <td><?= !empty($p['granted_at']) ? $this->e(date('d.m.Y', strtotime((string)$p['granted_at']))) : '–' ?></td>
                        <td><?= $this->e($p['granted_by_name'] ?? '–') ?></td>
                        <td style="text-align:right;">
                            <form method="POST" action="/admin/permissions/revoke" style="display:inline;"
                                  onsubmit="return confirm('<?= $this->te('Diese Zuweisung wirklich entziehen?') ?>');">
                                <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
                                <input type="hidden" name="assignment_id" value="<?= (int)$p['id'] ?>">
                                <input type="hidden" name="return_to" value="/admin/permissions/user/<?= (int)$user['id'] ?>">
                                <button type="submit" class="btn btn-danger btn-sm" title="<?= $this->te('Entziehen') ?>">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php else: ?>
        <div class="empty-state">
            <i class="fas fa-key"></i>
            <p><?= $this->te('Diesem Benutzer ist noch keine Rolle zugewiesen.') ?></p>
        </div>
        <?php endif; ?>
    </div>
</div>

<?php if (!empty($nachGebiet)): ?>
<div class="detail-card" style="margin-top:1.25rem;">
    <div class="detail-card-header">
        <span class="detail-card-title"><?= $this->te('Wirksame Rechte') ?></span>
    </div>
    <div class="detail-card-body">
        <p class="form-hint" style="margin-top:0;">
            <?= $this->te('Was aus den Rollen zusammen folgt – je Geltungsbereich.') ?>
        </p>
        <?php foreach ($nachGebiet as $gruppe): ?>
            <?php $rechte = $gruppe['rechte']; ?>
            <h4 style="font-size:.88rem;margin:1rem 0 .4rem;">
                <?= $this->partial('permission-scope', [
                        'scope_type'    => $gruppe['bereich']['scope_type'] ?? '',
                        'topic_id'      => $gruppe['bereich']['topic_id'] ?? null,
                        'topic_name'    => $gruppe['bereich']['topic_name'] ?? '',
                        'location_id'   => $gruppe['bereich']['location_id'] ?? null,
                        'location_name' => $gruppe['bereich']['location_name'] ?? '',
                    ]) ?>
            </h4>
            <div class="table-wrapper">
                <table class="data-table">
                    <thead>
                        <tr>
                            <th scope="col"><?= $this->te('Recht') ?></th>
                            <th scope="col"><?= $this->te('Bedeutung') ?></th>
                            <th scope="col"><?= $this->te('aus Rolle') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($rechte as $r): ?>
                        <tr>
                            <td><code><?= $this->e($r['capability']) ?></code></td>
                            <td><?= $this->e($r['capability_description'] ?? '') ?></td>
                            <td>
                                <?php foreach (array_unique($r['from_roles']) as $rolle): ?>
                                    <span class="badge badge-secondary"><?= $this->e($rolle) ?></span>
                                <?php endforeach; ?>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endforeach; ?>
    </div>
</div>
<?php endif; ?>