Exemplo n.º 1
0
 function POST_create()
 {
     $this->requireAuthentication();
     $event = App::i()->repo('Event')->find($this->postData['eventId']);
     $occurrence = new \MapasCulturais\Entities\EventOccurrence();
     $occurrence->event = $event;
     if (@$this->postData['spaceId']) {
         $occurrence->space = App::i()->repo('Space')->find($this->postData['spaceId']);
     }
     $postData = $this->postData;
     unset($postData['eventId']);
     $occurrence->rule = $postData;
     if ($errors = $occurrence->validationErrors) {
         $this->errorJson($errors);
     } else {
         $occurrence->save(true);
         $this->json($occurrence);
     }
 }
Exemplo n.º 2
0
 function testEventOccurrencePermissions()
 {
     $this->app->disableWorkflow();
     $this->resetTransactions();
     $rule = array('startsAt' => '11:11', 'duration' => '01h00', 'frequency' => 'once', 'startsOn' => '2014-07-16', 'until' => '', 'description' => 'das 11:11 às 12:11 do dia 16 de Julho', 'price' => 'R$11,11');
     $user0 = $this->getUser('normal', 0);
     $user1 = $this->getUser('normal', 1);
     $space = $user1->spaces[0];
     // Asserting that a normal user CANNOT create an event occurrence on spaces that he don't have control
     $this->user = $user0;
     $event = $this->getNewEntity('Event');
     $event->owner = $user0->profile;
     $event->save();
     $this->assertPermissionDenied(function () use($event, $space, $rule) {
         $occ = new \MapasCulturais\Entities\EventOccurrence();
         $occ->event = $event;
         $occ->space = $space;
         $occ->rule = $rule;
         $occ->save();
     }, "Asserting that a normal user CANNOT create an event occurrence on spaces that he don't have control");
     // Asserting that a normal user CAN create an event occurrence on spaces that he have control
     $this->user = $user1;
     $space->createAgentRelation($user0->profile, "AGENTS WITH CONTROL", true, true);
     $this->user = $user0;
     $this->assertPermissionGranted(function () use($event, $space, $rule) {
         $occ = new \MapasCulturais\Entities\EventOccurrence();
         $occ->event = $event;
         $occ->space = $space;
         $occ->rule = $rule;
         $occ->save();
     }, "Asserting that a normal user CAN create an event occurrence on spaces that he have control");
     // Assert that a normal user CAN create an event occurrence in public spaces that he don't have control
     $this->user = $user0;
     $public_space = $this->getNewEntity('Space');
     $public_space->owner = $user0->profile;
     $public_space->public = true;
     $public_space->save();
     $this->user = $user1;
     $event = $this->getNewEntity('Event');
     $event->owner = $user1->profile;
     $event->save();
     $this->assertPermissionGranted(function () use($event, $public_space, $rule) {
         $occ = new \MapasCulturais\Entities\EventOccurrence();
         $occ->event = $event;
         $occ->space = $public_space;
         $occ->rule = $rule;
         $occ->save();
     }, "Asserting that a normal user CAN create an event occurrence in public spaces that he don't have control");
     $this->app->enableWorkflow();
 }