diff options
author | dartcafe <github@dartcafe.de> | 2020-01-29 18:27:47 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-01-29 18:27:47 +0300 |
commit | 601c8f197cea95ad8807ed19a72c8051e83d75b0 (patch) | |
tree | 5063e024c8a1f61677d62d1ab32ff7816c7cf4c8 | |
parent | a6e66f17078dc111a112ca446037e13ddb83b739 (diff) |
Add displayname for LDAP users #715
-rw-r--r-- | lib/Controller/CommentController.php | 7 | ||||
-rw-r--r-- | lib/Controller/SystemController.php | 13 | ||||
-rw-r--r-- | lib/Db/Comment.php | 13 | ||||
-rw-r--r-- | lib/Db/Poll.php | 13 | ||||
-rw-r--r-- | lib/Db/Share.php | 12 | ||||
-rw-r--r-- | lib/Db/Vote.php | 14 | ||||
-rw-r--r-- | lib/Model/Acl.php | 16 | ||||
-rw-r--r-- | src/js/components/Base/ParticipantsList.vue | 5 | ||||
-rw-r--r-- | src/js/components/Base/UserDiv.vue | 36 | ||||
-rw-r--r-- | src/js/components/Comments/Comments.vue | 2 | ||||
-rw-r--r-- | src/js/components/SideBar/SideBarTabShare.vue | 4 | ||||
-rw-r--r-- | src/js/components/VoteTable/VoteTable.vue | 19 | ||||
-rw-r--r-- | src/js/store/modules/votes.js | 38 |
13 files changed, 146 insertions, 46 deletions
diff --git a/lib/Controller/CommentController.php b/lib/Controller/CommentController.php index a2e864df..d37836eb 100644 --- a/lib/Controller/CommentController.php +++ b/lib/Controller/CommentController.php @@ -142,11 +142,14 @@ class CommentController extends Controller { * @NoAdminRequired * @NoCSRFRequired * @param int $pollId + * @param string $userId * @param string $message * @return DataResponse */ public function write($pollId, $userId, $message) { + $this->logger->alert('write'); if (!\OC::$server->getUserSession()->isLoggedIn() && !$this->acl->getFoundByToken()) { + $this->logger->alert('not allowed ' . json_encode(\OC::$server->getUserSession()->isLoggedIn())); return new DataResponse(null, Http::STATUS_UNAUTHORIZED); } @@ -155,7 +158,6 @@ class CommentController extends Controller { } if ($this->acl->getAllowComment()) { - // code... $comment = new Comment(); $comment->setPollId($pollId); $comment->setUserId($userId); @@ -166,13 +168,16 @@ class CommentController extends Controller { try { $comment = $this->mapper->insert($comment); } catch (\Exception $e) { + $this->logger->alert('conflict ' . json_encode($e)); return new DataResponse($e, Http::STATUS_CONFLICT); } } else { + $this->logger->alert('unauthorized '); return new DataResponse(null, Http::STATUS_UNAUTHORIZED); } + $this->logger->alert('ok '. json_encode($comment)); return new DataResponse($comment, Http::STATUS_OK); } diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index 933b925f..3b63d314 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -255,6 +255,19 @@ class SystemController extends Controller { 'list' => $list ], Http::STATUS_OK); } + + public function getDisplayName() { + $this->userManager = \OC::$server->getUserManager(); + + if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { + return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); + } else { + return $this->userId; + } + } + + + // // // /** diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php index 0226ffb1..4935c077 100644 --- a/lib/Db/Comment.php +++ b/lib/Db/Comment.php @@ -27,6 +27,7 @@ namespace OCA\Polls\Db; use JsonSerializable; +use OCP\IUser; use OCP\AppFramework\Db\Entity; /** @@ -76,7 +77,17 @@ class Comment extends Entity implements JsonSerializable { 'userId' => $this->userId, 'dt' => $this->dt, 'timestamp' => intval($timestamp), - 'comment' => $this->comment + 'comment' => $this->comment, + 'displayName' => $this->getDisplayName() ]; } + + private function getDisplayName() { + + if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { + return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); + } else { + return $this->userId; + } + } } diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php index ef8ffc28..e98c4124 100644 --- a/lib/Db/Poll.php +++ b/lib/Db/Poll.php @@ -27,6 +27,7 @@ namespace OCA\Polls\Db; use JsonSerializable; +use OCP\IUser; use OCP\AppFramework\Db\Entity; /** @@ -131,7 +132,17 @@ class Poll extends Entity implements JsonSerializable { 'settings' => $this->settings, 'voteLimit' => intval($this->voteLimit), 'showResults' => $this->showResults, - 'adminAccess' => intVal($this->adminAccess) + 'adminAccess' => intVal($this->adminAccess), + 'ownerDisplayName' => $this->getDisplayName() ]; } + + private function getDisplayName() { + + if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) { + return \OC::$server->getUserManager()->get($this->owner)->getDisplayName(); + } else { + return $this->owner; + } + } } diff --git a/lib/Db/Share.php b/lib/Db/Share.php index d290f2ab..d9e9587c 100644 --- a/lib/Db/Share.php +++ b/lib/Db/Share.php @@ -25,6 +25,7 @@ namespace OCA\Polls\Db; use JsonSerializable; +use OCP\IUser; use OCP\AppFramework\Db\Entity; /** @@ -66,8 +67,17 @@ class Share extends Entity implements JsonSerializable { 'type' => $this->type, 'pollId' => intval($this->pollId), 'userId' => $this->userId, - 'userEmail' => $this->userEmail + 'userEmail' => $this->userEmail, + 'displayName' => $this->getDisplayName() ]; + } + + private function getDisplayName() { + if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { + return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); + } else { + return $this->userId; + } } } diff --git a/lib/Db/Vote.php b/lib/Db/Vote.php index b890e55d..b6013467 100644 --- a/lib/Db/Vote.php +++ b/lib/Db/Vote.php @@ -26,7 +26,7 @@ namespace OCA\Polls\Db; use JsonSerializable; - +use OCP\IUser; use OCP\AppFramework\Db\Entity; /** @@ -65,7 +65,17 @@ class Vote extends Entity implements JsonSerializable { 'userId' => $this->userId, 'voteOptionId' => intval($this->voteOptionId), 'voteOptionText' => $this->voteOptionText, - 'voteAnswer' => $this->voteAnswer + 'voteAnswer' => $this->voteAnswer, + 'displayName' => $this->getDisplayName() ]; } + + private function getDisplayName() { + + if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { + return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); + } else { + return $this->userId; + } + } } diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php index 315091a3..5b7356e3 100644 --- a/lib/Model/Acl.php +++ b/lib/Model/Acl.php @@ -30,6 +30,7 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\IGroupManager; use OCP\ILogger; +use OCP\IUser; use OCA\Polls\Db\Poll; use OCA\Polls\Db\Share; use OCA\Polls\Db\PollMapper; @@ -117,6 +118,20 @@ class Acl implements JsonSerializable { * @NoAdminRequired * @return string */ + public function getDisplayName() { + $this->userManager = \OC::$server->getUserManager(); + + if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { + return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); + } else { + return $this->userId; + } + } + + /** + * @NoAdminRequired + * @return string + */ public function setUserId($userId): Acl { $this->userId = $userId; return $this; @@ -389,6 +404,7 @@ class Acl implements JsonSerializable { public function jsonSerialize(): array { return [ 'userId' => $this->getUserId(), + 'displayName' => $this->getDisplayName(), 'loggedIn' => $this->getLoggedIn(), 'pollId' => $this->getPollId(), 'token' => $this->getToken(), diff --git a/src/js/components/Base/ParticipantsList.vue b/src/js/components/Base/ParticipantsList.vue index ac160d59..c2acccbc 100644 --- a/src/js/components/Base/ParticipantsList.vue +++ b/src/js/components/Base/ParticipantsList.vue @@ -30,9 +30,10 @@ </h2> <div v-if="participantsVoted.length" class="participants"> <userDiv v-for="(participant) in participantsVoted" - :key="participant" + :key="participant.userId" :hide-names="true" - :user-id="participant" + :user-id="participant.userId" + :display-name="participant.displayName" type="user" /> </div> </div> diff --git a/src/js/components/Base/UserDiv.vue b/src/js/components/Base/UserDiv.vue index debffa9a..484acca2 100644 --- a/src/js/components/Base/UserDiv.vue +++ b/src/js/components/Base/UserDiv.vue @@ -27,13 +27,13 @@ </div> <Avatar :disable-menu="true" :user="userId" :is-guest="!Boolean(OC.currentUser)" - :display-name="computedDisplayName" + :display-name="displayName" :is-no-user="isNoUser" /> <div class="avatar" :class="iconClass" /> <div v-if="!hideNames" class="user-name"> - {{ computedDisplayName }} + {{ displayName }} </div> </div> </template> @@ -100,23 +100,23 @@ export default { } else { return '' } - }, - - computedDisplayName() { - let value = this.displayName - - if (!this.displayName) { - if (this.type === 'user') { - value = this.userId - } else if (this.type === 'group') { - value = value + ' (' + t('polls', 'Group') + ')' - } else { - value = this.userId - } - } - return value - } + + // computedDisplayName() { + // let value = this.displayName + // + // if (!this.displayName) { + // if (this.type === 'user') { + // value = this.userId + // } else if (this.type === 'group') { + // value = value + ' (' + t('polls', 'Group') + ')' + // } else { + // value = this.userId + // } + // } + // return value + + // } } } diff --git a/src/js/components/Comments/Comments.vue b/src/js/components/Comments/Comments.vue index 24f118bb..238fb9b2 100644 --- a/src/js/components/Comments/Comments.vue +++ b/src/js/components/Comments/Comments.vue @@ -28,7 +28,7 @@ tag="ul"> <li v-for="(comment) in sortedList" :key="comment.id"> <div class="comment-item"> - <user-div :user-id="comment.userId" /> + <user-div :user-id="comment.userId" :display-name="comment.displayName" /> <Actions v-if="comment.userId === acl.userId"> <ActionButton icon="icon-delete" @click="deleteComment(comment)"> {{ t('polls', 'Delete comment') }} diff --git a/src/js/components/SideBar/SideBarTabShare.vue b/src/js/components/SideBar/SideBarTabShare.vue index 9aef6c92..a97ce6ac 100644 --- a/src/js/components/SideBar/SideBarTabShare.vue +++ b/src/js/components/SideBar/SideBarTabShare.vue @@ -169,7 +169,9 @@ export default { shareDisplayName(share) { let displayName = '' - if (share.type === 'user' || share.type === 'contact' || share.type === 'external') { + if (share.type === 'user') { + displayName = share.displayName + } else if (share.type === 'contact' || share.type === 'external') { displayName = share.userId if (share.userEmail) { displayName = displayName + ' (' + share.userEmail + ')' diff --git a/src/js/components/VoteTable/VoteTable.vue b/src/js/components/VoteTable/VoteTable.vue index 4cca0281..3145f079 100644 --- a/src/js/components/VoteTable/VoteTable.vue +++ b/src/js/components/VoteTable/VoteTable.vue @@ -31,16 +31,17 @@ :poll-type="poll.type" /> </div> - <div v-for="(participant) in participants" :key="participant" :class="{currentuser: (participant === currentUser) }"> - <UserDiv :key="participant" + <div v-for="(participant) in participants" :key="participant.userId" :class="{currentuser: (participant.userId === currentUser) }"> + <UserDiv :key="participant.userId" class="sticky" - :class="{currentuser: (participant === currentUser) }" - :user-id="participant" /> + :class="{currentuser: (participant.userId === currentUser) }" + :user-id="participant.userId" + :display-name="participant.displayName" /> <VoteTableItem v-for="(option) in sortedOptions" :key="option.id" - :user-id="participant" + :user-id="participant.userId" :option="option" - @voteClick="setVote(option, participant)" /> + @voteClick="setVote(option, participant.userId)" /> </div> </div> </template> @@ -74,14 +75,14 @@ export default { }, methods: { - setVote(option, participant) { + setVote(option, userId) { this.$store .dispatch('setVoteAsync', { option: option, - userId: participant, + userId: userId, setTo: this.$store.getters.getNextAnswer({ option: option, - userId: participant + userId: userId }) }) .then(() => { diff --git a/src/js/store/modules/votes.js b/src/js/store/modules/votes.js index 0c37b334..b2b6e1ab 100644 --- a/src/js/store/modules/votes.js +++ b/src/js/store/modules/votes.js @@ -64,21 +64,42 @@ const getters = { }, participantsVoted: (state, getters) => { - return [...new Set(state.list.map(item => item.userId))] + // return [...new Set(state.list.map(item => item.userId))] + const list = [] + const map = new Map() + for (const item of state.list) { + if (!map.has(item.userId)) { + map.set(item.userId, true) + list.push({ + userId: item.userId, + displayName: item.displayName + }) + } + } + return list }, participants: (state, getters, rootState) => { const list = [] - state.list.forEach(function(vote) { - if (!list.includes(vote.userId)) { - list.push(vote.userId) + const map = new Map() + for (const item of state.list) { + if (!map.has(item.userId)) { + map.set(item.userId, true) + list.push({ + userId: item.userId, + displayName: item.displayName, + voted: true + }) } - }) - - if (!list.includes(rootState.acl.userId) && rootState.acl.userId && rootState.acl.allowVote) { - list.push(rootState.acl.userId) } + if (!map.has(rootState.acl.userId) && rootState.acl.userId && rootState.acl.allowVote) { + list.push({ + userId: rootState.acl.userId, + displayName: rootState.acl.displayName, + voted: false + }) + } return list }, @@ -152,7 +173,6 @@ const actions = { }, setVoteAsync(context, payload) { - let endPoint = 'apps/polls/vote/set/' if (context.rootState.acl.foundByToken) { |