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

Add support for room shares #1050

Merged
merged 43 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
98dea91
Add helper for ShareAPIController
danxuliu Jul 2, 2018
4713912
Add helper for DeletedShareAPIController
danxuliu Jul 15, 2018
6481786
Delete created users and groups after each scenario
danxuliu Jul 2, 2018
2207260
Add skeleton for RoomShareProvider
danxuliu Jul 2, 2018
06d2f0d
Add Behat context for integration tests of sharing rooms
danxuliu Jul 2, 2018
1634f2c
Implement creating room shares
danxuliu Jul 2, 2018
c51b6b9
Implement getting room shares by user
danxuliu Jul 2, 2018
5638a23
Implement getting room shares by ID
danxuliu Jul 2, 2018
7a206b1
Implement getting room shares by recipient
danxuliu Jul 3, 2018
6b4a090
Add integration tests for creating room shares
danxuliu Jul 3, 2018
8f3d493
Add integration tests for getting shares
danxuliu Jul 3, 2018
c673564
Implement moving room shares
danxuliu Jul 4, 2018
1ac8027
Add integration tests for moving room shares into other folders
danxuliu Jul 4, 2018
99aec02
Add integration tests for received shares
danxuliu Jul 4, 2018
17e25bc
Add integration tests for creating and getting reshares
danxuliu Jul 4, 2018
f4a5048
Add integration tests for getting shares
danxuliu Jul 5, 2018
c32c697
Implement updating room shares
danxuliu Jul 5, 2018
9d1d1a1
Add integration tests for updating room shares
danxuliu Jul 5, 2018
46d755b
Add integration tests for moving shares into other shares
danxuliu Jul 5, 2018
1b3fdb1
Implement deleting room shares
danxuliu Jul 6, 2018
4fe537d
Add integration tests for deleting shares
danxuliu Jul 6, 2018
dfa6e26
Implement deleting received room shares
danxuliu Jul 6, 2018
bdf09a3
Add integration tests for deleting received room shares
danxuliu Jul 6, 2018
836e454
Add integration tests for getting expired shares
danxuliu Jul 6, 2018
8fb35e0
Add integration tests for updating a deleted share
danxuliu Jul 6, 2018
ce162a5
Implement restoring deleted room shares
danxuliu Jul 15, 2018
4cfded4
Add integration tests for getting deleted room shares
danxuliu Jul 15, 2018
452e2f1
Add integration tests for restoring deleted room shares
danxuliu Jul 15, 2018
1918604
Implement hooks for deleting shares
danxuliu Jul 6, 2018
4dd51cc
Add integration tests for room shares when removing participants
danxuliu Jul 6, 2018
8e55f0b
Add integration tests for room shares when adding participants back
danxuliu Jul 6, 2018
2f21a84
Add integration tests for room shares when deleting rooms
danxuliu Jul 7, 2018
14ef816
Add integration tests for room shares when deleting users
danxuliu Jul 7, 2018
c25dc2c
Implement getting room shares in folder
danxuliu Jul 8, 2018
97e5a88
Add integration tests for getting DAV properties of room shares
danxuliu Jul 8, 2018
a34984a
Implement getting room shares by token
danxuliu Jul 8, 2018
31cc436
Implement getting access list for room shares
danxuliu Jul 9, 2018
0b8b745
Add integration tests for getting the recent files including room shares
danxuliu Jul 14, 2018
b288578
Add integration tests for transfering ownership of room shares
danxuliu Jul 14, 2018
2ca4e1a
Add reference to original sources in licence
danxuliu Jul 14, 2018
1dc87c7
Add tokens to room shares
danxuliu Aug 1, 2018
e273ac4
Include the token of shares with public rooms in share API responses
danxuliu Aug 8, 2018
57bf6e6
Add a system message for "file shared into room"
nickvergessen Aug 24, 2018
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 js/richobjectstringparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_userLocalTemplate: '<span class="mention-user {{#if isCurrentUser}}current-user{{/if}}" data-user="{{id}}">@{{name}}</span>',

_unknownTemplate: '<strong>{{name}}</strong>',
_unknownLinkTemplate: '<a href="{{link}}">{{name}}</a>',
_unknownLinkTemplate: '<a href="{{link}}" class="external" target="_blank" rel="noopener noreferrer"><strong>{{name}}</strong></a>',

