Skip to content

Commit

Permalink
updated addPermissions and fixed helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kodeine committed Mar 12, 2015
1 parent 8904127 commit e7cbd24
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/Kodeine/Acl/Helper/Helper.php
Expand Up @@ -39,11 +39,11 @@ protected function parseOperator($str)
{
// if its an array lets use
// and operator by default
if (is_array($str)) {
if ( is_array($str) ) {
$str = implode(',', $str);
}

if (preg_match('/([,|])(?:\s+)?/', $str, $m)) {
if ( preg_match('/([,|])(?:\s+)?/', $str, $m) ) {
return $m[1] == '|' ? 'or' : 'and';
}

Expand All @@ -65,7 +65,8 @@ protected function hasDelimiterToArray($str)
}

return is_array($str) ?
array_filter($str, 'strtolower') : strtolower($str);
array_filter($str, 'strtolower') : is_object($str) ?
$str : strtolower($str);
}

/**
Expand All @@ -79,7 +80,7 @@ protected function mapArray($item, \Closure $closure)

// multiple items
if ( is_array($item) ) {
// is an array of One Role
// is an array of One Role/Permission
// its an array containing id
// we dont have to loop through
if ( isset($item['id']) )
Expand Down
3 changes: 3 additions & 0 deletions src/Kodeine/Acl/Models/Eloquent/Permission.php
Expand Up @@ -59,6 +59,9 @@ public function setSlugAttribute($value)
// if attribute is being updated.
if ( isset($this->original['slug']) ) {
$value = $value + json_decode($this->original['slug'], true);

// sort by key
ksort($value);
}

// remove null values.
Expand Down
14 changes: 10 additions & 4 deletions src/Kodeine/Acl/Traits/HasUserPermission.php
Expand Up @@ -34,10 +34,13 @@ public function addPermission($name, $permission = true)
];

if ( ! $slugs->has($alias) ) {
return $this->permissions()->create($array);
$new = $this->permissions()->create($array);
$this->permissions->push($new);
return $new;
}

return $slugs[$alias]->update($array['slug']);
unset($array['name']);
return $slugs[$alias]->update($array);
}

public function removePermission($name)
Expand Down Expand Up @@ -91,10 +94,13 @@ protected function addPermissionCrud($name)
];

if ( ! $slugs->has($alias) ) {
return $this->permissions()->create($array);
$new = $this->permissions()->create($array);
$this->permissions->push($new);
return $new;
}

return $slugs[$alias]->update($array['slug']);
unset($array['name']);
return $slugs[$alias]->update($array);
}

protected function extractAlias($str)
Expand Down

0 comments on commit e7cbd24

Please sign in to comment.