Skip to content
This repository was archived by the owner on Nov 27, 2021. It is now read-only.

Commit 6997630

Browse files
committed
Verify access to dashboard page for users: admin, secretaries, and secretaries.
1 parent 5727666 commit 6997630

File tree

8 files changed

+139
-5
lines changed

8 files changed

+139
-5
lines changed

app/Http/Middleware/Authenticate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace App\Http\Middleware;
44

55
use Closure;
6+
use Illuminate\Contracts\Auth\Guard;
67
use Illuminate\Http\Request;
78
use Illuminate\Support\Facades\Auth;
8-
use Illuminate\Contracts\Auth\Guard;
99

1010
/**
1111
* Class Authenticate.
@@ -28,7 +28,7 @@ public function handle(Request $request, Closure $next, Guard $guard = null)
2828
if ($request->ajax() || $request->wantsJson()) {
2929
return response('Unauthorized.', 401);
3030
} else {
31-
return redirect()->guest('login');
31+
return redirect()->guest(route('login.get'));
3232
}
3333
}
3434

app/Http/routes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
$this->group(['middleware' => 'web'], function () {
44
$this->group(['middleware' => 'auth'], function () {
55
$this->get('dashboard', ['as' => 'dashboard_path', 'uses' => 'DashboardController@index']);
6-
$this->get('appointments/calendar', ['as' => 'dashboard_path', 'uses' => 'Auth\AuthController@getLogin']);
7-
$this->resource('appointments', 'Auth\AuthController');
8-
$this->resource('staff', 'Auth\AuthController');
6+
// $this->get('appointments/calendar', ['as' => 'appointments.calendar', 'uses' => 'Auth\AuthController@getLogin']);
7+
// $this->resource('appointments', 'Auth\AuthController');
8+
// $this->resource('staff', 'Auth\AuthController');
99
});
1010

1111
$this->get('/', ['as' => 'landing_page', 'uses' => 'LandingPagesController@getActive']);

app/Sass/Repositories/User/DbUserRepository.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,28 @@ public function assignAdminRole(User $user)
9090

9191
return $this->assignRole($user, $role);
9292
}
93+
94+
/**
95+
* Check if given user has a role of secretary.
96+
*
97+
* @param User $user
98+
* @return mixed
99+
*/
100+
public function hasSecretaryRole(User $user)
101+
{
102+
return $this->hasRole($user, Role::SECRETARY_ROLE);
103+
}
104+
105+
/**
106+
* Assign the 'secretary' role to the given user.
107+
*
108+
* @param User $user
109+
* @return mixed
110+
*/
111+
public function assignSecretaryRole(User $user)
112+
{
113+
$role = Role::where('name', Role::SECRETARY_ROLE)->firstOrFail();
114+
115+
return $this->assignRole($user, $role);
116+
}
93117
}

app/Sass/Repositories/User/UserRepository.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,20 @@ public function hasAdminRole(User $user);
4343
* @return mixed
4444
*/
4545
public function assignAdminRole(User $user);
46+
47+
/**
48+
* Check if given user has a role of secretary.
49+
*
50+
* @param User $user
51+
* @return mixed
52+
*/
53+
public function hasSecretaryRole(User $user);
54+
55+
/**
56+
* Assign the 'secretary' role to the given user.
57+
*
58+
* @param User $user
59+
* @return mixed
60+
*/
61+
public function assignSecretaryRole(User $user);
4662
}

tests/functional/admin/DashboardTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Tests\functional\admin;
77

8+
use App\Sass\Repositories\User\DbUserRepository;
9+
use App\User;
810
use Illuminate\Foundation\Testing\DatabaseTransactions;
911
use Tests\TestCase;
1012

@@ -18,5 +20,12 @@ class DashboardTest extends TestCase
1820
/** @test */
1921
public function it_reads_dashboard_elements()
2022
{
23+
$dbUserRepository = new DbUserRepository();
24+
$administrator = factory(User::class)->create();
25+
$dbUserRepository->assignAdminRole($administrator);
26+
27+
$this->actingAs($administrator)
28+
->visit(route('dashboard_path'))
29+
->seePageIs(route('dashboard_path'));
2130
}
2231
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* @author Rizart Dokollari <r.dokollari@gmail.com>
4+
* @since 4/11/16
5+
*/
6+
namespace Tests\functional\secretary;
7+
8+
use App\Sass\Repositories\User\DbUserRepository;
9+
use App\User;
10+
use Illuminate\Foundation\Testing\DatabaseTransactions;
11+
use Tests\TestCase;
12+
13+
/**
14+
* Class DashboardTest.
15+
*/
16+
class DashboardTest extends TestCase
17+
{
18+
use DatabaseTransactions;
19+
20+
/** @test */
21+
public function it_reads_dashboard_elements()
22+
{
23+
$dbUserRepository = new DbUserRepository();
24+
$secretary = factory(User::class)->create();
25+
$dbUserRepository->assignSecretaryRole($secretary);
26+
27+
$this->actingAs($secretary)
28+
->visit(route('dashboard_path'))
29+
->seePageIs(route('dashboard_path'));
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* @author Rizart Dokollari <r.dokollari@gmail.com>
4+
* @since 4/11/16
5+
*/
6+
namespace Tests\functional\tutor;
7+
8+
use App\Sass\Repositories\User\DbUserRepository;
9+
use App\User;
10+
use Illuminate\Foundation\Testing\DatabaseTransactions;
11+
use Tests\TestCase;
12+
13+
/**
14+
* Class DashboardTest.
15+
*/
16+
class DashboardTest extends TestCase
17+
{
18+
use DatabaseTransactions;
19+
20+
/** @test */
21+
public function it_reads_dashboard_elements()
22+
{
23+
$dbUserRepository = new DbUserRepository();
24+
$tutor = factory(User::class)->create();
25+
$dbUserRepository->assignTutorRole($tutor);
26+
27+
$this->actingAs($tutor)
28+
->visit(route('dashboard_path'))
29+
->seePageIs(route('dashboard_path'));
30+
}
31+
}

tests/integration/app/Sass/Repositories/User/DbUserRepositoryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ public function it_assigns_tutor_role_to_user()
2626
$this->assertTrue($dbUserRepository->hasTutorRole($user));
2727
}
2828

29+
/** @test */
30+
public function it_assigns_secretary_role_to_user()
31+
{
32+
$dbUserRepository = new DbUserRepository();
33+
$user = factory(User::class)->create();
34+
35+
$this->assertFalse($dbUserRepository->hasSecretaryRole($user));
36+
$this->assertNotFalse($user = $dbUserRepository->assignSecretaryRole($user));
37+
$this->assertTrue($dbUserRepository->hasSecretaryRole($user));
38+
}
39+
40+
/** @test */
41+
public function it_checks_if_user_has_secretary_role()
42+
{
43+
$dbUserRepository = new DbUserRepository();
44+
$user = factory(User::class)->create();
45+
46+
$this->assertFalse($dbUserRepository->hasSecretaryRole($user));
47+
$this->assertNotFalse($user = $dbUserRepository->assignSecretaryRole($user));
48+
$this->assertTrue($dbUserRepository->hasSecretaryRole($user));
49+
}
50+
51+
2952
/** @test */
3053
public function it_assigns_admin_role_to_user()
3154
{

0 commit comments

Comments
 (0)