Skip to content

Commit 03e29c3

Browse files
committed
first commit
0 parents  commit 03e29c3

File tree

164 files changed

+18553
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+18553
-0
lines changed

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
15+
[*.{yml,yaml}]
16+
indent_size = 2
17+
18+
[docker-compose.yml]
19+
indent_size = 4

.env.example

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
APP_NAME=ACL
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_TIMEZONE=America/Sao_Paulo
6+
APP_URL=http://localhost
7+
8+
APP_LOCALE=pt-br
9+
APP_FALLBACK_LOCALE=pt-br
10+
APP_FAKER_LOCALE=pt_BR
11+
12+
APP_MAINTENANCE_DRIVER=file
13+
APP_MAINTENANCE_STORE=database
14+
15+
BCRYPT_ROUNDS=12
16+
17+
LOG_CHANNEL=stack
18+
LOG_STACK=single
19+
LOG_DEPRECATIONS_CHANNEL=null
20+
LOG_LEVEL=debug
21+
22+
DB_CONNECTION=mysql
23+
DB_HOST=127.0.0.1
24+
DB_PORT=3306
25+
DB_DATABASE=aclbasic
26+
DB_USERNAME=root
27+
DB_PASSWORD=
28+
29+
SESSION_DRIVER=database
30+
SESSION_LIFETIME=120
31+
SESSION_ENCRYPT=false
32+
SESSION_PATH=/
33+
SESSION_DOMAIN=null
34+
35+
BROADCAST_CONNECTION=log
36+
FILESYSTEM_DISK=local
37+
QUEUE_CONNECTION=database
38+
39+
CACHE_STORE=database
40+
CACHE_PREFIX=
41+
42+
MEMCACHED_HOST=127.0.0.1
43+
44+
REDIS_CLIENT=phpredis
45+
REDIS_HOST=127.0.0.1
46+
REDIS_PASSWORD=null
47+
REDIS_PORT=6379
48+
49+
MAIL_MAILER=log
50+
MAIL_HOST=127.0.0.1
51+
MAIL_PORT=2525
52+
MAIL_USERNAME=null
53+
MAIL_PASSWORD=null
54+
MAIL_ENCRYPTION=null
55+
MAIL_FROM_ADDRESS="[email protected]"
56+
MAIL_FROM_NAME="${APP_NAME}"
57+
58+
AWS_ACCESS_KEY_ID=
59+
AWS_SECRET_ACCESS_KEY=
60+
AWS_DEFAULT_REGION=us-east-1
61+
AWS_BUCKET=
62+
AWS_USE_PATH_STYLE_ENDPOINT=false
63+
64+
VITE_APP_NAME="${APP_NAME}"

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto eol=lf
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.github export-ignore
10+
CHANGELOG.md export-ignore
11+
.styleci.yml export-ignore

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/.phpunit.cache
2+
/node_modules
3+
/public/build
4+
/public/hot
5+
/public/storage
6+
/storage/*.key
7+
/vendor
8+
.env
9+
.env.backup
10+
.env.production
11+
.phpunit.result.cache
12+
Homestead.json
13+
Homestead.yaml
14+
auth.json
15+
npm-debug.log
16+
yarn-error.log
17+
/.fleet
18+
/.idea
19+
/.vscode

README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
ACL Basic
2+
3+
Description
4+
This is a web application built using the Laravel framework and Livewire component. The application manages users, roles, and abilities, allowing certain users to access different parts of the system based on their abilities associated with their roles. Additionally, roles have a hierarchy, ensuring that users with lower hierarchy cannot alter data of users with higher hierarchy.
5+
6+
Technologies Used
7+
PHP
8+
Laravel
9+
Livewire
10+
Database (MySQL, PostgreSQL, etc.)
11+
Key Features
12+
User Management: User registration, editing, deletion, and viewing.
13+
Role Management: Definition of roles with hierarchy, assignment of abilities to roles.
14+
Access Control Based on Abilities: Access to specific parts of the system based on abilities associated with user roles.
15+
Role Hierarchy: Access restriction for users with lower hierarchy in relation to users with higher hierarchy.
16+
17+
Installation Requirements
18+
1. Clone the repository.
19+
20+
2. Install dependencies using Composer, Node:
21+
-- composer install
22+
-- npm run build
23+
24+
3. Configure the .env file with the database information.
25+
4. Run database migrations to create the necessary tables:
26+
-- php artisan migrate
27+
28+
5. Start the local server:
29+
-- php artisan serve
30+
31+
6. Access the application in the browser using the address provided by the local server.
32+
33+
Contributing
34+
Contributions are welcome! Feel free to open an issue to report bugs, suggest improvements, or to submit a pull request.
35+
36+
37+
Descrição
38+
Esta é uma aplicação web construída utilizando o framework Laravel e o componente Livewire. A aplicação gerencia usuários, roles e habilidades, permitindo que determinados usuários tenham acesso a diferentes partes do sistema com base em suas habilidades associadas às suas roles. Além disso, as roles possuem uma hierarquia, garantindo que usuários com uma hierarquia inferior não possam alterar dados de usuários com hierarquia superior.
39+
40+
Tecnologias Utilizadas
41+
PHP
42+
Laravel
43+
Livewire
44+
Banco de Dados (MySQL, PostgreSQL, etc.)
45+
Funcionalidades Principais
46+
Gerenciamento de Usuários: Cadastro, edição, exclusão e visualização de usuários.
47+
Gerenciamento de Roles: Definição de roles com hierarquia, atribuição de habilidades às roles.
48+
Controle de Acesso Baseado em Habilidades: Acesso a partes específicas do sistema com base nas habilidades associadas às roles do usuário.
49+
Hierarquia de Roles: Restrição de acesso para usuários com hierarquia inferior em relação a usuários com hierarquia superior.
50+
Requisitos de Instalação
51+
1. Clone o repositório.
52+
2. Instale as dependências usando Composer, NPM:
53+
-- composer install
54+
-- npm run dev
55+
56+
3. Configure o arquivo .env com as informações do banco de dados.
57+
4. Execute as migrações do banco de dados para criar as tabelas necessárias:
58+
59+
-- php artisan migrate
60+
61+
5. Inicie o servidor local:
62+
63+
-- php artisan serve
64+
65+
6. Acesse a aplicação no navegador usando o endereço fornecido pelo servidor local.
66+
67+
Contribuindo
68+
69+
Contribuições são bem-vindas! Sinta-se à vontade para abrir uma issue para relatar bugs, sugestões de melhorias ou para enviar um pull request.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Auth\Events\Verified;
7+
use Illuminate\Foundation\Auth\EmailVerificationRequest;
8+
use Illuminate\Http\RedirectResponse;
9+
10+
class VerifyEmailController extends Controller
11+
{
12+
/**
13+
* Mark the authenticated user's email address as verified.
14+
*/
15+
public function __invoke(EmailVerificationRequest $request): RedirectResponse
16+
{
17+
if ($request->user()->hasVerifiedEmail()) {
18+
return redirect()->intended(route('dashboard', absolute: false) . '?verified=1');
19+
}
20+
21+
if ($request->user()->markEmailAsVerified()) {
22+
event(new Verified($request->user()));
23+
}
24+
25+
return redirect()->intended(route('dashboard', absolute: false) . '?verified=1');
26+
}
27+
}

