Skip to content

Commit

Permalink
build(core): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbmaulana committed Nov 14, 2023
0 parents commit b093f6a
Show file tree
Hide file tree
Showing 54 changed files with 3,056 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Laravel.php ACL

on: push

jobs:
cd:
runs-on: ubuntu-latest
steps:
- name: cd
uses: tripteki/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
repotoken: ${{ secrets.REPOSITORY_TOKEN }}
repouser: tripteki
repository: https://packagist.org
language: php
artifact: composer.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Trip Teknologi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<h1 align="center">ACL</h1>

This package provides implementation of Access Control List (ACL) Roles-Permissions in repository pattern for Lumen and Laravel besides REST API starterpack of admin management with no intervention to codebase and keep clean.

Getting Started
---

Installation :

```
$ composer require tripteki/laravelphp-acl
```

How to use it :

- Read detail optional instruction here [Lumen](https://spatie.be/docs/laravel-permission/installation-lumen) or [Laravel](https://spatie.be/docs/laravel-permission/installation-laravel).

- Put to any of your model ruleable.

```php

/**
* @return array<string, string>
*/
protected $dispatchesEvents = [

"created" => \Tripteki\ACL\Events\Created::class,
"deleted" => \Tripteki\ACL\Events\Deleted::class,
"restored" => \Tripteki\ACL\Events\Created::class,
"forceDeleted" => \Tripteki\ACL\Events\Deleted::class,
];
```

- Put `Tripteki\ACL\Providers\ACLServiceProvider` to service provider configuration list.

- Put `Tripteki\ACL\Providers\ACLServiceProvider::ignoreConfig()` into `register` provider, then publish config file into your project's directory with running :

```
php artisan vendor:publish --tag=tripteki-laravelphp-acl
```

- Put `Tripteki\ACL\Providers\ACLServiceProvider::ignoreMigrations()` into `register` provider, then publish migrations file into your project's directory with running (optionally) :

```
php artisan vendor:publish --tag=tripteki-laravelphp-acl-migrations
```

- Migrate.

```
$ php artisan migrate
```

- Emit Event-Listener.

```
php artisan queue:work
```

- Publish tests file into your project's directory with running (optionally) :

```
php artisan vendor:publish --tag=tripteki-laravelphp-acl-tests
```

- Sample :

```php
use Tripteki\ACL\Contracts\Repository\Admin\IACLRoleRepository;
use Tripteki\ACL\Contracts\Repository\Admin\IACLPermissionRepository;
use Tripteki\ACL\Contracts\Repository\IACLRepository;

$roleRepository = app(IACLRoleRepository::class);
$permissionRepository = app(IACLPermissionRepository::class);

/*
* As `{resource}`.`{action}`.`{target}` is representing :
*
* - {resource} : 'posts' = 'posts.*' = 'posts.*.*'
* - {action} : 'viewAny', 'view', 'create', 'update', 'delete'
* - {target} : '[identifier]'
*/

// $permissionRepository->rule("posts.update.*"); //
// $permissionRepository->unrule("posts.update.*"); //
// $permissionRepository->get("posts.update.*"); //
// $permissionRepository->all(); //

// $roleRepository->rule("admin"); //
// $roleRepository->rule("user"); //
// $roleRepository->unrule("admin"); //
// $roleRepository->unrule("user"); //
// $roleRepository->get("admin"); //
// $roleRepository->get("user"); //
// $roleRepository->all(); //

// $roleRepository->forRole("admin"); //
// $roleRepository->grant("posts.update.*"); //
// $roleRepository->revoke("posts.update.*"); //
// $roleRepository->ability("posts.update.*"); //
// $roleRepository->permissions(); //

$repository = app(IACLRepository::class);
// $repository->setUser(...); //
// $repository->getUser(); //

// $repository->grantAs("admin"); //
// $repository->revokeAs("admin"); //
// $repository->is("admin"); //
// $repository->permissions(); //
// $repository->grant("posts.update.5"); //
// $repository->revoke("posts.update.5"); //
// $repository->owns(); //
// $repository->can(iacl(\App\Models\Post::class, "update", 5)); //
// $repository->can("posts.update.5"); //
// auth()->user()->can("posts.update.5"); //
// auth()->user()->canAny([ "posts.update.5", ]); //
// auth()->user()->cant("posts.update.5"); //
// auth()->user()->cantAny([ "posts.update.5", ]); //
```

- Generate swagger files into your project's directory with putting this into your annotation configuration (optionally) :

```
base_path("app/Http/Controllers/ACL")
```

```
base_path("app/Http/Controllers/Admin/ACL")
```

Usage
---

`php artisan adminer:install:acl`

Author
---

- Trip Teknologi ([@tripteki](https://linkedin.com/company/tripteki))
- Hasby Maulana ([@hsbmaulana](https://linkedin.com/in/hsbmaulana))
63 changes: 63 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "tripteki/laravelphp-acl",
"version": "1.0.0",
"description": "Trip Teknologi's Laravel.php ACLs",

"readme": "README.md",
"license": "MIT",
"authors": [ { "name": "Trip Teknologi", "email": "[email protected]" } ],
"homepage": "https://github.com/tripteki/laravelphp-acl",
"support": { "issues": "https://github.com/tripteki/laravelphp-acl/issues" },

"require": {

"php": "^8.0.2",

"tripteki/laravelphp-repository": "^1.0.0",
"tripteki/laravelphp-helpers": "^1.0.0",
"tripteki/laravelphp-adminer": "^1.0.0",
"tripteki/laravelphp-import-export": "^1.0.0",
"tripteki/laravelphp-request-response-query": "^1.0.0",

"spatie/laravel-permission": "^5.8.0"
},

"require-dev": {},

"suggest": {

"laravel/lumen-framework": "Required when using lumen framework (^9.0).",
"laravel/framework": "Required when using laravel framework (^9.0)."
},

"autoload": {

"files": [

"src/Helpers/IACL.php",
"src/Helpers/Accesses.php"
],

"psr-4": {

"Tripteki\\ACL\\": "src/"
}
},

"autoload-dev": {},

"extra": {

"laravel": {

"dont-discover": [],

"providers": [

"Tripteki\\ACL\\Providers\\ACLServiceProvider"
],

"aliases": []
}
}
}
74 changes: 74 additions & 0 deletions config/acl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

use Illuminate\Support\Str;

return [

"models" => [

"permission" => Tripteki\ACL\Models\Admin\Permission::class,
"role" => Tripteki\ACL\Models\Admin\Role::class,
],

"table_names" => [

"permissions" => "acl_permissions",
"roles" => "acl_roles",

"model_has_permissions" => "acl_user_has_permissions",
"model_has_roles" => "acl_user_has_roles",
"role_has_permissions" => "acl_role_has_permissions",
],

/**
* Owns :
*
* "index" => "viewAny"
* "show" => "view"
* "create" => "create"
* "store" => "create"
* "edit" => "update"
* "update" => "update"
* "destroy" => "delete"
*/
"own_resources" => [

"show",
"update",
"destroy",
],



"column_names" => [

"role_pivot_key" => null,

"permission_pivot_key" => null,

"model_morph_key" => "model_id",

"team_foreign_key" => "team_id",
],

"teams" => false,



"enable_wildcard_permission" => true,

"register_permission_check_method" => true,

"display_permission_in_exception" => false,

"display_role_in_exception" => false,

"cache" => [

"expiration_time" => \DateInterval::createFromDateString("24 hours"),

"key" => Str::slug(env("APP_NAME"), "_")."_acl",

"store" => "default",
],
];
Loading

0 comments on commit b093f6a

Please sign in to comment.