File tree Expand file tree Collapse file tree
templates/dashboard/errors
tests/FunctionalTests/Controller/Dashboard Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010use EasyCorp \Bundle \EasyAdminBundle \Field \ChoiceField ;
1111use EasyCorp \Bundle \EasyAdminBundle \Field \TextareaField ;
1212use EasyCorp \Bundle \EasyAdminBundle \Field \TextField ;
13+ use Symfony \Component \Security \Http \Attribute \IsGranted ;
1314
1415#[AdminRoute(path: '/credentials ' , name: 'credentials ' )]
16+ #[IsGranted('ROLE_ADMIN ' )]
1517class DashboardCredentialsController extends AbstractCrudController
1618{
1719 public static function getEntityFqcn (): string
Original file line number Diff line number Diff line change 1919use EasyCorp \Bundle \EasyAdminBundle \Field \TextField ;
2020use EasyCorp \Bundle \EasyAdminBundle \Router \AdminUrlGenerator ;
2121use Symfony \Component \HttpFoundation \RedirectResponse ;
22+ use Symfony \Component \Security \Http \Attribute \IsGranted ;
2223
2324#[AdminRoute(path: '/registries ' , name: 'registries ' )]
25+ #[IsGranted('ROLE_ADMIN ' )]
2426class DashboardRegistryController extends AbstractCrudController
2527{
2628 public static function getEntityFqcn (): string
Original file line number Diff line number Diff line change 1515use EasyCorp \Bundle \EasyAdminBundle \Field \EmailField ;
1616use EasyCorp \Bundle \EasyAdminBundle \Field \TextField ;
1717use Symfony \Component \Form \Extension \Core \Type \PasswordType ;
18+ use Symfony \Component \Security \Http \Attribute \IsGranted ;
1819
1920#[AdminRoute(path: '/users ' , name: 'users ' )]
21+ #[IsGranted('ROLE_ADMIN ' )]
2022class DashboardUserController extends AbstractCrudController
2123{
2224 public static function getEntityFqcn (): string
Original file line number Diff line number Diff line change 1+ {% extends ' @EasyAdmin/page/content.html.twig' %}
2+
3+ {% block page_title %}Access Denied{% endblock %}
4+
5+ {% block page_content %}
6+ <p class =" text-muted" >You do not have permission to access this page.</p >
7+ {% endblock %}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodedMonkey \Dirigent \Tests \FunctionalTests \Controller \Dashboard ;
4+
5+ use CodedMonkey \Dirigent \Tests \Helper \WebTestCaseTrait ;
6+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
7+ use Symfony \Component \HttpFoundation \Response ;
8+
9+ class DashboardCredentialsControllerTest extends WebTestCase
10+ {
11+ use WebTestCaseTrait;
12+
13+ public function testUserDoesNotHaveAccess (): void
14+ {
15+ $ client = static ::createClient ();
16+ $ this ->loginUser ();
17+
18+ $ client ->request ('GET ' , '/credentials ' );
19+
20+ $ this ->assertResponseStatusCodeSame (Response::HTTP_FORBIDDEN );
21+ }
22+
23+ public function testAdministratorHasAccess (): void
24+ {
25+ $ client = static ::createClient ();
26+ $ this ->loginUser ('admin ' );
27+
28+ $ client ->request ('GET ' , '/credentials ' );
29+
30+ $ this ->assertResponseStatusCodeSame (Response::HTTP_OK );
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodedMonkey \Dirigent \Tests \FunctionalTests \Controller \Dashboard ;
4+
5+ use CodedMonkey \Dirigent \Tests \Helper \WebTestCaseTrait ;
6+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
7+ use Symfony \Component \HttpFoundation \Response ;
8+
9+ class DashboardRegistryControllerTest extends WebTestCase
10+ {
11+ use WebTestCaseTrait;
12+
13+ public function testUserDoesNotHaveAccess (): void
14+ {
15+ $ client = static ::createClient ();
16+ $ this ->loginUser ();
17+
18+ $ client ->request ('GET ' , '/registries ' );
19+
20+ $ this ->assertResponseStatusCodeSame (Response::HTTP_FORBIDDEN );
21+ }
22+
23+ public function testAdministratorHasAccess (): void
24+ {
25+ $ client = static ::createClient ();
26+ $ this ->loginUser ('admin ' );
27+
28+ $ client ->request ('GET ' , '/registries ' );
29+
30+ $ this ->assertResponseStatusCodeSame (Response::HTTP_OK );
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodedMonkey \Dirigent \Tests \FunctionalTests \Controller \Dashboard ;
4+
5+ use CodedMonkey \Dirigent \Tests \Helper \WebTestCaseTrait ;
6+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
7+ use Symfony \Component \HttpFoundation \Response ;
8+
9+ class DashboardRootControllerPermissionsTest extends WebTestCase
10+ {
11+ use WebTestCaseTrait;
12+
13+ public function testAdministratorHasAdminMenu (): void
14+ {
15+ $ client = static ::createClient ();
16+ $ this ->loginUser ('admin ' );
17+
18+ $ client ->request ('GET ' , '/ ' );
19+
20+ $ this ->assertResponseStatusCodeSame (Response::HTTP_OK );
21+
22+ $ this ->assertAnySelectorTextSame ('.menu-item-label ' , 'Administration ' );
23+ }
24+
25+ public function testUserDoesNotHaveAdminMenu (): void
26+ {
27+ $ client = static ::createClient ();
28+ $ this ->loginUser ();
29+
30+ $ client ->request ('GET ' , '/ ' );
31+
32+ $ this ->assertResponseStatusCodeSame (Response::HTTP_OK );
33+
34+ $ this ->assertAnySelectorTextNotContains ('.menu-item-label ' , 'Administration ' );
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodedMonkey \Dirigent \Tests \FunctionalTests \Controller \Dashboard ;
4+
5+ use CodedMonkey \Dirigent \Tests \Helper \WebTestCaseTrait ;
6+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
7+ use Symfony \Component \HttpFoundation \Response ;
8+
9+ class DashboardUserControllerTest extends WebTestCase
10+ {
11+ use WebTestCaseTrait;
12+
13+ public function testUserDoesNotHaveAccess (): void
14+ {
15+ $ client = static ::createClient ();
16+ $ this ->loginUser ();
17+
18+ $ client ->request ('GET ' , '/users ' );
19+
20+ $ this ->assertResponseStatusCodeSame (Response::HTTP_FORBIDDEN );
21+ }
22+
23+ public function testAdministratorHasAccess (): void
24+ {
25+ $ client = static ::createClient ();
26+ $ this ->loginUser ('admin ' );
27+
28+ $ client ->request ('GET ' , '/users ' );
29+
30+ $ this ->assertResponseStatusCodeSame (Response::HTTP_OK );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments