Skip to content

Commit e7cbd24

Browse files
committed
updated addPermissions and fixed helper
1 parent 8904127 commit e7cbd24

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/Kodeine/Acl/Helper/Helper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ protected function parseOperator($str)
3939
{
4040
// if its an array lets use
4141
// and operator by default
42-
if (is_array($str)) {
42+
if ( is_array($str) ) {
4343
$str = implode(',', $str);
4444
}
4545

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

@@ -65,7 +65,8 @@ protected function hasDelimiterToArray($str)
6565
}
6666

6767
return is_array($str) ?
68-
array_filter($str, 'strtolower') : strtolower($str);
68+
array_filter($str, 'strtolower') : is_object($str) ?
69+
$str : strtolower($str);
6970
}
7071

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

8081
// multiple items
8182
if ( is_array($item) ) {
82-
// is an array of One Role
83+
// is an array of One Role/Permission
8384
// its an array containing id
8485
// we dont have to loop through
8586
if ( isset($item['id']) )

src/Kodeine/Acl/Models/Eloquent/Permission.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public function setSlugAttribute($value)
5959
// if attribute is being updated.
6060
if ( isset($this->original['slug']) ) {
6161
$value = $value + json_decode($this->original['slug'], true);
62+
63+
// sort by key
64+
ksort($value);
6265
}
6366

6467
// remove null values.

src/Kodeine/Acl/Traits/HasUserPermission.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ public function addPermission($name, $permission = true)
3434
];
3535

3636
if ( ! $slugs->has($alias) ) {
37-
return $this->permissions()->create($array);
37+
$new = $this->permissions()->create($array);
38+
$this->permissions->push($new);
39+
return $new;
3840
}
3941

40-
return $slugs[$alias]->update($array['slug']);
42+
unset($array['name']);
43+
return $slugs[$alias]->update($array);
4144
}
4245

4346
public function removePermission($name)
@@ -91,10 +94,13 @@ protected function addPermissionCrud($name)
9194
];
9295

9396
if ( ! $slugs->has($alias) ) {
94-
return $this->permissions()->create($array);
97+
$new = $this->permissions()->create($array);
98+
$this->permissions->push($new);
99+
return $new;
95100
}
96101

97-
return $slugs[$alias]->update($array['slug']);
102+
unset($array['name']);
103+
return $slugs[$alias]->update($array);
98104
}
99105

100106
protected function extractAlias($str)

0 commit comments

Comments
 (0)