diff options
author | Maxence Lange <maxence@nextcloud.com> | 2017-08-01 18:40:31 +0300 |
---|---|---|
committer | Maxence Lange <maxence@nextcloud.com> | 2017-08-01 18:40:31 +0300 |
commit | 2b96d68551a3f9a37b852a93bf35399b9c7504b2 (patch) | |
tree | 4da021c8723c92805f1642650af75fe77e6c6ee7 | |
parent | d901b9cdb21125b7027b36cf7d66652d92106983 (diff) |
rewrite on getDisplayName() and Personal Circle
Signed-off-by: Maxence Lange <maxence@nextcloud.com>
-rw-r--r-- | CHANGELOG.md | 12 | ||||
-rw-r--r-- | js/circles.app.elements.js | 2 | ||||
-rw-r--r-- | js/circles.app.navigation.js | 2 | ||||
-rw-r--r-- | js/circles.app.results.circles.js | 4 | ||||
-rw-r--r-- | lib/Api/Sharees.php | 11 | ||||
-rw-r--r-- | lib/Api/v1/Circles.php | 36 | ||||
-rw-r--r-- | lib/IBroadcaster.php | 5 | ||||
-rw-r--r-- | lib/Model/BaseMember.php | 5 | ||||
-rw-r--r-- | lib/Model/Circle.php | 33 | ||||
-rw-r--r-- | lib/Model/SharingFrame.php | 30 | ||||
-rw-r--r-- | lib/Service/BroadcastService.php | 39 | ||||
-rw-r--r-- | lib/Service/FederatedService.php | 1 | ||||
-rw-r--r-- | lib/Service/MiscService.php | 30 | ||||
-rw-r--r-- | lib/Service/SharesService.php | 1 |
14 files changed, 159 insertions, 52 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 678b7a5a..a278756a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,18 @@ All notable changes to this project will be documented in this file. ## 0.12.0 -- Security: SQL incremented ID is not used anymore; Every request on a Circle will require a 14 chars version of its Unique ID. (API v0.10.0) +- Security: SQL incremented ID is not used anymore; Every request on a Circle will require a 14 chars version of its Unique ID. (API v0.10.0). - Security: When leaving a circle, shared files are not accessible by said circle anymore. -- Bug: Fix icons -- Bug: Fix strange behaviour when the app is deleted from disk, but not disabled in the cloud -- Code design: Getting rid of Mapper/Entity and using pure QueryBuilder -- Feature: Edit Name and Description of a circle +- Bug: Fix icons. +- Bug: Fix strange behaviour when the app is deleted from disk, but not disabled in the cloud. +- Code design: Getting rid of Mapper/Entity and using pure QueryBuilder. +- Feature: Edit Name and Description of a circle. - Feature: Activities are now sent by email. - Feature: Mass invite group members to a circle. - Feature: Link groups to circle and assign level to linked group. - UI: fixing some glitches. +- Global: Private circle are now named Closed circle. +- Global: Hidden circle are now named Secret circle. ## 0.11.0 diff --git a/js/circles.app.elements.js b/js/circles.app.elements.js index 2f7497d2..7e97c4a9 100644 --- a/js/circles.app.elements.js +++ b/js/circles.app.elements.js @@ -422,7 +422,7 @@ var elements = { var tmpl = $('#tmpl_circle').html(); tmpl = tmpl.replace(/%title%/g, escapeHTML(entry.name)); - tmpl = tmpl.replace(/%type%/g, t('circles', escapeHTML(entry.typeString))); + tmpl = tmpl.replace(/%type%/g, t('circles', escapeHTML(entry.type_string))); tmpl = tmpl.replace(/%owner%/g, escapeHTML(entry.owner.display_name)); tmpl = tmpl.replace(/%status%/g, t('circles', escapeHTML(entry.user.status))); tmpl = tmpl.replace(/%level_string%/g, t('circles', escapeHTML(entry.user.level_string))); diff --git a/js/circles.app.navigation.js b/js/circles.app.navigation.js index 95d2f2ad..83090fd3 100644 --- a/js/circles.app.navigation.js +++ b/js/circles.app.navigation.js @@ -579,7 +579,7 @@ var nav = { elements.circleDetails.children('#name').text(details.name); elements.circleDesc.text(details.description); - elements.circleDetails.children('#type').text(t('circles', details.typeLongString)); + elements.circleDetails.children('#type').text(t('circles', details.type_long_string)); if (details.description !== '') { elements.circleDesc.html( escapeHTML(details.description).replace(/\n/g, ' <br />')).show( diff --git a/js/circles.app.results.circles.js b/js/circles.app.results.circles.js index a1bcb8d8..72e8e1f3 100644 --- a/js/circles.app.results.circles.js +++ b/js/circles.app.results.circles.js @@ -102,7 +102,7 @@ var resultCircles = { name: result.name })); elements.emptyCircleCreation(); - nav.displayCirclesList(result.circle.typeString); + nav.displayCirclesList(result.circle.type_string); actions.selectCircle(result.circle.unique_id); return; } @@ -121,7 +121,7 @@ var resultCircles = { elements.mainUIMembersTable.emptyTable(); if (result.status < 1) { OCA.notification.onFail( - t('circles', 'Issue while retrieving the details of this circle') + '" ' + + t('circles', 'Issue while retrieving the details of this circle') + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); return; } diff --git a/lib/Api/Sharees.php b/lib/Api/Sharees.php index 26933ca0..c1437dfc 100644 --- a/lib/Api/Sharees.php +++ b/lib/Api/Sharees.php @@ -29,6 +29,7 @@ namespace OCA\Circles\Api; use OCA\Circles\AppInfo\Application; use OCA\Circles\Model\Circle; use OCA\Circles\Model\Member; +use OCA\Circles\Service\MiscService; use OCP\Share; @@ -83,12 +84,10 @@ class Sharees { 'shareType' => Share::SHARE_TYPE_CIRCLE, 'shareWith' => $entry->getUniqueId(), 'circleInfo' => $entry->getInfo(), - 'circleOwner' => \OC::$server->getUserManager() - ->get( - $entry->getOwner() - ->getUserId() - ) - ->getDisplayName() + 'circleOwner' => MiscService::staticGetUserManager( + $entry->getOwner() + ->getUserId() + ) ], ]; diff --git a/lib/Api/v1/Circles.php b/lib/Api/v1/Circles.php index 427e02fd..7185611d 100644 --- a/lib/Api/v1/Circles.php +++ b/lib/Api/v1/Circles.php @@ -33,6 +33,7 @@ use OCA\Circles\Model\Circle; use OCA\Circles\Model\FederatedLink; use OCA\Circles\Model\Member; use OCA\Circles\Model\SharingFrame; +use OCA\Circles\Service\MiscService; class Circles { @@ -387,4 +388,39 @@ class Circles { . '-' . $link->getToken(); } + + /** + * @param SharingFrame $frame + * + * @return array + */ + public static function generateUserParameter(SharingFrame $frame) { + + if ($frame->getCloudId() !== null) { + $name = $frame->getAuthor() . '@' . $frame->getCloudId(); + } else { + $name = MiscService::staticGetDisplayName($frame->getAuthor()); + } + + return [ + 'type' => 'user', + 'id' => $frame->getAuthor(), + 'name' => $name + ]; + } + + + /** + * @param SharingFrame $frame + * + * @return array + */ + public static function generateCircleParameter(SharingFrame $frame) { + return [ + 'type' => 'circle', + 'id' => $frame->getCircleId(), + 'name' => $frame->getCircleName(), + 'link' => self::generateLink($frame->getCircleId()) + ]; + } }
\ No newline at end of file diff --git a/lib/IBroadcaster.php b/lib/IBroadcaster.php index dc61e621..df7f5868 100644 --- a/lib/IBroadcaster.php +++ b/lib/IBroadcaster.php @@ -4,6 +4,7 @@ namespace OCA\Circles; +use OCA\Circles\Model\Member; use OCA\Circles\Model\SharingFrame; interface IBroadcaster { @@ -15,7 +16,7 @@ interface IBroadcaster { /** - * broadcast a creation of $share to $circleId. + * broadcast a creation of a Share to a circle. * * @param SharingFrame $frame * @@ -25,7 +26,7 @@ interface IBroadcaster { /** - * broadcast a creation of $share to $userId. + * broadcast a creation of a Share to a $userId. * * @param SharingFrame $frame * @param string $userId diff --git a/lib/Model/BaseMember.php b/lib/Model/BaseMember.php index bec1e431..c1235347 100644 --- a/lib/Model/BaseMember.php +++ b/lib/Model/BaseMember.php @@ -27,6 +27,7 @@ namespace OCA\Circles\Model; use OC\L10N\L10N; +use OCA\Circles\Service\MiscService; class BaseMember implements \JsonSerializable { @@ -146,9 +147,7 @@ class BaseMember implements \JsonSerializable { if ($userId !== null && $userId !== '') { $this->setDisplayName( - \OC::$server->getUserManager() - ->get($userId) - ->getDisplayName() + MiscService::staticGetDisplayName($userId) ); } diff --git a/lib/Model/Circle.php b/lib/Model/Circle.php index a456e323..d249d716 100644 --- a/lib/Model/Circle.php +++ b/lib/Model/Circle.php @@ -68,22 +68,22 @@ class Circle extends BaseCircle implements \JsonSerializable { public function jsonSerialize() { $json = array( - 'id' => $this->getId(), - 'name' => $this->getName(), - 'owner' => $this->getOwner(), - 'user' => $this->getViewer(), - 'group' => $this->getGroupViewer(), - 'viewer' => $this->getHigherViewer(), - 'description' => $this->getDescription(), - 'settings' => $this->getSettings(), - 'type' => $this->getType(), - 'creation' => $this->getCreation(), - 'typeString' => $this->getTypeString(), - 'typeLongString' => $this->getTypeLongString(), - 'unique_id' => $this->getUniqueId($this->fullJson), - 'members' => $this->getMembers(), - 'groups' => $this->getGroups(), - 'links' => $this->getLinks() + 'id' => $this->getId(), + 'name' => $this->getName(), + 'owner' => $this->getOwner(), + 'user' => $this->getViewer(), + 'group' => $this->getGroupViewer(), + 'viewer' => $this->getHigherViewer(), + 'description' => $this->getDescription(), + 'settings' => $this->getSettings(), + 'type' => $this->getType(), + 'creation' => $this->getCreation(), + 'type_string' => $this->getTypeString(), + 'type_long_string' => $this->getTypeLongString(), + 'unique_id' => $this->getUniqueId($this->fullJson), + 'members' => $this->getMembers(), + 'groups' => $this->getGroups(), + 'links' => $this->getLinks() ); if ($this->lightJson) { @@ -168,7 +168,6 @@ class Circle extends BaseCircle implements \JsonSerializable { } - /** * @throws CircleTypeNotValidException */ diff --git a/lib/Model/SharingFrame.php b/lib/Model/SharingFrame.php index 83105de6..398d520d 100644 --- a/lib/Model/SharingFrame.php +++ b/lib/Model/SharingFrame.php @@ -42,6 +42,9 @@ class SharingFrame implements \JsonSerializable { /** @var string */ private $circleName; + /** @var int */ + private $circleType; + /** @var string */ private $author; @@ -111,6 +114,21 @@ class SharingFrame implements \JsonSerializable { /** + * @param int $circleType + */ + public function setCircleType($circleType) { + $this->circleType = $circleType; + } + + /** + * @return int + */ + public function getCircleType() { + return $this->circleType; + } + + + /** * @param string $author */ public function setAuthor($author) { @@ -273,11 +291,12 @@ class SharingFrame implements \JsonSerializable { } } - + public function jsonSerialize() { return array( 'circle_id' => $this->getCircleId(), 'circle_name' => $this->getCircleName(), + 'circle_type' => $this->getCircleType(), 'unique_id' => $this->getUniqueId(), 'source' => $this->getSource(), 'type' => $this->getType(), @@ -292,7 +311,7 @@ class SharingFrame implements \JsonSerializable { public static function fromJSON($json) { $arr = json_decode($json, true); - if (!key_exists('source', $arr)) { + if (!is_array($arr) || !key_exists('source', $arr)) { return null; } @@ -301,6 +320,10 @@ class SharingFrame implements \JsonSerializable { if (key_exists('circle_name', $arr)) { $share->setCircleName($arr['circle_name']); } + if (key_exists('circle_type', $arr)) { + $share->setCircleType($arr['circle_type']); + } + if (key_exists('headers', $arr)) { $share->setHeaders($arr['headers']); @@ -318,4 +341,5 @@ class SharingFrame implements \JsonSerializable { return $share; } -}
\ No newline at end of file +} + diff --git a/lib/Service/BroadcastService.php b/lib/Service/BroadcastService.php index 59fba597..d93ae358 100644 --- a/lib/Service/BroadcastService.php +++ b/lib/Service/BroadcastService.php @@ -27,10 +27,12 @@ namespace OCA\Circles\Service; +use Exception; use OCA\Circles\Db\CirclesRequest; use OCA\Circles\Db\MembersRequest; use OCA\Circles\Exceptions\BroadcasterIsNotCompatibleException; use OCA\Circles\IBroadcaster; +use OCA\Circles\Model\Circle; use OCA\Circles\Model\Member; use OCA\Circles\Model\SharingFrame; @@ -81,10 +83,14 @@ class BroadcastService { * broadcast the SharingFrame item using a IBroadcaster. * The broadcast is usually set by the app that created the SharingFrame item. * + * If the circle is not a Personal Circle, we first call createShareToCircle() + * Then for each members of the circle, we call createShareToUser() + * If the circle is a Personal Circle, we don't send data about the SharingFrame but null. + * * @param string $broadcast * @param SharingFrame $frame * - * @throws BroadcasterIsNotCompatibleException + * @throws Exception */ public function broadcastFrame($broadcast, SharingFrame $frame) { @@ -92,16 +98,27 @@ class BroadcastService { return; } - $broadcaster = \OC::$server->query((string)$broadcast); - if (!($broadcaster instanceof IBroadcaster)) { - throw new BroadcasterIsNotCompatibleException(); - } - - $broadcaster->init(); - $broadcaster->createShareToCircle($frame); - $users = $this->membersRequest->forceGetMembers($frame->getCircleId(), Member::LEVEL_MEMBER, true); - foreach ($users AS $user) { - $broadcaster->createShareToUser($frame, $user->getUserId()); + try { + $broadcaster = \OC::$server->query((string)$broadcast); + if (!($broadcaster instanceof IBroadcaster)) { + throw new BroadcasterIsNotCompatibleException(); + } + + $circle = $this->circlesRequest->forceGetCircle($frame->getCircleId()); + + $broadcaster->init(); + if ($circle->getType() !== Circle::CIRCLES_PERSONAL) { + $broadcaster->createShareToCircle($frame); + } + + $users = $this->membersRequest->forceGetMembers( + $circle->getUniqueId(), Member::LEVEL_MEMBER, true + ); + foreach ($users AS $user) { + $broadcaster->createShareToUser($frame, $user->getUserId()); + } + } catch (Exception $e) { + throw $e; } } diff --git a/lib/Service/FederatedService.php b/lib/Service/FederatedService.php index 4015c2e8..98b6a877 100644 --- a/lib/Service/FederatedService.php +++ b/lib/Service/FederatedService.php @@ -718,6 +718,7 @@ class FederatedService { $frame->setCircleId($link->getCircleId()); $frame->setCircleName($circle->getName()); + $frame->setCircleType($circle->getType()); $this->circlesRequest->saveFrame($frame); $this->broadcastService->broadcastFrame($frame->getHeader('broadcast'), $frame); diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index 90371019..e504815b 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -68,6 +68,33 @@ class MiscService { * @return string * @throws NoUserException */ + public static function staticGetDisplayName($userId, $noException = false) { + $user = \OC::$server->getUserManager() + ->get($userId); + if ($user === null) { + if ($noException) { + return $userId; + } else { + throw new NoUserException(); + } + } + + return $user->getDisplayName(); + } + + + /** + * return Display Name if user exists and display name exists. + * returns Exception if user does not exist. + * + * However, with noException set to true, will return userId even if user does not exist + * + * @param $userId + * @param bool $noException + * + * @return string + * @throws NoUserException + */ public function getDisplayName($userId, $noException = false) { $user = $this->userManager->get($userId); if ($user === null) { @@ -80,4 +107,5 @@ class MiscService { return $user->getDisplayName(); } -}
\ No newline at end of file +} + diff --git a/lib/Service/SharesService.php b/lib/Service/SharesService.php index 507bb0a6..8f5a8145 100644 --- a/lib/Service/SharesService.php +++ b/lib/Service/SharesService.php @@ -145,6 +145,7 @@ class SharesService { $frame->setHeader('broadcast', (string)$broadcast); $frame->generateUniqueId(); $frame->setCircleName($circle->getName()); + $frame->setCircleType($circle->getType()); } catch (Exception $e) { throw new $e; |