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

Added hooks for setting the name of the user and the editor permission #115

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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 appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-nextcloud/master/screenshots/new.png</screenshot>
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-nextcloud/master/screenshots/open.png</screenshot>
<dependencies>
<nextcloud min-version="14" max-version="17"/>
<nextcloud min-version="13" max-version="17"/>
</dependencies>
<settings>
<admin>OCA\Onlyoffice\AdminSettings</admin>
Expand Down
39 changes: 35 additions & 4 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
use OCA\Onlyoffice\Crypt;
use OCA\Onlyoffice\DocumentService;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Controller with the main functions
*/
Expand Down Expand Up @@ -125,6 +128,13 @@ class EditorController extends Controller {
*/
private $session;

/**
* EventDispatcherInterface
*
*@var EventDispatcherInterface
*/
private $dispatcher;

/**
* Mobile regex from https://github.com/ONLYOFFICE/CommunityServer/blob/v9.1.1/web/studio/ASC.Web.Studio/web.appsettings.config#L35
*/
Expand Down Expand Up @@ -153,7 +163,8 @@ public function __construct($AppName,
AppConfig $config,
Crypt $crypt,
IManager $shareManager,
ISession $session
ISession $session,
EventDispatcherInterface $dispatcher
) {
parent::__construct($AppName, $request);

Expand All @@ -166,6 +177,7 @@ public function __construct($AppName,
$this->crypt = $crypt;
$this->shareManager = $shareManager;
$this->session = $session;
$this->dispatcher = $dispatcher;
}

/**
Expand Down Expand Up @@ -596,7 +608,7 @@ public function config($fileId, $filePath = NULL, $shareToken = NULL, $desktop =
"documentType" => $format["type"],
"editorConfig" => [
"lang" => str_replace("_", "-", \OC::$server->getL10NFactory("")->get("")->getLanguageCode()),
"region" => str_replace("_", "-", \OC::$server->getL10NFactory("")->findLocale())
//"region" => str_replace("_", "-", \OC::$server->getL10NFactory("")->findLocale())
]
];

Expand All @@ -607,8 +619,17 @@ public function config($fileId, $filePath = NULL, $shareToken = NULL, $desktop =

$canEdit = isset($format["edit"]) && $format["edit"];
$editable = $file->isUpdateable()
&& (empty($shareToken) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE);
&& (empty($token) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE);

$event = new GenericEvent($fileId, ['token' => $token]);
$this->dispatcher->dispatch(self::class . '::getEditable', $event);
if ($event->hasArgument('editable')) {
$editable = $event->getArgument('editable');
}

$params["document"]["permissions"]["edit"] = $editable;


if ($editable && $canEdit) {
$ownerId = NULL;
$owner = $file->getOwner();
Expand Down Expand Up @@ -638,6 +659,16 @@ public function config($fileId, $filePath = NULL, $shareToken = NULL, $desktop =
"name" => $user->getDisplayName()
];
}
else {
$event = new GenericEvent($fileId, ['token' => $token]);
$this->dispatcher->dispatch(self::class . '::getName', $event);
if ($event->hasArgument('name')) {
$name = $event->getArgument('name');
$params["editorConfig"]["user"] = [
"name" => $name
];
}
}

$folderLink = NULL;

Expand Down Expand Up @@ -1087,4 +1118,4 @@ private function renderError($error, $hint = "") {
))
), "error");
}
}
}