Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ If you change or add translations, you need to update the `messages` XLIFF file

You can use:

./bin/phpunit
./vendor/bin/phpunit

## ✨ Code linting

Expand Down
18 changes: 9 additions & 9 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ When `API_KEY` is not set, the API endpoints are disabled and will return a 500
Each endpoint displays information related to the User:

* [Get Users](v1/users/all.md) : `GET /api/v1/users`
* [Get User Details](v1/users/details.md) : `GET /api/v1/users/:username`
* [Get User Details](v1/users/details.md) : `GET /api/v1/users/:user_id`

#### Calendars related

Endpoints for viewing and modifying user calendars.

* [Show All User Calendars](v1/calendars/all.md) : `GET /api/v1/calendars/:username`
* [Show User Calendar Details](v1/calendars/details.md) : `GET /api/v1/calendars/:username/:calendar_id`
* [Create User Calendar](v1/calendars/create.md) : `POST /api/v1/calendars/:username/create`
* [Edit User Calendar](v1/calendars/edit.md) : `POST /api/v1/calendars/:username/:calendar_id/edit`
* [Delete User Calendar](v1/calendars/delete.md) : `POST /api/v1/calendars/:username/:calendar_id/delete`
* [Show User Calendar Shares](v1/calendars/shares.md) : `GET /api/v1/calendars/:username/shares/:calendar_id`
* [Share User Calendar](v1/calendars/share_add.md) : `POST /api/v1/calendars/:username/share/:calendar_id/add`
* [Remove Share User Calendar](v1/calendars/share_remove.md) : `POST /api/v1/calendars/:username/share/:calendar_id/remove`
* [Show All User Calendars](v1/calendars/all.md) : `GET /api/v1/calendars/:user_id`
* [Show User Calendar Details](v1/calendars/details.md) : `GET /api/v1/calendars/:user_id/:calendar_id`
* [Create User Calendar](v1/calendars/create.md) : `POST /api/v1/calendars/:user_id/create`
* [Edit User Calendar](v1/calendars/edit.md) : `PUT /api/v1/calendars/:user_id/:calendar_id`
* [Delete User Calendar](v1/calendars/delete.md) : `DELETE /api/v1/calendars/:user_id/:calendar_id`
* [Show User Calendar Shares](v1/calendars/shares.md) : `GET /api/v1/calendars/:user_id/shares/:calendar_id`
* [Share User Calendar](v1/calendars/share_add.md) : `POST /api/v1/calendars/:user_id/share/:calendar_id/add`
* [Remove Share User Calendar](v1/calendars/share_remove.md) : `POST /api/v1/calendars/:user_id/share/:calendar_id/remove`
4 changes: 2 additions & 2 deletions docs/api/v1/calendars/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gets a list of all available calendars for a specific user.

**URL** : `/api/v1/calendars/:username`
**URL** : `/api/v1/calendars/:user_id`

**Method** : `GET`

Expand All @@ -11,7 +11,7 @@ Gets a list of all available calendars for a specific user.
**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
```

**URL example**
Expand Down
4 changes: 2 additions & 2 deletions docs/api/v1/calendars/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Creates a new calendar for a specific user.

**URL** : `/api/v1/calendars/:username/create`
**URL** : `/api/v1/calendars/:user_id/create`

**Method** : `POST`

Expand All @@ -11,7 +11,7 @@ Creates a new calendar for a specific user.
**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
```

**Request Body constraints**
Expand Down
8 changes: 4 additions & 4 deletions docs/api/v1/calendars/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

Deletes a specific calendar for a specific user.

**URL** : `/api/v1/calendars/:username/:calendar_id/delete`
**URL** : `/api/v1/calendars/:user_id/:calendar_id`

**Method** : `POST`
**Method** : `DELETE`

**Auth required** : YES

