diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2017-08-24 17:27:08 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2017-08-24 17:27:08 +0300 |
commit | 615c9f4fe7bf742a3a253044d015e9d3f31affae (patch) | |
tree | 8e1a991b4a456065c79a83ba11c35915ed951a28 | |
parent | 7125932e3c6f6ff905298237a273f57fdd18571b (diff) |
include Contact to Circles
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | js/circles.app.results.members.js | 51 | ||||
-rw-r--r-- | lib/Api/Sharees.php | 4 | ||||
-rw-r--r-- | lib/Api/v1/Circles.php | 2 | ||||
-rw-r--r-- | lib/Circles/FileSharingBroadcaster.php | 2 | ||||
-rw-r--r-- | lib/Controller/MembersController.php | 71 | ||||
-rw-r--r-- | lib/Db/MembersRequest.php | 6 | ||||
-rw-r--r-- | lib/Model/BaseMember.php | 10 | ||||
-rw-r--r-- | lib/Service/MembersService.php | 110 | ||||
-rw-r--r-- | lib/Service/MiscService.php | 54 |
9 files changed, 193 insertions, 117 deletions
diff --git a/js/circles.app.results.members.js b/js/circles.app.results.members.js index a8bb90d4..00589e5d 100644 --- a/js/circles.app.results.members.js +++ b/js/circles.app.results.members.js @@ -106,7 +106,6 @@ var resultMembers = { }); $('.members_search').on('click', function () { - //curr.searchUserSelected = $(this).attr('searchresult'); var ident = $(this).attr('data-ident'); var type = $(this).attr('data-type'); @@ -149,7 +148,7 @@ var resultMembers = { resultMembers.addMemberUserResult(result); resultMembers.addMemberGroupResult(result); resultMembers.addMemberMailResult(result); - // resultMembers.addMemberContactResult(result); + resultMembers.addMemberContactResult(result); }, @@ -166,14 +165,15 @@ var resultMembers = { if (result.status === 1) { OCA.notification.onSuccess( t('circles', "The member '{name}' was added to the circle", - {name: result.name})); + {name: result.ident})); nav.displayMembers(result.members); return; } + OCA.notification.onFail( t('circles', "The member '{name}' could not be added to the circle", - {name: result.name}) + + {name: result.ident}) + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); }, @@ -186,14 +186,33 @@ var resultMembers = { if (result.status === 1) { OCA.notification.onSuccess( t('circles', "The email address '{email}' was added to the circle", - {email: result.email})); + {email: result.ident})); nav.displayMembers(result.members); return; } OCA.notification.onFail( t('circles', "The email address '{email}' could not be added to the circle", - {email: result.email}) + + {email: result.ident}) + + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); + }, + + addMemberContactResult: function (result) { + if (result.user_type !== define.typeContact) { + return; + } + + if (result.status === 1) { + OCA.notification.onSuccess( + t('circles', "The contact '{contact}' was added to the circle", + {contact: result.ident})); + + nav.displayMembers(result.members); + return; + } + OCA.notification.onFail( + t('circles', "The contact '{contact}' could not be added to the circle", + {contact: result.ident}) + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); }, @@ -203,14 +222,14 @@ var resultMembers = { if (result.status === 1) { OCA.notification.onSuccess( t('circles', "The member '{name}' was invited to the circle", - {name: result.name})); + {name: result.ident})); nav.displayMembers(result.members); return; } OCA.notification.onFail( t('circles', "The member '{name}' could not be invited to the circle", - {name: result.name}) + + {name: result.ident}) + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); }, @@ -229,14 +248,14 @@ var resultMembers = { if (result.status === 1) { OCA.notification.onSuccess( t('circles', "Members of the group '{name}' were added to the circle", - {name: result.name})); + {name: result.ident})); nav.displayMembers(result.members); return; } OCA.notification.onFail( t('circles', "Members of the group '{name}' could not be added to the circle", - {name: result.name}) + + {name: result.ident}) + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); }, @@ -247,14 +266,14 @@ var resultMembers = { if (result.status === 1) { OCA.notification.onSuccess( t('circles', "Members of the group '{name}' were invited to the circle", - {name: result.name})); + {name: result.ident})); nav.displayMembers(result.members); return; } OCA.notification.onFail( t('circles', "Members of the group '{name}' could not be invited to the circle", - {name: result.name}) + + {name: result.ident}) + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); }, @@ -271,13 +290,13 @@ var resultMembers = { }); OCA.notification.onSuccess( t('circles', "The member '{name}' was removed from the circle", - {name: result.name})); + {name: result.ident})); return; } OCA.notification.onFail( t('circles', "The member '{name}' could not be removed from the circle", - {name: result.name}) + + {name: result.ident}) + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); }, @@ -286,7 +305,7 @@ var resultMembers = { if (result.status === 1) { OCA.notification.onSuccess( t('circles', "Member '{name}' updated", - {name: result.name})); + {name: result.ident})); nav.displayMembers(result.members); return; @@ -294,7 +313,7 @@ var resultMembers = { nav.displayMembers(''); OCA.notification.onFail( - t('circles', "The member '{name}' could not be updated", {name: result.name}) + + t('circles', "The member '{name}' could not be updated", {name: result.ident}) + ': ' + ((result.error) ? result.error : t('circles', 'no error message'))); } diff --git a/lib/Api/Sharees.php b/lib/Api/Sharees.php index d308422f..c02118ae 100644 --- a/lib/Api/Sharees.php +++ b/lib/Api/Sharees.php @@ -84,9 +84,9 @@ class Sharees { 'shareType' => Share::SHARE_TYPE_CIRCLE, 'shareWith' => $entry->getUniqueId(), 'circleInfo' => $entry->getInfo(), - 'circleOwner' => MiscService::staticGetDisplayName( + 'circleOwner' => MiscService::getDisplay( $entry->getOwner() - ->getUserId() + ->getUserId(), Member::TYPE_USER ) ], ]; diff --git a/lib/Api/v1/Circles.php b/lib/Api/v1/Circles.php index 9a9ffd2a..3cd29a2d 100644 --- a/lib/Api/v1/Circles.php +++ b/lib/Api/v1/Circles.php @@ -401,7 +401,7 @@ class Circles { if ($frame->getCloudId() !== null) { $name = $frame->getAuthor() . '@' . $frame->getCloudId(); } else { - $name = MiscService::staticGetDisplayName($frame->getAuthor()); + $name = MiscService::getDisplay($frame->getAuthor(), Member::TYPE_USER); } return [ diff --git a/lib/Circles/FileSharingBroadcaster.php b/lib/Circles/FileSharingBroadcaster.php index 7c01e140..19f6cab2 100644 --- a/lib/Circles/FileSharingBroadcaster.php +++ b/lib/Circles/FileSharingBroadcaster.php @@ -187,7 +187,7 @@ class FileSharingBroadcaster implements IBroadcaster { ); $this->sendMail( $share->getNode() - ->getName(), $link, MiscService::staticGetDisplayName($share->getSharedBy()), + ->getName(), $link, MiscService::getDisplay($share->getSharedBy(), Member::TYPE_USER), $circleName, $email ); diff --git a/lib/Controller/MembersController.php b/lib/Controller/MembersController.php index 336d4369..bece845c 100644 --- a/lib/Controller/MembersController.php +++ b/lib/Controller/MembersController.php @@ -27,6 +27,7 @@ namespace OCA\Circles\Controller; use OCA\Circles\Model\Member; +use OCA\Circles\Service\MiscService; use OCP\AppFramework\Http\DataResponse; class MembersController extends BaseController { @@ -89,7 +90,7 @@ class MembersController extends BaseController { 'circle_id' => $uniqueId, 'user_id' => $ident, 'user_type' => (int)$type, - 'name' => $this->miscService->getDisplayName($ident, true), + 'ident' => MiscService::getDisplay($ident, (int)$type), 'error' => $e->getMessage() ] ); @@ -100,7 +101,7 @@ class MembersController extends BaseController { 'circle_id' => $uniqueId, 'user_id' => $ident, 'user_type' => (int)$type, - 'name' => $this->miscService->getDisplayName($ident, true), + 'ident' => MiscService::getDisplay($ident, (int)$type), 'members' => $data ] ); @@ -142,39 +143,39 @@ class MembersController extends BaseController { // } - /** - * @NoAdminRequired - * @NoSubAdminRequired - * - * @param $uniqueId - * @param string $name - * - * @return DataResponse - */ - public function importFromGroup($uniqueId, $name) { - - try { - $data = $this->membersService->importMembersFromGroup($uniqueId, $name); - } catch (\Exception $e) { - return $this->fail( - [ - 'circle_id' => $uniqueId, - 'user_id' => $name, - 'name' => $this->miscService->getDisplayName($name, true), - 'error' => $e->getMessage() - ] - ); - } - - return $this->success( - [ - 'circle_id' => $uniqueId, - 'user_id' => $name, - 'name' => $this->miscService->getDisplayName($name, true), - 'members' => $data - ] - ); - } +// /** +// * @NoAdminRequired +// * @NoSubAdminRequired +// * +// * @param $uniqueId +// * @param string $name +// * +// * @return DataResponse +// */ +// public function importFromGroup($uniqueId, $name) { +// +// try { +// $data = $this->membersService->importMembersFromGroup($uniqueId, $name); +// } catch (\Exception $e) { +// return $this->fail( +// [ +// 'circle_id' => $uniqueId, +// 'user_id' => $name, +// 'name' => $this->miscService->getDisplayName($name, true), +// 'error' => $e->getMessage() +// ] +// ); +// } +// +// return $this->success( +// [ +// 'circle_id' => $uniqueId, +// 'user_id' => $name, +// 'name' => $this->miscService->getDisplayName($name, true), +// 'members' => $data +// ] +// ); +// } /** diff --git a/lib/Db/MembersRequest.php b/lib/Db/MembersRequest.php index 50045b89..c447f39e 100644 --- a/lib/Db/MembersRequest.php +++ b/lib/Db/MembersRequest.php @@ -29,7 +29,6 @@ namespace OCA\Circles\Db; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; -use OC\User\NoUserException; use OCA\Circles\Exceptions\MemberAlreadyExistsException; use OCA\Circles\Exceptions\MemberDoesNotExistException; use OCA\Circles\Model\Member; @@ -241,14 +240,9 @@ class MembersRequest extends MembersRequestBuilder { public function getFreshNewMember($circleUniqueId, $name, $type) { try { - if ($type === Member::TYPE_USER) { - $name = $this->miscService->getRealUserId($name); - } $member = $this->forceGetMember($circleUniqueId, $name, $type); - } catch (NoUserException $e) { - throw new NoUserException($this->l10n->t("This user does not exist")); } catch (MemberDoesNotExistException $e) { $member = new Member($name, $type, $circleUniqueId); $this->createMember($member); diff --git a/lib/Model/BaseMember.php b/lib/Model/BaseMember.php index 716c23ea..b499d774 100644 --- a/lib/Model/BaseMember.php +++ b/lib/Model/BaseMember.php @@ -137,11 +137,11 @@ class BaseMember implements \JsonSerializable { public function setUserId($userId) { $this->userId = $userId; - if ($this->getType() === Member::TYPE_USER) { - $this->setDisplayName(MiscService::staticGetDisplayName($userId, true)); - } else { - $this->setDisplayName($userId); - } +// if ($this->getType() === Member::TYPE_USER) { + $this->setDisplayName(MiscService::getDisplay($userId, $this->getType())); +// } else { +// $this->setDisplayName($userId); +// } return $this; } diff --git a/lib/Service/MembersService.php b/lib/Service/MembersService.php index 9a30ff50..df472999 100644 --- a/lib/Service/MembersService.php +++ b/lib/Service/MembersService.php @@ -27,6 +27,8 @@ namespace OCA\Circles\Service; +use Exception; +use OC\User\NoUserException; use OCA\Circles\Db\CirclesRequest; use OCA\Circles\Db\MembersRequest; use OCA\Circles\Exceptions\CircleTypeNotValidException; @@ -113,6 +115,7 @@ class MembersService { ->hasToBeModerator(); if (!$this->addMemberMassively($circle, $type, $ident)) { + $this->verifyIdentBasedOnItsType($ident, $type); $member = $this->membersRequest->getFreshNewMember($circleUniqueId, $ident, $type); $member->hasToBeInviteAble(); @@ -145,59 +148,64 @@ class MembersService { private function addMemberBasedOnItsType(Circle $circle, Member &$member) { $this->addLocalMember($circle, $member); $this->addEmailAddress($member); + $this->addContact($member); } /** - * @param Circle $circle - * @param Member $member + * @param string $ident + * @param int $type * - * @throws \Exception + * @throws Exception */ - public function addLocalMember(Circle $circle, Member $member) { + private function verifyIdentBasedOnItsType(&$ident, $type) { + try { + $this->verifyIdentLocalMember($ident, $type); + $this->verifyIdentContact($ident, $type); + } catch (Exception $e) { + throw $e; + } + } - if ($member->getType() !== Member::TYPE_USER) { + private function verifyIdentLocalMember(&$ident, $type) { + if ($type !== Member::TYPE_USER) { return; } - $member->inviteToCircle($circle->getType()); + try { + $ident = $this->miscService->getRealUserId($ident); + } catch (NoUserException $e) { + throw new NoUserException($this->l10n->t("This user does not exist")); + } + } + + + private function verifyIdentContact(&$ident, $type) { + if ($type !== Member::TYPE_CONTACT) { + return; + } + +// try { +// $ident = $this->miscService->getRealUserId($ident); +// } catch (NoUserException $e) { +// throw new NoUserException($this->l10n->t("This user does not exist")); +// } } /** * @param Circle $circle - * @param string $groupId + * @param Member $member * - * @return bool * @throws \Exception */ - private function addGroupMembers(Circle $circle, $groupId) { - - $group = \OC::$server->getGroupManager() - ->get($groupId); - if ($group === null) { - throw new GroupDoesNotExistException($this->l10n->t('This group does not exist')); - } - - foreach ($group->getUsers() as $user) { - try { - $member = - $this->membersRequest->getFreshNewMember( - $circle->getUniqueId(), $user->getUID(), Member::TYPE_USER - ); - $member->hasToBeInviteAble(); - - $member->inviteToCircle($circle->getType()); - $this->membersRequest->updateMember($member); + public function addLocalMember(Circle $circle, Member $member) { - $this->eventsService->onMemberNew($circle, $member); - } catch (MemberAlreadyExistsException $e) { - } catch (\Exception $e) { - throw $e; - } + if ($member->getType() !== Member::TYPE_USER) { + return; } - return true; + $member->inviteToCircle($circle->getType()); } @@ -206,7 +214,7 @@ class MembersService { * * @throws \Exception */ - public function addEmailAddress(Member $member) { + private function addEmailAddress(Member $member) { if ($member->getType() !== Member::TYPE_MAIL) { return; @@ -223,22 +231,29 @@ class MembersService { /** - * @param string $circleUniqueId - * @param string $groupId + * @param Member $member * - * @return array * @throws \Exception */ - public function importMembersFromGroup($circleUniqueId, $groupId) { + private function addContact(Member $member) { - try { - $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); - $circle->getHigherViewer() - ->hasToBeModerator(); - } catch (\Exception $e) { - throw $e; + if ($member->getType() !== Member::TYPE_CONTACT) { + return; } + $member->addMemberToCircle(); + } + + + /** + * @param Circle $circle + * @param string $groupId + * + * @return bool + * @throws \Exception + */ + private function addGroupMembers(Circle $circle, $groupId) { + $group = \OC::$server->getGroupManager() ->get($groupId); if ($group === null) { @@ -249,7 +264,7 @@ class MembersService { try { $member = $this->membersRequest->getFreshNewMember( - $circleUniqueId, $user->getUID(), Member::TYPE_USER + $circle->getUniqueId(), $user->getUID(), Member::TYPE_USER ); $member->hasToBeInviteAble(); @@ -263,9 +278,7 @@ class MembersService { } } - return $this->membersRequest->getMembers( - $circle->getUniqueId(), $circle->getHigherViewer() - ); + return true; } @@ -319,7 +332,8 @@ class MembersService { ); } - $member = $this->membersRequest->forceGetMember($circle->getUniqueId(), $name, $type); + $member = + $this->membersRequest->forceGetMember($circle->getUniqueId(), $name, $type); $member->levelHasToBeEditable(); if ($member->getLevel() !== $level) { if ($level === Member::LEVEL_OWNER) { diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index f8eca1f5..2ac7268c 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -27,6 +27,7 @@ namespace OCA\Circles\Service; use OC\User\NoUserException; +use OCA\Circles\Model\Member; use OCP\ILogger; use OCP\IUserManager; @@ -57,7 +58,6 @@ class MiscService { } - /** * return the real userId, with its real case * @@ -76,7 +76,6 @@ class MiscService { } - /** * return Display Name if user exists and display name exists. * returns Exception if user does not exist. @@ -84,12 +83,13 @@ class MiscService { * However, with noException set to true, will return userId even if user does not exist * * @param $userId + * @param int $type * @param bool $noException * * @return string * @throws NoUserException */ - public static function staticGetDisplayName($userId, $noException = false) { + public static function staticGetDisplayName($userId, $type = Member::TYPE_USER) { $user = \OC::$server->getUserManager() ->get($userId); if ($user === null) { @@ -105,6 +105,54 @@ class MiscService { /** + * @param string $ident + * @param int $type + * + * @return string + */ + public static function getDisplay($ident, $type) { + $display = $ident; + + self::getDisplayMember($display, $ident, $type); + self::getDisplayContact($display, $ident, $type); + + return $display; + } + + + /** + * @param string $display + * @param string $ident + * @param int $type + */ + private static function getDisplayMember(&$display, $ident, $type) { + if ($type !== Member::TYPE_USER) { + return; + } + + $user = \OC::$server->getUserManager() + ->get($ident); + if ($user !== null) { + $display = $user->getDisplayName(); + } + } + + + /** + * @param string $display + * @param string $ident + * @param int $type + */ + private static function getDisplayContact(&$display, $ident, $type) { + if ($type !== Member::TYPE_CONTACT) { + return; + } + + $display = 'Contaaaact'; + } + + + /** * return Display Name if user exists and display name exists. * returns Exception if user does not exist. * |