В интерфейсе показываем только те действия, что разрешены правом

This commit is contained in:
rsgrinko committed 2026-09-17 16:37:13 +03:00
1 parent cb7d40aaff
commit 5552239161
15 files changed
+196 -43

No files matched your search

+43 -10
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use Rsgrinko\Proton\Access\AccessDenied; use Rsgrinko\Proton\Access\AccessDenied;
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Access\Viewer; use Rsgrinko\Proton\Access\Viewer;
use Rsgrinko\Proton\Database\Model\Model; use Rsgrinko\Proton\Database\Model\Model;
use Rsgrinko\Proton\Events\Events; use Rsgrinko\Proton\Events\Events;
@@ -25,7 +26,7 @@ final class TrashController extends Controller
{ {
public function index(Request $request, Viewer $viewer): Response public function index(Request $request, Viewer $viewer): Response
{ {
$kinds = $this->allowed($viewer); $kinds = $this->visible($viewer);
if ($kinds === []) { if ($kinds === []) {
throw new AccessDenied('Корзина пуста для вашей роли'); throw new AccessDenied('Корзина пуста для вашей роли');
@@ -46,6 +47,9 @@ final class TrashController extends Controller
'kind' => $key, 'kind' => $key,
'label' => $kind['label'], 'label' => $kind['label'],
'title' => $kind['title'], 'title' => $kind['title'],
// Смотреть раздел корзины и возвращать/добивать из него — разные права:
// trash.view даёт только первое
'canAct' => $this->canAct($viewer, $kind),
'page' => $page ?? ['items' => [], 'total' => 0, 'page' => 1, 'pages' => 1, 'per_page' => 0], 'page' => $page ?? ['items' => [], 'total' => 0, 'page' => 1, 'pages' => 1, 'per_page' => 0],
], 'Корзина'); ], 'Корзина');
} }
@@ -103,7 +107,7 @@ final class TrashController extends Controller
], ['action' => 'Действие']); ], ['action' => 'Действие']);
$key = (string) $request->input('kind', ''); $key = (string) $request->input('kind', '');
$kinds = $this->allowed($viewer); $kinds = $this->actionable($viewer);
if (!isset($kinds[$key])) { if (!isset($kinds[$key])) {
throw new AccessDenied('Этот раздел корзины вам не доступен'); throw new AccessDenied('Этот раздел корзины вам не доступен');
@@ -153,7 +157,7 @@ final class TrashController extends Controller
public function clear(Request $request, Viewer $viewer): Response public function clear(Request $request, Viewer $viewer): Response
{ {
$key = (string) $request->input('kind', ''); $key = (string) $request->input('kind', '');
$kinds = $this->allowed($viewer); $kinds = $this->actionable($viewer);
if (!isset($kinds[$key])) { if (!isset($kinds[$key])) {
throw new AccessDenied('Этот раздел корзины вам не доступен'); throw new AccessDenied('Этот раздел корзины вам не доступен');
@@ -181,7 +185,7 @@ final class TrashController extends Controller
private function find(Request $request, Viewer $viewer): array private function find(Request $request, Viewer $viewer): array
{ {
$key = (string) $request->input('kind', ''); $key = (string) $request->input('kind', '');
$kinds = $this->allowed($viewer); $kinds = $this->actionable($viewer);
if (!isset($kinds[$key])) { if (!isset($kinds[$key])) {
throw new AccessDenied('Этот раздел корзины вам не доступен'); throw new AccessDenied('Этот раздел корзины вам не доступен');
@@ -200,21 +204,50 @@ final class TrashController extends Controller
} }
/** /**
* Разделы, доступные этому человеку. * Разделы, которые этому человеку видно, — своё право раздела, а если
* его нет, хватает и общего trash.view (или trash.manage — кто может
* действовать, тот и видит).
* *
* @return array<string, array{model: class-string<Model>, label: string, title: callable, permission: string}> * @return array<string, array{model: class-string<Model>, label: string, title: callable, permission: string}>
*/ */
private function allowed(Viewer $viewer): array private function visible(Viewer $viewer): array
{ {
$allowed = []; $visible = [];
foreach (Trash::kinds() as $key => $kind) { foreach (Trash::kinds() as $key => $kind) {
if ($kind['permission'] === '' || $viewer->can($kind['permission'])) { if ($kind['permission'] === '' || $viewer->can($kind['permission']) || $viewer->canAny([Permission::TRASH_VIEW, Permission::TRASH_MANAGE])) {
$allowed[$key] = $kind; $visible[$key] = $kind;
} }
} }
return $allowed; return $visible;
}
/**
* Разделы, в которых этому человеку можно возвращать и добивать записи —
* trash.view сюда не пускает, только своё право раздела или trash.manage.
*
* @return array<string, array{model: class-string<Model>, label: string, title: callable, permission: string}>
*/
private function actionable(Viewer $viewer): array
{
$actionable = [];
foreach (Trash::kinds() as $key => $kind) {
if ($kind['permission'] === '' || $viewer->can($kind['permission']) || $viewer->can(Permission::TRASH_MANAGE)) {
$actionable[$key] = $kind;
}
}
return $actionable;
}
/**
* @param array{model: class-string<Model>, label: string, title: callable, permission: string} $kind
*/
private function canAct(Viewer $viewer, array $kind): bool
{
return $kind['permission'] === '' || $viewer->can($kind['permission']) || $viewer->can(Permission::TRASH_MANAGE);
} }
/** /**
+8 -1
View File
@@ -12,8 +12,11 @@ declare(strict_types=1);
* @var bool $ftp задан ли FTP для отправки копий * @var bool $ftp задан ли FTP для отправки копий
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Backup\Backup; use Rsgrinko\Proton\Backup\Backup;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$canManage = View::can(Permission::BACKUPS_MANAGE);
?> ?>
<h1>Резервные копии</h1> <h1>Резервные копии</h1>
@@ -55,12 +58,14 @@ use Rsgrinko\Proton\View\View;
</tr> </tr>
</table> </table>
<?php if ($canManage) { ?>
<div class="row" style="margin-top: 12px;"> <div class="row" style="margin-top: 12px;">
<form method="post" action="<?= View::e(View::route('admin.backups.store')) ?>"> <form method="post" action="<?= View::e(View::route('admin.backups.store')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<button type="submit" class="primary">Сделать копию</button> <button type="submit" class="primary">Сделать копию</button>
</form> </form>
</div> </div>
<?php } ?>
<p class="muted small"> <p class="muted small">
Восстановление — только из консоли: <span class="mono">php bin/proton backup:restore &lt;файл&gt; --force</span>. Восстановление — только из консоли: <span class="mono">php bin/proton backup:restore &lt;файл&gt; --force</span>.
@@ -80,7 +85,7 @@ use Rsgrinko\Proton\View\View;
<th>Файл</th> <th>Файл</th>
<th>Размер</th> <th>Размер</th>
<th class="hide-sm">Когда</th> <th class="hide-sm">Когда</th>
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($files as $file) { ?> <?php foreach ($files as $file) { ?>
@@ -88,6 +93,7 @@ use Rsgrinko\Proton\View\View;
<td class="mono small break"><?= View::e($file['name']) ?></td> <td class="mono small break"><?= View::e($file['name']) ?></td>
<td><?= View::e(Backup::size($file['size'])) ?></td> <td><?= View::e(Backup::size($file['size'])) ?></td>
<td class="hide-sm muted small"><?= View::e(View::date($file['created'])) ?></td> <td class="hide-sm muted small"><?= View::e(View::date($file['created'])) ?></td>
<?php if ($canManage) { ?>
<td class="right"> <td class="right">
<div class="row end"> <div class="row end">
<form method="post" action="<?= View::e(View::route('admin.backups.download')) ?>"> <form method="post" action="<?= View::e(View::route('admin.backups.download')) ?>">
@@ -117,6 +123,7 @@ use Rsgrinko\Proton\View\View;
</form> </form>
</div> </div>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
+4
View File
@@ -10,10 +10,12 @@ declare(strict_types=1);
* @var array<string, array{label: string, token: string, handler: callable}> $sources * @var array<string, array{label: string, token: string, handler: callable}> $sources
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Models\IncomingHook; use Rsgrinko\Proton\Models\IncomingHook;
use Rsgrinko\Proton\Support\Config; use Rsgrinko\Proton\Support\Config;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$canManage = View::can(Permission::WEBHOOKS_MANAGE);
$base = rtrim((string) Config::get('app.url', ''), '/'); $base = rtrim((string) Config::get('app.url', ''), '/');
/** /**
@@ -148,11 +150,13 @@ $pretty = static function (mixed $payload): string {
<?php } ?> <?php } ?>
</td> </td>
<td class="right"> <td class="right">
<?php if ($canManage) { ?>
<form method="post" action="<?= View::e(View::route('admin.webhooks.incoming.test')) ?>"> <form method="post" action="<?= View::e(View::route('admin.webhooks.incoming.test')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<input type="hidden" name="source" value="<?= View::e((string) $key) ?>"> <input type="hidden" name="source" value="<?= View::e((string) $key) ?>">
<button type="submit">Проверить</button> <button type="submit">Проверить</button>
</form> </form>
<?php } ?>
</td> </td>
</tr> </tr>
<?php } ?> <?php } ?>
+10 -4
View File
@@ -12,9 +12,11 @@ declare(strict_types=1);
* @var array<int, array{name: string, interval: int, at: string, last: string, fromFinish: bool}> $schedule * @var array<int, array{name: string, interval: int, at: string, last: string, fromFinish: bool}> $schedule
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Queue\Queue; use Rsgrinko\Proton\Queue\Queue;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$canManage = View::can(Permission::QUEUE_MANAGE);
$badges = [ $badges = [
Queue::QUEUED => 'info', Queue::QUEUED => 'info',
Queue::RUNNING => 'warn', Queue::RUNNING => 'warn',
@@ -46,7 +48,7 @@ $badges = [
<th>Задача</th> <th>Задача</th>
<th>Когда</th> <th>Когда</th>
<th>Последний раз</th> <th>Последний раз</th>
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($schedule as $task) { ?> <?php foreach ($schedule as $task) { ?>
@@ -59,6 +61,7 @@ $badges = [
<?php } ?> <?php } ?>
</td> </td>
<td class="muted small"><?= View::e($task['last'] === '' ? 'ни разу' : View::ago($task['last'])) ?></td> <td class="muted small"><?= View::e($task['last'] === '' ? 'ни разу' : View::ago($task['last'])) ?></td>
<?php if ($canManage) { ?>
<td class="right"> <td class="right">
<form method="post" action="<?= View::e(View::route('admin.queue.run')) ?>"> <form method="post" action="<?= View::e(View::route('admin.queue.run')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
@@ -66,6 +69,7 @@ $badges = [
<button type="submit" data-confirm="Выполнить «<?= View::e($task['name']) ?>» прямо сейчас?">Выполнить</button> <button type="submit" data-confirm="Выполнить «<?= View::e($task['name']) ?>» прямо сейчас?">Выполнить</button>
</form> </form>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
@@ -81,6 +85,7 @@ $badges = [
<?php if ($page['items'] === []) { ?> <?php if ($page['items'] === []) { ?>
<p class="muted">Ничего не нашлось.</p> <p class="muted">Ничего не нашлось.</p>
<?php } else { ?> <?php } else { ?>
<?php if ($canManage) { ?>
<form method="post" action="<?= View::e(View::route('admin.queue.retry')) ?>"> <form method="post" action="<?= View::e(View::route('admin.queue.retry')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
@@ -99,11 +104,12 @@ $badges = [
<span class="muted small" data-check-count>ничего не отмечено</span> <span class="muted small" data-check-count>ничего не отмечено</span>
</div> </div>
<?php } ?>
<div class="table-wrap"> <div class="table-wrap">
<table class="list"> <table class="list">
<tr class="head"> <tr class="head">
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
<th>Задача</th> <th>Задача</th>
<th>Очередь</th> <th>Очередь</th>
<th><?= View::partial('sort', ['filters' => $filters, 'route' => 'admin.queue', 'column' => 'priority', 'label' => 'Важность']) ?></th> <th><?= View::partial('sort', ['filters' => $filters, 'route' => 'admin.queue', 'column' => 'priority', 'label' => 'Важность']) ?></th>
@@ -117,7 +123,7 @@ $badges = [
<?php foreach ($page['items'] as $job) { ?> <?php foreach ($page['items'] as $job) { ?>
<?php $status = (string) $job['status']; ?> <?php $status = (string) $job['status']; ?>
<tr> <tr>
<td><input type="checkbox" name="ids[]" value="<?= (int) $job['id'] ?>" data-check-item></td> <?php if ($canManage) { ?><td><input type="checkbox" name="ids[]" value="<?= (int) $job['id'] ?>" data-check-item></td><?php } ?>
<td> <td>
<span class="mono small"><?= View::e((string) $job['job_class']) ?></span> <span class="mono small"><?= View::e((string) $job['job_class']) ?></span>
@@ -138,7 +144,7 @@ $badges = [
<?php } ?> <?php } ?>
</table> </table>
</div> </div>
</form> <?php if ($canManage) { ?></form><?php } ?>
<?= View::partial('pagination', [ <?= View::partial('pagination', [
'route' => 'admin.queue', 'route' => 'admin.queue',
+10 -5
View File
@@ -9,11 +9,16 @@ declare(strict_types=1);
* @var array<string, array<string, string>> $groups права по разделам * @var array<string, array<string, string>> $groups права по разделам
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$isNew = !$role->existsInDatabase(); $isNew = !$role->existsInDatabase();
$action = $isNew ? View::route('admin.roles.create') : View::route('admin.roles.show', ['id' => $role->id()]); $action = $isNew ? View::route('admin.roles.create') : View::route('admin.roles.show', ['id' => $role->id()]);
$granted = $role->permissions(); $granted = $role->permissions();
// Новая роль — только у тех, кто прошёл can:roles.manage в маршруте; карточку
// существующей открывает и roles.view — тогда поля и галочки не трогать
$canManage = View::can(Permission::ROLES_MANAGE);
$readOnly = !$isNew && !$canManage;
?> ?>
<h1><?= $isNew ? 'Новая роль' : View::e((string) $role->name) ?></h1> <h1><?= $isNew ? 'Новая роль' : View::e((string) $role->name) ?></h1>
@@ -23,12 +28,12 @@ $granted = $role->permissions();
<label> <label>
<span>Название</span> <span>Название</span>
<input type="text" name="name" value="<?= View::e((string) $role->name) ?>" <?= $isNew ? 'autofocus' : '' ?> required> <input type="text" name="name" value="<?= View::e((string) $role->name) ?>" <?= $isNew ? 'autofocus' : '' ?> <?= $readOnly ? 'disabled' : '' ?> required>
</label> </label>
<label> <label>
<span>Описание</span> <span>Описание</span>
<input type="text" name="description" value="<?= View::e((string) $role->description) ?>"> <input type="text" name="description" value="<?= View::e((string) $role->description) ?>" <?= $readOnly ? 'disabled' : '' ?>>
</label> </label>
<?php if ($role->isSystem()) { ?> <?php if ($role->isSystem()) { ?>
@@ -46,7 +51,7 @@ $granted = $role->permissions();
<?php foreach ($permissions as $code => $label) { ?> <?php foreach ($permissions as $code => $label) { ?>
<label class="inline" style="margin-bottom: 6px;"> <label class="inline" style="margin-bottom: 6px;">
<input type="checkbox" name="permissions[]" value="<?= View::e($code) ?>" <input type="checkbox" name="permissions[]" value="<?= View::e($code) ?>"
<?= in_array($code, $granted, true) ? 'checked' : '' ?>> <?= in_array($code, $granted, true) ? 'checked' : '' ?> <?= $readOnly ? 'disabled' : '' ?>>
<span><?= View::e($label) ?> <span class="muted mono"><?= View::e($code) ?></span></span> <span><?= View::e($label) ?> <span class="muted mono"><?= View::e($code) ?></span></span>
</label> </label>
<?php } ?> <?php } ?>
@@ -55,13 +60,13 @@ $granted = $role->permissions();
<?php } ?> <?php } ?>
<div class="row"> <div class="row">
<button type="submit" class="primary">Сохранить</button> <?php if (!$readOnly) { ?><button type="submit" class="primary">Сохранить</button><?php } ?>
<a class="btn" href="<?= View::e(View::route('admin.roles')) ?>">К списку</a> <a class="btn" href="<?= View::e(View::route('admin.roles')) ?>">К списку</a>
</div> </div>
</form> </form>
</div> </div>
<?php if (!$isNew && !$role->isSystem()) { ?> <?php if (!$isNew && !$role->isSystem() && $canManage) { ?>
<div class="card"> <div class="card">
<h2>Удаление</h2> <h2>Удаление</h2>
<p class="muted small">Роль удаляется, только если она никому не выдана.</p> <p class="muted small">Роль удаляется, только если она никому не выдана.</p>
+3
View File
@@ -8,12 +8,15 @@ declare(strict_types=1);
* @var array<int, \Rsgrinko\Proton\Models\Role> $roles * @var array<int, \Rsgrinko\Proton\Models\Role> $roles
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
?> ?>
<div class="row"> <div class="row">
<h1 style="margin: 0;">Роли</h1> <h1 style="margin: 0;">Роли</h1>
<span class="spacer"></span> <span class="spacer"></span>
<?php if (View::can(Permission::ROLES_MANAGE)) { ?>
<a class="btn primary" href="<?= View::e(View::route('admin.roles.create')) ?>">Новая роль</a> <a class="btn primary" href="<?= View::e(View::route('admin.roles.create')) ?>">Новая роль</a>
<?php } ?>
</div> </div>
<div class="card" style="margin-top: 16px;"> <div class="card" style="margin-top: 16px;">
+13 -2
View File
@@ -12,12 +12,16 @@ declare(strict_types=1);
* @var array<string, int> $top самые шумные адреса за сутки * @var array<string, int> $top самые шумные адреса за сутки
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Models\SecurityEvent; use Rsgrinko\Proton\Models\SecurityEvent;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$canManage = View::can(Permission::SECURITY_MANAGE);
?> ?>
<h1>Безопасность</h1> <h1>Безопасность</h1>
<div class="grid cols-2"> <div class="grid cols-2">
<?php if ($canManage) { ?>
<div class="card"> <div class="card">
<h2>Закрыть адрес</h2> <h2>Закрыть адрес</h2>
@@ -47,6 +51,7 @@ use Rsgrinko\Proton\View\View;
</div> </div>
</form> </form>
</div> </div>
<?php } ?>
<div class="card"> <div class="card">
<h2>Кого подбирают</h2> <h2>Кого подбирают</h2>
@@ -75,6 +80,7 @@ use Rsgrinko\Proton\View\View;
<td class="mono small"><?= View::e((string) $ip) ?></td> <td class="mono small"><?= View::e((string) $ip) ?></td>
<td class="right"><?= (int) $count ?></td> <td class="right"><?= (int) $count ?></td>
<td class="right"> <td class="right">
<?php if ($canManage) { ?>
<form method="post" action="<?= View::e(View::route('admin.security.block')) ?>"> <form method="post" action="<?= View::e(View::route('admin.security.block')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<input type="hidden" name="ip" value="<?= View::e((string) $ip) ?>"> <input type="hidden" name="ip" value="<?= View::e((string) $ip) ?>">
@@ -82,6 +88,7 @@ use Rsgrinko\Proton\View\View;
<input type="hidden" name="minutes" value="60"> <input type="hidden" name="minutes" value="60">
<button type="submit">Закрыть на час</button> <button type="submit">Закрыть на час</button>
</form> </form>
<?php } ?>
</td> </td>
</tr> </tr>
<?php } ?> <?php } ?>
@@ -104,7 +111,7 @@ use Rsgrinko\Proton\View\View;
<th>Адрес</th> <th>Адрес</th>
<th>Причина</th> <th>Причина</th>
<th>До</th> <th>До</th>
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($blocks as $block) { ?> <?php foreach ($blocks as $block) { ?>
@@ -118,6 +125,7 @@ use Rsgrinko\Proton\View\View;
<?= View::e(View::date($block->until())) ?> <?= View::e(View::date($block->until())) ?>
<?php } ?> <?php } ?>
</td> </td>
<?php if ($canManage) { ?>
<td class="right"> <td class="right">
<form method="post" action="<?= View::e(View::route('admin.security.unblock')) ?>"> <form method="post" action="<?= View::e(View::route('admin.security.unblock')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
@@ -125,6 +133,7 @@ use Rsgrinko\Proton\View\View;
<button type="submit">Открыть</button> <button type="submit">Открыть</button>
</form> </form>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
@@ -153,7 +162,7 @@ use Rsgrinko\Proton\View\View;
<th>Адрес</th> <th>Адрес</th>
<th>Логин</th> <th>Логин</th>
<th class="hide-sm">Страница</th> <th class="hide-sm">Страница</th>
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($page['items'] as $event) { ?> <?php foreach ($page['items'] as $event) { ?>
@@ -163,6 +172,7 @@ use Rsgrinko\Proton\View\View;
<td class="mono small"><?= View::e((string) $event->raw('ip')) ?></td> <td class="mono small"><?= View::e((string) $event->raw('ip')) ?></td>
<td class="small"><?= View::e((string) $event->raw('login') ?: '—') ?></td> <td class="small"><?= View::e((string) $event->raw('login') ?: '—') ?></td>
<td class="hide-sm muted small"><?= View::e((string) $event->raw('path') ?: '—') ?></td> <td class="hide-sm muted small"><?= View::e((string) $event->raw('path') ?: '—') ?></td>
<?php if ($canManage) { ?>
<td class="right"> <td class="right">
<?php if ((string) $event->raw('ip') !== '') { ?> <?php if ((string) $event->raw('ip') !== '') { ?>
<form method="post" action="<?= View::e(View::route('admin.security.block')) ?>"> <form method="post" action="<?= View::e(View::route('admin.security.block')) ?>">
@@ -174,6 +184,7 @@ use Rsgrinko\Proton\View\View;
</form> </form>
<?php } ?> <?php } ?>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
+12 -2
View File
@@ -9,8 +9,11 @@ declare(strict_types=1);
* @var array<string, mixed> $values текущие значения * @var array<string, mixed> $values текущие значения
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Support\Settings; use Rsgrinko\Proton\Support\Settings;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$canManage = View::can(Permission::SETTINGS_MANAGE);
?> ?>
<h1>Настройки</h1> <h1>Настройки</h1>
@@ -28,6 +31,7 @@ use Rsgrinko\Proton\View\View;
<form method="post" action="<?= View::e(View::route('admin.settings')) ?>"> <form method="post" action="<?= View::e(View::route('admin.settings')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<fieldset <?= $canManage ? '' : 'disabled' ?> style="border: 0; padding: 0; margin: 0;">
<?php foreach ($groups as $title => $items) { ?> <?php foreach ($groups as $title => $items) { ?>
<div class="card"> <div class="card">
@@ -79,11 +83,15 @@ use Rsgrinko\Proton\View\View;
</div> </div>
<?php } ?> <?php } ?>
</fieldset>
<?php if ($canManage) { ?>
<div class="card"> <div class="card">
<div class="row"> <div class="row">
<button type="submit" class="primary">Сохранить</button> <button type="submit" class="primary">Сохранить</button>
</div> </div>
</div> </div>
<?php } ?>
</form> </form>
<?php <?php
@@ -101,20 +109,21 @@ foreach ($groups as $items) {
<?php if ($overridden !== []) { ?> <?php if ($overridden !== []) { ?>
<div class="card"> <div class="card">
<h2>Изменённые настройки</h2> <h2>Изменённые настройки</h2>
<p class="muted small">Эти значения взяты из базы. Сброс вернёт то, что задано в <span class="mono">.env</span>.</p> <p class="muted small">Эти значения взяты из базы<?= $canManage ? '. Сброс вернёт то, что задано в <span class="mono">.env</span>.' : '.' ?></p>
<div class="table-wrap"> <div class="table-wrap">
<table class="list"> <table class="list">
<tr class="head"> <tr class="head">
<th>Настройка</th> <th>Настройка</th>
<th>Ключ</th> <th>Ключ</th>
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($overridden as $key => $label) { ?> <?php foreach ($overridden as $key => $label) { ?>
<tr> <tr>
<td><?= View::e($label) ?></td> <td><?= View::e($label) ?></td>
<td class="mono small"><?= View::e($key) ?></td> <td class="mono small"><?= View::e($key) ?></td>
<?php if ($canManage) { ?>
<td class="right"> <td class="right">
<form method="post" action="<?= View::e(View::route('admin.settings.reset')) ?>"> <form method="post" action="<?= View::e(View::route('admin.settings.reset')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
@@ -122,6 +131,7 @@ foreach ($groups as $items) {
<button type="submit">Сбросить</button> <button type="submit">Сбросить</button>
</form> </form>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
+5 -3
View File
@@ -18,12 +18,14 @@ declare(strict_types=1);
* @var string $php * @var string $php
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Support\Diagnostics; use Rsgrinko\Proton\Support\Diagnostics;
use Rsgrinko\Proton\Support\Str; use Rsgrinko\Proton\Support\Str;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$badges = [Diagnostics::OK => 'ok', Diagnostics::WARN => 'warn', Diagnostics::ERROR => 'error']; $badges = [Diagnostics::OK => 'ok', Diagnostics::WARN => 'warn', Diagnostics::ERROR => 'error'];
$labels = [Diagnostics::OK => 'в порядке', Diagnostics::WARN => 'внимание', Diagnostics::ERROR => 'проблема']; $labels = [Diagnostics::OK => 'в порядке', Diagnostics::WARN => 'внимание', Diagnostics::ERROR => 'проблема'];
$canManage = View::can(Permission::SYSTEM_MANAGE);
?> ?>
<h1>Состояние</h1> <h1>Состояние</h1>
@@ -92,7 +94,7 @@ $labels = [Diagnostics::OK => 'в порядке', Diagnostics::WARN => 'вни
</table> </table>
</div> </div>
<?php if (View::can('system.manage')) { ?> <?php if (View::can(Permission::SYSTEM_MANAGE)) { ?>
<div class="row" style="margin-top: 12px;"> <div class="row" style="margin-top: 12px;">
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'queue-retry'])) ?>"> <form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'queue-retry'])) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
@@ -138,7 +140,7 @@ $labels = [Diagnostics::OK => 'в порядке', Diagnostics::WARN => 'вни
</div> </div>
<?php } ?> <?php } ?>
<?php if (View::can('system.manage')) { ?> <?php if (View::can(Permission::SYSTEM_MANAGE)) { ?>
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'schedule-run'])) ?>" style="margin-top: 12px;"> <form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'schedule-run'])) ?>" style="margin-top: 12px;">
<?= View::csrf() ?> <?= View::csrf() ?>
<button type="submit">Выполнить, что пора</button> <button type="submit">Выполнить, что пора</button>
@@ -175,7 +177,7 @@ $labels = [Diagnostics::OK => 'в порядке', Diagnostics::WARN => 'вни
он держит загруженные классы в памяти, и задачи продолжали бы выполняться старым кодом. он держит загруженные классы в памяти, и задачи продолжали бы выполняться старым кодом.
</p> </p>
<?php if (View::can('system.manage')) { ?> <?php if (View::can(Permission::SYSTEM_MANAGE)) { ?>
<div class="row"> <div class="row">
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'worker-restart'])) ?>"> <form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'worker-restart'])) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
+8 -1
View File
@@ -12,7 +12,10 @@ declare(strict_types=1);
* @var string $issued только что выпущенный ключ — показывается один раз * @var string $issued только что выпущенный ключ — показывается один раз
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$canManage = View::can(Permission::TOKENS_MANAGE);
?> ?>
<h1>Ключи API</h1> <h1>Ключи API</h1>
@@ -25,6 +28,7 @@ use Rsgrinko\Proton\View\View;
</div> </div>
<?php } ?> <?php } ?>
<?php if ($canManage) { ?>
<div class="card"> <div class="card">
<h2>Выпустить ключ</h2> <h2>Выпустить ключ</h2>
@@ -67,6 +71,7 @@ use Rsgrinko\Proton\View\View;
</div> </div>
</form> </form>
</div> </div>
<?php } ?>
<?= View::partial('filters', ['filters' => $filters, 'route' => 'admin.tokens', 'total' => $page['total']]) ?> <?= View::partial('filters', ['filters' => $filters, 'route' => 'admin.tokens', 'total' => $page['total']]) ?>
@@ -87,7 +92,7 @@ use Rsgrinko\Proton\View\View;
<th>Состояние</th> <th>Состояние</th>
<th class="hide-sm">Срок</th> <th class="hide-sm">Срок</th>
<th class="hide-sm">Использован</th> <th class="hide-sm">Использован</th>
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($page['items'] as $token) { ?> <?php foreach ($page['items'] as $token) { ?>
@@ -117,6 +122,7 @@ use Rsgrinko\Proton\View\View;
<?php } ?> <?php } ?>
</td> </td>
<td class="hide-sm muted small"><?= View::e(View::ago((string) $token->raw('last_used_at'))) ?></td> <td class="hide-sm muted small"><?= View::e(View::ago((string) $token->raw('last_used_at'))) ?></td>
<?php if ($canManage) { ?>
<td class="right"> <td class="right">
<div class="row end"> <div class="row end">
<?php if ((int) $token->raw('active') === 1) { ?> <?php if ((int) $token->raw('active') === 1) { ?>
@@ -132,6 +138,7 @@ use Rsgrinko\Proton\View\View;
</form> </form>
</div> </div>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
+11 -6
View File
@@ -11,6 +11,7 @@ declare(strict_types=1);
* @var string $label его подпись * @var string $label его подпись
* @var callable $title как назвать запись * @var callable $title как назвать запись
* @var array{items: array<int, \Rsgrinko\Proton\Database\Model\Model>, total: int, page: int, pages: int, per_page: int} $page * @var array{items: array<int, \Rsgrinko\Proton\Database\Model\Model>, total: int, page: int, pages: int, per_page: int} $page
* @var bool $canAct смотреть раздел и возвращать/добивать из него — разные права
*/ */
use Rsgrinko\Proton\Database\Model\Model; use Rsgrinko\Proton\Database\Model\Model;
@@ -22,7 +23,7 @@ use Rsgrinko\Proton\View\View;
<div class="row"> <div class="row">
<?php foreach ($kinds as $key => $item) { ?> <?php foreach ($kinds as $key => $item) { ?>
<?php if ($key === $kind) { ?> <?php if ($key === $kind) { ?>
<span class="badge info"><?= View::e($item['label']) ?>: <?= (int) ($counts[$key] ?? 0) ?></span> <span class="btn small primary"><?= View::e($item['label']) ?> (<?= (int) ($counts[$key] ?? 0) ?>)</span>
<?php } else { ?> <?php } else { ?>
<a class="btn small" href="<?= View::e(View::route('admin.trash', ['kind' => $key])) ?>"> <a class="btn small" href="<?= View::e(View::route('admin.trash', ['kind' => $key])) ?>">
<?= View::e($item['label']) ?> (<?= (int) ($counts[$key] ?? 0) ?>) <?= View::e($item['label']) ?> (<?= (int) ($counts[$key] ?? 0) ?>)
@@ -40,7 +41,7 @@ use Rsgrinko\Proton\View\View;
<h2 style="margin: 0;"><?= View::e($label) ?></h2> <h2 style="margin: 0;"><?= View::e($label) ?></h2>
<span class="spacer"></span> <span class="spacer"></span>
<?php if (($counts[$kind] ?? 0) > 0) { ?> <?php if ($canAct && ($counts[$kind] ?? 0) > 0) { ?>
<form method="post" action="<?= View::e(View::route('admin.trash.clear')) ?>"> <form method="post" action="<?= View::e(View::route('admin.trash.clear')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<input type="hidden" name="kind" value="<?= View::e($kind) ?>"> <input type="hidden" name="kind" value="<?= View::e($kind) ?>">
@@ -55,6 +56,7 @@ use Rsgrinko\Proton\View\View;
<?php if ($page['items'] === []) { ?> <?php if ($page['items'] === []) { ?>
<p class="muted">Здесь пусто — ничего не удаляли или всё уже вернули.</p> <p class="muted">Здесь пусто — ничего не удаляли или всё уже вернули.</p>
<?php } else { ?> <?php } else { ?>
<?php if ($canAct) { ?>
<form method="post" action="<?= View::e(View::route('admin.trash.bulk')) ?>"> <form method="post" action="<?= View::e(View::route('admin.trash.bulk')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<input type="hidden" name="kind" value="<?= View::e($kind) ?>"> <input type="hidden" name="kind" value="<?= View::e($kind) ?>">
@@ -66,21 +68,23 @@ use Rsgrinko\Proton\View\View;
], ],
'confirm' => 'Выполнить действие над отмеченными записями? Удаление совсем — без возврата.', 'confirm' => 'Выполнить действие над отмеченными записями? Удаление совсем — без возврата.',
]) ?> ]) ?>
<?php } ?>
<div class="table-wrap"> <div class="table-wrap">
<table class="list"> <table class="list">
<tr class="head"> <tr class="head">
<th></th> <?php if ($canAct) { ?><th></th><?php } ?>
<th>Запись</th> <th>Запись</th>
<th>Удалена</th> <th>Удалена</th>
<th></th> <?php if ($canAct) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($page['items'] as $record) { ?> <?php foreach ($page['items'] as $record) { ?>
<tr> <tr>
<td><input type="checkbox" name="ids[]" value="<?= $record->id() ?>" data-check-item></td> <?php if ($canAct) { ?><td><input type="checkbox" name="ids[]" value="<?= $record->id() ?>" data-check-item></td><?php } ?>
<td><?= View::e(($title)($record)) ?></td> <td><?= View::e(($title)($record)) ?></td>
<td class="muted small nowrap"><?= View::e(View::ago((string) $record->raw(Model::DELETED_AT))) ?></td> <td class="muted small nowrap"><?= View::e(View::ago((string) $record->raw(Model::DELETED_AT))) ?></td>
<?php if ($canAct) { ?>
<td class="right"> <td class="right">
<div class="row end"> <div class="row end">
<form method="post" action="<?= View::e(View::route('admin.trash.restore')) ?>"> <form method="post" action="<?= View::e(View::route('admin.trash.restore')) ?>">
@@ -98,11 +102,12 @@ use Rsgrinko\Proton\View\View;
</form> </form>
</div> </div>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
</div> </div>
</form> <?php if ($canAct) { ?></form><?php } ?>
<?= View::partial('pagination', [ <?= View::partial('pagination', [
'route' => 'admin.trash', 'route' => 'admin.trash',
+37
View File
@@ -20,12 +20,25 @@ use Rsgrinko\Proton\View\View;
$isNew = !$user->existsInDatabase(); $isNew = !$user->existsInDatabase();
$action = $isNew ? View::route('admin.users.create') : View::route('admin.users.show', ['id' => $user->id()]); $action = $isNew ? View::route('admin.users.create') : View::route('admin.users.show', ['id' => $user->id()]);
$hint = $isNew ? 'пусто — придумаем сами' : 'пусто — не менять'; $hint = $isNew ? 'пусто — придумаем сами' : 'пусто — не менять';
// Новый — только у тех, кто прошёл can:users.manage в маршруте; карточку же
// существующего человека открывает и users.view — форму правки там не покажем
$canManage = View::can(Permission::USERS_MANAGE);
$roleName = '—';
foreach ($roles as $role) {
if ($role->id() === (int) $user->raw('role_id')) {
$roleName = (string) $role->name;
break;
}
}
?> ?>
<div class="row"> <div class="row">
<?php if (!$isNew) { ?><?= View::avatar($user) ?><?php } ?> <?php if (!$isNew) { ?><?= View::avatar($user) ?><?php } ?>
<h1 style="margin: 0;"><?= $isNew ? 'Новый пользователь' : View::e((string) $user->login) ?></h1> <h1 style="margin: 0;"><?= $isNew ? 'Новый пользователь' : View::e((string) $user->login) ?></h1>
</div> </div>
<?php if ($isNew || $canManage) { ?>
<div class="card"> <div class="card">
<form method="post" action="<?= View::e($action) ?>"> <form method="post" action="<?= View::e($action) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
@@ -74,6 +87,28 @@ $hint = $isNew ? 'пусто — придумаем сами' : 'пусто
</div> </div>
</form> </form>
</div> </div>
<?php } else { ?>
<div class="card">
<dl class="props">
<dt>Логин</dt>
<dd><?= View::e((string) $user->login) ?></dd>
<dt>Имя</dt>
<dd><?= $user->name !== '' ? View::e((string) $user->name) : '<span class="muted">—</span>' ?></dd>
<dt>Почта</dt>
<dd><?= $user->email !== '' ? View::e((string) $user->email) : '<span class="muted">—</span>' ?></dd>
<dt>Роль</dt>
<dd><?= View::e($roleName) ?></dd>
<dt>Активен</dt>
<dd><?= $user->isActive() ? 'да' : 'нет' ?></dd>
</dl>
<p style="margin-top: 12px;"><a class="btn" href="<?= View::e(View::route('admin.users')) ?>">К списку</a></p>
</div>
<?php } ?>
<?php if (!$isNew) { ?> <?php if (!$isNew) { ?>
<div class="card"> <div class="card">
@@ -155,6 +190,7 @@ $hint = $isNew ? 'пусто — придумаем сами' : 'пусто
</div> </div>
<?php } ?> <?php } ?>
<?php if ($canManage) { ?>
<div class="card"> <div class="card">
<h2>Удаление</h2> <h2>Удаление</h2>
<p class="muted small">Пользователь исчезнет вместе со своими сеансами. Его записи останутся.</p> <p class="muted small">Пользователь исчезнет вместе со своими сеансами. Его записи останутся.</p>
@@ -164,6 +200,7 @@ $hint = $isNew ? 'пусто — придумаем сами' : 'пусто
<button type="submit" class="danger">Удалить пользователя</button> <button type="submit" class="danger">Удалить пользователя</button>
</form> </form>
</div> </div>
<?php } ?>
<?php } ?> <?php } ?>
<?php if ($user->id() > 0) { ?> <?php if ($user->id() > 0) { ?>
+12 -3
View File
@@ -10,12 +10,19 @@ declare(strict_types=1);
* @var \Rsgrinko\Proton\Support\Filters $filters * @var \Rsgrinko\Proton\Support\Filters $filters
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
// Список открыт и по users.view — правки и массовые действия показываем
// только тому, у кого есть users.manage
$canManage = View::can(Permission::USERS_MANAGE);
?> ?>
<div class="row"> <div class="row">
<h1 style="margin: 0;">Пользователи</h1> <h1 style="margin: 0;">Пользователи</h1>
<span class="spacer"></span> <span class="spacer"></span>
<?php if ($canManage) { ?>
<a class="btn primary" href="<?= View::e(View::route('admin.users.create')) ?>">Новый пользователь</a> <a class="btn primary" href="<?= View::e(View::route('admin.users.create')) ?>">Новый пользователь</a>
<?php } ?>
</div> </div>
<div style="margin-top: 16px;"> <div style="margin-top: 16px;">
@@ -26,6 +33,7 @@ use Rsgrinko\Proton\View\View;
<?php if ($page['items'] === []) { ?> <?php if ($page['items'] === []) { ?>
<p class="muted">Ничего не нашлось.</p> <p class="muted">Ничего не нашлось.</p>
<?php } else { ?> <?php } else { ?>
<?php if ($canManage) { ?>
<form method="post" action="<?= View::e(View::route('admin.users.bulk')) ?>"> <form method="post" action="<?= View::e(View::route('admin.users.bulk')) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
@@ -37,11 +45,12 @@ use Rsgrinko\Proton\View\View;
], ],
'confirm' => 'Выполнить действие над отмеченными пользователями?', 'confirm' => 'Выполнить действие над отмеченными пользователями?',
]) ?> ]) ?>
<?php } ?>
<div class="table-wrap"> <div class="table-wrap">
<table class="list"> <table class="list">
<tr class="head"> <tr class="head">
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
<th></th> <th></th>
<th><?= View::partial('sort', ['filters' => $filters, 'route' => 'admin.users', 'column' => 'login', 'label' => 'Логин']) ?></th> <th><?= View::partial('sort', ['filters' => $filters, 'route' => 'admin.users', 'column' => 'login', 'label' => 'Логин']) ?></th>
<th class="hide-sm">Имя</th> <th class="hide-sm">Имя</th>
@@ -53,7 +62,7 @@ use Rsgrinko\Proton\View\View;
<?php foreach ($page['items'] as $user) { ?> <?php foreach ($page['items'] as $user) { ?>
<tr> <tr>
<td><input type="checkbox" name="ids[]" value="<?= $user->id() ?>" data-check-item></td> <?php if ($canManage) { ?><td><input type="checkbox" name="ids[]" value="<?= $user->id() ?>" data-check-item></td><?php } ?>
<td><?= View::avatar($user) ?></td> <td><?= View::avatar($user) ?></td>
<td><a href="<?= View::e(View::route('admin.users.show', ['id' => $user->id()])) ?>"><?= View::e((string) $user->login) ?></a></td> <td><a href="<?= View::e(View::route('admin.users.show', ['id' => $user->id()])) ?>"><?= View::e((string) $user->login) ?></a></td>
<td class="hide-sm"><?= View::e((string) $user->name) ?></td> <td class="hide-sm"><?= View::e((string) $user->name) ?></td>
@@ -72,7 +81,7 @@ use Rsgrinko\Proton\View\View;
</table> </table>
</div> </div>
</form> <?php if ($canManage) { ?></form><?php } ?>
<?= View::partial('pagination', [ <?= View::partial('pagination', [
'route' => 'admin.users', 'route' => 'admin.users',
+13 -5
View File
@@ -11,6 +11,7 @@ declare(strict_types=1);
* @var string $fresh только что выданный секрет — показывается один раз * @var string $fresh только что выданный секрет — показывается один раз
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Models\Webhook; use Rsgrinko\Proton\Models\Webhook;
use Rsgrinko\Proton\Models\WebhookDelivery; use Rsgrinko\Proton\Models\WebhookDelivery;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
@@ -19,6 +20,9 @@ $isNew = !$webhook->existsInDatabase();
$action = $isNew ? View::route('admin.webhooks.create') : View::route('admin.webhooks.show', ['id' => $webhook->id()]); $action = $isNew ? View::route('admin.webhooks.create') : View::route('admin.webhooks.show', ['id' => $webhook->id()]);
$selected = $webhook->events(); $selected = $webhook->events();
$all = in_array(Webhook::ALL_EVENTS, $selected, true); $all = in_array(Webhook::ALL_EVENTS, $selected, true);
$canManage = View::can(Permission::WEBHOOKS_MANAGE);
$canDelete = View::can(Permission::WEBHOOKS_DELETE);
$readOnly = !$isNew && !$canManage;
?> ?>
<h1><?= $isNew ? 'Новый вебхук' : View::e((string) $webhook->name) ?></h1> <h1><?= $isNew ? 'Новый вебхук' : View::e((string) $webhook->name) ?></h1>
@@ -37,12 +41,12 @@ $all = in_array(Webhook::ALL_EVENTS, $selected, true);
<label> <label>
<span>Название</span> <span>Название</span>
<input type="text" name="name" value="<?= View::e((string) $webhook->name) ?>" placeholder="склад 1С" <?= $isNew ? 'autofocus' : '' ?>> <input type="text" name="name" value="<?= View::e((string) $webhook->name) ?>" placeholder="склад 1С" <?= $isNew ? 'autofocus' : '' ?> <?= $readOnly ? 'disabled' : '' ?>>
</label> </label>
<label> <label>
<span>Адрес подписчика</span> <span>Адрес подписчика</span>
<input type="url" name="url" value="<?= View::e((string) $webhook->url) ?>" placeholder="https://example.com/hooks/proton" required> <input type="url" name="url" value="<?= View::e((string) $webhook->url) ?>" placeholder="https://example.com/hooks/proton" <?= $readOnly ? 'disabled' : '' ?> required>
</label> </label>
<?php if ($isNew) { ?> <?php if ($isNew) { ?>
@@ -55,7 +59,7 @@ $all = in_array(Webhook::ALL_EVENTS, $selected, true);
<h2 style="margin-top: 16px;">События</h2> <h2 style="margin-top: 16px;">События</h2>
<label class="inline" style="margin-bottom: 6px;"> <label class="inline" style="margin-bottom: 6px;">
<input type="checkbox" name="events[]" value="<?= View::e(Webhook::ALL_EVENTS) ?>" <?= $all ? 'checked' : '' ?>> <input type="checkbox" name="events[]" value="<?= View::e(Webhook::ALL_EVENTS) ?>" <?= $all ? 'checked' : '' ?> <?= $readOnly ? 'disabled' : '' ?>>
<span>Все события — в том числе те, что появятся позже</span> <span>Все события — в том числе те, что появятся позже</span>
</label> </label>
@@ -66,7 +70,7 @@ $all = in_array(Webhook::ALL_EVENTS, $selected, true);
<?php foreach ($events as $code => $label) { ?> <?php foreach ($events as $code => $label) { ?>
<label class="inline" style="margin-bottom: 6px;"> <label class="inline" style="margin-bottom: 6px;">
<input type="checkbox" name="events[]" value="<?= View::e($code) ?>" <input type="checkbox" name="events[]" value="<?= View::e($code) ?>"
<?= in_array($code, $selected, true) ? 'checked' : '' ?>> <?= in_array($code, $selected, true) ? 'checked' : '' ?> <?= $readOnly ? 'disabled' : '' ?>>
<span><?= View::e($label) ?> <span class="muted mono"><?= View::e($code) ?></span></span> <span><?= View::e($label) ?> <span class="muted mono"><?= View::e($code) ?></span></span>
</label> </label>
<?php } ?> <?php } ?>
@@ -74,7 +78,7 @@ $all = in_array(Webhook::ALL_EVENTS, $selected, true);
<?php } ?> <?php } ?>
<div class="row"> <div class="row">
<button type="submit" class="primary">Сохранить</button> <?php if (!$readOnly) { ?><button type="submit" class="primary">Сохранить</button><?php } ?>
<a class="btn" href="<?= View::e(View::route('admin.webhooks')) ?>">К списку</a> <a class="btn" href="<?= View::e(View::route('admin.webhooks')) ?>">К списку</a>
</div> </div>
</form> </form>
@@ -121,6 +125,7 @@ $all = in_array(Webhook::ALL_EVENTS, $selected, true);
</table> </table>
<div class="row" style="margin-top: 12px;"> <div class="row" style="margin-top: 12px;">
<?php if ($canManage) { ?>
<form method="post" action="<?= View::e(View::route('admin.webhooks.test', ['id' => $webhook->id()])) ?>"> <form method="post" action="<?= View::e(View::route('admin.webhooks.test', ['id' => $webhook->id()])) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<button type="submit" class="primary">Отправить пробную посылку</button> <button type="submit" class="primary">Отправить пробную посылку</button>
@@ -135,11 +140,14 @@ $all = in_array(Webhook::ALL_EVENTS, $selected, true);
<?= View::csrf() ?> <?= View::csrf() ?>
<button type="submit">Заменить секрет</button> <button type="submit">Заменить секрет</button>
</form> </form>
<?php } ?>
<?php if ($canDelete) { ?>
<form method="post" action="<?= View::e(View::route('admin.webhooks.delete', ['id' => $webhook->id()])) ?>"> <form method="post" action="<?= View::e(View::route('admin.webhooks.delete', ['id' => $webhook->id()])) ?>">
<?= View::csrf() ?> <?= View::csrf() ?>
<button type="submit" class="danger">Удалить вебхук</button> <button type="submit" class="danger">Удалить вебхук</button>
</form> </form>
<?php } ?>
</div> </div>
</div> </div>
+7 -1
View File
@@ -11,11 +11,13 @@ declare(strict_types=1);
* @var \Rsgrinko\Proton\Support\Filters $filters * @var \Rsgrinko\Proton\Support\Filters $filters
*/ */
use Rsgrinko\Proton\Access\Permission;
use Rsgrinko\Proton\Models\IncomingHook; use Rsgrinko\Proton\Models\IncomingHook;
use Rsgrinko\Proton\Models\Webhook; use Rsgrinko\Proton\Models\Webhook;
use Rsgrinko\Proton\Models\WebhookDelivery; use Rsgrinko\Proton\Models\WebhookDelivery;
use Rsgrinko\Proton\View\View; use Rsgrinko\Proton\View\View;
$canManage = View::can(Permission::WEBHOOKS_MANAGE);
$events = 0; $events = 0;
foreach ($groups as $group) { foreach ($groups as $group) {
@@ -38,9 +40,11 @@ foreach ($groups as $group) {
не доставлено <?= (int) ($stats[WebhookDelivery::FAILED] ?? 0) ?>. не доставлено <?= (int) ($stats[WebhookDelivery::FAILED] ?? 0) ?>.
</p> </p>
<?php if ($canManage) { ?>
<div class="row"> <div class="row">
<a class="btn primary" href="<?= View::e(View::route('admin.webhooks.create')) ?>">Новый вебхук</a> <a class="btn primary" href="<?= View::e(View::route('admin.webhooks.create')) ?>">Новый вебхук</a>
</div> </div>
<?php } ?>
</div> </div>
<?= View::partial('filters', ['filters' => $filters, 'route' => 'admin.webhooks', 'total' => $page['total']]) ?> <?= View::partial('filters', ['filters' => $filters, 'route' => 'admin.webhooks', 'total' => $page['total']]) ?>
@@ -59,7 +63,7 @@ foreach ($groups as $group) {
<th class="hide-sm">События</th> <th class="hide-sm">События</th>
<th>Состояние</th> <th>Состояние</th>
<th class="hide-sm">Последняя посылка</th> <th class="hide-sm">Последняя посылка</th>
<th></th> <?php if ($canManage) { ?><th></th><?php } ?>
</tr> </tr>
<?php foreach ($page['items'] as $webhook) { ?> <?php foreach ($page['items'] as $webhook) { ?>
@@ -90,6 +94,7 @@ foreach ($groups as $group) {
<span class="mono">(<?= (int) $webhook->raw('last_status') ?>)</span> <span class="mono">(<?= (int) $webhook->raw('last_status') ?>)</span>
<?php } ?> <?php } ?>
</td> </td>
<?php if ($canManage) { ?>
<td class="right"> <td class="right">
<div class="row end"> <div class="row end">
<form method="post" action="<?= View::e(View::route('admin.webhooks.test', ['id' => $webhook->id()])) ?>"> <form method="post" action="<?= View::e(View::route('admin.webhooks.test', ['id' => $webhook->id()])) ?>">
@@ -98,6 +103,7 @@ foreach ($groups as $group) {
</form> </form>
</div> </div>
</td> </td>
<?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>