-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change usage novauser.gates.user.model to auth.providers.users.model
* make custom ActionResource * change CustomAuthorize to NovauserAuthorize. * patch NovaServiceProvider * add route web to test permission on local * add action to navigation.
- Loading branch information
Showing
16 changed files
with
812 additions
and
40 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
This file was deleted.
Oops, something went wrong.
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,70 @@ | ||
<?php | ||
|
||
|
||
namespace Tsung\NovaUserManagement\Http\Middleware; | ||
|
||
|
||
use Laravel\Nova\Nova; | ||
use Spatie\Permission\PermissionRegistrar; | ||
|
||
class NovauserAuthorize | ||
{ | ||
public function handle($request, $next) | ||
{ | ||
if(Nova::check($request)) { | ||
|
||
//$this->logonUserStillActive($request); | ||
|
||
$this->forgetCachedPermissions($request); | ||
|
||
return $next($request); | ||
} | ||
else { | ||
// if the user dont have viewNova permissions then redirect to '/' | ||
// return abort(403); | ||
return redirect('/'); | ||
} | ||
} | ||
|
||
/** | ||
* @param $request | ||
* | ||
* this method will check user is still active, if not logout the user, | ||
* note: nova will redirect the user if dont have viewNova permission but the user still login | ||
* dont need this cause web user and admin user using the same model | ||
*/ | ||
private function logonUserStillActive($request) | ||
{ | ||
$user = $request->user(); | ||
if ($user) { | ||
if( ! $user = auth()->user()->is_active) { | ||
auth()->logout(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param $request | ||
* | ||
* this method will reset cache for permission after adding | ||
* laravel nova using cache permission, so it need to be reset before useable | ||
*/ | ||
private function forgetCachedPermissions($request) | ||
{ | ||
if ( $request->is('nova-api/*/detach') || $request->is('nova-api/*/*/attach*/*') ) { | ||
// $permissionKey = Nova::resourceForModel(app(PermissionRegistrar::class)->getPermissionClass())::uriKey(); | ||
// | ||
// if ($request->viaRelationship === $permissionKey) { | ||
// app(PermissionRegistrar::class)->forgetCachedPermissions(); | ||
// } | ||
|
||
/* | ||
* if the request->viaRelationship is roles / permissions will reset permission cache | ||
*/ | ||
if( $request->viaRelationship === "roles" || $request->viaRelationship === "permissions" ) { | ||
app(PermissionRegistrar::class)->forgetCachedPermissions(); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.