use Cubist\Backpack\app\Magic\EntityData;
use Cubist\Backpack\app\Magic\Fields\Field;
use Cubist\Backpack\app\Magic\PageData;
+use Cubist\Backpack\app\Magic\Policies\CubistMagicPermissivePolicy;
use Cubist\Backpack\app\Magic\QueryBuilder;
use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
use Cubist\Backpack\app\Magic\Util;
protected $_operations = [];
public $timestamps = true;
+ protected $_policy = null;
protected $_enableClone = true;
protected $_enableDeletion = true;
protected $_enableEdition = true;
Cache::tags($tags)->flush();
}
- public function canView(CubistMagicAuthenticatable $user)
+ public function isOwner(CubistMagicAuthenticatable $user)
{
return true;
}
+ public function canView(CubistMagicAuthenticatable $user)
+ {
+ return $this->isOwner($user);
+ }
+
public function canUpdate(CubistMagicAuthenticatable $user)
{
- return true;
+ return $this->isOwner($user);
}
public function canDelete(CubistMagicAuthenticatable $user)
{
- return true;
+ return $this->isOwner($user);
}
public function canForceDelete(CubistMagicAuthenticatable $user)
{
return $this->canUpdate($user);
}
+
+ public function getPolicyClass()
+ {
+ return $this->_policy;
+ }
}
namespace Cubist\Backpack\app\Providers;
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+use Cubist\Backpack\app\Magic\Policies\CubistMagicPermissivePolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
+use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
+ protected $_defaultPolicy = CubistMagicPermissivePolicy::class;
+ /**
+ * The policy mappings for the application.
+ *
+ * @var array
+ */
+ protected $policies = [];
+ /**
+ * Register any authentication / authorization services.
+ *
+ * @return void
+ */
+ public function boot()
+ {
+ $this->registerPolicies();
+ Gate::guessPolicyNamesUsing(function ($modelClass) {
+ $i = new $modelClass;
+ if ($i instanceof CubistMagicAbstractModel) {
+ $policy = $i->getPolicyClass();
+ if (null !== $policy) {
+ return $policy;
+ }
+ return $this->_defaultPolicy;
+ }
+ });
+ }
}