1
0
Fork 0
mirror of synced 2024-09-16 17:40:04 +12:00
appwrite/app/views/console/comps/permissions-matrix.phtml

112 lines
3.7 KiB
PHTML
Raw Normal View History

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', '');
$data = $this->getParam('data', '');
$form = $this->getParam('form', 'permissionsForm');
2022-08-13 18:33:11 +12:00
$permissions = $this->getParam('permissions', Database::PERMISSIONS);
$escapedPermissions = \array_map(function ($perm) {
// Alpine won't bind to a parameter named delete :/
if ($perm == 'delete') {
return 'xdelete';
}
return $perm;
}, $permissions);
?>
<div
<?php if ($method): ?>
data-method="<?php echo $method; ?>"
<?php endif; ?>
<?php foreach ($params as $key => $value): ?>
data-param-<?php echo $key; ?>="<?php echo $value; ?>"
<?php endforeach; ?>
data-scope="sdk"
data-event="load<?php if (!empty($events)) echo ',' . $events; ?>"
data-name="<?php echo $data; ?>"
class="permissions-matrix margin-bottom-large"
x-data="permissionsMatrix">
<form id="<?php echo $form ?>"></form>
2022-08-13 18:33:11 +12:00
<input
type="hidden"
name="<?php echo $form; ?>"
2022-08-13 18:33:11 +12:00
data-cast-from="csv"
data-cast-to="array"
data-ls-bind="{{<?php echo $data ?>.$permissions}}"
:value="rawPermissions"/>
<table data-ls-attrs="x-init=load({{<?php echo $data ?>.$permissions}})">
<thead>
<tr>
<th>Role</th>
<?php foreach ($permissions as $permission): ?>
<th><?php echo \ucfirst($permission); ?></th>
<?php endforeach; ?>
<th></th>
</tr>
</thead>
<tbody>
<template x-for="(permission, index) in permissions">
<tr>
<td>
<p x-text="permission.role"></p>
</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>
<tr x-data="permissionsRow"
@addrow.window="addPermission(<?php echo $form; ?>,role,{<?php echo \implode(',', $escapedPermissions) ?>})">
2022-08-13 18:33:11 +12:00
<td>
<datalist id="types">
<option value="user:">
<option value="team:">
<option value="users">
<option value="guests">
<option value="any">
</datalist>
<input
required
id="<?php echo $form; ?>"
name="<?php echo $form; ?>"
form="<?php echo $form ?>"
list="types"
type="text"
x-model="role" />
2022-08-13 18:33:11 +12:00
</td>
<?php foreach ($escapedPermissions as $permission): ?>
<td>
<input type="checkbox" name="<?php echo $permission ?>" x-model="<?php echo $permission; ?>"/>
</td>
<?php endforeach; ?>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="6">
<button type="button" class="btn btn-primary margin-top-small" @click="$dispatch('addrow')">Add</button>
</td>
</tr>
</tfoot>
</table>
</div>