Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix urls parteners and access for social network list #675

Merged
merged 2 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/profile, roles: ROLE_USER }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/, role: ROLE_USER }
- { path: ^/profile/, roles: ROLE_USER }
- { path: ^/admin/, role: ROLE_ADMIN }

when@test:
Expand Down
32 changes: 24 additions & 8 deletions config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
presta_sitemap:
resource: "@PrestaSitemapBundle/config/routing.yml"

controllers:
resource: ../src/Controller/
type: annotation

kernel:
resource: ../src/Kernel.php
type: annotation

profile:
resource: ../src/Controller/Profile/
type: annotation
prefix: /profile/{_locale}
name_prefix: profile_
requirements:
_locale: en|pt_BR
defaults:
_locale: pt_BR

admin:
resource: ../src/Controller/Admin/
type: annotation
prefix: /admin/{_locale}
name_prefix: admin_
requirements:
_locale: en|pt_BR
defaults:
_locale: pt_BR

site:
resource: ../src/Controller/Site/
type: annotation
requirements:
_locale: en|pt_BR

kernel:
resource: ../src/Kernel.php
type: annotation

# it's a fake endpoint, ThirdPartyAuthenticator will handle it.
app_auth_third_party__callback:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Controller;
namespace App\Controller\Admin;

use App\Entity\SocialNetworking;
use App\Form\SocialNetworkingType;
Expand All @@ -12,7 +12,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route(path: '/{_locale}/admin/socialnetworking', name: 'admin_socialnetworking_', requirements: ['_locale' => 'en|pt_BR'], defaults: ['_locale' => 'pt_BR'])]
#[Route(path: '/socialnetworking', name: 'socialnetworking_')]
class SocialNetworkingController extends AbstractController
{
public function __construct(private readonly EntityManagerInterface $entityManager)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Controller;
namespace App\Controller\Admin;

use App\Entity\User;
use App\Repository\UserRepository;
Expand All @@ -12,7 +12,7 @@
/**
* User controller.
*/
#[Route(path: '/admin/{_locale}/user', name: 'admin_user_')]
#[Route(path: '/user', name: 'user_')]
class UserController extends AbstractController
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Controller;
namespace App\Controller\Site;

use League\OAuth2\Client\Provider\AbstractProvider;
use LogicException;
Expand All @@ -11,10 +11,10 @@
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;

#[Route(name: 'app_', defaults: ['_locale' => 'pt_BR'], priority: 10)]
#[Route(name: 'app_')]
class SecurityController extends AbstractController
{
#[Route(path: '/logout/{_locale}', name: 'logout')]
#[Route(path: '/logout/{_locale}', name: 'logout', defaults: ['_locale' => 'pt_BR'])]
public function logout(): never
{
throw new LogicException('it will be intercepted by the logout key on your firewall.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Controller;
namespace App\Controller\Site;

use App\Entity\User;
use App\Repository\UserRepository;
Expand All @@ -17,7 +17,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route(name: 'app_', requirements: ['_locale' => 'en|pt_BR'])]
#[Route(name: 'app_')]
class SiteController extends AbstractController
{
#[Route(path: '/{_locale}/privacy-policy', name: 'privacy_policy', defaults: ['_locale' => 'pt_BR'])]
Expand All @@ -36,7 +36,7 @@ public function robots(): Response
}

#[Route(path: '/{_locale}', name: 'homepage', defaults: ['_locale' => 'pt_BR'])]
#[Route(path: '/login/{_locale}', name: 'login')]
#[Route(path: '/login/{_locale}', name: 'login', defaults: ['_locale' => 'pt_BR'])]
public function homepage(UserRepository $userRepository): Response
{
$users = $userRepository->findBy(['isVerified' => true], ['updatedAt' => 'desc'], 18);
Expand All @@ -52,20 +52,12 @@ public function homepage(UserRepository $userRepository): Response
]);
}

#[Route(path: '/{slug}/{_locale}', name: 'user_profile', defaults: ['_locale' => 'pt_BR'])]
public function userProfileAction(User $user): Response
{
return $this->render('default/profile.html.twig', [
'user' => $user,
]);
}

/**
* _locale need to be the last parameter because it'll be curriculum name.
* I removed _locale default from Class because here it's required,
* but it can be resolved creating other controller.
*/
#[Route(path: '/{slug}/curriculum/{_locale}', name: 'curriculum')]
#[Route(path: '/curriculum/{slug}/{_locale}', name: 'curriculum')]
public function curriculumAction(User $user): Response
{
return $this->render('@!Curriculum/cv01/index.html.twig', [
Expand All @@ -79,4 +71,12 @@ public function curriculumAction(User $user): Response
UserInfoInterface::INDEX => $user,
]);
}

#[Route(path: '/{slug}/{_locale}', name: 'user_profile', defaults: ['_locale' => 'pt_BR'])]
public function userProfileAction(User $user): Response
{
return $this->render('default/profile.html.twig', [
'user' => $user,
]);
}
}
11 changes: 7 additions & 4 deletions tests/Functional/SmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
'Public user profile (Portuguese)' => ['/test-mock', '#home-title'],
'Public user profile (English)' => ['/test-mock/en', '#home-title'],

'Curriculum (Portuguese)' => ['/test-mock/curriculum/pt_BR', '#name'],
'Curriculum (English)' => ['/test-mock/curriculum/en', '#name'],
'Curriculum (Portuguese)' => ['/curriculum/test-mock/pt_BR', '#name'],
'Curriculum (English)' => ['/curriculum/test-mock/en', '#name'],

'Privacy policy (Portuguese)' => ['/pt_BR/privacy-policy', '#privacy-policy-title'],
'Privacy policy (English)' => ['/en/privacy-policy', '#privacy-policy-title'],

'Login (Portuguese)' => ['/login/pt_BR', '#logo'],
'Login (Portuguese)' => ['/login', '#logo'],
'Login (English)' => ['/login/en', '#logo'],

'Main sitemap' => ['/sitemap.xml'],
Expand All @@ -46,6 +46,9 @@
$client->request(Request::METHOD_GET, $redirectTo);
expect($client->getResponse()->isRedirect())->toBeFalse();
})->with([
'Logout (Portuguese)' => ['/logout/pt_BR', 'http://localhost/login/pt_BR'],
'Logout (Portuguese)' => ['/logout', 'http://localhost/login'],
'Logout (English)' => ['/logout/en', 'http://localhost/login/en'],

'list all users - Admin' => ['/admin/en/user', '/login/en'],
'list all social network - Admin' => ['/admin/en/socialnetworking/', '/login/en'],
]);