$this->_seenFieldTypes[$type] = true;
return true;
}
+
+ public function hasAccess($operation)
+ {
+ // First filter with standard backpack gate
+ if (!parent::hasAccess($operation)) {
+ return false;
+ }
+
+ // Then, apply model rules
+ if ($this->model instanceof CubistMagicAbstractModel) {
+ $funcMap = ['list' => 'canList',
+ 'create' => 'canCreate',
+ 'update' => 'canUpdate',
+ 'delete' => 'canDelete',
+ 'revisions' => 'canUpdate',
+ 'revise' => 'canUpdate',
+ 'bulkClone' => 'canCreate',
+ 'clone' => 'canCreate',
+ 'bulkDelete' => 'canDelete',
+ ];
+
+ if (isset($funcMap[$operation])) {
+ $func = $funcMap[$operation];
+ } else {
+ $func = 'can' . ucfirst($operation);
+ }
+ $model = $this->entry ?? $this->model;
+ if (is_callable([$model, $func])) {
+ return $model->$func(backpack_user());
+ }
+ return true;
+ }
+ return true;
+ }
+
+ public function hasAccessOrFail($operation)
+ {
+ if (!$this->hasAccess($operation)) {
+ throw new AccessDeniedException(trans('backpack::crud.unauthorized_access', ['access' => $operation]));
+ }
+
+ return true;
+ }
+
+ public function hasAccessToAll($operation_array)
+ {
+ foreach ((array)$operation_array as $key => $operation) {
+ if (!$this->hasAccess($operation)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public function hasAccessToAny($operation_array)
+ {
+ foreach ((array)$operation_array as $key => $operation) {
+ if ($this->hasAccess($operation) == true) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
if (null !== $this->getAttribute('can', null)) {
if (!can($this->getAttribute('can'))) {
+ $this->setAttribute('column',false);
$this->setAttribute('auth', false);
$this->setAttribute('type', 'authhidden');
$this->setAttribute('view_namespace', CubistBackpackServiceProvider::NAMESPACE . '::fields');
Cache::tags($tags)->flush();
}
- /**
- * @param $user CubistMagicAuthenticatable
- * @return bool
- */
- public function isOwner($user)
- {
- if (null === $this->id) {
- return true;
- }
-
- return null !== $user && ($this->canAdmin($user) || $this->getAttribute($this->_ownerAttribute) === $user->id);
- }
-
/**
* @param $user CubistMagicAuthenticatable
* @return bool
return false;
}
$permission = $this->getOption('name') . ':' . $operation;
- return $user->can($permission);
+ return $user->hasPermissionTo($permission);
}
/**
*/
public function canView($user)
{
- return $this->isOwner($user);
+ return $this->canList($user);
}
/**
*/
public function canUpdate($user)
{
- return $this->isOwner($user);
+ return $this->canCreate($user);
}
/**
*/
public function canDelete($user)
{
- return $this->isOwner($user);
+ return $this->canUpdate($user);
}
/**