diff --git a/src/Controller/HomepageController.php b/src/Controller/HomepageController.php
index 08c7824f..221d84ec 100644
--- a/src/Controller/HomepageController.php
+++ b/src/Controller/HomepageController.php
@@ -10,6 +10,7 @@
namespace App\Controller;
use App\Entity\User;
+use App\Form\Type\InitialViewType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@@ -30,8 +31,9 @@ class HomepageController extends AbstractController
*/
public function indexAction(Request $request)
{
- // make me configurable via UserPreference
- $route = 'timesheet';
+ /** @var User $user */
+ $user = $this->getUser();
+ $route = $user->getPreferenceValue('login.initial_view', InitialViewType::DEFAULT_VIEW);
/** @var User $user */
$user = $this->getUser();
diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php
index f68fccb4..cd31f136 100644
--- a/src/Controller/ProfileController.php
+++ b/src/Controller/ProfileController.php
@@ -55,6 +55,7 @@ class ProfileController extends AbstractController
/**
* @Route(path="/", name="fos_user_profile_show", methods={"GET"})
+ * @Route(path="/", name="my_profile", methods={"GET"})
*/
public function profileAction()
{
diff --git a/src/EventSubscriber/UserPreferenceSubscriber.php b/src/EventSubscriber/UserPreferenceSubscriber.php
index b7488978..c2bc7e6a 100644
--- a/src/EventSubscriber/UserPreferenceSubscriber.php
+++ b/src/EventSubscriber/UserPreferenceSubscriber.php
@@ -14,6 +14,7 @@ use App\Entity\UserPreference;
use App\Event\PrepareUserEvent;
use App\Event\UserPreferenceEvent;
use App\Form\Type\CalendarViewType;
+use App\Form\Type\InitialViewType;
use App\Form\Type\LanguageType;
use App\Form\Type\SkinType;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -124,6 +125,11 @@ class UserPreferenceSubscriber implements EventSubscriberInterface
->setName('calendar.initial_view')
->setValue(CalendarViewType::DEFAULT_VIEW)
->setType(CalendarViewType::class),
+
+ (new UserPreference())
+ ->setName('login.initial_view')
+ ->setValue(InitialViewType::DEFAULT_VIEW)
+ ->setType(InitialViewType::class),
];
}
diff --git a/src/Form/Type/InitialViewType.php b/src/Form/Type/InitialViewType.php
new file mode 100644
index 00000000..9bf342e9
--- /dev/null
+++ b/src/Form/Type/InitialViewType.php
@@ -0,0 +1,89 @@
+ 'menu.homepage',
+ 'timesheet' => 'menu.timesheet',
+ 'calendar' => 'calendar.title',
+ 'my_profile' => 'profile.title',
+ 'admin_timesheet' => 'menu.admin_timesheet',
+ 'invoice' => 'menu.invoice',
+ 'admin_user' => 'menu.admin_user',
+ 'admin_customer' => 'menu.admin_customer',
+ 'admin_project' => 'menu.admin_project',
+ 'admin_activity' => 'menu.admin_activity',
+ ];
+
+ protected const ROUTE_PERMISSION = [
+ 'dashboard' => 'menu.homepage',
+ 'timesheet' => 'view_own_timesheet',
+ 'calendar' => 'view_own_timesheet',
+ 'my_profile' => 'view_own_profile',
+ 'admin_timesheet' => 'view_other_timesheet',
+ 'invoice' => 'view_invoice',
+ 'admin_user' => 'view_user',
+ 'admin_customer' => 'view_customer',
+ 'admin_project' => 'view_project',
+ 'admin_activity' => 'view_activity',
+ ];
+
+ /**
+ * @var AuthorizationCheckerInterface
+ */
+ protected $voter;
+
+ /**
+ * @param AuthorizationCheckerInterface $voter
+ */
+ public function __construct(AuthorizationCheckerInterface $voter)
+ {
+ $this->voter = $voter;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $choices = [];
+ foreach (self::ROUTE_PERMISSION as $route => $permission) {
+ if ($this->voter->isGranted($permission)) {
+ $name = self::ALLOWED_VIEWS[$route];
+ $choices[$name] = $route;
+ }
+ }
+
+ $resolver->setDefaults([
+ 'required' => true,
+ 'choices' => $choices,
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getParent()
+ {
+ return ChoiceType::class;
+ }
+}
diff --git a/templates/calendar/user.html.twig b/templates/calendar/user.html.twig
index 5e49e826..345d2af6 100644
--- a/templates/calendar/user.html.twig
+++ b/templates/calendar/user.html.twig
@@ -3,8 +3,8 @@
{% import "macros/datatables.html.twig" as tables %}
{% import "macros/toolbar.html.twig" as toolbar %}
-{% block page_title %}{{ 'timesheet.title'|trans }}{% endblock %}
-{% block page_subtitle %}{{ 'timesheet.subtitle'|trans }}{% endblock %}
+{% block page_title %}{{ 'calendar.title'|trans }}{% endblock %}
+{% block page_subtitle %}{{ 'calendar.subtitle'|trans }}{% endblock %}
{% block page_actions %}{{ widgets.page_actions({'list': path('timesheet'), 'create': path('timesheet_create')}) }}{% endblock %}
{% block main %}
diff --git a/tests/Controller/HomepageControllerTest.php b/tests/Controller/HomepageControllerTest.php
index 10b19a6f..09ef1e30 100644
--- a/tests/Controller/HomepageControllerTest.php
+++ b/tests/Controller/HomepageControllerTest.php
@@ -11,6 +11,7 @@ namespace App\Tests\Controller;
use App\Entity\User;
use App\Entity\UserPreference;
+use App\Form\Type\InitialViewType;
use App\Form\Type\LanguageType;
/**
@@ -31,13 +32,20 @@ class HomepageControllerTest extends ControllerBaseTest
$this->assertIsRedirect($client, '/en/timesheet/');
}
- public function testIndexActionWithChangedLanguage()
+ public function testIndexActionWithChangedPreferences()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $this->getUserByRole($em, User::ROLE_USER);
+ $pref = (new UserPreference())
+ ->setName('login.initial_view')
+ ->setValue('my_profile')
+ ->setType(InitialViewType::class);
+
+ $user->addPreference($pref);
+
$pref = (new UserPreference())
->setName('language')
->setValue('ar')
@@ -48,6 +56,6 @@ class HomepageControllerTest extends ControllerBaseTest
$em->persist($pref);
$this->request($client, '/homepage');
- $this->assertIsRedirect($client, '/ar/timesheet/');
+ $this->assertIsRedirect($client, '/ar/profile/');
}
}
diff --git a/translations/messages.de.xliff b/translations/messages.de.xliff
index 1c55a73d..424cd73c 100644
--- a/translations/messages.de.xliff
+++ b/translations/messages.de.xliff
@@ -387,6 +387,10 @@
label.calendar.initial_view
Initiale Darstellung des Kalenders
+
+ label.login.initial_view
+ Initiale Ansicht nach Anmeldung
+
month
@@ -401,6 +405,18 @@
Tag
+
+
+ calendar.title
+ Kalender
+
+
+ calendar.subtitle
+ Ansicht und Verwaltung ihrer gebuchten Zeiteinträge anhand eines Kalenders
+
+
diff --git a/translations/messages.en.xliff b/translations/messages.en.xliff
index ee86ba82..7fd23fbd 100644
--- a/translations/messages.en.xliff
+++ b/translations/messages.en.xliff
@@ -387,6 +387,10 @@
label.calendar.initial_view
Initial calendar view
+
+ label.login.initial_view
+ Initial view after login
+
month
@@ -401,6 +405,18 @@
Day
+
+
+ calendar.title
+ Calendar
+
+
+ calendar.subtitle
+ View and manage your timesheet data within a calendar
+
+