Skip to content

Commit de19c1e

Browse files
api condensed on one page, configuration added
1 parent c298211 commit de19c1e

File tree

7 files changed

+382
-238
lines changed

7 files changed

+382
-238
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace App\Command;
10+
11+
use Ibexa\Contracts\Collaboration\Invitation\InvitationCreateStruct;
12+
use Ibexa\Contracts\Collaboration\Invitation\InvitationQuery;
13+
use Ibexa\Contracts\Collaboration\Invitation\InvitationStatus;
14+
use Ibexa\Contracts\Collaboration\Invitation\InvitationUpdateStruct;
15+
use Ibexa\Contracts\Collaboration\Invitation\Query\Criterion\Session;
16+
use Ibexa\Contracts\Collaboration\InvitationServiceInterface;
17+
use Ibexa\Contracts\Collaboration\Participant\ExternalParticipantCreateStruct;
18+
use Ibexa\Contracts\Collaboration\Participant\InternalParticipantCreateStruct;
19+
use Ibexa\Contracts\Collaboration\Participant\InternalParticipantUpdateStruct;
20+
use Ibexa\Contracts\Collaboration\Session\Query\Criterion\Token;
21+
use Ibexa\Contracts\Collaboration\Session\SessionQuery;
22+
use Ibexa\Contracts\Collaboration\SessionServiceInterface;
23+
use Ibexa\Contracts\Core\Repository\ContentService;
24+
use Ibexa\Contracts\Core\Repository\PermissionResolver;
25+
use Ibexa\Contracts\Core\Repository\UserService;
26+
use Ibexa\Contracts\Share\Collaboration\ContentSessionCreateStruct;
27+
use Ibexa\Contracts\Share\Collaboration\ContentSessionScope;
28+
use Ibexa\Contracts\Share\Collaboration\ContentSessionUpdateStruct;
29+
use Symfony\Component\Console\Command\Command;
30+
use Symfony\Component\Console\Input\InputInterface;
31+
use Symfony\Component\Console\Output\OutputInterface;
32+
33+
final class ManageSessionsCommand extends Command
34+
{
35+
protected static $defaultName = 'app:manage-sessions';
36+
37+
private InvitationServiceInterface $invitationService;
38+
39+
private SessionServiceInterface $sessionService;
40+
41+
private ContentService $contentService;
42+
43+
private UserService $userService;
44+
45+
private PermissionResolver $permissionResolver;
46+
47+
public function __construct(
48+
InvitationServiceInterface $invitationService,
49+
SessionServiceInterface $sessionService,
50+
ContentService $contentService,
51+
UserService $userService,
52+
PermissionResolver $permissionResolver
53+
) {
54+
parent::__construct(self::$defaultName);
55+
56+
$this->invitationService = $invitationService;
57+
$this->sessionService = $sessionService;
58+
$this->contentService = $contentService;
59+
$this->userService = $userService;
60+
$this->permissionResolver = $permissionResolver;
61+
}
62+
63+
public function execute(InputInterface $input, OutputInterface $output): int
64+
{
65+
$this->permissionResolver->setCurrentUserReference(
66+
$this->userService->loadUserByLogin('admin')
67+
);
68+
69+
// Create a sharing session for Content
70+
$versionInfo = $this->contentService->loadContent(52)->getVersionInfo();
71+
$createStruct = new ContentSessionCreateStruct(
72+
$versionInfo,
73+
$versionInfo->getInitialLanguage()
74+
);
75+
$createStruct->setHasPublicLink(false);
76+
77+
$token = 'my-secret-token-12345';
78+
$createStruct->setToken($token);
79+
80+
$sessionId = $this->sessionService->createSession($createStruct)->getId();
81+
82+
// Get a session by ID or token
83+
$session = $this->sessionService->getSession($sessionId);
84+
$session = $this->sessionService->getSessionByToken($token);
85+
86+
// Find sessions
87+
$sessionQuery = new SessionQuery(new Token($token));
88+
$session = $this->sessionService->findSessions($sessionQuery)->getFirst();
89+
90+
// Update a session
91+
$updateStruct = new ContentSessionUpdateStruct();
92+
$updateStruct->setHasPublicLink(true);
93+
94+
$this->sessionService->updateSession($session, $updateStruct);
95+
96+
// Deactivate a session
97+
$updateStruct = new ContentSessionUpdateStruct();
98+
$updateStruct->setIsActive(false);
99+
100+
$this->sessionService->updateSession($session, $updateStruct);
101+
102+
// Manage participants
103+
$user = $this->userService->loadUserByLogin('another_user');
104+
$internalParticipantCreateStruct = new InternalParticipantCreateStruct(
105+
$user,
106+
ContentSessionScope::VIEW
107+
);
108+
$externalParticipantCreateStruct = new ExternalParticipantCreateStruct(
109+
110+
ContentSessionScope::VIEW,
111+
'personal-secret-token-12345'
112+
);
113+
114+
$internalParticipant = $this->sessionService->addParticipant($session, $internalParticipantCreateStruct);
115+
$externalParticipant = $this->sessionService->addParticipant($session, $externalParticipantCreateStruct);
116+
117+
// Get and update participants
118+
$participant = $this->sessionService
119+
->getSession($session->getId())
120+
->getParticipants()
121+
->getByEmail($user->email);
122+
123+
$internalParticipantUpdateStruct = new InternalParticipantUpdateStruct(ContentSessionScope::EDIT);
124+
$this->sessionService->updateParticipant($session, $participant, $internalParticipantUpdateStruct);
125+
126+
// Remove participant
127+
$this->sessionService->removeParticipant($session, $externalParticipant);
128+
129+
// Check ownerships. If no user is provided, current user is used.
130+
$this->sessionService->isSessionOwner(
131+
$session,
132+
$this->userService->loadUserByLogin('another_user')
133+
);
134+
135+
// Check participation
136+
$this->sessionService->isSessionParticipant(
137+
$session,
138+
$this->permissionResolver->getCurrentUserReference()
139+
);
140+
141+
// Manage invitations
142+
$invitationQuery = new InvitationQuery(new Session($session));
143+
$invitations = $this->invitationService->findInvitations($invitationQuery)->getInvitations();
144+
145+
foreach ($invitations as $invitation) {
146+
$output->writeln('Invitation ID: ' . $invitation->getId() . ' Status: ' . $invitation->getStatus());
147+
}
148+
149+
$invitation = $this->invitationService->getInvitationByParticipant($participant);
150+
151+
// Create invitation - use when auto-inviting participants is not enabled
152+
$invitationCreateStruct = new InvitationCreateStruct(
153+
$session,
154+
$internalParticipant
155+
);
156+
157+
$this->invitationService->createInvitation($invitationCreateStruct);
158+
159+
// Update invitation
160+
$invitationUpdateStruct = new InvitationUpdateStruct();
161+
$invitationUpdateStruct->setStatus(InvitationStatus::STATUS_REJECTED);
162+
163+
$this->invitationService->updateInvitation($invitation, $invitationUpdateStruct);
164+
165+
// Delete invitation
166+
$invitation = $this->invitationService->getInvitation(2);
167+
$this->invitationService->deleteInvitation($invitation);
168+
169+
// Delete a session
170+
$this->sessionService->deleteSession($session);
171+
172+
return Command::SUCCESS;
173+
}
174+
}

docs/content_management/collaborative_editing/collaborative_editing.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ Real-time collaboration syncs changes instantly and shows user avatars and color
1919
This feature also introduces new dashboard tabs for managing shared drafts and joining collaboration sessions easily.
2020

2121
[[= cards([
22-
"content_management/collaborative_editing/collaborative_editing",
23-
"content_management/collaborative_editing/collaborative_editing_api",
24-
"content_management/collaborative_editing/invitation_api",
25-
"content_management/collaborative_editing/session_api",
26-
"content_management/collaborative_editing/collaborative_editing_guide"
22+
"content_management/collaborative_editing/collaborative_editing_guide",
23+
"content_management/collaborative_editing/install_collaborative_editing",
24+
"content_management/collaborative_editing/collaborative_editing_api"
2725
], columns=3) =]]

0 commit comments

Comments
 (0)