Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:spira/spira into feature/admin-at…
…omised-content * 'master' of github.com:spira/spira: (56 commits) Fixed upstream PHPSecLib api change Attempt to use node 0.12 Attempt to use node 4.2 lts in travis Resolved conflict with master in composer.lock locked selenium wd to a specific version Switched user admin checking to many roles, added roleAssignment model to track roles with a model. Switched user admin checking to many roles, added roleAssignment model to track roles with a model. role_name changed to role_key add roles to token style patch related to user role models Composer update to get latest illuminate/database just for test just for test and style patch =(( another annoying fix test fix and style patch user based storage covered with tests roles returned to the user model User storage added for assignments ...
- Loading branch information
Showing
82 changed files
with
3,546 additions
and
1,049 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
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,108 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Spira framework. | ||
* | ||
* @link https://github.com/spira/spira | ||
* | ||
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Extensions\Rbac; | ||
|
||
use App\Models\User; | ||
use Spira\Contract\Exception\NotImplementedException; | ||
use Spira\Rbac\Item\Assignment; | ||
use Spira\Rbac\Item\Role; | ||
use Spira\Rbac\Storage\AssignmentStorageInterface; | ||
|
||
class UserAssignmentStorage implements AssignmentStorageInterface | ||
{ | ||
/** | ||
* Returns all role assignment information for the specified user. | ||
* @param string|int $userId the user ID | ||
* @return Assignment[] the assignments indexed by role names. An empty array will be | ||
* returned if there is no role assigned to the user. | ||
*/ | ||
public function getAssignments($userId) | ||
{ | ||
/** @var User $user */ | ||
$user = User::findOrFail($userId); | ||
$assignments = []; | ||
|
||
/** @var \App\Models\Role $role */ | ||
foreach ($user->roles as $role) { | ||
$assignment = new Assignment(); | ||
$assignment->userId = $userId; | ||
$assignment->roleName = $role->role_key; | ||
$assignments[$role->role_key] = $assignment; | ||
} | ||
|
||
return $assignments; | ||
} | ||
|
||
/** | ||
* Assigns a role to a user. | ||
* | ||
* @param Role $role | ||
* @param string|int $userId the user ID | ||
* @return Assignment the role assignment information. | ||
*/ | ||
public function assign(Role $role, $userId) | ||
{ | ||
/** @var User $user */ | ||
$user = User::findOrFail($userId); | ||
|
||
$roleModel = new \App\Models\Role(); | ||
$roleModel->role_key = $role->name; | ||
|
||
$user->roles()->save($roleModel); | ||
|
||
$assignment = new Assignment(); | ||
$assignment->userId = $userId; | ||
$assignment->roleName = $role->name; | ||
|
||
return $assignment; | ||
} | ||
|
||
/** | ||
* Revokes a role from a user. | ||
* | ||
* @param Role $role | ||
* @param string|int $userId the user ID | ||
* @return bool whether the revoking is successful | ||
*/ | ||
public function revoke(Role $role, $userId) | ||
{ | ||
if (! $userId) { | ||
return false; | ||
} | ||
|
||
$role = \App\Models\Role::where('user_id', '=', $userId)->where('role_key', '=', $role->name)->first(); | ||
|
||
if ($role && $role->delete()) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param Role $role | ||
* @return bool | ||
*/ | ||
public function removeAllAssignments(Role $role) | ||
{ | ||
throw new NotImplementedException('Massive removal via Storage is disabled'); | ||
} | ||
|
||
/** | ||
* @param $oldName | ||
* @param Role $role | ||
* @return bool | ||
*/ | ||
public function updateAllAssignments($oldName, Role $role) | ||
{ | ||
throw new NotImplementedException('Massive update via Storage is disabled'); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Spira framework. | ||
* | ||
* @link https://github.com/spira/spira | ||
* | ||
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Http\Auth; | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Spira\Rbac\Item\Rule; | ||
|
||
class ManipulateWithOwn extends Rule | ||
{ | ||
/** | ||
* Executes the rule. | ||
* | ||
* @param callable $userResolver | ||
* @param array $params parameters passed to check. | ||
* @return bool a value indicating whether the rule permits the auth item it is associated with. | ||
*/ | ||
public function execute(callable $userResolver, $params) | ||
{ | ||
/** @var Authenticatable $user */ | ||
$user = $userResolver(); | ||
|
||
return isset($params['model']) ? $params['model']->user_id == $user->getAuthIdentifier() : false; | ||
} | ||
} |
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
Oops, something went wrong.