use BookStack\Chapter;
use BookStack\Entity;
use BookStack\JointPermission;
+use BookStack\Ownable;
use BookStack\Page;
use BookStack\Role;
use BookStack\User;
/**
* Checks if an entity has a restriction set upon it.
- * @param Entity $entity
+ * @param Ownable $ownable
* @param $permission
* @return bool
*/
- public function checkEntityUserAccess(Entity $entity, $permission)
+ public function checkOwnableUserAccess(Ownable $ownable, $permission)
{
if ($this->isAdmin) return true;
$explodedPermission = explode('-', $permission);
- $baseQuery = $entity->where('id', '=', $entity->id);
+ $baseQuery = $ownable->where('id', '=', $ownable->id);
$action = end($explodedPermission);
$this->currentAction = $action;
$allPermission = $this->currentUser && $this->currentUser->can($permission . '-all');
$ownPermission = $this->currentUser && $this->currentUser->can($permission . '-own');
$this->currentAction = 'view';
- $isOwner = $this->currentUser && $this->currentUser->id === $entity->created_by;
+ $isOwner = $this->currentUser && $this->currentUser->id === $ownable->created_by;
return ($allPermission || ($isOwner && $ownPermission));
}
}
});
- if ($this->isAdmin) return $query;
- $this->currentAction = $action;
- return $this->entityRestrictionQuery($query);
+ return $this->enforceEntityRestrictions($query, $action);
}
/**
*/
public function enforceChapterRestrictions($query, $action = 'view')
{
- if ($this->isAdmin) return $query;
- $this->currentAction = $action;
- return $this->entityRestrictionQuery($query);
+ return $this->enforceEntityRestrictions($query, $action);
}
/**
* @return mixed
*/
public function enforceBookRestrictions($query, $action = 'view')
+ {
+ return $this->enforceEntityRestrictions($query, $action);
+ }
+
+ /**
+ * Add restrictions for a generic entity
+ * @param $query
+ * @param string $action
+ * @return mixed
+ */
+ public function enforceEntityRestrictions($query, $action = 'view')
{
if ($this->isAdmin) return $query;
$this->currentAction = $action;