/**
* @param {string} subject
Expand Down
36 changes: 36 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Spreed\GuestManager;
use OCA\Spreed\HookListener;
use OCA\Spreed\Notification\Notifier;
use OCA\Spreed\Participant;
use OCA\Spreed\Room;
use OCA\Spreed\Settings\Personal;
use OCA\Spreed\Signaling\BackendNotifier;
Expand Down Expand Up @@ -70,6 +71,7 @@ public function register() {
$this->registerRoomInvitationHook($dispatcher);
$this->registerCallNotificationHook($dispatcher);
$this->registerChatHooks($dispatcher);
$this->registerRoomHooks($dispatcher);
$this->registerClientLinks($server);

/** @var Listener $systemMessageListener */
Expand Down Expand Up @@ -321,4 +323,38 @@ protected function registerChatHooks(EventDispatcherInterface $dispatcher) {
};
$dispatcher->addListener(Room::class . '::postDeleteRoom', $listener);
}

protected function registerRoomHooks(EventDispatcherInterface $dispatcher) {
$listener = function(GenericEvent $event) {
/** @var Room $room */
$room = $event->getSubject();

if ($event->getArgument('selfJoin')) {
/** @var \OCA\Spreed\Share\RoomShareProvider $roomShareProvider */
$roomShareProvider = $this->getContainer()->query(\OCA\Spreed\Share\RoomShareProvider::class);
$roomShareProvider->deleteInRoom($room->getToken(), $event->getArgument('userId'));
}
};
$dispatcher->addListener(Room::class . '::postUserDisconnectRoom', $listener);

$listener = function(GenericEvent $event) {
/** @var Room $room */
$room = $event->getSubject();

/** @var \OCA\Spreed\Share\RoomShareProvider $roomShareProvider */
$roomShareProvider = $this->getContainer()->query(\OCA\Spreed\Share\RoomShareProvider::class);
$roomShareProvider->deleteInRoom($room->getToken(), $event->getArgument('user')->getUID());
};
$dispatcher->addListener(Room::class . '::postRemoveUser', $listener);

$listener = function(GenericEvent $event) {
/** @var Room $room */
$room = $event->getSubject();

/** @var \OCA\Spreed\Share\RoomShareProvider $roomShareProvider */
$roomShareProvider = $this->getContainer()->query(\OCA\Spreed\Share\RoomShareProvider::class);
$roomShareProvider->deleteInRoom($room->getToken());
};
$dispatcher->addListener(Room::class . '::postDeleteRoom', $listener);
}
}
19 changes: 18 additions & 1 deletion lib/Chat/SystemMessage/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@


use OCA\Spreed\Chat\ChatManager;
use OCA\Spreed\Manager;
use OCA\Spreed\Participant;
use OCA\Spreed\Room;
use OCA\Spreed\TalkSession;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand All @@ -37,14 +40,17 @@ class Listener {
protected $dispatcher;
/** @var ChatManager */
protected $chatManager;
/** @var Manager */
protected $roomManager;
/** @var TalkSession */
protected $talkSession;
/** @var IUserSession */
protected $userSession;

public function __construct(EventDispatcherInterface $dispatcher, ChatManager $chatManager, TalkSession $talkSession, IUserSession $userSession) {
public function __construct(EventDispatcherInterface $dispatcher, ChatManager $chatManager, Manager $roomManager, TalkSession $talkSession, IUserSession $userSession) {
$this->dispatcher = $dispatcher;
$this->chatManager = $chatManager;
$this->roomManager = $roomManager;
$this->talkSession = $talkSession;
$this->userSession = $userSession;
}
Expand Down Expand Up @@ -129,6 +135,17 @@ public function register() {
$this->sendSystemMessage($room, 'moderator_demoted', ['user' => $event->getArgument('user')]);
}
});
$this->dispatcher->addListener('OCP\Share::postShare', function(GenericEvent $event) {
/** @var IShare $share */
$share = $event->getSubject();

if ($share->getShareType() !== Share::SHARE_TYPE_ROOM) {
return;
}

$room = $this->roomManager->getRoomByToken($share->getSharedWith());
$this->sendSystemMessage($room, 'file_shared', ['share' => $share->getId()]);
});
}

