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

Feature/user avatar #462

Merged
merged 4 commits into from
Mar 4, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
21 changes: 21 additions & 0 deletions controller/editorapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class EditorApiController extends OCSController {
*/
private $versionManager;

/**
* Avatar manager
*
* @var IAvatarManager
*/
private $avatarManager;

/**
* Tag manager
*
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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;
Expand Down
66 changes: 66 additions & 0 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
35 changes: 25 additions & 10 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading