/**
  * Display the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     //TODO check if start_time = null in authorize
     $group = Group::with('meetings')->findOrFail($id);
     $this->authorize($group);
     return $group;
 }
 private function getNonPlannerInAGroup()
 {
     $group = \plunner\Group::has('employees', '>=', '2')->has('meetings', '>=', '1')->whereHas('employees', function ($query) {
         $query->whereNotIn('id', \plunner\Planner::all()->pluck('id'));
         //TODO do in a better way less expensive
     })->firstOrFail();
     $employee = $group->employees()->whereNotIn('id', \plunner\Planner::all()->pluck('id'))->firstOrFail();
     return [$group, $employee];
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $groupId
  * @param  int $employeeId
  * @return \Illuminate\Http\Response
  */
 public function destroy($groupId, $employeeId)
 {
     //
     $employee = Employee::findOrFail($employeeId);
     $this->authorize($employee);
     $group = Group::findOrFail($groupId);
     if (!$employee->belongsToGroup($group)) {
         return Response::json(['error' => 'employId <> groupId'], 404);
     }
     $employee->groups()->detach($groupId);
     return $group->employees;
 }
 public function testIndexCurrent()
 {
     //one meeting planed new, one meeting planed old, one to be planed
     $employee = factory(\plunner\Employee::class)->make();
     $this->company->employees()->save($employee);
     $group = factory(\plunner\Group::class)->make();
     $this->company->groups()->save($group);
     $employee->groups()->attach($group);
     $group->meetings()->save(factory(\plunner\Meeting::class)->make());
     //to be planed
     $new = factory(\plunner\Meeting::class)->make(['start_time' => (new \DateTime())->add(new \DateInterval('PT100S'))]);
     $group->meetings()->save($new);
     // new planed
     $employee->meetings()->attach($new->id);
     $old = factory(\plunner\Meeting::class)->make(['start_time' => (new \DateTime())->sub(new \DateInterval('PT100S'))]);
     $group->meetings()->save($old);
     // old planed
     $employee->meetings()->attach($old->id);
     //other planner meeting planned to test or condition
     $groupOther = \plunner\Group::whereNotIn('id', $employee->groups->pluck('id'))->firstOrFail();
     $other = factory(\plunner\Meeting::class)->make(['start_time' => (new \DateTime())->add(new \DateInterval('PT100S'))]);
     $groupOther->meetings()->save($other);
     $response = $this->actingAs($employee)->json('GET', '/employees/meetings/?current=1');
     $response->assertResponseOk();
     $employee = $employee->fresh();
     $response->seeJsonEquals($employee->meetings()->where(function ($query) {
         $query->where('start_time', '=', NULL);
         //to be planned
         $query->orWhere('start_time', '>=', new \DateTime());
         //planned
     })->get()->toArray());
     $content = $response->response->content();
     $content = json_decode($content, true);
     $content = collect($content);
     $content = $content->pluck('id')->toArray();
     $this->assertFalse(in_array($old->id, $content));
     $this->assertTrue(in_array($new->id, $content));
     $this->assertFalse(in_array($other->id, $content));
 }
 public function testUpdate()
 {
     $group = $this->company->groups()->firstOrFail();
     //correct request
     $response = $this->actingAs($this->company)->json('PUT', '/companies/groups/' . $group->id, $this->data);
     $response->assertResponseOk();
     $data2 = $this->data;
     $response->seeJson($data2);
     //dame data OK normal update
     $response = $this->actingAs($this->company)->json('PUT', '/companies/groups/' . $group->id, $this->data);
     $response->assertResponseOk();
     $data2 = $this->data;
     $response->seeJson($data2);
     //duplicate group
     $response = $this->actingAs($this->company)->json('PUT', '/companies/groups/' . ($group->id + 1), $this->data);
     $response->seeStatusCode(422);
     //a no my group
     $group2 = \plunner\Group::where('company_id', '<>', $this->company->id)->firstOrFail();
     $data2 = $this->data;
     $data2['name'] = 'Testers2';
     //this since we are acting as original company -> see how requests work
     $response = $this->actingAs($this->company)->json('PUT', '/companies/groups/' . $group2->id, $data2);
     $response->seeStatusCode(403);
     //force field
     $data2 = $this->data;
     $data2['name'] = 'Testers2';
     $data2['company_id'] = 2;
     $response = $this->actingAs($this->company)->json('PUT', '/companies/groups/' . $group->id, $data2);
     $response->assertResponseOk();
     $data3 = $data2;
     $json = $response->response->content();
     $json = json_decode($json, true);
     $this->assertNotEquals($data2['company_id'], $json['company_id']);
     //this for travis problem due to consider 1 as number instead of string
     $this->assertEquals(1, $json['company_id']);
     unset($data3['company_id']);
     $response->SeeJson($data3);
 }
 public function testShowGroupNotManagedByMe()
 {
     $group = \plunner\Group::where('planner_id', '<>', $this->planner->id)->first();
     if (!$group) {
         $employee = $this->company->employees()->create(['name' => 'test', 'email' => '*****@*****.**', 'password' => 'testest', 'password_confirmation' => 'testest']);
         $group = $this->company->Groups()->create(['name' => 'Testers', 'description' => 'Group for testing stuff', 'planner_id' => $employee->id]);
     }
     $response = $this->actingAs($this->planner)->json('GET', '/employees/planners/groups/' . $group->id);
     $response->seeStatusCode(403);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param int $groupId
  * @param int $meetingId
  * @param int $timeslotId
  * @return mixed
  */
 public function destroy($groupId, $meetingId, $timeslotId)
 {
     $group = Group::findOrFail($groupId);
     $this->authorize($group);
     $meeting = Meeting::findOrFail($meetingId);
     $this->authorize($meeting);
     if ($meeting->start_time != NULL) {
         return Response::json(['error' => 'the meeting is already planned'], 422);
     }
     $timeslot = MeetingTimeslot::findOrFail($timeslotId);
     $this->authorize($timeslot);
     if ($meeting->group_id == $groupId && $timeslot->meeting_id == $meetingId) {
         $timeslot->delete();
         return $timeslot;
     }
     return Response::json(['error' => 'meeting->group_id <> groupId || timeslot->meeting_id <> meetingId'], 403);
 }
 public function testDeleteGroupNotMine()
 {
     $company = \plunner\Company::findOrFail(1);
     $group = \plunner\Group::where('company_id', '<>', $company->id)->firstOrFail();
     $employee = $group->employees()->first();
     $response = $this->actingAs($company)->json('DELETE', '/companies/groups/' . $group->id . '/employees/' . $employee->id);
     $response->seeStatusCode(403);
 }
Beispiel #9
0
 public function testUpdateOtherGroupsMeeting()
 {
     $other_group = \plunner\Group::where('planner_id', '<>', $this->planner->id)->first();
     $other_groups_meeting_id = $other_group->meetings()->first()->id;
     $test_data = $this->getUpdateData();
     $response = $this->actingAs($this->planner)->json('PUT', 'employees/planners/groups/' . $other_group->id . '/meetings/' . $other_groups_meeting_id, $test_data);
     $response->seeStatusCode(403);
 }
Beispiel #10
0
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $group = Group::with('meetings', 'employees')->findOrFail($id);
     $this->authorize($group);
     return $group;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param int $groupId
  * @param int $meetingId
  * @return mixed
  */
 public function destroy($groupId, $meetingId)
 {
     $group = Group::findOrFail($groupId);
     $this->authorize($group);
     $meeting = Meeting::findOrFail($meetingId);
     $this->authorize($meeting);
     $meeting->delete();
     return $meeting;
 }
Beispiel #12
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $group = Group::findOrFail($id);
     $this->authorize($group);
     $group->delete();
     return $group;
 }