2022-08-13 18:33:11 +12:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Utopia\Database\Database;
|
|
|
|
|
|
|
|
$method = $this->getParam('method', '');
|
|
|
|
$params = $this->getParam('params', []);
|
|
|
|
$events = $this->getParam('events', '');
|
|
|
|
$permissions = $this->getParam('permissions', Database::PERMISSIONS);
|
2022-08-13 21:01:33 +12:00
|
|
|
$data = $this->getParam('data', '');
|
2022-08-29 22:25:00 +12:00
|
|
|
$form = $this->getParam('form');
|
2022-08-13 18:33:11 +12:00
|
|
|
|
|
|
|
$escapedPermissions = \array_map(function ($perm) {
|
2022-08-26 15:34:26 +12:00
|
|
|
// Alpine won't bind to a parameter named delete
|
2022-08-13 18:33:11 +12:00
|
|
|
if ($perm == 'delete') {
|
|
|
|
return 'xdelete';
|
|
|
|
}
|
|
|
|
return $perm;
|
|
|
|
}, $permissions);
|
|
|
|
|
|
|
|
?>
|
|
|
|
<div
|
2022-08-26 15:34:26 +12:00
|
|
|
x-data="permissionsMatrix"
|
|
|
|
class="permissions-matrix margin-bottom-large"
|
|
|
|
data-scope="sdk"
|
|
|
|
<?php if (!empty($method)): ?>
|
2022-08-13 18:33:11 +12:00
|
|
|
data-method="<?php echo $method; ?>"
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php foreach ($params as $key => $value): ?>
|
|
|
|
data-param-<?php echo $key; ?>="<?php echo $value; ?>"
|
|
|
|
<?php endforeach; ?>
|
2022-08-26 15:34:26 +12:00
|
|
|
<?php if (!empty($events)): ?>
|
|
|
|
data-events="<?php echo $events; ?>"
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($data)): ?>
|
|
|
|
data-name="<?php echo $data; ?>"
|
|
|
|
<?php endif; ?>
|
2022-08-29 15:12:20 +12:00
|
|
|
@reset.window="permissions.length = rawPermissions.length = 0">
|
2022-08-13 18:33:11 +12:00
|
|
|
|
|
|
|
<input
|
|
|
|
type="hidden"
|
2022-08-13 21:01:33 +12:00
|
|
|
name="permissions"
|
2022-08-13 18:33:11 +12:00
|
|
|
data-cast-from="csv"
|
|
|
|
data-cast-to="array"
|
2022-08-26 15:34:26 +12:00
|
|
|
<?php if (!empty(($data))): ?>
|
|
|
|
data-ls-bind="{{<?php echo $data ?>.$permissions}}"
|
|
|
|
<?php endif; ?>
|
2022-08-13 18:33:11 +12:00
|
|
|
:value="rawPermissions"/>
|
|
|
|
|
2022-09-12 16:20:37 +12:00
|
|
|
<datalist id="types">
|
|
|
|
<option value="user:">
|
|
|
|
<option value="team:">
|
|
|
|
<option value="member:">
|
|
|
|
<option value="users">
|
|
|
|
<option value="guests">
|
|
|
|
<option value="any">
|
|
|
|
</datalist>
|
|
|
|
|
2022-09-12 14:04:05 +12:00
|
|
|
<table
|
|
|
|
class="u-table-layout-normal"
|
|
|
|
data-ls-attrs="x-init=load({{<?php if (!empty($data)) echo $data . '.$permissions' ?>}})">
|
|
|
|
|
|
|
|
<thead x-show="permissions.length > 0">
|
2022-08-13 18:33:11 +12:00
|
|
|
<tr>
|
|
|
|
<th>Role</th>
|
|
|
|
<?php foreach ($permissions as $permission): ?>
|
2022-09-02 22:05:04 +12:00
|
|
|
<th class="u-no-trim"><?php echo \ucfirst($permission); ?></th>
|
2022-08-13 18:33:11 +12:00
|
|
|
<?php endforeach; ?>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<template x-for="(permission, index) in permissions">
|
2022-09-13 16:12:47 +12:00
|
|
|
<tr>
|
2022-08-13 18:33:11 +12:00
|
|
|
<td>
|
2022-09-10 11:46:32 +12:00
|
|
|
<input
|
|
|
|
required
|
2022-09-12 15:54:55 +12:00
|
|
|
autocomplete="off"
|
|
|
|
:id="'<?php echo $form; ?>Input' + index"
|
2022-09-10 11:46:32 +12:00
|
|
|
name="<?php echo $form; ?>"
|
|
|
|
form="<?php echo $form ?>"
|
|
|
|
list="types"
|
|
|
|
type="text"
|
|
|
|
x-model="permission.role"
|
2022-09-20 22:04:15 +12:00
|
|
|
@keydown.enter="prevent($event)"
|
2022-09-20 22:03:13 +12:00
|
|
|
@keydown="clearPermission(index)"
|
2022-09-10 11:46:32 +12:00
|
|
|
@keyup="updatePermission(index)"/>
|
2022-08-13 18:33:11 +12:00
|
|
|
</td>
|
|
|
|
<?php foreach ($escapedPermissions as $permission): ?>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="<?php echo $permission ?>"
|
|
|
|
x-model="permission.<?php echo $permission; ?>"
|
|
|
|
@click="updatePermission(index)"/>
|
|
|
|
</td>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
<td>
|
|
|
|
<span class="action" @click="removePermission(index)">
|
|
|
|
<i class="icon-trash"></i>
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
</tbody>
|
|
|
|
<tfoot>
|
|
|
|
<tr>
|
2022-08-13 21:01:33 +12:00
|
|
|
<td colspan="<?php \count($permissions) + 2 ?>">
|
2022-09-15 00:00:35 +12:00
|
|
|
<button type="button" class="margin-top reverse" @click="addPermission('<?php echo $form ?>')">Add Role</button>
|
2022-08-13 18:33:11 +12:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tfoot>
|
|
|
|
</table>
|
2022-08-26 15:34:26 +12:00
|
|
|
</div>
|