**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
:calendar_id -> "[numeric id of a calendar owned by the user]",
```

**URL example**

```
/api/v1/calendars/jdoe/1/delete
/api/v1/calendars/jdoe/1
```

## Success Response
Expand Down
4 changes: 2 additions & 2 deletions docs/api/v1/calendars/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gets a list of all available calendars for a specific user.

**URL** : `/api/v1/calendars/:username/:calendar_id`
**URL** : `/api/v1/calendars/:user_id/:calendar_id`

**Method** : `GET`

Expand All @@ -11,7 +11,7 @@ Gets a list of all available calendars for a specific user.
**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
:calendar_id -> "[numeric id of a calendar owned by the user]",
```

Expand Down
8 changes: 4 additions & 4 deletions docs/api/v1/calendars/edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

Edits an existing calendar for a specific user.

**URL** : `/api/v1/calendars/:username/:calendar_id/edit`
**URL** : `/api/v1/calendars/:user_id/:calendar_id`

**Method** : `POST`
**Method** : `PUT` or `PATCH`

**Auth required** : YES

**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
:calendar_id -> "[numeric id of a calendar owned by the user]",
```

Expand All @@ -30,7 +30,7 @@ Edits an existing calendar for a specific user.
**URL example**

```
/api/v1/calendars/jdoe/1/edit
/api/v1/calendars/jdoe/1
```

**Body example**
Expand Down
4 changes: 2 additions & 2 deletions docs/api/v1/calendars/share_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Shares (or updates write access) a calendar owned by the specified user to another user.

**URL** : `/api/v1/calendars/:username/share/:calendar_id/add`
**URL** : `/api/v1/calendars/:user_id/share/:calendar_id/add`

**Method** : `POST`

Expand All @@ -11,7 +11,7 @@ Shares (or updates write access) a calendar owned by the specified user to anoth
**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
:calendar_id -> "[numeric id of a calendar owned by the user]",
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/v1/calendars/share_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Removes access to a specific shared calendar for a specific user.

**URL** : `/api/v1/calendars/:username/share/:calendar_id/remove`
**URL** : `/api/v1/calendars/:user_id/share/:calendar_id/remove`

**Method** : `POST`

Expand All @@ -11,7 +11,7 @@ Removes access to a specific shared calendar for a specific user.
**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
:calendar_id -> "[numeric id of a calendar owned by the user]",
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/v1/calendars/shares.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gets a list of all users with whom a specific user calendar is shared.

**URL** : `/api/v1/calendars/:username/shares/:calendar_id`
**URL** : `/api/v1/calendars/:user_id/shares/:calendar_id`

**Method** : `GET`

Expand All @@ -11,7 +11,7 @@ Gets a list of all users with whom a specific user calendar is shared.
**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
:calendar_id -> "[numeric id of a calendar owned by the user]",
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/v1/users/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gets details about a specific user account.

**URL** : `/api/v1/users/:username`
**URL** : `/api/v1/users/:user_id`

**Method** : `GET`

Expand All @@ -11,7 +11,7 @@ Gets details about a specific user account.
**Params constraints**

```
:username -> "[username in plain text]",
:user_id -> "[user id as an int]",
```

**URL example**
Expand Down
54 changes: 38 additions & 16 deletions src/Controller/Admin/AddressBookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\AddressBook;
use App\Entity\Principal;
use App\Entity\User;
use App\Form\AddressBookType;
use App\Services\BirthdayService;
use Doctrine\Persistence\ManagerRegistry;
Expand All @@ -16,24 +17,40 @@
#[Route('/addressbooks', name: 'addressbook_')]
class AddressBookController extends AbstractController
{
#[Route('/{username}', name: 'index')]
public function addressBooks(ManagerRegistry $doctrine, string $username): Response
#[Route('/{userId}', name: 'index')]
public function addressBooks(ManagerRegistry $doctrine, int $userId): Response
{
$principal = $doctrine->getRepository(Principal::class)->findOneByUri(Principal::PREFIX.$username);
$addressbooks = $doctrine->getRepository(AddressBook::class)->findByPrincipalUri(Principal::PREFIX.$username);
$user = $doctrine->getRepository(User::class)->findOneById($userId);
if (!$user) {
throw $this->createNotFoundException('User not found');
}

$username = $user->getUsername();
$principalUri = Principal::PREFIX.$username;

$principal = $doctrine->getRepository(Principal::class)->findOneByUri($principalUri);
$addressbooks = $doctrine->getRepository(AddressBook::class)->findByPrincipalUri($principalUri);

return $this->render('addressbooks/index.html.twig', [
'addressbooks' => $addressbooks,
'principal' => $principal,
'username' => $username,
'userId' => $userId,
]);
}

#[Route('/{username}/new', name: 'create')]
#[Route('/{username}/edit/{id}', name: 'edit', requirements: ['id' => "\d+"])]
public function addressbookCreate(ManagerRegistry $doctrine, Request $request, string $username, ?int $id, TranslatorInterface $trans, BirthdayService $birthdayService): Response
#[Route('/{userId}/new', name: 'create')]
#[Route('/{userId}/edit/{id}', name: 'edit', requirements: ['id' => "\d+"])]
public function addressbookCreate(ManagerRegistry $doctrine, Request $request, int $userId, ?int $id, TranslatorInterface $trans, BirthdayService $birthdayService): Response
{
$principal = $doctrine->getRepository(Principal::class)->findOneByUri(Principal::PREFIX.$username);
$user = $doctrine->getRepository(User::class)->findOneById($userId);
if (!$user) {
throw $this->createNotFoundException('User not found');
}

$username = $user->getUsername();
$principalUri = Principal::PREFIX.$username;

$principal = $doctrine->getRepository(Principal::class)->findOneByUri($principalUri);

if (!$principal) {
throw $this->createNotFoundException('User not found');
Expand All @@ -55,7 +72,7 @@ public function addressbookCreate(ManagerRegistry $doctrine, Request $request, s
if ($isBirthdayCalendarEnabled) {
$form->get('includedInBirthdayCalendar')->setData($addressbook->isIncludedInBirthdayCalendar());
}
$form->get('principalUri')->setData(Principal::PREFIX.$username);
$form->get('principalUri')->setData($principalUri);

$form->handleRequest($request);

Expand All @@ -78,20 +95,25 @@ public function addressbookCreate(ManagerRegistry $doctrine, Request $request, s
$birthdayService->syncUser($username);
}

return $this->redirectToRoute('addressbook_index', ['username' => $username]);
return $this->redirectToRoute('addressbook_index', ['userId' => $userId]);
}

return $this->render('addressbooks/edit.html.twig', [
'form' => $form->createView(),
'principal' => $principal,
'username' => $username,
'userId' => $userId,
'addressbook' => $addressbook,
]);
}

#[Route('/{username}/delete/{id}', name: 'delete', requirements: ['id' => "\d+"])]
public function addressbookDelete(ManagerRegistry $doctrine, string $username, string $id, TranslatorInterface $trans, BirthdayService $birthdayService): Response
#[Route('/{userId}/delete/{id}', name: 'delete', requirements: ['id' => "\d+"])]
public function addressbookDelete(ManagerRegistry $doctrine, int $userId, string $id, TranslatorInterface $trans, BirthdayService $birthdayService): Response
{
$user = $doctrine->getRepository(User::class)->findOneById($userId);
if (!$user) {
throw $this->createNotFoundException('User not found');
}

$addressbook = $doctrine->getRepository(AddressBook::class)->findOneById($id);
if (!$addressbook) {
throw $this->createNotFoundException('Address Book not found');
Expand All @@ -113,9 +135,9 @@ public function addressbookDelete(ManagerRegistry $doctrine, string $username, s
$isBirthdayCalendarEnabled = $this->getParameter('caldav_enabled') && $this->getParameter('carddav_enabled');
if ($isBirthdayCalendarEnabled) {
// Let's sync the user birthday calendar if needed
$birthdayService->syncUser($username);
$birthdayService->syncUser($user->getUsername());
}

return $this->redirectToRoute('addressbook_index', ['username' => $username]);
return $this->redirectToRoute('addressbook_index', ['userId' => $userId]);
}
}
Loading