protected function sendSystemMessage(Room $room, string $message, array $parameters = []) {
Expand Down
58 changes: 57 additions & 1 deletion lib/Chat/SystemMessage/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

use OCA\Spreed\Exceptions\ParticipantNotFoundException;
use OCA\Spreed\GuestManager;
use OCA\Spreed\Share\RoomShareProvider;
use OCP\Comments\IComment;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
Expand All @@ -38,6 +40,10 @@ class Parser {
protected $guestManager;
/** @var IUserSession */
protected $userSession;
/** @var RoomShareProvider */
protected $shareProvider;
/** @var IURLGenerator */
protected $url;
/** @var IL10N */
protected $l;

Expand All @@ -46,10 +52,17 @@ class Parser {
/** @var string[] */
protected $guestNames = [];

public function __construct(IUserManager $userManager, GuestManager $guestManager, IUserSession $userSession, IL10N $l) {
public function __construct(IUserManager $userManager,
GuestManager $guestManager,
IUserSession $userSession,
RoomShareProvider $shareProvider,
IURLGenerator $url,
IL10N $l) {
$this->userManager = $userManager;
$this->guestManager = $guestManager;
$this->userSession = $userSession;
$this->shareProvider = $shareProvider;
$this->url = $url;
$this->l = $l;
}

Expand Down Expand Up @@ -146,6 +159,19 @@ public function parseMessage(IComment $comment, string $displayName): array {
} else if ($currentUser instanceof IUser && $currentUser->getUID() === $parsedParameters['user']['id']) {
$parsedMessage = $this->l->t('{actor} demoted you from moderator');
}
} else if ($message === 'file_shared') {
try {
$parsedParameters['file'] = $this->getFileFromShare($parameters['share']);
$parsedMessage = $this->l->t('{actor} shared {file} into the conversation');
if ($currentUserIsActor) {
$parsedMessage = $this->l->t('You shared {file} into the conversation');
}
} catch (\Exception $e) {
$parsedMessage = $this->l->t('{actor} shared a file which is no longer available');
if ($currentUserIsActor) {
$parsedMessage = $this->l->t('You shared a file which is no longer available');
}
}
}

$comment->setMessage($message);
Expand All @@ -161,6 +187,36 @@ protected function getActor(IComment $comment): array {
return $this->getUser($comment->getActorId());
}

/**
* @param string $shareId
* @return array
* @throws \OCP\Files\InvalidPathException
* @throws \OCP\Files\NotFoundException
* @throws \OCP\Share\Exceptions\ShareNotFound
*/
protected function getFileFromShare(string $shareId): array {
$share = $this->shareProvider->getShareById($shareId);
$node = $share->getNode();


if ($this->userSession->isLoggedIn()) {
$url = $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', [
'fileid' => $node->getId(),
]);
} else {
$url = $this->url->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', [
'token' => $share->getToken(),
]);
}

return [
'type' => 'file',
'id' => $shareId,
'name' => $node->getName(),
'link' => $url,
];
}

protected function getUser(string $uid): array {
if (!isset($this->displayNames[$uid])) {
$this->displayNames[$uid] = $this->getDisplayName($uid);
Expand Down
101 changes: 101 additions & 0 deletions lib/Share/Helper/DeletedShareAPIController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
declare(strict_types=1);

/**
*
* @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Spreed\Share\Helper;

use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Room;
use OCP\IUserManager;
use OCP\Share\IShare;

/**
* Helper of OCA\Files_Sharing\Controller\DeletedShareAPIController for room
* shares.
*
* The methods of this class are called from the DeletedShareAPIController to
* perform actions or checks specific to room shares.
*/
class DeletedShareAPIController {

/** @var string */
private $userId;

/** @var IUserManager */
private $userManager;

/** @var Manager */
private $manager;

/**
* DeletedShareAPIController constructor.
*
* @param string $UserId
* @param IUserManager $userManager
* @param Manager $manager
*/
public function __construct(
string $UserId,
IUserManager $userManager,
Manager $manager
) {
$this->userId = $UserId;
$this->userManager = $userManager;
$this->manager = $manager;
}

/**
* Formats the specific fields of a room share for OCS output.
*
* The returned fields override those set by the main
* DeletedShareAPIController.
*
* @param IShare $share
* @return array
*/
public function formatShare(IShare $share): array {
$result = [];

try {
$room = $this->manager->getRoomByToken($share->getSharedWith());
} catch (RoomNotFoundException $e) {
return $result;
}

// The display name of one-to-one rooms is set to the display name of
// the other participant.
$roomName = $room->getName();
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
$participantsList = $room->getParticipants()['users'];
unset($participantsList[$this->userId]);

$roomName = $this->userManager->get(key($participantsList))->getDisplayName();
}

$result['share_with_displayname'] = $roomName;

return $result;
}

}
Loading