Skip to content

Commit

Permalink
Update ACLRepository.php
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbmaulana authored Oct 14, 2024
1 parent f20705f commit 14ab5be
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Repositories/Eloquent/ACLRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use Illuminate\Support\Facades\DB;
use Tripteki\Repository\AbstractRepository;
use Tripteki\ACL\Scopes\OwnScope;
use Tripteki\ACL\Events\Granting;
use Tripteki\ACL\Events\Granted;
use Tripteki\ACL\Events\Revoking;
Expand Down Expand Up @@ -198,8 +199,24 @@ public function permissions()
* @param int|string $target
* @return \Illuminate\Support\Collection
*/
public function owns($resource = "%", $target = "%")
public function owns($resource = "*", $target = "*")
{
return $resource === "%" ? $this->user->getDirectPermissions() : $this->user->getDirectPermissions()->whereLike("name", iacl($resource, "%", $target));
$acls = $this->user->getDirectPermissions()->map(function ($value, $key) {

$acl = explode(".", $value["name"]);

return [

"id" => $acl[2],
"type" => $acl[0],
"acls" => explode(",", $acl[1]),
];
});

if ($resource != "*") $acls = $acls->where("type", OwnScope::space(app($resource)));

if ($target != "*") $acls = $acls->where("id", $target);

return $acls;
}
};

0 comments on commit 14ab5be

Please sign in to comment.