diff --git a/CHANGELOG.md b/CHANGELOG.md index d331cb45..3ff449e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - opening a reference data source - changing a reference data source - setting for disable editors cron check +- support of user avatar in editor ## 8.2.3 ## Added diff --git a/appinfo/routes.php b/appinfo/routes.php index 0edcc195..cac20538 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -27,6 +27,7 @@ ["name" => "editor#download", "url" => "/downloadas", "verb" => "GET"], ["name" => "editor#index", "url" => "/{fileId}", "verb" => "GET"], ["name" => "editor#public_page", "url" => "/s/{shareToken}", "verb" => "GET"], + ["name" => "editor#user_info", "url" => "/ajax/userInfo", "verb" => "GET"], ["name" => "editor#users", "url" => "/ajax/users", "verb" => "GET"], ["name" => "editor#mention", "url" => "/ajax/mention", "verb" => "POST"], ["name" => "editor#reference", "url" => "/ajax/reference", "verb" => "POST"], diff --git a/controller/editorapicontroller.php b/controller/editorapicontroller.php index 91558b84..822b25e7 100644 --- a/controller/editorapicontroller.php +++ b/controller/editorapicontroller.php @@ -113,6 +113,13 @@ class EditorApiController extends OCSController { */ private $versionManager; + /** + * Avatar manager + * + * @var IAvatarManager + */ + private $avatarManager; + /** * Tag manager * @@ -167,6 +174,7 @@ public function __construct( $this->versionManager = new VersionManager($AppName, $root); $this->fileUtility = new FileUtility($AppName, $trans, $logger, $config, $shareManager, $session); + $this->avatarManager = \OC::$server->getAvatarManager(); } /** @@ -436,6 +444,19 @@ public function config($fileId, $filePath = null, $shareToken = null, $version = "id" => $this->buildUserId($userId), "name" => $user->getDisplayName() ]; + $avatar = $this->avatarManager->getAvatar($userId); + if ($avatar->exists()) { + $userAvatarUrl = $this->urlGenerator->getAbsoluteURL( + $this->urlGenerator->linkToRoute( + "core.avatar.getAvatar", + [ + "userId" => $userId, + "size" => 64, + ] + ) + ); + $params["editorConfig"]["user"]["image"] = $userAvatarUrl; + } } $folderLink = null; diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index db269095..b2d97e77 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -140,6 +140,13 @@ class EditorController extends Controller { */ private $groupManager; + /** + * Avatar manager + * + * @var IAvatarManager + */ + private $avatarManager; + /** * @param string $AppName - application name * @param IRequest $request - request object @@ -186,6 +193,7 @@ public function __construct( $this->versionManager = new VersionManager($AppName, $root); $this->fileUtility = new FileUtility($AppName, $trans, $logger, $config, $shareManager, $session); + $this->avatarManager = \OC::$server->getAvatarManager(); } /** @@ -415,6 +423,49 @@ public function users($fileId, $operationType = null) { return $result; } + /** + * Get user for Info + * + * @param string $userIds - users identifiers + * + * @return array + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function userInfo($userIds) { + $result = []; + $userIds = json_decode($userIds, true); + + if ($userIds !== null && is_array($userIds)) { + foreach ($userIds as $userId) { + $userData = []; + $user = $this->userManager->get($this->getUserId($userId)); + if (!empty($user)) { + $userData = [ + "name" => $user->getDisplayName(), + "id" => $userId + ]; + $avatar = $this->avatarManager->getAvatar($user->getUID()); + if ($avatar->exists()) { + $userAvatarUrl = $this->urlGenerator->getAbsoluteURL( + $this->urlGenerator->linkToRoute( + "core.avatar.getAvatar", + [ + "userId" => $user->getUID(), + "size" => 64, + ] + ) + ); + $userData["image"] = $userAvatarUrl; + } + array_push($result, $userData); + } + } + } + return $result; + } + /** * Send notify about mention * @@ -1460,6 +1511,21 @@ private function limitEnumerationToGroups() { return false; } + /** + * Get Nextcloud userId from unique user identifier + * + * @param string $userId - current user identifier + * + * @return string + */ + private function getUserId($userId) { + if (str_contains($userId, "_")) { + $userIdExp = explode("_", $userId); + $userId = end($userIdExp); + } + return $userId; + } + /** * Print error page * diff --git a/js/editor.js b/js/editor.js index 512df2a0..f637724c 100644 --- a/js/editor.js +++ b/js/editor.js @@ -511,16 +511,31 @@ OCA.Onlyoffice.onRequestUsers = function (event) { let operationType = typeof(event.data.c) !== "undefined" ? event.data.c : null; - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/users?fileId={fileId}&operationType=" + operationType, - { - fileId: OCA.Onlyoffice.fileId || 0 - }), - function onSuccess(response) { - OCA.Onlyoffice.docEditor.setUsers({ - "c": operationType, - "users": response - }); - }); + switch (operationType) { + case "info": + $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/userInfo?userIds={userIds}", + { + userIds: JSON.stringify(event.data.id) + }), + function onSuccess(response) { + OCA.Onlyoffice.docEditor.setUsers({ + "c": operationType, + "users": response + }); + }); + break; + default: + $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/users?fileId={fileId}&operationType=" + operationType, + { + fileId: OCA.Onlyoffice.fileId || 0 + }), + function onSuccess(response) { + OCA.Onlyoffice.docEditor.setUsers({ + "c": operationType, + "users": response + }); + }); + } }; OCA.Onlyoffice.onRequestReferenceData = function (event) {