- * @param $query
- * @return mixed
- */
- protected function entityRestrictionQuery($query)
- {
- $q = $query->where(function ($parentQuery) {
- $parentQuery->whereHas('jointPermissions', function ($permissionQuery) {
- $permissionQuery->whereIn('role_id', $this->getRoles())
- ->where('action', '=', $this->currentAction)
- ->where(function ($query) {
- $query->where('has_permission', '=', true)
- ->orWhere(function ($query) {
- $query->where('has_permission_own', '=', true)
- ->where('owned_by', '=', $this->currentUser()->id);
- });
+ */
+ protected function entityRestrictionQuery(Builder $query, string $action): Builder
+ {
+ $q = $query->where(function ($parentQuery) use ($action) {
+ $parentQuery->whereHas('jointPermissions', function ($permissionQuery) use ($action) {
+ $permissionQuery->whereIn('role_id', $this->getCurrentUserRoles())
+ ->where('action', '=', $action)
+ ->where(function (Builder $query) {
+ $this->addJointHasPermissionCheck($query, $this->currentUser()->id);