Esempio n. 1
0
 /**
  * Trigger when saving the model.
  *
  * @return void
  */
 public function creating(Permission $permission)
 {
     if ($permission->priority) {
         return;
     }
     $reference = $permission->newInstance()->where('permissible_id', $permission->permissible_id)->where('permissible_type', $permission->permissible_type)->orderBy('priority', 'DESC')->first();
     if (!$reference) {
         $permission->priority = 1;
         return;
     }
     $permission->priority = $reference->priority + 1;
 }
Esempio n. 2
0
 /**
  * Set up the tests
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Role::observe(new AddSlugAttribute());
     User::observe(new UserObserver());
     Permission::observe(new PermissionObserver());
 }
Esempio n. 3
0
 /**
  * Register any other events for your application.
  *
  * @return void
  */
 public function boot()
 {
     $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
     Role::observe(new AddSlugAttribute());
     User::observe(new UserObserver());
     Permission::observe(new PermissionObserver());
 }
Esempio n. 4
0
 /** @test **/
 public function it_sets_the_priority_to_1_gven_a_null_priority_and_no_other_priority_references()
 {
     $user = factory(User::class)->create();
     $user->deny('admin.*');
     $denyAdmin = Permission::first();
     $this->assertEquals(1, $denyAdmin->priority);
 }
 /**
  * Rearrange the permissions of the given permissions
  *
  * @param  Request  $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function store(Request $request)
 {
     foreach ($request->permissions as $key => $permission) {
         $permission = Permission::find($permission);
         $permission->priority = $key + 1;
         $permission->save();
     }
     return ['response' => true];
 }
 /**
  * Destroy the given permissions.
  *
  * @param  int  $id
  * @return void
  */
 public function destroy(int $id)
 {
     Permission::destroy($id);
     return ['response' => true];
 }
 /**
  * Swap the two given permissions.
  *
  * @param  Request  $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function store(Request $request)
 {
     $this->permission->swap(...$request->permissions);
     return ['response' => true];
 }