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-26 20:55:22 +0300
committerGitHub <noreply@github.com>2020-01-26 20:55:22 +0300
commit3b2695e62217acb084bd12c8ac9d4d6cad980972 (patch)
treeaa750cd5cefbb7a66f98d1e7332041697c71903f
parenta428b645d80b5f2d63e1fcfac0b8bfa5d0819dd4 (diff)
parent09e8d4b95f81340263504477392d2878a8cdbc1a (diff)
Merge pull request #786 from nextcloud/deleteCommentsv1.2.0-beta
Delete comments
-rw-r--r--appinfo/routes.php2
-rw-r--r--lib/Controller/CommentController.php69
-rw-r--r--lib/Db/CommentMapper.php19
-rw-r--r--src/js/components/Comments/Comments.vue26
-rw-r--r--src/js/store/modules/comments.js30
-rw-r--r--src/js/views/Vote.vue3
6 files changed, 130 insertions, 19 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index c5f42d6c..47b5c6d9 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -36,6 +36,8 @@ return [
['name' => 'comment#writeByToken', 'url' => '/comment/write/s/', 'verb' => 'POST'],
['name' => 'comment#get', 'url' => '/comments/get/{pollId}', 'verb' => 'GET'],
['name' => 'comment#write', 'url' => '/comment/write/', 'verb' => 'POST'],
+ ['name' => 'comment#delete', 'url' => '/comment/delete/', 'verb' => 'POST'],
+ ['name' => 'comment#deleteByToken', 'url' => '/comment/delete/s/', 'verb' => 'POST'],
['name' => 'vote#getByToken', 'url' => '/votes/get/s/{token}', 'verb' => 'GET'],
['name' => 'vote#setByToken', 'url' => '/vote/set/s/', 'verb' => 'POST'],
diff --git a/lib/Controller/CommentController.php b/lib/Controller/CommentController.php
index 071bbdc5..a2e864df 100644
--- a/lib/Controller/CommentController.php
+++ b/lib/Controller/CommentController.php
@@ -150,19 +150,29 @@ class CommentController extends Controller {
return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
}
- $comment = new Comment();
- $comment->setPollId($pollId);
- $comment->setUserId($userId);
- $comment->setComment($message);
- $comment->setDt(date('Y-m-d H:i:s'));
+ if (!$this->acl->getFoundByToken()) {
+ $this->acl->setPollId($pollId);
+ }
+ if ($this->acl->getAllowComment()) {
+ // code...
+ $comment = new Comment();
+ $comment->setPollId($pollId);
+ $comment->setUserId($userId);
+ $comment->setComment($message);
+ $comment->setDt(date('Y-m-d H:i:s'));
- try {
- $comment = $this->mapper->insert($comment);
- } catch (\Exception $e) {
- return new DataResponse($e, Http::STATUS_CONFLICT);
+
+ try {
+ $comment = $this->mapper->insert($comment);
+ } catch (\Exception $e) {
+ return new DataResponse($e, Http::STATUS_CONFLICT);
+ }
+ } else {
+ return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
}
+
return new DataResponse($comment, Http::STATUS_OK);
}
@@ -181,11 +191,12 @@ class CommentController extends Controller {
try {
$this->acl->setToken($token);
+ return $this->write($this->acl->getPollId(), $this->acl->getUserId(), $message);
+
} catch (DoesNotExistException $e) {
return new DataResponse($e, Http::STATUS_NOT_FOUND);
}
- return $this->write($this->acl->getPollId(), $this->acl->getUserId(), $message);
}
@@ -199,17 +210,49 @@ class CommentController extends Controller {
* @return DataResponse
*/
public function delete($comment) {
- if (\OC::$server->getUserSession()->isLoggedIn()) {
+ if (!\OC::$server->getUserSession()->isLoggedIn() && !$this->acl->getFoundByToken()) {
return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
}
+ if (!$this->acl->getFoundByToken()) {
+ $this->acl->setPollId($comment['pollId']);
+ }
+
try {
- $comment = $this->mapper->delete($comment['id']);
+ if ( $comment['userId'] === $this->acl->getUserId() ) {
+ $comment = $this->mapper->find($comment['id']);
+ $comment = $this->mapper->delete($comment);
+ }
} catch (\Exception $e) {
return new DataResponse($e, Http::STATUS_CONFLICT);
}
- return new DataResponse($comment, Http::STATUS_OK);
+ return new DataResponse(['comment' => $comment], Http::STATUS_OK);
}
+
+ /**
+ * writeByToken
+ * @NoAdminRequired
+ * @PublicPage
+ * @NoCSRFRequired
+ * @param Array $option
+ * @param string $setTo
+ * @param string $token
+ * @return DataResponse
+ */
+ public function deleteByToken($token, $comment) {
+
+ try {
+ $this->acl->setToken($token);
+ return $this->delete($comment);
+
+ } catch (DoesNotExistException $e) {
+ return new DataResponse($e, Http::STATUS_NOT_FOUND);
+ }
+
+
+
+ }
+
}
diff --git a/lib/Db/CommentMapper.php b/lib/Db/CommentMapper.php
index c6ac77d2..93da02ae 100644
--- a/lib/Db/CommentMapper.php
+++ b/lib/Db/CommentMapper.php
@@ -39,6 +39,25 @@ class CommentMapper extends QBMapper {
}
/**
+ * @param int $id
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ * @return Comment
+ */
+
+ public function find($id) {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where(
+ $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
+ );
+
+ return $this->findEntity($qb);
+ }
+
+ /**
* @param int $pollId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return array
diff --git a/src/js/components/Comments/Comments.vue b/src/js/components/Comments/Comments.vue
index 9c43ffa8..24f118bb 100644
--- a/src/js/components/Comments/Comments.vue
+++ b/src/js/components/Comments/Comments.vue
@@ -29,15 +29,22 @@
<li v-for="(comment) in sortedList" :key="comment.id">
<div class="comment-item">
<user-div :user-id="comment.userId" />
+ <Actions v-if="comment.userId === acl.userId">
+ <ActionButton icon="icon-delete" @click="deleteComment(comment)">
+ {{ t('polls', 'Delete comment') }}
+ </ActionButton>
+ </Actions>
<div class="date">
{{ moment.utc(comment.dt).fromNow() }}
</div>
</div>
+
<div class="message wordwrap comment-content">
{{ comment.comment }}
</div>
</li>
</transition-group>
+
<div v-else class="emptycontent">
<div class="icon-comment" />
<p> {{ t('polls', 'No comments yet. Be the first.') }}</p>
@@ -47,12 +54,15 @@
<script>
import CommentAdd from './CommentAdd'
-import { mapState, mapGetters } from 'vuex'
import sortBy from 'lodash/sortBy'
+import { Actions, ActionButton } from '@nextcloud/vue'
+import { mapState, mapGetters } from 'vuex'
export default {
name: 'Comments',
components: {
+ Actions,
+ ActionButton,
CommentAdd
},
data() {
@@ -80,6 +90,18 @@ export default {
}
}
+ },
+
+ methods: {
+ deleteComment(comment) {
+ this.$store.dispatch({ type: 'deleteComment', comment: comment })
+ .then(() => {
+ OC.Notification.showTemporary(t('polls', 'Comment deleted'), { type: 'success' })
+ }, (error) => {
+ OC.Notification.showTemporary(t('polls', 'Error while deleting Comment'), { type: 'error' })
+ console.error(error.response)
+ })
+ }
}
}
</script>
@@ -108,7 +130,7 @@ ul {
}
}
& > .message {
- margin-left: 44px;
+ margin-left: 53px;
flex: 1 1;
}
}
diff --git a/src/js/store/modules/comments.js b/src/js/store/modules/comments.js
index 129f7f2b..e0f032d5 100644
--- a/src/js/store/modules/comments.js
+++ b/src/js/store/modules/comments.js
@@ -43,8 +43,14 @@ const mutations = {
addComment(state, payload) {
state.list.push(payload)
- }
+ },
+ removeComment(state, payload) {
+ console.log('removeComment', payload)
+ state.list = state.list.filter(comment => {
+ return comment.id !== payload.comment.id
+ })
+ }
}
const getters = {
@@ -76,6 +82,28 @@ const actions = {
})
},
+ deleteComment(context, payload) {
+ let endPoint = 'apps/polls/comment/delete/'
+
+ if (context.rootState.acl.foundByToken) {
+ endPoint = endPoint.concat('s/')
+ }
+
+ return axios.post(OC.generateUrl(endPoint), {
+ token: context.rootState.acl.token,
+ comment: payload.comment
+ })
+ .then((response) => {
+ console.error('removed', response.data)
+ context.commit('removeComment', { comment: response.data.comment })
+ return response.data
+ }, (error) => {
+ console.error('Error deleting comment', { error: error.response }, { payload: payload })
+ throw error
+ })
+
+ },
+
setCommentAsync(context, payload) {
let endPoint = 'apps/polls/comment/write/'
diff --git a/src/js/views/Vote.vue b/src/js/views/Vote.vue
index 50d8663e..6c98e636 100644
--- a/src/js/views/Vote.vue
+++ b/src/js/views/Vote.vue
@@ -45,7 +45,6 @@
<Subscription />
<div class="additional">
<ParticipantsList v-if="acl.allowSeeUsernames" />
- <!-- <Comments /> -->
</div>
</div>
@@ -55,7 +54,6 @@
</template>
<script>
-// import Comments from '../components/Comments/Comments'
import { AppContent } from '@nextcloud/vue'
import Subscription from '../components/Subscription/Subscription'
import ParticipantsList from '../components/Base/ParticipantsList'
@@ -78,7 +76,6 @@ export default {
PollInformation,
PollTitle,
LoadingOverlay,
- // Comments,
SideBar,
VoteTable,
VoteList