See the README for current tweaks

This commit is contained in:
2023-05-31 11:51:12 +01:00
parent 97407e9532
commit a67214d024
18 changed files with 1260 additions and 2 deletions

View File

View File

@@ -1,3 +1,13 @@
# sprinkle-anti-dashboard # sprinkle-uf-tweaks
Removes the dashboard permission from 'users' role. Fixes/tweaks a few "issues" with the default UserFrosting installation, including:
- Removes the uri_dashboard permission from 'users' role
- Adds the uri_dashboard permission to the site-admin and group-admin roles
- Restructures the dashboard to be more role-friendly
- Fixes the authenticator generating 'PHP Notice's (parameter to count() must be an array)
- Don't send the user to the account settings on login, send them to the index instead
- Adds a user creation button to the group admin page
- Fixes showing user activity depending on the current user's permission to view it
- Allow site-admins to view roles & permissions
- Allow site-admins to edit basic role details (name, slug & description)

14
asset-bundles.json Normal file
View File

@@ -0,0 +1,14 @@
{
"bundle": {
"js/pages/group": {
"scripts": [
"uf-tweaks/js/pages/group.js"
],
"options": {
"sprinkle": {
"onCollision": "merge"
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
/**
* Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
* example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
*
* This script depends on uf-table.js, moment.js, handlebars-helpers.js
*
* Target page: /groups/g/{slug}
*/
$(document).ready(function() {
// Bind user creation button
bindUserCreationButton($("#widget-group-users"));
});

10
composer.json Normal file
View File

@@ -0,0 +1,10 @@
{
"name": "avsdev/sprinkle-uf-tweaks",
"type": "userfrosting-sprinkle",
"description": "Sprinkle to tweak the base UF installation to be tighter.",
"autoload": {
"psr-4": {
"UserFrosting\\Sprinkle\\UFTweaks\\": "src/"
}
}
}

45
config/default.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
/*
* AVSDev UF Tweaks (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
*/
return [
'debug' => [
'auth' => true,
],
/*
* ----------------------------------------------------------------------
* Database Config
* ----------------------------------------------------------------------
* Added schema to default with a default schema of public (postgres)
*/
'db' => [
'default' => [
'schema' => [env('DB_SCHEMA'), 'public'],
],
],
/*
* ----------------------------------------------------------------------
* Session Config
* ----------------------------------------------------------------------
* Extended session timeout to be 9 hours (average working day) for development
*/
'session' => [
'minutes' => 540,
],
/*
* ----------------------------------------------------------------------
* PHP global settings
* ----------------------------------------------------------------------
* Personal pereference of default timezone...
*/
'php' => [
'timezone' => 'Europe/London',
],
];

30
config/production.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
/*
* AVSDev UF Tweaks (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
*/
return [
/*
* ----------------------------------------------------------------------
* Session Config
* ----------------------------------------------------------------------
* Default session timeout to be 1 hour
*/
'session' => [
'minutes' => 60,
],
/*
* ----------------------------------------------------------------------
* PHP global settings
* ----------------------------------------------------------------------
* Default to php's recommended production value for error_reporting
*/
'php' => [
'error_reporting' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
],
];

View File

@@ -0,0 +1,33 @@
<?php
/*
* AVSDev UF Tweaks (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
*/
namespace UserFrosting\Sprinkle\UFTweaks\Database\Seeds;
use UserFrosting\Sprinkle\Account\Database\Models\Permission;
use UserFrosting\Sprinkle\Account\Database\Models\Role;
use UserFrosting\Sprinkle\Core\Database\Seeder\BaseSeed;
use UserFrosting\Sprinkle\Core\Facades\Seeder;
/**
* Removes all permissions from the system
*/
class ClearPermissions extends BaseSeed
{
/**
* {@inheritdoc}
*/
public function run()
{
Permission::all()->each(function($perm) {
$perm->roles()->sync([]);
});
Permission::whereRaw('1 = 1')->delete();
}
}

View File

@@ -0,0 +1,185 @@
<?php
/*
* AVSDev UF Tweaks (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
*/
namespace UserFrosting\Sprinkle\UFTweaks\Database\Seeds;
use UserFrosting\Sprinkle\Account\Database\Models\Permission;
use UserFrosting\Sprinkle\Account\Database\Models\Role;
use UserFrosting\Sprinkle\Account\Database\Seeds\DefaultPermissions as UFDefaultPermissions;
use UserFrosting\Sprinkle\Core\Facades\Seeder;
/**
* Seeder for the dashboard permissions.
*/
class DefaultPermissions extends UFDefaultPermissions
{
/**
* {@inheritdoc}
*/
public function run()
{
// We require the default roles
Seeder::execute('DefaultRoles');
// Get and save permissions
$permissions = $this->getPermissions();
$this->savePermissions($permissions);
// Add default mappings to permissions
$this->syncPermissionsRole($permissions);
}
/**
* @return array Permissions to seed
*/
protected function getPermissions()
{
$base_permissions = parent::getPermissions();
$defaultRoleIds = [
'user' => Role::where('slug', 'user')->first()->id,
'group-admin' => Role::where('slug', 'group-admin')->first()->id,
'site-admin' => Role::where('slug', 'site-admin')->first()->id,
];
return array_merge(
$base_permissions,
[
'uri_role' => new Permission([
'slug' => 'uri_role',
'name' => 'View role',
'conditions' => 'always()',
'description' => 'View the role page of any role.',
]),
'uri_roles' => new Permission([
'slug' => 'uri_roles',
'name' => 'Role management page',
'conditions' => 'always()',
'description' => 'View a page containing a table of roles.',
]),
'uri_permission' => new Permission([
'slug' => 'uri_permission',
'name' => 'View permission',
'conditions' => 'always()',
'description' => 'View the permission page of any permission.',
]),
'uri_permissions' => new Permission([
'slug' => 'uri_permissions',
'name' => 'Permission management page',
'conditions' => 'always()',
'description' => 'View a page containing a table of permissions.',
]),
'create_role' => new Permission([
'slug' => 'create_role',
'name' => 'Create role',
'conditions' => 'always()',
'description' => 'Create a new role.',
]),
'view_role_field' => new Permission([
'slug' => 'view_role_field',
'name' => 'View role',
'conditions' => "in(property,['slug','name','description','permissions','users'])",
'description' => 'View certain properties of any role.',
]),
'update_role_permissions' => new Permission([
'slug' => 'update_role_permissions',
'name' => 'Edit role permissions',
'conditions' => "is_master(self.id) || subset(fields,['permissions'])",
'description' => 'Edit permissions of any role.',
]),
'update_role_permissions_limited' => new Permission([
'slug' => 'update_role_permissions',
'name' => 'Edit role permissions',
'conditions' => "is_master(self.id) || (!has_role(self.id,role.id) && role.id != {$defaultRoleIds['site-admin']} && subset(fields,['permissions']))",
'description' => 'Edit basic properties of any role, except the Site Administrators role (unless you are the root user).',
]),
'update_role_field' => new Permission([
'slug' => 'update_role_field',
'name' => 'Edit role',
'conditions' => "is_master(self.id) || (!has_role(self.id,role.id) && role.id != {$defaultRoleIds['site-admin']} && subset(fields,['slug','name','description']))",
'description' => 'Edit basic properties of any role, except the Site Administrators role (unless you are the root user).',
]),
'delete_role_any' => new Permission([
'slug' => 'delete_role',
'name' => 'Delete role',
'conditions' => 'always()',
'description' => 'Delete a role.',
]),
'delete_role' => new Permission([
'slug' => 'delete_role',
'name' => 'Delete role',
'conditions' => "is_master(self.id) || (!has_role(self.id,role.id) && role.id != {$defaultRoleIds['site-admin']})",
'description' => 'Delete a role, except the Site Administrators role (unless you are the root user).',
]),
]
);
}
/**
* Save permissions.
*
* @param array $permissions
*/
protected function savePermissions(array &$permissions)
{
foreach ($permissions as $slug => $permission) {
// Trying to find if the permission already exist
$existingPermission = Permission::where(['slug' => $permission->slug, 'conditions' => $permission->conditions])->first();
// Don't save if already exist, use existing permission reference
// otherwise to re-sync permissions and roles
if ($existingPermission == null) {
$permission->save();
} else {
$permissions[$slug] = $existingPermission;
}
}
}
/**
* Sync permissions with default roles.
*
* @param array $permissions
*/
protected function syncPermissionsRole(array $permissions)
{
parent::syncPermissionsRole($permissions);
$roleSiteAdmin = Role::where('slug', 'site-admin')->first();
if ($roleSiteAdmin) {
$roleSiteAdmin->permissions()->syncWithoutDetaching([
$permissions['uri_dashboard']->id,
$permissions['uri_role']->id,
$permissions['uri_roles']->id,
$permissions['uri_permission']->id,
$permissions['uri_permissions']->id,
// Too much power: $permissions['create_role']->id,
$permissions['view_role_field']->id,
$permissions['update_role_field']->id,
// Too much power: $permissions['update_role_permissions']->id,
// Too much power: $permissions['update_role_permissions_limited']->id,
// Too much power: $permissions['delete_role']->id,
// Too much power: $permissions['delete_role_any']->id,
]);
}
$roleGroupAdmin = Role::where('slug', 'group-admin')->first();
if ($roleGroupAdmin) {
$roleGroupAdmin->permissions()->syncWithoutDetaching([
$permissions['uri_dashboard']->id,
]);
}
$roleUser = Role::where('slug', 'user')->first();
if ($roleUser) {
$roleUser->permissions()->detach($permissions['uri_dashboard']);
}
}
}

View File

@@ -0,0 +1,107 @@
<?php
/*
* AVSDev UF Tweaks (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
*/
namespace UserFrosting\Sprinkle\UFTweaks\ServicesProvider;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
/**
* Registers services for the UFTweaks sprinkle.
*
* @author Craig Williams (https://avsdev.uk)
*/
class ServicesProvider
{
/**
* Register UserFrosting's services.
*
* @param ContainerInterface $container A DI container implementing ArrayAccess and psr-container.
*/
public function register(ContainerInterface $container)
{
/*
* Returns a callback that handles setting the `UF-Redirect` header after a successful login.
*
* Overrides the service definition in the account Sprinkle.
*
* @return callable
*/
$container['redirect.onLogin'] = function ($c) {
/*
* This method is invoked when a user completes the login process.
*
* Returns a callback that handles setting the `UF-Redirect` header after a successful login.
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param array $args
* @return \Psr\Http\Message\ResponseInterface
*/
return function (Request $request, Response $response, array $args) use ($c) {
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $c->authorizer;
$currentUser = $c->authenticator->user();
if ($authorizer->checkAccess($currentUser, 'uri_dashboard')) {
return $response->withHeader('UF-Redirect', $c->router->pathFor('dashboard'));
} else {
return $response->withHeader('UF-Redirect', $c->router->pathFor('index'));
}
};
};
/*
* Extend the 'authorizer' service to fix some callbacks
*
* @return \UserFrosting\Sprinkle\Core\Util\ClassMapper
*/
$container->extend('authorizer', function ($authorizer, $c) {
/*
* Check if all values in the array $needle are present in the values of $haystack.
*
* @param array[mixed] $needle the array whose values we should look for in $haystack
* @param array[mixed] $haystack the array of values to search.
* @return bool true if every value in $needle is present in the values of $haystack, false otherwise.
*/
$authorizer->addCallback(
'subset',
function ($needle, $haystack) {
if (!is_countable($needle)) {
$needle = [ $needle ];
}
return count($needle) == count(array_intersect($needle, $haystack));
}
);
/*
* Check if all keys of the array $needle are present in the values of $haystack.
*
* This function is useful for whitelisting an array of key-value parameters.
* @param array[mixed] $needle the array whose keys we should look for in $haystack
* @param array[mixed] $haystack the array of values to search.
* @return bool true if every key in $needle is present in the values of $haystack, false otherwise.
*/
$authorizer->addCallback(
'subset_keys',
function ($needle, $haystack) {
if (!is_countable($needle)) {
$needle = [ $needle ];
}
return count($needle) == count(array_intersect(array_keys($needle), $haystack));
}
);
return $authorizer;
});
}
}

21
src/UFTweaks.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
/*
* AVSDev UF Tweaks (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
*/
namespace UserFrosting\Sprinkle\UFTweaks;
use UserFrosting\System\Sprinkle\Sprinkle;
/**
* Bootstrapper class for the 'UFTweaks' sprinkle.
*
* @author Craig Williams (https://avsdev.uk)
*/
class UFTweaks extends Sprinkle
{
}

View File

@@ -0,0 +1,305 @@
{% extends "@admin/pages/abstract/dashboard.html.twig" %}
{# Overrides blocks in head of base template #}
{% block page_title %}{{ translate("DASHBOARD") }}{% endblock %}
{% block page_description %}{% endblock %}
{% block body_matter %}
{% set dashboard_is_empty = true %}
<!-- Info boxes -->
<div class="row">
{% if checkAccess('uri_users') %}
{% set dashboard_is_empty = false %}
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="{{site.uri.public}}/users">
<div class="info-box">
<span class="info-box-icon bg-aqua"><i class="fas fa-user fa-fw"></i></span>
<div class="info-box-content">
<span class="info-box-text">{{ translate("USER", 2) }}</span>
<span class="info-box-number">{{counter.users}}</span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</a>
</div>
<!-- /.col -->
{% endif %}
{% if checkAccess('uri_roles') %}
{% set dashboard_is_empty = false %}
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="{{site.uri.public}}/roles">
<div class="info-box">
<span class="info-box-icon bg-red"><i class="fas fa-id-card"></i></span>
<div class="info-box-content">
<span class="info-box-text">{{ translate("ROLE", 2) }}</span>
<span class="info-box-number">{{counter.roles}}</span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</a>
</div>
<!-- /.col -->
{% endif %}
{% if checkAccess('uri_groups') %}
{% set dashboard_is_empty = false %}
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="{{site.uri.public}}/groups">
<div class="info-box">
<span class="info-box-icon bg-green"><i class="fas fa-users"></i></span>
<div class="info-box-content">
<span class="info-box-text">{{ translate("GROUP", 2) }}</span>
<span class="info-box-number">{{counter.groups}}</span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</a>
</div>
<!-- /.col -->
{% endif %}
</div>
<!-- /.row -->
<!-- Main panels -->
<div class="row">
{% if checkAccess('view_system_info') %}
{% set dashboard_is_empty = false %}
<div class="col-md-6 col-sm-12 col-xs-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">{{translate("SYSTEM_INFO")}}</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<dl class="dl-horizontal">
<dt>{{translate("SYSTEM_INFO.UF_VERSION")}}</dt>
<dd>{{info.version.UF}}</dd>
<dt>{{translate("SYSTEM_INFO.PHP_VERSION")}}</dt>
<dd>{{info.version.php}}</dd>
<dt>{{translate("SYSTEM_INFO.SERVER")}}</dt>
<dd>{{info.environment.SERVER_SOFTWARE}}</dd>
<dt>{{translate("SYSTEM_INFO.DB_VERSION")}}</dt>
<dd>{{info.version.database.type}} {{info.version.database.version}}</dd>
<dt>{{translate("SYSTEM_INFO.DB_NAME")}}</dt>
<dd>{{info.database.name}}</dd>
<dt>{{translate("SYSTEM_INFO.DIRECTORY")}}</dt>
<dd>{{info.path.project}}</dd>
<dt>{{translate("SYSTEM_INFO.URL")}}</dt>
<dd>{{site.uri.public}}</dd>
<dt>{{translate("SYSTEM_INFO.SPRINKLES")}}</dt>
<dd>
<ul class="list-unstyled">
{% for sprinkle in sprinkles %}
<li>
{{sprinkle}}
</li>
{% endfor %}
</ul>
</dd>
</dl>
</div>
<!-- /.box-body -->
<div class="box-footer text-center">
<a href="javascript:void(0)" class="js-clear-cache uppercase">{{ translate("CACHE.CLEAR") }}</a>
</div>
<!-- /.box-footer -->
</div>
<!--/.box -->
</div>
<!-- /.col -->
{% endif %}
{% if checkAccess('uri_users') %}
{% set dashboard_is_empty = false %}
<div class="col-md-6 col-sm-12 col-xs-12">
<!-- USERS LIST -->
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">{{translate("USER.LATEST")}}</h3>
</div>
<!-- /.box-header -->
<div class="box-body no-padding">
<ul class="users-list clearfix">
{% for user in users %}
<li>
<img src="{{ user.avatar }}" alt="User Image">
<a class="users-list-name" href="{{site.uri.public}}/users/u/{{user.user_name}}">{{user.first_name}} {{user.last_name}}</a>
<span class="users-list-date">{{ user.registered }}</span>
</li>
{% endfor %}
</ul>
<!-- /.users-list -->
</div>
<!-- /.box-body -->
<div class="box-footer text-center">
<a href="{{site.uri.public}}/users" class="uppercase">{{translate("USER.VIEW_ALL")}}</a>
</div>
<!-- /.box-footer -->
</div>
<!--/.box -->
</div>
<!-- /.col -->
{% endif %}
{% if checkAccess('uri_activities') %}
{% set dashboard_is_empty = false %}
<div class="col-md-6 col-sm-12 col-xs-12">
<div id="widget-activities" class="box box-primary">
<div class="box-header">
<h3 class="box-title"><i class="fas fa-tasks fa-fw"></i> {{translate('ACTIVITY', 2)}}</h3>
{% include "tables/table-tool-menu.html.twig" %}
</div>
<div class="box-body">
{% include "tables/activities.html.twig" with {
"table" : {
"id" : "table-activities",
"columns" : ["user"]
}
}
%}
</div>
</div>
</div>
{% endif %}
</div>
<!-- /.row -->
{% if current_user.group %}
<!-- Group info boxes -->
<div class="row">
{% if checkAccess('uri_group', {
'group': current_user.group
}) %}
{% set dashboard_is_empty = false %}
<div class="col-sm-6 col-xs-12">
<div class="info-box">
<span class="info-box-icon bg-aqua"><i class="{{current_user.group.icon}}"></i></span>
<div class="info-box-content">
<h1>{{current_user.group.name}}</h1>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
<div class="col-sm-6 col-xs-12">
<div class="info-box">
<span class="info-box-icon bg-aqua"><i class="fas fa-user fa-fw"></i></span>
<div class="info-box-content">
<span class="info-box-text">{{ translate("USER", 2) }}</span>
<span class="info-box-number">{{current_user.group.users.count}}</span>
</div>
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
<!-- /.col -->
{% endif %}
</div>
<!-- /.row -->
<!-- Main panels -->
<div class="row">
{% if checkAccess('view_group_field', {
'group': current_user.group,
'property': 'users'
}) %}
{% set dashboard_is_empty = false %}
<div class="col-md-offset-3 col-md-6 col-sm-12 col-xs-12">
<div id="widget-group-users" class="box box-primary">
<div class="box-header">
<h3 class="box-title"><i class="fas fa-fw fa-user"></i> {{translate('GROUP')}} {{translate('USER', 2)}}</h3>
{% include "tables/table-tool-menu.html.twig" %}
</div>
<div class="box-body">
{% include "tables/users.html.twig" with {
"table" : {
"id" : "table-group-users",
"columns" : [
(checkAccess('view_user_field', { "property" : 'activities' }) ? "last_activity" : "")
]
}
}
%}
</div>
<div class="box-footer">
<button type="button" class="btn btn-success js-user-create">
<i class="fas fa-plus-square"></i> {{translate("USER.CREATE")}}
</button>
</div>
</div>
</div>
{% endif %}
</div>
<!-- /.row -->
<!-- /User's group -->
{% endif %}
{% if dashboard_is_empty %}
<div class="row">
<div class="col-sm-4 col-sm-offset-4 col-xs-12">
<div class="box box-widget widget-user">
<!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-black-active">
<h3 class="widget-user-username">
{{translate("WELCOME", {
'first_name': current_user.first_name
})}}
</h3>
</div>
<div class="widget-user-image">
<img class="img-circle" src="{{assets.url('assets://userfrosting/images/cupcake.png')}}" alt="User Avatar">
</div>
<div class="box-footer">
<h4>
{{translate("WELCOME_TO", {
'title': site.title
})}}
</h4>
<p>
{{translate("NO_FEATURES_YET")}}
</p>
</div>
</div>
<!-- /.widget-user -->
</div>
<!-- /.column -->
</div>
<!-- /.row -->
{% endif %}
{% endblock %}
{% block scripts_page %}
<!-- Include page variables -->
<script>
{% include "pages/partials/page.js.twig" %}
// Add user name
page = $.extend(
true, // deep extend
{
"group_slug": "{{current_user.group.slug}}"
},
page
);
</script>
<!-- Include page-specific JS -->
{{ assets.js('js/pages/dashboard') | raw }}
{% endblock %}

View File

@@ -0,0 +1,80 @@
{% extends "@admin/pages/group.html.twig" %}
{% block body_matter %}
<div class="row">
<div class="col-lg-4">
<div id="view-group" class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">{{translate('GROUP.SUMMARY')}}</h3>
{% if 'tools' not in tools.hidden %}
<div class="box-tools pull-right">
<div class="btn-group">
<button type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-cog"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu box-tool-menu">
{% block tools %}
<li>
<a href="#" class="js-group-edit" data-slug="{{group.slug}}">
<i class="fas fa-edit fa-fw"></i> {{translate('EDIT')}}
</a>
</li>
{% if 'delete' not in tools.hidden %}
<li>
<a href="#" class="js-group-delete" data-slug="{{group.slug}}">
<i class="fas fa-trash-alt fa-fw"></i> {{translate('DELETE')}}
</a>
</li>
{% endif %}
{% endblock %}
</ul>
</div>
</div>
{% endif %}
</div>
<div class="box-body box-profile">
<div class="text-center">
<i class="{{group.icon}} fa-5x"></i>
</div>
<h3 class="profile-username text-center">{{group.name}}</h3>
{% if 'description' not in fields.hidden %}
<p class="text-muted">
{{group.description}}
</p>
{% endif %}
{% if 'users' not in fields.hidden %}
<hr>
<strong><i class="fas fa-users margin-r-5"></i> {{ translate('USER', 2)}}</strong>
<p class="badge bg-blue box-profile-property">
{{group.users.count}}
</p>
{% endif %}
{% block group_profile %}{% endblock %}
</div>
</div>
</div>
<div class="col-lg-8">
<div id="widget-group-users" class="box box-primary">
<div class="box-header">
<h3 class="box-title"><i class="fas fa-fw fa-user"></i> {{translate('USER', 2)}}</h3>
{% include "tables/table-tool-menu.html.twig" %}
</div>
<div class="box-body">
{% include "tables/users.html.twig" with {
"table" : {
"id" : "table-group-users"
}
}
%}
</div>
<div class="box-footer">
<button type="button" class="btn btn-success js-user-create">
<i class="fas fa-plus-square"></i> {{translate("USER.CREATE")}}
</button>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,108 @@
{% extends "@admin/pages/role.html.twig" %}
{% block body_matter %}
<div class="row">
<div class="col-lg-4">
<div id="view-role" class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">{{translate('ROLE.SUMMARY')}}</h3>
{% if 'tools' not in tools.hidden %}
<div class="box-tools pull-right">
<div class="btn-group">
<button type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-cog"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu box-tool-menu">
{% block tools %}
{% if (checkAccess('update_role_field', { fields: ['slug','name','description'] })) %}
<li>
<a href="#" class="js-role-edit" data-slug="{{role.slug}}">
<i class="fas fa-edit fa-fw"></i> {{translate('EDIT')}}
</a>
</li>
{% endif %}
{% if 'permissions' not in tools.hidden %}
{% if (checkAccess('update_role_permissions', { role: role })) %}
<li>
<a href="#" class="js-role-permissions" data-slug="{{role.slug}}">
<i class="fas fa-key"></i> {{translate("PERMISSION.MANAGE")}}
</a>
</li>
{% endif %}
{% endif %}
{% if 'delete' not in tools.hidden %}
{% if (checkAccess('delete_role')) %}
<li>
<a href="#" class="js-role-delete" data-slug="{{role.slug}}">
<i class="fas fa-trash-alt fa-fw"></i> {{translate('DELETE')}}
</a>
</li>
{% endif %}
{% endif %}
{% endblock %}
</ul>
</div>
</div>
{% endif %}
</div>
<div class="box-body box-profile">
<div class="text-center">
<i class="fas fa-id-card fa-5x"></i>
</div>
<h3 class="profile-username text-center">{{role.name}}</h3>
{% if 'description' not in fields.hidden %}
<p class="text-muted">
{{role.description}}
</p>
{% endif %}
{% if 'users' not in fields.hidden %}
<hr>
<strong><i class="fas fa-users margin-r-5"></i> {{ translate('USER', 2)}}</strong>
<p class="badge bg-blue box-profile-property">
{{role.users.count}}
</p>
{% endif %}
</div>
</div>
</div>
<div class="col-lg-8">
{% if (checkAccess('view_role_field', { property: 'permissions' })) %}
<div id="widget-role-permissions" class="box box-primary">
<div class="box-header">
<h3 class="box-title"><i class="fas fa-fw fa-key"></i> {{translate('PERMISSION', 2)}}</h3>
{% include "tables/table-tool-menu.html.twig" %}
</div>
<div class="box-body">
{% include "tables/permissions.html.twig" with {
"table" : {
"id" : "table-role-permissions"
}
}
%}
</div>
</div>
{% endif %}
</div>
<div class="col-lg-12">
{% if (checkAccess('view_role_field', { property: 'users' })) %}
<div id="widget-role-users" class="box box-primary">
<div class="box-header">
<h3 class="box-title"><i class="fas fa-fw fa-key"></i> {{translate('USER', 2)}}</h3>
{% include "tables/table-tool-menu.html.twig" %}
</div>
<div class="box-body">
{% include "tables/users.html.twig" with {
"table" : {
"id" : "table-role-users",
"columns" : ["last_activity"]
}
}
%}
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,29 @@
{% extends "@admin/pages/roles.html.twig" %}
{% block body_matter %}
<div class="row">
<div class="col-md-12">
<div id="widget-roles" class="box box-primary">
<div class="box-header">
<h3 class="box-title"><i class="fas fa-fw fa-id-card"></i> {{translate('ROLE', 2)}}</h3>
{% include "tables/table-tool-menu.html.twig" %}
</div>
<div class="panel-body">
{% include "tables/roles.html.twig" with {
"table" : {
"id" : "table-roles"
}
}
%}
</div>
<div class="box-footer">
{% if (checkAccess('create_role')) %}
<button type="button" class="btn btn-success js-role-create">
<i class="fas fa-plus-square"></i> {{translate("ROLE.CREATE")}}
</button>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,32 @@
{% extends "@admin/pages/users.html.twig" %}
{% block body_matter %}
<div class="row">
<div class="col-md-12">
<div id="widget-users" class="box box-primary">
<div class="box-header">
<h3 class="box-title pull-left"><i class="fas fa-fw fa-user"></i> {{translate('USER', 2)}}</h3>
{% include "tables/table-tool-menu.html.twig" %}
</div>
<div class="box-body">
{% include "tables/users.html.twig" with {
"table" : {
"id" : "table-users",
"columns" : [
(checkAccess('view_user_field', { "property" : 'activities' }) ? "last_activity" : "")
]
}
}
%}
</div>
{% if checkAccess('create_user') %}
<div class="box-footer">
<button type="button" class="btn btn-success js-user-create">
<i class="fas fa-plus-square"></i> {{ translate("USER.CREATE")}}
</button>
</div>
{% endif %}
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,80 @@
{# This partial template renders a table of roles, to be populated with rows via an AJAX request.
# This extends a generic template for paginated tables.
#
# Note that this template contains a "skeleton" table with an empty table body, and then a block of Handlebars templates which are used
# to render the table cells with the data from the AJAX request.
#}
{% extends "tables/table-paginated.html.twig" %}
{% block table %}
<table id="{{table.id}}" class="tablesorter table table-bordered table-hover table-striped" data-sortlist="{{table.sortlist}}">
<thead>
<tr>
<th class="sorter-metatext" data-column-name="name" data-column-template="#role-table-column-info" data-priority="1">{{translate('ROLE')}} <i class="fas fa-sort"></i></th>
<th class="sorter-metatext" data-column-name="description" data-column-template="#role-table-column-description" data-priority="2">{{translate('DESCRIPTION')}} <i class="fas fa-sort"></i></th>
<th data-column-template="#role-table-column-actions" data-sorter="false" data-filter="false" data-priority="1">{{translate('ACTIONS')}}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
{% endblock %}
{% block table_cell_templates %}
{# This contains a series of <script> blocks, each of which is a client-side Handlebars template.
# Note that these are NOT Twig templates, although the syntax is similar. We wrap them in the `verbatim` tag,
# so that Twig will output them directly into the DOM instead of trying to treat them like Twig templates.
#
# These templates require handlebars-helpers.js, moment.js
#}
{% verbatim %}
<script id="role-table-column-info" type="text/x-handlebars-template">
<td data-text="{{row.name}}">
<strong>
<a href="{{site.uri.public}}/roles/r/{{row.slug}}">{{row.name}}</a>
</strong>
</td>
</script>
<script id="role-table-column-description" type="text/x-handlebars-template">
<td>
{{row.description}}
</td>
</script>
<script id="role-table-column-actions" type="text/x-handlebars-template">
<td>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
{% endverbatim %}{{translate("ACTIONS")}}{% verbatim %}
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
{% endverbatim %}{% if (checkAccess('update_role_permissions')) %}{% verbatim %}
<li>
<a href="#" data-slug="{{row.slug}}" class="js-role-permissions">
<i class="fas fa-key"></i> {% endverbatim %}{{translate("PERMISSION.MANAGE")}}{% verbatim %}
</a>
</li>
{% endverbatim %}{% endif %}{% verbatim %}
<li>
<a href="#" data-slug="{{row.slug}}" class="js-role-edit">
<i class="fas fa-edit"></i> {% endverbatim %}{{translate("ROLE.EDIT")}}{% verbatim %}
</a>
</li>
{% endverbatim %}{% if (checkAccess('delete_role')) %}{% verbatim %}
<li>
<a href="#" data-slug="{{row.slug}}" class="js-role-delete">
<i class="fas fa-trash-alt"></i> {% endverbatim %}{{translate("ROLE.DELETE")}}{% verbatim %}
</a>
</li>
{% endverbatim %}{% endif %}{% verbatim %}
</ul>
</div>
</td>
</script>
{% endverbatim %}
{% endblock %}

View File

@@ -0,0 +1,156 @@
{# This partial template renders a table of users, to be populated with rows via an AJAX request.
# This extends a generic template for paginated tables.
#
# Note that this template contains a "skeleton" table with an empty table body, and then a block of Handlebars templates which are used
# to render the table cells with the data from the AJAX request.
#}
{% extends "tables/table-paginated.html.twig" %}
{% block table %}
<table id="{{table.id}}" class="tablesorter table table-bordered table-hover table-striped" data-sortlist="{{table.sortlist}}">
<thead>
<tr>
<th class="sorter-metatext" data-column-name="name" data-column-template="#user-table-column-info" data-priority="1">{{translate('USER')}} <i class="fas fa-sort"></i></th>
{% if 'last_activity' in table.columns %}
<th class="sorter-metanum" data-column-name="last_activity" data-column-template="#user-table-column-last-activity" data-priority="3">{{translate("ACTIVITY.LAST")}} <i class="fas fa-sort"></i></th>
{% endif %}
{% if 'via_roles' in table.columns %}
<th data-column-template="#user-table-column-via-roles" data-sorter="false" data-filter="false" data-priority="1">{{translate('PERMISSION.VIA_ROLES')}}</th>
{% endif %}
<th class="filter-select filter-metatext" data-column-name="status" data-column-template="#user-table-column-status" data-priority="2">{{translate("STATUS")}} <i class="fas fa-sort"></i></th>
<th data-column-name="actions" data-column-template="#user-table-column-actions" data-sorter="false" data-filter="false" data-priority="1">{{translate("ACTIONS")}}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
{% endblock %}
{% block table_cell_templates %}
{# This contains a series of <script> blocks, each of which is a client-side Handlebars template.
# Note that these are NOT Twig templates, although the syntax is similar. We wrap them in the `verbatim` tag,
# so that Twig will output them directly into the DOM instead of trying to treat them like Twig templates.
#
# These templates require handlebars-helpers.js, moment.js
#}
{% verbatim %}
<script id="user-table-column-info" type="text/x-handlebars-template">
<td data-text="{{row.last_name}}">
<strong>
<a href="{{site.uri.public}}/users/u/{{row.user_name}}">{{row.first_name}} {{row.last_name}} ({{row.user_name}})</a>
</strong>
<div class="js-copy-container">
<span class="js-copy-target">{{row.email}}</span>
<button class="btn btn-xs uf-copy-trigger js-copy-trigger"><i class="fas fa-copy"></i></button>
</div>
</td>
</script>
<script id="user-table-column-last-activity" type="text/x-handlebars-template">
{{#if row.last_activity }}
<td data-num="{{dateFormat row.last_activity.occurred_at format='x'}}">
{{dateFormat row.last_activity.occurred_at format="dddd"}}<br>{{dateFormat row.last_activity.occurred_at format="MMM Do, YYYY h:mm a"}}
<br>
<i>{{row.last_activity.description}}</i>
</td>
{{ else }}
<td data-num="0">
<i>{% endverbatim %}{{translate("UNKNOWN")}}{% verbatim %}</i>
</td>
{{/if }}
</script>
<script id="user-table-column-status" type="text/x-handlebars-template">
<td
{{#ifx row.flag_enabled '==' 0 }}
data-text="disabled"
{{ else }}
{{#ifx row.flag_verified '==' 0 }}
data-text="unactivated"
{{ else }}
data-text="active"
{{/ifx }}
{{/ifx }}
>
{{#ifx row.flag_enabled '==' 0 }}
<span class="text-muted">
{% endverbatim %}{{translate("DISABLED")}}{% verbatim %}
</span>
{{ else }}
{{#ifx row.flag_verified '==' 0 }}
<span class="text-yellow">
{% endverbatim %}{{translate("UNACTIVATED")}}{% verbatim %}
</span>
{{ else }}
<span>
{% endverbatim %}{{translate("ACTIVE")}}{% verbatim %}
</span>
{{/ifx }}
{{/ifx }}
</td>
</script>
<script id="user-table-column-actions" type="text/x-handlebars-template">
<td class="uf-table-fit-width">
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">{% endverbatim %}{{translate("ACTIONS")}}{% verbatim %}<span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right-responsive" role="menu">
{{#ifx row.flag_verified '==' 0 }}
<li>
<a href="#" data-user_name="{{row.user_name}}" class="js-user-activate">
<i class="fas fa-bolt"></i> {% endverbatim %}{{translate("USER.ACTIVATE")}}{% verbatim %}
</a>
</li>
{{/ifx }}
<li>
<a href="#" data-user_name="{{row.user_name}}" class="js-user-edit">
<i class="fas fa-edit"></i> {% endverbatim %}{{translate("USER.EDIT")}}{% verbatim %}
</a>
</li>
{% endverbatim %}{% if checkAccess('uri_roles') %}{% verbatim %}
<li>
<a href="#" data-user_name="{{row.user_name}}" class="js-user-roles">
<i class="fas fa-id-card"></i> {% endverbatim %}{{translate("ROLE.MANAGE")}}{% verbatim %}
</a>
</li>
{% endverbatim %}{% endif %}{% verbatim %}
<li>
<a href="#" data-user_name="{{row.user_name}}" class="js-user-password">
<i class="fas fa-key"></i> {% endverbatim %}{{translate("USER.ADMIN.CHANGE_PASSWORD")}}{% verbatim %}
</a>
</li>
<li>
{{#ifx row.flag_enabled '==' 1 }}
<a href="#" data-user_name="{{row.user_name}}" class="js-user-disable">
<i class="fas fa-minus-circle"></i> {% endverbatim %}{{translate("USER.DISABLE")}}{% verbatim %}
</a>
{{ else }}
<a href="#" data-user_name="{{row.user_name}}" class="js-user-enable">
<i class="fas fa-plus-circle"></i> {% endverbatim %}{{translate("USER.ENABLE")}}{% verbatim %}
</a>
{{/ifx }}
</li>
<li>
<a href="#" data-user_name="{{row.user_name}}" class="js-user-delete">
<i class="fas fa-trash-alt"></i> {% endverbatim %}{{translate("USER.DELETE")}}{% verbatim %}
</a>
</li>
</ul>
</div>
</td>
</script>
<script id="user-table-column-via-roles" type="text/x-handlebars-template">
<td>
{{#each row.roles_via }}
<a href="{% endverbatim %}{# Handlebars can't access variables in the global scope, so we have to use Twig to insert the base url #}{{site.uri.public}}{% verbatim %}/roles/r/{{this.slug}}" class="label label-primary" title="{{this.description}}">{{this.name}}</a>
{{/each}}
</td>
</script>
{% endverbatim %}
{% endblock %}