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

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2020-01-29 18:41:30 +0300
committerGitHub <noreply@github.com>2020-01-29 18:41:30 +0300
commitdc29c583b94433c51605d645a4397d1324f131fd (patch)
tree6bf5107fcb06caa2d4c18c8479f014bdf9dc2f39
parenta6e66f17078dc111a112ca446037e13ddb83b739 (diff)
parent6b23f5c63ed119e6f41c339c2af31639ef1228a5 (diff)
Merge pull request #798 from nextcloud/addDisplayNamesv1.2.0-beta4
Add display names
-rw-r--r--lib/Controller/CommentController.php7
-rw-r--r--lib/Controller/SystemController.php13
-rw-r--r--lib/Db/Comment.php13
-rw-r--r--lib/Db/Poll.php13
-rw-r--r--lib/Db/Share.php12
-rw-r--r--lib/Db/Vote.php14
-rw-r--r--lib/Model/Acl.php16
-rw-r--r--lib/Service/MailService.php10
-rw-r--r--src/js/components/Base/ParticipantsList.vue5
-rw-r--r--src/js/components/Base/UserDiv.vue36
-rw-r--r--src/js/components/Comments/CommentAdd.vue12
-rw-r--r--src/js/components/Comments/Comments.vue2
-rw-r--r--src/js/components/SideBar/SideBarTabShare.vue4
-rw-r--r--src/js/components/VoteTable/VoteTable.vue19
-rw-r--r--src/js/store/modules/votes.js38
15 files changed, 158 insertions, 56 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/lib/Service/MailService.php b/lib/Service/MailService.php
index 4031d947..883015bb 100644
--- a/lib/Service/MailService.php
+++ b/lib/Service/MailService.php
@@ -164,7 +164,7 @@ class MailService {
),
'link' => $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute(
- 'polls.page.polls',
+ 'polls.page.indexvote',
array('id' => $share->getPollId())
)
)
@@ -183,7 +183,7 @@ class MailService {
'language' => $defaultLang,
'link' => $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute(
- 'polls.page.vote_public',
+ 'polls.page.vote_publicpublic',
array('token' => $share->getToken())
)
)
@@ -202,7 +202,7 @@ class MailService {
'language' => $defaultLang,
'link' => $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute(
- 'polls.page.vote_public',
+ 'polls.page.vote_publicpublic',
array('token' => $share->getToken())
)
)
@@ -228,7 +228,7 @@ class MailService {
'language' => $this->config->getUserValue($share->getUserId(), 'core', 'lang'),
'link' => $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute(
- 'polls.page.polls', ['id' => $share->getPollId()]
+ 'polls.page.indexvote', ['id' => $share->getPollId()]
)
)
);
@@ -327,7 +327,7 @@ class MailService {
$url = $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute(
- 'polls.page.polls',
+ 'polls.page.indexvote',
array('id' => $subscription->getPollId())
)
);
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/CommentAdd.vue b/src/js/components/Comments/CommentAdd.vue
index 984cb978..65f7c7d4 100644
--- a/src/js/components/Comments/CommentAdd.vue
+++ b/src/js/components/Comments/CommentAdd.vue
@@ -22,13 +22,15 @@
<template lang="html">
<div class="comment">
- <user-div :user-id="currentUser" />
+ <user-div :user-id="currentUser" :display-name="$store.state.acl.DisplayName" />
- <form class="commentAdd" name="send-comment" @submit="writeComment">
- <input v-model="comment" class="message" data-placeholder="New Comment ...">
- <button v-show="!isLoading" type="submit" class="submit-comment icon-confirm" />
+ <div class="commentAdd" name="send-comment" @submit="writeComment">
+ <input v-model="comment" class="message" data-placeholder="New Comment ..."
+ @keyup.enter="writeComment">
+ <button v-show="!isLoading" class="submit-comment icon-confirm"
+ @click="writeComment" />
<span v-show="isLoading" class="icon-loading-small" style="float:right;" />
- </form>
+ </div>
</div>
</template>
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) {