Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 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
95 changes: 95 additions & 0 deletions code_samples/collaboration/config/mysql/ibexa_share.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
CREATE TABLE ibexa_collaboration
(
id INT AUTO_INCREMENT NOT NULL,
owner_id INT NOT NULL,
token VARCHAR(160) NOT NULL,
discriminator VARCHAR(190) NOT NULL,
is_active TINYINT(1) NOT NULL,
has_public_link TINYINT(1) NOT NULL,
created_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
UNIQUE INDEX ibexa_collaboration_token_idx (token),
INDEX ibexa_collaboration_owner_idx (owner_id),
UNIQUE INDEX ibexa_collaboration_token_uc (token),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4
COLLATE `utf8mb4_unicode_520_ci`
ENGINE = InnoDB;
CREATE TABLE ibexa_collaboration_participant
(
id INT AUTO_INCREMENT NOT NULL,
session_id INT NOT NULL,
discriminator VARCHAR(190) NOT NULL,
scope VARCHAR(255) DEFAULT NULL,
token VARCHAR(255) DEFAULT NULL,
created_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
INDEX IDX_9C5C6401613FECDF (session_id),
UNIQUE INDEX ibexa_collaboration_participant_token_idx (token),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4
COLLATE `utf8mb4_unicode_520_ci`
ENGINE = InnoDB;
CREATE TABLE ibexa_collaboration_participant_internal
(
id INT NOT NULL,
user_id INT NOT NULL,
INDEX IDX_E838B79AA76ED395 (user_id),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4
COLLATE `utf8mb4_unicode_520_ci`
ENGINE = InnoDB;
CREATE TABLE ibexa_collaboration_participant_external
(
id INT NOT NULL,
email VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4
COLLATE `utf8mb4_unicode_520_ci`
ENGINE = InnoDB;
CREATE TABLE ibexa_collaboration_invitation
(
id INT AUTO_INCREMENT NOT NULL,
session_id INT NOT NULL,
participant_id INT NOT NULL,
sender_id INT NOT NULL,
status VARCHAR(64) NOT NULL,
context LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)',
created_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
updated_at DATETIME NOT NULL COMMENT '(DC2Type:datetimetz_immutable)',
INDEX IDX_36C63687613FECDF (session_id),
INDEX IDX_36C636879D1C3019 (participant_id),
INDEX IDX_36C63687F624B39D (sender_id),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4
COLLATE `utf8mb4_unicode_520_ci`
ENGINE = InnoDB;
ALTER TABLE ibexa_collaboration
ADD CONSTRAINT ibexa_collaboration_owner_id_fk FOREIGN KEY (owner_id) REFERENCES ezuser (contentobject_id) ON DELETE RESTRICT;
ALTER TABLE ibexa_collaboration_participant
ADD CONSTRAINT ibexa_collaboration_participant_session_id_fk FOREIGN KEY (session_id) REFERENCES ibexa_collaboration (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ibexa_collaboration_participant_internal
ADD CONSTRAINT ibexa_collaboration_participant_internal_pk FOREIGN KEY (id) REFERENCES ibexa_collaboration_participant (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ibexa_collaboration_participant_internal
ADD CONSTRAINT ibexa_collaboration_participant_internal_user_id_fk FOREIGN KEY (user_id) REFERENCES ezuser (contentobject_id) ON DELETE RESTRICT;
ALTER TABLE ibexa_collaboration_participant_external
ADD CONSTRAINT ibexa_collaboration_participant_external_pk FOREIGN KEY (id) REFERENCES ibexa_collaboration_participant (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ibexa_collaboration_invitation
ADD CONSTRAINT ibexa_collaboration_invitation_session_id_fk FOREIGN KEY (session_id) REFERENCES ibexa_collaboration (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ibexa_collaboration_invitation
ADD CONSTRAINT ibexa_collaboration_invitation_participant_id_fk FOREIGN KEY (participant_id) REFERENCES ibexa_collaboration_participant (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ibexa_collaboration_invitation
ADD CONSTRAINT ibexa_collaboration_invitation_sender_id_fk FOREIGN KEY (sender_id) REFERENCES ezuser (contentobject_id) ON DELETE RESTRICT;
CREATE TABLE ibexa_collaboration_content
(
id INT NOT NULL,
content_id INT NOT NULL,
version_no INT NOT NULL,
language_id BIGINT NOT NULL,
INDEX ibexa_collaboration_session_content_version_language_idx (content_id, version_no, language_id),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8mb4_unicode_520_ci` ENGINE = InnoDB;
ALTER TABLE
ibexa_collaboration_content
ADD
CONSTRAINT ibexa_collaboration_content_pk FOREIGN KEY (id) REFERENCES ibexa_collaboration (id) ON UPDATE CASCADE ON DELETE CASCADE;
97 changes: 97 additions & 0 deletions code_samples/collaboration/config/postgresql/ibexa_share.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
CREATE TABLE ibexa_collaboration
(
id SERIAL NOT NULL,
owner_id INT NOT NULL,
token VARCHAR(160) NOT NULL,
discriminator VARCHAR(190) NOT NULL,
is_active BOOLEAN NOT NULL,
has_public_link BOOLEAN NOT NULL,
created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX ibexa_collaboration_token_idx ON ibexa_collaboration (token);
CREATE INDEX ibexa_collaboration_owner_idx ON ibexa_collaboration (owner_id);
CREATE UNIQUE INDEX ibexa_collaboration_token_uc ON ibexa_collaboration (token);
COMMENT
ON COLUMN ibexa_collaboration.created_at IS '(DC2Type:datetimetz_immutable)';
COMMENT
ON COLUMN ibexa_collaboration.updated_at IS '(DC2Type:datetimetz_immutable)';
CREATE TABLE ibexa_collaboration_participant
(
id SERIAL NOT NULL,
session_id INT NOT NULL,
discriminator VARCHAR(190) NOT NULL,
scope VARCHAR(255) DEFAULT NULL,
token VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX ibexa_collaboration_participant_idx ON ibexa_collaboration_participant (session_id);
CREATE UNIQUE INDEX ibexa_collaboration_participant_token_idx ON ibexa_collaboration_participant (token);
COMMENT
ON COLUMN ibexa_collaboration_participant.created_at IS '(DC2Type:datetimetz_immutable)';
COMMENT
ON COLUMN ibexa_collaboration_participant.updated_at IS '(DC2Type:datetimetz_immutable)';
CREATE TABLE ibexa_collaboration_participant_internal
(
id INT NOT NULL,
user_id INT NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX ibexa_collaboration_participant_internal_idx ON ibexa_collaboration_participant_internal (user_id);
CREATE TABLE ibexa_collaboration_participant_external
(
id INT NOT NULL,
email VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE ibexa_collaboration_invitation
(
id SERIAL NOT NULL,
session_id INT NOT NULL,
participant_id INT NOT NULL,
sender_id INT NOT NULL,
status VARCHAR(64) NOT NULL,
context JSON DEFAULT NULL,
created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX ibexa_collaboration_invitation_idx ON ibexa_collaboration_invitation (session_id);
CREATE INDEX ibexa_collaboration_invitation_idx ON ibexa_collaboration_invitation (participant_id);
CREATE INDEX ibexa_collaboration_invitation_idx ON ibexa_collaboration_invitation (sender_id);
COMMENT
ON COLUMN ibexa_collaboration_invitation.created_at IS '(DC2Type:datetimetz_immutable)';
COMMENT
ON COLUMN ibexa_collaboration_invitation.updated_at IS '(DC2Type:datetimetz_immutable)';
ALTER TABLE ibexa_collaboration
ADD CONSTRAINT ibexa_collaboration_owner_id_fk FOREIGN KEY (owner_id) REFERENCES ezuser (contentobject_id) ON DELETE RESTRICT NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE ibexa_collaboration_participant
ADD CONSTRAINT ibexa_collaboration_participant_session_id_fk FOREIGN KEY (session_id) REFERENCES ibexa_collaboration (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE ibexa_collaboration_participant_internal
ADD CONSTRAINT ibexa_collaboration_participant_internal_pk FOREIGN KEY (id) REFERENCES ibexa_collaboration_participant (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE ibexa_collaboration_participant_internal
ADD CONSTRAINT ibexa_collaboration_participant_internal_user_id_fk FOREIGN KEY (user_id) REFERENCES ezuser (contentobject_id) ON DELETE RESTRICT NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE ibexa_collaboration_participant_external
ADD CONSTRAINT ibexa_collaboration_participant_external_pk FOREIGN KEY (id) REFERENCES ibexa_collaboration_participant (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE ibexa_collaboration_invitation
ADD CONSTRAINT ibexa_collaboration_invitation_session_id_fk FOREIGN KEY (session_id) REFERENCES ibexa_collaboration (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE ibexa_collaboration_invitation
ADD CONSTRAINT ibexa_collaboration_invitation_participant_id_fk FOREIGN KEY (participant_id) REFERENCES ibexa_collaboration_participant (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE ibexa_collaboration_invitation
ADD CONSTRAINT ibexa_collaboration_invitation_sender_id_fk FOREIGN KEY (sender_id) REFERENCES ezuser (contentobject_id) ON DELETE RESTRICT NOT DEFERRABLE INITIALLY IMMEDIATE;
CREATE TABLE ibexa_collaboration_content
(
id INT NOT NULL,
content_id INT NOT NULL,
version_no INT NOT NULL,
language_id BIGINT NOT NULL,
PRIMARY KEY (id)
);

CREATE INDEX ibexa_collaboration_session_content_version_language_idx ON ibexa_collaboration_content (content_id, version_no, language_id);

ALTER TABLE ibexa_collaboration_content
ADD CONSTRAINT ibexa_collaboration_content_pk FOREIGN KEY (id) REFERENCES ibexa_collaboration (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
174 changes: 174 additions & 0 deletions code_samples/collaboration/src/Command/ManageSessionsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace App\Command;

use Ibexa\Contracts\Collaboration\Invitation\InvitationCreateStruct;
use Ibexa\Contracts\Collaboration\Invitation\InvitationQuery;
use Ibexa\Contracts\Collaboration\Invitation\InvitationStatus;
use Ibexa\Contracts\Collaboration\Invitation\InvitationUpdateStruct;
use Ibexa\Contracts\Collaboration\Invitation\Query\Criterion\Session;
use Ibexa\Contracts\Collaboration\InvitationServiceInterface;
use Ibexa\Contracts\Collaboration\Participant\ExternalParticipantCreateStruct;
use Ibexa\Contracts\Collaboration\Participant\InternalParticipantCreateStruct;
use Ibexa\Contracts\Collaboration\Participant\InternalParticipantUpdateStruct;
use Ibexa\Contracts\Collaboration\Session\Query\Criterion\Token;
use Ibexa\Contracts\Collaboration\Session\SessionQuery;
use Ibexa\Contracts\Collaboration\SessionServiceInterface;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Share\Collaboration\ContentSessionCreateStruct;
use Ibexa\Contracts\Share\Collaboration\ContentSessionScope;
use Ibexa\Contracts\Share\Collaboration\ContentSessionUpdateStruct;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class ManageSessionsCommand extends Command
{
protected static $defaultName = 'app:manage-sessions';

private InvitationServiceInterface $invitationService;

private SessionServiceInterface $sessionService;

private ContentService $contentService;

private UserService $userService;

private PermissionResolver $permissionResolver;

public function __construct(
InvitationServiceInterface $invitationService,
SessionServiceInterface $sessionService,
ContentService $contentService,
UserService $userService,
PermissionResolver $permissionResolver
) {
parent::__construct(self::$defaultName);

$this->invitationService = $invitationService;
$this->sessionService = $sessionService;
$this->contentService = $contentService;
$this->userService = $userService;
$this->permissionResolver = $permissionResolver;
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$this->permissionResolver->setCurrentUserReference(
$this->userService->loadUserByLogin('admin')
);

// Create a sharing session for Content
$versionInfo = $this->contentService->loadContent(52)->getVersionInfo();
$createStruct = new ContentSessionCreateStruct(
$versionInfo,
$versionInfo->getInitialLanguage()
);
$createStruct->setHasPublicLink(false);

$token = 'my-secret-token-12345';
$createStruct->setToken($token);

$sessionId = $this->sessionService->createSession($createStruct)->getId();

// Get a session by ID or token
$session = $this->sessionService->getSession($sessionId);
$session = $this->sessionService->getSessionByToken($token);

// Find sessions
$sessionQuery = new SessionQuery(new Token($token));
$session = $this->sessionService->findSessions($sessionQuery)->getFirst();

// Update a session
$updateStruct = new ContentSessionUpdateStruct();
$updateStruct->setHasPublicLink(true);

$this->sessionService->updateSession($session, $updateStruct);

// Deactivate a session
$updateStruct = new ContentSessionUpdateStruct();
$updateStruct->setIsActive(false);

$this->sessionService->updateSession($session, $updateStruct);

// Manage participants
$user = $this->userService->loadUserByLogin('another_user');
$internalParticipantCreateStruct = new InternalParticipantCreateStruct(
$user,
ContentSessionScope::VIEW
);
$externalParticipantCreateStruct = new ExternalParticipantCreateStruct(
'[email protected]',
ContentSessionScope::VIEW,
'personal-secret-token-12345'
);

$internalParticipant = $this->sessionService->addParticipant($session, $internalParticipantCreateStruct);
$externalParticipant = $this->sessionService->addParticipant($session, $externalParticipantCreateStruct);

// Get and update participants
$participant = $this->sessionService
->getSession($session->getId())
->getParticipants()
->getByEmail($user->email);

$internalParticipantUpdateStruct = new InternalParticipantUpdateStruct(ContentSessionScope::EDIT);
$this->sessionService->updateParticipant($session, $participant, $internalParticipantUpdateStruct);

// Remove participant
$this->sessionService->removeParticipant($session, $externalParticipant);

// Check ownerships. If no user is provided, current user is used.
$this->sessionService->isSessionOwner(
$session,
$this->userService->loadUserByLogin('another_user')
);

// Check participation
$this->sessionService->isSessionParticipant(
$session,
$this->permissionResolver->getCurrentUserReference()
);

// Manage invitations
$invitationQuery = new InvitationQuery(new Session($session));
$invitations = $this->invitationService->findInvitations($invitationQuery)->getInvitations();

foreach ($invitations as $invitation) {
$output->writeln('Invitation ID: ' . $invitation->getId() . ' Status: ' . $invitation->getStatus());
}

$invitation = $this->invitationService->getInvitationByParticipant($participant);

// Create invitation - use when auto-inviting participants is not enabled
$invitationCreateStruct = new InvitationCreateStruct(
$session,
$internalParticipant
);

$this->invitationService->createInvitation($invitationCreateStruct);

// Update invitation
$invitationUpdateStruct = new InvitationUpdateStruct();
$invitationUpdateStruct->setStatus(InvitationStatus::STATUS_REJECTED);

$this->invitationService->updateInvitation($invitation, $invitationUpdateStruct);

// Delete invitation
$invitation = $this->invitationService->getInvitation(2);
$this->invitationService->deleteInvitation($invitation);

// Delete a session
$this->sessionService->deleteSession($session);

return Command::SUCCESS;
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
"ibexa/discounts": "~4.6.x-dev",
"ibexa/discounts-codes": "~4.6.x-dev",
"ibexa/product-catalog-symbol-attribute": "~4.6.x-dev",
"ibexa/messenger": "~4.6.x-dev"
"ibexa/messenger": "~4.6.x-dev",
"ibexa/collaboration": "~4.6.x-dev",
"ibexa/share": "~4.6.x-dev"
},
"scripts": {
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
Expand Down
Loading
Loading