Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-06-07 13:04:56 +0300
committerJulius Härtl <jus@bitgrid.net>2019-06-07 13:04:56 +0300
commit3f5169c9c263fc41028f91ce9a73df3e35bc5899 (patch)
tree29835155345eb7b79bccaac5310856a06832f7ac /lib
parentefc373373d0e577f9d1dd605abfb142a13ef69d3 (diff)
Implement guestName for public shares
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/PublicSessionController.php4
-rw-r--r--lib/Db/Session.php3
-rw-r--r--lib/Db/SessionMapper.php2
-rw-r--r--lib/Service/ApiService.php4
-rw-r--r--lib/Service/SessionService.php11
5 files changed, 13 insertions, 11 deletions
diff --git a/lib/Controller/PublicSessionController.php b/lib/Controller/PublicSessionController.php
index ee5b446fc..68eb2c937 100644
--- a/lib/Controller/PublicSessionController.php
+++ b/lib/Controller/PublicSessionController.php
@@ -74,8 +74,8 @@ class PublicSessionController extends PublicShareController {
* @NoAdminRequired
* @PublicPage
*/
- public function create(string $token, string $file = null): DataResponse {
- return $this->apiService->create(null, $file, $token);
+ public function create(string $token, string $file = null, $guestName = null): DataResponse {
+ return $this->apiService->create(null, $file, $token, $guestName);
}
/**
diff --git a/lib/Db/Session.php b/lib/Db/Session.php
index 5801ea0ab..dc3bc9b7d 100644
--- a/lib/Db/Session.php
+++ b/lib/Db/Session.php
@@ -49,7 +49,8 @@ class Session extends Entity implements \JsonSerializable {
'userId' => $this->userId,
'token' => $this->token,
'color' => $this->color,
- 'lastContact' => $this->lastContact
+ 'lastContact' => $this->lastContact,
+ 'guestName' => $this->guestName
];
}
}
diff --git a/lib/Db/SessionMapper.php b/lib/Db/SessionMapper.php
index aa8b081a0..36e355d00 100644
--- a/lib/Db/SessionMapper.php
+++ b/lib/Db/SessionMapper.php
@@ -64,7 +64,7 @@ class SessionMapper extends QBMapper {
public function findAllActive($documentId) {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
- $qb->select('id','color','document_id', 'last_contact','user_id')
+ $qb->select('id','color','document_id', 'last_contact','user_id','guest_name')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->gt('last_contact', $qb->createNamedParameter(time()-SessionService::SESSION_VALID_TIME)))
diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php
index 80b349ef8..af4bb5687 100644
--- a/lib/Service/ApiService.php
+++ b/lib/Service/ApiService.php
@@ -47,7 +47,7 @@ class ApiService {
$this->documentService = $documentService;
}
- public function create($fileId = null, $filePath = null, $token = null): DataResponse {
+ public function create($fileId = null, $filePath = null, $token = null, $guestName = null): DataResponse {
try {
$readOnly = true;
/** @var File $file */
@@ -71,7 +71,7 @@ class ApiService {
return new DataResponse($e->getMessage(), 500);
}
- $session = $this->sessionService->initSession($document->getId());
+ $session = $this->sessionService->initSession($document->getId(), $guestName);
return new DataResponse([
'document' => $document,
'session' => $session,
diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php
index a23447914..9de0ea0a9 100644
--- a/lib/Service/SessionService.php
+++ b/lib/Service/SessionService.php
@@ -46,20 +46,21 @@ class SessionService {
$this->sessionMapper = $sessionMapper;
$this->secureRandom = $secureRandom;
$this->timeFactory = $timeFactory;
- $this->userId = $userId ?? 'Guest';
+ $this->userId = $userId;
}
- public function initSession($documentId): Session {
+ public function initSession($documentId, $guestName = null): Session {
$session = new Session();
$session->setDocumentId($documentId);
- $session->setUserId($this->userId);
+ $userName = $this->userId ? $this->userId : $guestName;
+ $session->setUserId($userName);
$session->setToken($this->secureRandom->generate(64));
/** @var IAvatarManager $avatarGenerator */
$avatarGenerator = \OC::$server->query(IAvatarManager::class);
- $color = $avatarGenerator->getGuestAvatar($this->userId)->avatarBackgroundColor($this->userId);
+ $color = $avatarGenerator->getGuestAvatar($userName)->avatarBackgroundColor($userName);
$color = sprintf("#%02x%02x%02x", $color->r, $color->g, $color->b);
$session->setColor($color);
- $session->setGuestName(null);
+ $session->setGuestName($guestName);
$session->setLastContact($this->timeFactory->getTime());
return $this->sessionMapper->insert($session);
}