app/Http/Controllers/Controller.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
abstract class Controller
6+
{
7+
//
8+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use App\Models\Role;
6+
use Closure;
7+
use Illuminate\Http\Request;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
class CheckRoleHierarchy
11+
{
12+
/**
13+
* Handle an incoming request.
14+
*
15+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
16+
*/
17+
public function handle(Request $request, Closure $next): Response
18+
{
19+
if ($request->user()->roles()->pluck('hierarchy')->max() <= Role::find($request->route('id'))->hierarchy) {
20+
return $next($request);
21+
} else {
22+
abort(403);
23+
}
24+
}
25+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
9+
class CheckUserHierarchy
10+
{
11+
/**
12+
* Handle an incoming request.
13+
*
14+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
15+
*/
16+
public function handle(Request $request, Closure $next): Response
17+
{
18+
if ($request->user()->hierarchy($request->route('id'))) { /** @phpstan-ignore-line */
19+
return $next($request);
20+
} else {
21+
abort(403);
22+
}
23+
}
24+
}

app/Livewire/Ability/AbilityRole.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Livewire\Ability;
4+
5+
use App\Models\{Ability, Role};
6+
use Illuminate\Contracts\View\View;
7+
use Livewire\Component;
8+
9+
class AbilityRole extends Component
10+
{
11+
public ?Role $role;
12+
13+
public Object $abilities;
14+
15+
public function mount(int $id): void
16+
{
17+
$this->role = Role::find($id);
18+
$this->abilities = Ability::all();
19+
}
20+
21+
public function render(): View
22+
{
23+
return view('livewire.ability.ability-role');
24+
}
25+
26+
public function toggleAbility(int $abilityId): void
27+
{
28+
$this->role->abilities()->toggle($abilityId);
29+
}
30+
31+
public function goBack(): void
32+
{
33+
$this->redirectRoute('roles');
34+
}
35+
}

app/Livewire/Actions/Logout.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Livewire\Actions;
4+
5+
use Illuminate\Support\Facades\{Auth, Session};
6+
7+
class Logout
8+
{
9+
/**
10+
* Log the current user out of the application.
11+
*/
12+
public function __invoke(): void
13+
{
14+
Auth::guard('web')->logout();
15+
16+
Session::invalidate();
17+
Session::regenerateToken();
18+
}
19+
}

app/Livewire/Dashboard.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Livewire;
4+
5+
use Illuminate\Contracts\View\View;
6+
use Livewire\Component;
7+
8+
class Dashboard extends Component
9+
{
10+
public function render(): View
11+
{
12+
return view('livewire.dashboard');
13+
}
14+
}

0 commit comments

Comments
 (0)