Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit cb169c0

Browse files
committed
wip
Signed-off-by: Dieter Coopman <dieter@deltasolutions.be>
1 parent a1f5441 commit cb169c0

37 files changed

+1310
-2
lines changed

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
1-
# enforce
2-
A toolset to kickstart your application on top of Laravel Jetstream and Spatie Permissions.
1+
# TODO
2+
3+
* put the navigation part in code via package
4+
5+
## Installation of ui package
6+
7+
### Clone this repo somewhere on your computer
8+
9+
for example in /Users/your-user/packages
10+
11+
### Installing package
12+
13+
add this to composer.json ( change folder with location of cloned repo )
14+
15+
```json
16+
17+
"repositories": [
18+
{
19+
"type": "path",
20+
"url": "/Users/your-user/packages/laravel-permissions-ui"
21+
}
22+
],
23+
24+
```
25+
26+
### Require package with
27+
28+
```shell
29+
composer require deltasolutions-kifed/laravel-permission-ui
30+
```
31+
32+
### Publish installation file
33+
34+
```shell
35+
php artisan vendor:publish --tag=LLoadoutEnforce-installer
36+
```
37+
38+
### Run installation file
39+
40+
```shell
41+
bash install.sh
42+
```
43+
44+
### Add navigation
45+
46+
add this to 'navigation-menu.blade.php'
47+
```php
48+
49+
<div class="hidden sm:flex sm:items-center sm:ml-6">
50+
<div class="ml-3 relative text-sm">
51+
<x-jet-dropdown align="right" width="60">
52+
<x-slot name="trigger">
53+
{{ __('User management') }}
54+
</x-slot>
55+
<x-slot name="content">
56+
<div class="w-60">
57+
<x-jet-dropdown-link href="{{ route('users.index') }}">
58+
{{ __('Manage users') }}
59+
</x-jet-dropdown-link>
60+
<x-jet-dropdown-link href="{{ route('users.roles') }}">
61+
{{ __('Manage roles') }}
62+
</x-jet-dropdown-link>
63+
<x-jet-dropdown-link href="{{ route('users.permissions') }}">
64+
{{ __('Manage permissions') }}
65+
</x-jet-dropdown-link>
66+
</div>
67+
</x-slot>
68+
</x-jet-dropdown>
69+
</div>
70+
</div>
71+
72+
```
73+
74+
### Permissions
75+
76+
if you manually create extra permissions in database than you need to run following code
77+
78+
```shell
79+
php artisan permission:cache-reset
80+
```

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "lloadout/enforce",
3+
"description": "A toolset to kickstart your application on top of Laravel Jetstream and Spatie Permissions.",
4+
"type": "library",
5+
"authors": [
6+
{
7+
"name": "Dieter Coopman",
8+
"email": "dieter@deltasolutions.be"
9+
}
10+
],
11+
"require": {
12+
"php": "^7.4|^8.0",
13+
"livewire/livewire": "^2.0",
14+
"mediconesystems/livewire-datatables": "dev-master",
15+
"spatie/laravel-package-tools": "^1.1",
16+
"spatie/laravel-permission": "^4.0",
17+
"laravel/jetstream": "^2.2"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"LLoadoutEnforce\\": "src",
22+
"LLoadoutEnforce\\tests\\": "tests",
23+
"LLoadoutEnforce\\Database\\Seeds\\": "database/seeds/"
24+
}
25+
},
26+
"extra": {
27+
"laravel": {
28+
"providers": [
29+
"LLoadoutEnforce\\LLoadoutEnforceServiceProvider"
30+
]
31+
}
32+
},
33+
"config": {
34+
"sort-packages": true
35+
},
36+
"require-dev": {
37+
"phpunit/phpunit": "^9.5"
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use Illuminate\Database\Seeder;
6+
use Illuminate\Support\Facades\DB;
7+
8+
class PermissionSeeder extends Seeder
9+
{
10+
/**
11+
* Run the database seeds.
12+
*
13+
* @return void
14+
*/
15+
public function run()
16+
{
17+
DB::table('permissions')->delete();
18+
DB::table('model_has_permissions')->delete();
19+
DB::table('role_has_permissions')->delete();
20+
DB::table('roles')->delete();
21+
22+
collect(['superuser', 'admin', 'user'])->each(function ($name) {
23+
DB::table('roles')->insert([
24+
'name' => $name,
25+
'guard_name' => 'web'
26+
]);
27+
});
28+
29+
collect(["customers", "suppliers", "products", "news"])->each(function ($section) {
30+
collect(['create', 'read', 'update', 'delete'])->each(function ($permission) use ($section) {
31+
DB::table('permissions')->insert([
32+
'name' => $section . "." . $permission,
33+
'guard_name' => 'web'
34+
]);
35+
});
36+
});
37+
}
38+
}

phpunit.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<x-slot name="header">
2+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
3+
{{ __('Access') }}
4+
</h2>
5+
</x-slot>
6+
7+
<div class="py-12">
8+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
9+
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
10+
<div class="container mx-auto">
11+
<div class="grid grid-cols-3 rounded-md ">
12+
<div>
13+
<!-- This example requires Tailwind CSS v2.0+ -->
14+
<nav aria-label="Sidebar">
15+
@foreach($roles as $role)
16+
<a href="#" wire:click="forRole({{ $role->id }})" class="@if(optional($this->selectedRole)->id === $role->id) bg-gray-100 @endif py-4 m-4 text-gray-600 hover:bg-gray-50 hover:text-gray-900 flex items-center px-3 py-2 text-sm font-medium rounded-md">
17+
<span class="truncate">{{ $role->name }}</span>
18+
</a>
19+
@endforeach
20+
</nav>
21+
22+
</div>
23+
<div>
24+
@if($selectedRole)
25+
<nav wire:key="{{ $selectedRole->id }}" aria-label="Sidebar">
26+
@foreach($permissionGroups as $name => $permissionGroup)
27+
<a href="#" wire:key="{{ $name }}" wire:click="withGroup('{{ $name }}')" class="@if($this->selectedGroup === $name) bg-gray-100 @endif py-4 m-4 text-gray-600 hover:bg-gray-50 hover:text-gray-900 flex items-center px-3 py-2 text-sm font-medium rounded-md">
28+
<span class="truncate">{{ $name }}</span>
29+
</a>
30+
@endforeach
31+
</nav>
32+
@endif
33+
</div>
34+
<div>
35+
@if($selectedGroup)
36+
@if($access)
37+
<label class=" items-center mx-4 bg-gray-300 flex items-center px-3 py-2 my-2 text-sm font-medium rounded-md">
38+
<input type="checkbox" class="form-checkbox" wire:click="assignAll()">
39+
<span class="ml-2">{{ __('Select all') }}</span>
40+
</label>
41+
@endif
42+
43+
@include('LLoadoutEnforce-views::access-ui.permission')
44+
45+
@endif
46+
</div>
47+
</div>
48+
</div>
49+
</div>
50+
</div>
51+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@foreach($access as $permission => $permissionId)
2+
@if(is_array($permissionId))
3+
<div class=" items-center mx-4 bg-gray-300 flex items-center px-3 py-2 my-2 text-sm font-medium rounded-md">{{ $permission }}</div>
4+
@include('LLoadoutEnforce-views::access-ui.permission', ["access" => $permissionId])
5+
@else
6+
7+
<label class=" items-center mx-4 bg-gray-100 flex items-center px-3 py-2 my-2 text-sm font-medium rounded-md">
8+
<input type="checkbox" class="form-checkbox" {{ $selectedRole->hasPermissionTo($permissionId) ? 'checked' : '' }} wire:click="assign({{ $permissionId }})">
9+
<span class="ml-2">{{ $permission }}</span>
10+
</label>
11+
12+
@endif
13+
@endforeach
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<div>
2+
<x-slot name="header">
3+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
4+
@if(!$menu->id) {{ __('New') }} @endif
5+
{{ __('Menu') }}
6+
@if($menu->id): {{ $menu->name }} @endif
7+
8+
</h2>
9+
</x-slot>
10+
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
11+
<x-jet-form-section submit="updatePermission">
12+
<x-slot name="title">
13+
{{ __('Menu') }}
14+
</x-slot>
15+
16+
<x-slot name="description">
17+
{{ __('You can group menus by dottet notation') }}
18+
19+
</x-slot>
20+
21+
<x-slot name="form">
22+
<div class="col-span-6 sm:col-span-4">
23+
<x-jet-label for="name" value="{{ __('Menu name') }}"/>
24+
<x-jet-input id="name" type="text" class="mt-1 block w-full" wire:model.debounce.250ms="menu.name" autocomplete="name"/>
25+
<x-jet-input-error for="permission.name" class="mt-2"/>
26+
</div>
27+
<div class="col-span-6 sm:col-span-4">
28+
<x-jet-label for="name" value="{{ __('Menu parent') }}"/>
29+
<select wire:model.defer="menu.parent_id" id="parent_id" name="parent_id" autocomplete="activity_id" class="mt-1 block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm">
30+
<option value="0">{{ __('Choose') }}</option>
31+
@foreach($parents as $id => $name)
32+
<option value="{{ $id }}">{{ $name }}</option>
33+
@endforeach
34+
</select>
35+
<x-jet-input-error for="permission.parent" class="mt-2"/>
36+
</div>
37+
<div class="col-span-6 sm:col-span-4">
38+
<x-jet-label for="route" value="{{ __('Menu links to route ( empty for no link )') }}"/>
39+
<x-jet-input id="route" type="text" class="mt-1 block w-full" wire:model.defer="menu.route" autocomplete="route"/>
40+
<x-jet-input-error for="menu.route" class="mt-2"/>
41+
</div>
42+
</x-slot>
43+
</x-jet-form-section>
44+
<x-jet-section-border/>
45+
46+
<x-jet-form-section submit="updatePermission">
47+
48+
<x-slot name="title">
49+
{{ __('Perks') }}
50+
</x-slot>
51+
52+
<x-slot name="description">
53+
{{ __('Perks are additional features ') }}
54+
</x-slot>
55+
<x-slot name="form">
56+
<div class="col-span-6 sm:col-span-4">
57+
<x-jet-label for="permission" value="{{ __('Permission') }}"/>
58+
<x-jet-input id="permission" type="text" class="mt-1 block w-full" wire:model.debounce.250ms="menu.permission" autocomplete="route"/>
59+
</div>
60+
<div class="col-span-6 sm:col-span-4">
61+
<x-jet-label for="icon" value="{{ __('Menu icon') }}" />
62+
<x-jet-input id="icon" type="text" class="mt-1 block w-full" wire:model.defer="menu.icon" autocomplete="icon"/>
63+
<x-jet-input-error for="menu.icon" class="mt-2"/>
64+
</div>
65+
</x-slot>
66+
<x-slot name="actions">
67+
<x-jet-action-message class="mr-3" on="saved">
68+
{{ __('Saved.') }}
69+
</x-jet-action-message>
70+
71+
<x-jet-button wire:loading.attr="disabled">
72+
{{ __('Save') }}
73+
</x-jet-button>
74+
</x-slot>
75+
</x-jet-form-section>
76+
</div>
77+
78+
</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<x-slot name="header">
2+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
3+
{{ __('Menus') }}
4+
</h2>
5+
</x-slot>
6+
7+
<div class="py-12">
8+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
9+
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
10+
<livewire:menus-table/>
11+
</div>
12+
</div>
13+
</div>
14+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="w-60">
2+
@foreach($menu->menu as $__menu)
3+
<x-jet-dropdown-link href="{{ route('users.index') }}">
4+
{{ $__menu->name }}
5+
</x-jet-dropdown-link>
6+
@if ($__menu->menu->count())
7+
<div class="absolute z-50 mt-2">
8+
@include('LLoadoutEnforce-views::menu-ui.navigation-item', array('menu' => $__menu))
9+
</div>
10+
@endif
11+
@endforeach
12+
</div>

0 commit comments

Comments
 (0)