Skip to content

Commit

Permalink
Add posibilityy to pass single role and permission string to ability
Browse files Browse the repository at this point in the history
Fix #213
  • Loading branch information
santigarcor committed Oct 30, 2017
1 parent 8badb71 commit 5d3600d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public static function assignRealValuesTo($team, $requireAllOrOptions, $method)
* @param string|array $value
* @return string|array
*/
public static function standardize($value)
public static function standardize($value, $toArray = false)
{
if (is_array($value) || strpos($value, '|') === false) {
if (is_array($value) || ((strpos($value, '|') === false) && !$toArray)) {
return $value;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Traits/LaratrustUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ public function ability($roles, $permissions, $team = null, $options = [])
{
list($team, $options) = Helper::assignRealValuesTo($team, $options, 'is_array');
// Convert string to array if that's what is passed in.
$roles = Helper::standardize($roles);
$permissions = Helper::standardize($permissions);
$roles = Helper::standardize($roles, true);
$permissions = Helper::standardize($permissions, true);

// Set up default values and validate options.
$options = Helper::checkOrSet('validate_all', $options, [false, true]);
Expand Down
2 changes: 1 addition & 1 deletion tests/LaratrustTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function getPackageProviders($app)

protected function getPackageAliases($app)
{
return ['Laratrust' => 'Laratrust\LaratrustServiceProvider'];
return ['Laratrust' => 'Laratrust\LaratrustFacade'];
}

protected function getEnvironmentSetUp($app)
Expand Down
13 changes: 13 additions & 0 deletions tests/LaratrustUserAbilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ public function testAbilityShouldAcceptStrings()
['return_type' => 'both']
)
);

$this->assertSame(
$this->user->ability(
['role_a'],
['permission_a'],
['return_type' => 'both']
),
$this->user->ability(
'role_a',
'permission_a',
['return_type' => 'both']
)
);
}

public function testAbilityDefaultOptions()
Expand Down

0 comments on commit 5d3600d

Please sign in to comment.