-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add user permissions and tests (#78)
Introduce user permissions to the `UserController` with corresponding tests. Define permissions for each controller function as follows: - `index()`: `list-users` - `store()`: `create-users` - `show()`: - For viewing own user: `show-users` - For viewing all users: `list-users` - `update()`: - For updating all users: `update-users` - For updating own user: `update-users-self` - `destroy()`: `delete-users` This update ensures that user controller functions are now restricted and accessible based on the specified permissions. The associated tests validate the correct implementation of these permissions. Signed-off-by: Valentin Sickert <[email protected]>
- Loading branch information
Showing
4 changed files
with
625 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Permissions; | ||
|
||
/** | ||
* Class UsersPermissions | ||
* | ||
* This class defines the permissions related to users. | ||
*/ | ||
class UsersPermissions | ||
{ | ||
/** Permission for listing and view all users. */ | ||
public const CAN_LIST_USERS = 'list-users'; | ||
|
||
/** Permission for showing users itself. */ | ||
public const CAN_SHOW_USERS = 'show-users'; | ||
|
||
/** Permission for creating users. */ | ||
public const CAN_CREATE_USERS = 'create-users'; | ||
|
||
/** Permission for updating users. */ | ||
public const CAN_UPDATE_USERS = 'update-users'; | ||
|
||
/** Permission for updating users itself. */ | ||
public const CAN_UPDATE_USERS_SELF = 'update-users-self'; | ||
|
||
/** Permission for deleting users. */ | ||
public const CAN_DELETE_USERS = 'delete-users'; | ||
} |
71 changes: 71 additions & 0 deletions
71
database/migrations/2023_12_13_214743_add_user_permissions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
use App\Permissions\UsersPermissions; | ||
use Carbon\Carbon; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
DB::table('permissions')->insert( | ||
[ | ||
[ | ||
'name' => UsersPermissions::CAN_LIST_USERS, | ||
'guard_name' => 'web', | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
], | ||
[ | ||
'name' => UsersPermissions::CAN_SHOW_USERS, | ||
'guard_name' => 'web', | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
], | ||
[ | ||
'name' => UsersPermissions::CAN_CREATE_USERS, | ||
'guard_name' => 'web', | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
], | ||
[ | ||
'name' => UsersPermissions::CAN_UPDATE_USERS, | ||
'guard_name' => 'web', | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
], | ||
[ | ||
'name' => UsersPermissions::CAN_UPDATE_USERS_SELF, | ||
'guard_name' => 'web', | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
], | ||
[ | ||
'name' => UsersPermissions::CAN_DELETE_USERS, | ||
'guard_name' => 'web', | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
] | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
DB::table('permissions')->whereIn('name', [ | ||
UsersPermissions::CAN_LIST_USERS, | ||
UsersPermissions::CAN_SHOW_USERS, | ||
UsersPermissions::CAN_CREATE_USERS, | ||
UsersPermissions::CAN_UPDATE_USERS, | ||
UsersPermissions::CAN_UPDATE_USERS_SELF, | ||
UsersPermissions::CAN_DELETE_USERS, | ||
])->delete(); | ||
} | ||
}; |
Oops, something went wrong.