From 89690472d83923f94138bd5301a9bb7823f94878 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 23 May 2020 11:15:04 +0200 Subject: [PATCH 001/117] experimental background style --- src/js/App.vue | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/js/App.vue b/src/js/App.vue index b30e329979..24dbdba735 100644 --- a/src/js/App.vue +++ b/src/js/App.vue @@ -21,7 +21,7 @@ --> diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js new file mode 100644 index 0000000000..43a4b6fdcf --- /dev/null +++ b/src/js/store/modules/settings.js @@ -0,0 +1,81 @@ +/* + * @copyright Copyright (c) 2019 Rene Gieling + * + * @author Rene Gieling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import axios from '@nextcloud/axios' +import { generateUrl } from '@nextcloud/router' + +const defaultSettings = () => { + return { + user: { + experimental: false, + useImage: false, + imageUrl: '', + glassyNavigation: false, + glassySidebar: false, + }, + } +} + +const state = defaultSettings() + +const mutations = { + reset(state) { + Object.assign(state, defaultSettings()) + }, + + setUserSetting(state, payload) { + Object.assign(state.user, payload) + }, +} + +const getters = { +} + +const actions = { + getSettings(context) { + const endPoint = 'apps/polls/preferences/get' + + return axios.get(generateUrl(endPoint)) + .then((response) => { + context.commit('setUserSetting', JSON.parse(response.data.preferences)) + }) + .catch(() => { + context.commit('reset') + }) + }, + writeSetting(context) { + const endPoint = 'apps/polls/preferences/write' + // context.commit('setUserSetting', { settings: payload }) + + return axios.post(generateUrl(endPoint), { settings: context.state.user }) + .then((response) => { + context.commit('setUserSetting', JSON.parse(response.data.preferences)) + }) + .catch((error) => { + console.error('Error writing preferences', { error: error.response }, { preferences: state.user }) + throw error + }) + }, + +} + +export default { state, mutations, getters, actions } From 13d15f19887869e3c62314226e42b80f14661f4a Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 23 May 2020 20:47:59 +0200 Subject: [PATCH 003/117] namespaced settings --- src/js/App.vue | 2 +- .../Navigation/NavigationSettings.vue | 4 ++-- src/js/store/modules/settings.js | 18 ++++++++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/js/App.vue b/src/js/App.vue index 8eedf41666..5afec9b12e 100644 --- a/src/js/App.vue +++ b/src/js/App.vue @@ -77,7 +77,7 @@ export default { }) - this.$store.dispatch('getSettings') + this.$store.dispatch('settings/get') if (getCurrentUser()) { this.updatePolls() subscribe('update-polls', () => { diff --git a/src/js/components/Navigation/NavigationSettings.vue b/src/js/components/Navigation/NavigationSettings.vue index df86989585..d17f798352 100644 --- a/src/js/components/Navigation/NavigationSettings.vue +++ b/src/js/components/Navigation/NavigationSettings.vue @@ -97,8 +97,8 @@ export default { methods: { writeValue(value) { - this.$store.commit('setUserSetting', value) - this.$store.dispatch('writeSetting') + this.$store.commit('settings/setPreference', value) + this.$store.dispatch('settings/write') }, }, } diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js index 43a4b6fdcf..d1f1b1c952 100644 --- a/src/js/store/modules/settings.js +++ b/src/js/store/modules/settings.js @@ -36,39 +36,37 @@ const defaultSettings = () => { } const state = defaultSettings() +const namespaced = true const mutations = { reset(state) { Object.assign(state, defaultSettings()) }, - setUserSetting(state, payload) { + setPreference(state, payload) { Object.assign(state.user, payload) }, } -const getters = { -} - const actions = { - getSettings(context) { + get(context) { const endPoint = 'apps/polls/preferences/get' return axios.get(generateUrl(endPoint)) .then((response) => { - context.commit('setUserSetting', JSON.parse(response.data.preferences)) + context.commit('setPreference', JSON.parse(response.data.preferences)) }) .catch(() => { context.commit('reset') }) }, - writeSetting(context) { + write(context) { const endPoint = 'apps/polls/preferences/write' - // context.commit('setUserSetting', { settings: payload }) + // context.commit('setPreference', { settings: payload }) return axios.post(generateUrl(endPoint), { settings: context.state.user }) .then((response) => { - context.commit('setUserSetting', JSON.parse(response.data.preferences)) + context.commit('setPreference', JSON.parse(response.data.preferences)) }) .catch((error) => { console.error('Error writing preferences', { error: error.response }, { preferences: state.user }) @@ -78,4 +76,4 @@ const actions = { } -export default { state, mutations, getters, actions } +export default { namespaced, state, mutations, actions } From 3856766a49c03b4c511eaa352322a272e0a50ea2 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 23 May 2020 20:53:57 +0200 Subject: [PATCH 004/117] json fix --- lib/Db/Preferences.php | 2 +- src/js/store/modules/settings.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Db/Preferences.php b/lib/Db/Preferences.php index db15d52924..670260a35e 100644 --- a/lib/Db/Preferences.php +++ b/lib/Db/Preferences.php @@ -55,7 +55,7 @@ public function jsonSerialize() { 'id' => intval($this->id), 'userId' => $this->userId, 'timestamp' => intval($this->timestamp), - 'preferences' => $this->preferences, + 'preferences' => json_decode($this->preferences), ]; } } diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js index d1f1b1c952..a9f638ca39 100644 --- a/src/js/store/modules/settings.js +++ b/src/js/store/modules/settings.js @@ -54,7 +54,7 @@ const actions = { return axios.get(generateUrl(endPoint)) .then((response) => { - context.commit('setPreference', JSON.parse(response.data.preferences)) + context.commit('setPreference', response.data.preferences) }) .catch(() => { context.commit('reset') @@ -62,11 +62,10 @@ const actions = { }, write(context) { const endPoint = 'apps/polls/preferences/write' - // context.commit('setPreference', { settings: payload }) return axios.post(generateUrl(endPoint), { settings: context.state.user }) .then((response) => { - context.commit('setPreference', JSON.parse(response.data.preferences)) + context.commit('setPreference', response.data.preferences) }) .catch((error) => { console.error('Error writing preferences', { error: error.response }, { preferences: state.user }) From a4a571a81a20fd0473c4cf72aaaf09105f5daa4c Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 11 Jun 2020 14:55:55 +0200 Subject: [PATCH 005/117] avoid fetching foto fix #912 --- appinfo/routes.php | 2 +- lib/Controller/SystemController.php | 22 +++++++------------ src/js/components/SideBar/SideBarTabShare.vue | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 50a9860c69..658fa24198 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -71,7 +71,7 @@ ['name' => 'acl#getByToken', 'url' => '/acl/get/s/{token}', 'verb' => 'GET'], ['name' => 'acl#get', 'url' => '/acl/get/{id}', 'verb' => 'GET'], - ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get/', 'verb' => 'POST'], + ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get', 'verb' => 'POST'], ['name' => 'system#validate_public_username', 'url' => '/check/username', 'verb' => 'POST'] ] ]; diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index 86051bfb26..894a789329 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -94,6 +94,7 @@ private function isValidEmail($email) { /** * Get a list of NC users, groups and contacts * @NoAdminRequired + * @PublicPage * @NoCSRFRequired * @param string $query * @param bool $getGroups - search in groups @@ -105,7 +106,7 @@ private function isValidEmail($email) { */ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $getContacts = true, $getMail = false, $skipGroups = array(), $skipUsers = array()) { $list = array(); - // if (filter_var($query, FILTER_VALIDATE_EMAIL)) { + if ($this->isValidEmail($query)) { $list[] = [ 'id' => '', @@ -124,10 +125,8 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers ]; } - if ($getGroups) { - $groups = $this->groupManager->search($query); - foreach ($groups as $group) { + foreach ($this->groupManager->search($query) as $group) { if (!in_array($group->getGID(), $skipGroups)) { $list[] = [ 'id' => $group->getGID(), @@ -149,8 +148,7 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers } if ($getUsers) { - $users = $this->userManager->searchDisplayName($query); - foreach ($users as $user) { + foreach ($this->userManager->searchDisplayName($query) as $user) { if (!in_array($user->getUID(), $skipUsers)) { $list[] = [ 'id' => $user->getUID(), @@ -170,13 +168,9 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers } } - $contactsManager = \OC::$server->getContactsManager(); - - - if ($getContacts && $contactsManager->isEnabled()) { - $contacts = $contactsManager->search($query, array('FN', 'EMAIL', 'ORG', 'CATEGORIES')); + if ($getContacts && \OC::$server->getContactsManager()->isEnabled()) { - foreach ($contacts as $contact) { + foreach (\OC::$server->getContactsManager()->search($query, array('FN', 'EMAIL', 'ORG', 'CATEGORIES')) as $contact) { if (!array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact)) { $emailAdresses = $contact['EMAIL']; @@ -199,9 +193,9 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers 'type' => 'contact', 'icon' => 'icon-mail', 'avatarURL' => '', - 'avatar' => isset($contact['PHOTO']) ? $contact['PHOTO'] : '', + 'avatar' => '', 'lastLogin' => '', - 'cloudId' => '' + 'cloudId' => '', ]; } diff --git a/src/js/components/SideBar/SideBarTabShare.vue b/src/js/components/SideBar/SideBarTabShare.vue index 9ffd316129..12ba431432 100644 --- a/src/js/components/SideBar/SideBarTabShare.vue +++ b/src/js/components/SideBar/SideBarTabShare.vue @@ -146,7 +146,7 @@ export default { loadUsersAsync(query) { this.isLoading = false this.siteUsersListOptions.query = query - axios.post(generateUrl('apps/polls/siteusers/get/'), this.siteUsersListOptions) + axios.post(generateUrl('apps/polls/siteusers/get'), this.siteUsersListOptions) .then((response) => { this.users = response.data.siteusers this.isLoading = false From 825c7a22dd1688e7006e83914d7bfa11832a43fe Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 11 Jun 2020 16:17:48 +0200 Subject: [PATCH 006/117] fix #920 --- src/js/components/VoteTable/VoteTable.vue | 15 +------------ .../VoteTable/VoteTableVoteItem.vue | 22 ++++++++++++++++++- src/js/store/modules/poll.js | 7 ++++++ src/js/store/modules/subModules/votes.js | 18 --------------- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/js/components/VoteTable/VoteTable.vue b/src/js/components/VoteTable/VoteTable.vue index 7575bb83e2..06cc3dfa5d 100644 --- a/src/js/components/VoteTable/VoteTable.vue +++ b/src/js/components/VoteTable/VoteTable.vue @@ -52,8 +52,7 @@ :key="option.id" :user-id="participant.userId" :option="option" - :is-active="acl.userId === participant.userId && acl.allowVote" - @voteClick="setVote(option, participant.userId)" /> + :is-active="acl.userId === participant.userId && acl.allowVote" /> @@ -155,18 +154,6 @@ export default { this.userToRemove = userId this.modal = true }, - - setVote(option, userId) { - this.$store - .dispatch('poll/votes/set', { - option: option, - userId: userId, - setTo: this.$store.getters['poll/votes/getNextAnswer']({ - option: option, - userId: userId, - }), - }) - }, }, } diff --git a/src/js/components/VoteTable/VoteTableVoteItem.vue b/src/js/components/VoteTable/VoteTableVoteItem.vue index 7719ea7c71..69495e7e0d 100644 --- a/src/js/components/VoteTable/VoteTableVoteItem.vue +++ b/src/js/components/VoteTable/VoteTableVoteItem.vue @@ -22,7 +22,7 @@ @@ -51,6 +51,7 @@ export default { computed: { ...mapGetters({ expired: 'poll/expired', + answerSequence: 'poll/answerSequence', }), answer() { @@ -64,6 +65,14 @@ export default { } }, + nextAnswer() { + if (this.answerSequence.indexOf(this.answer) < 0) { + return this.answerSequence[1] + } else { + return this.answerSequence[(this.answerSequence.indexOf(this.answer) + 1) % this.answerSequence.length] + } + }, + isValidUser() { return (this.userId !== '' && this.userId !== null) }, @@ -73,6 +82,17 @@ export default { }, }, + + methods: { + setVote() { + this.$store + .dispatch('poll/votes/set', { + option: this.option, + userId: this.userId, + setTo: this.nextAnswer, + }) + }, + }, } diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index 17cfd7a996..01db023d24 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -75,6 +75,13 @@ const mutations = { } const getters = { + answerSequence: (state) => { + if (state.allowMaybe) { + return ['no', 'yes', 'maybe'] + } else { + return ['no', 'yes'] + } + }, expired: (state) => { return (state.expire > 0 && moment.unix(state.expire).diff() < 0) diff --git a/src/js/store/modules/subModules/votes.js b/src/js/store/modules/subModules/votes.js index 591a585ac3..0a5338f2d0 100644 --- a/src/js/store/modules/subModules/votes.js +++ b/src/js/store/modules/subModules/votes.js @@ -62,14 +62,6 @@ const mutations = { const getters = { - answerSequence: (state, getters, rootState) => { - if (rootState.poll.allowMaybe) { - return ['no', 'maybe', 'yes', 'no'] - } else { - return ['no', 'yes', 'no'] - } - }, - ranked: (state, getters, rootState) => { let votesRank = [] rootState.poll.options.list.forEach(function(option) { @@ -101,16 +93,6 @@ const getters = { && vote.voteOptionText === payload.option.pollOptionText) }) }, - - getNextAnswer: (state, getters) => (payload) => { - try { - return getters.answerSequence[getters.answerSequence.indexOf(getters.getVote(payload).voteAnswer) + 1] - } catch (e) { - return getters.answerSequence[1] - } - - }, - } const actions = { From 9f5b0d9c8b9d39cb67421b1fe73f8ecb09518e6f Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 11 Jun 2020 21:00:05 +0200 Subject: [PATCH 007/117] minor fixes --- lib/Controller/ShareController.php | 2 +- lib/Controller/SystemController.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index 15eee19535..99746a786b 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -222,7 +222,7 @@ public function createPersonalShare($token, $userName) { return new DataResponse($publicShare, Http::STATUS_OK); } else { - return new DataResponse(['message'=> 'Wrong share type: ' . $userShare->getType()], Http::STATUS_FORBIDDEN); + return new DataResponse(['message'=> 'Wrong share type: ' . $publicShare->getType()], Http::STATUS_FORBIDDEN); } } catch (DoesNotExistException $e) { diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index 894a789329..9c8326cff5 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -85,7 +85,7 @@ public function __construct( * Validate string as email address * @NoAdminRequired * @param string $query - * @return Boolval + * @return Boolean */ private function isValidEmail($email) { return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $email)) ? false : true; @@ -107,7 +107,7 @@ private function isValidEmail($email) { public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $getContacts = true, $getMail = false, $skipGroups = array(), $skipUsers = array()) { $list = array(); - if ($this->isValidEmail($query)) { + if ($getMail && $this->isValidEmail($query)) { $list[] = [ 'id' => '', 'user' => '', From ca60c901461f660e1c55829ac8a4270fb3bbc838 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 11 Jun 2020 21:08:31 +0200 Subject: [PATCH 008/117] minor fixes --- lib/Controller/VoteController.php | 24 +++++------------------- src/js/store/modules/subModules/votes.js | 1 - 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/Controller/VoteController.php b/lib/Controller/VoteController.php index ad8936bd0c..c51f13b0e7 100644 --- a/lib/Controller/VoteController.php +++ b/lib/Controller/VoteController.php @@ -172,27 +172,13 @@ public function set($pollId, $option, $userId, $setTo) { * @param integer $pollId * @return DataResponse */ - public function delete($voteId = 0, $userId = '', $pollId = 0) { - $this->logger->alert('Deleting vote no. ' . $voteId); - + public function delete($userId = '', $pollId = 0) { try { - if ($voteId) { - $vote = $this->mapper->delete($voteId); - $this->logger->alert('Deleting vote no. ' . $voteId); - return new DataResponse(null, Http::STATUS_OK); - } elseif ($pollId && $userId) { - $votes = $this->mapper->deleteByPollAndUser($pollId, $userId); - $this->logger->alert('Deleting votes from ' . $userId . ' in poll ' . $pollId); - return new DataResponse(null, Http::STATUS_OK); - } elseif ($pollId) { - $votes = $this->mapper->deleteByPoll($pollId); - $this->logger->alert('Deleting all votes in poll ' . $pollId); - return new DataResponse(null, Http::STATUS_OK); - } else { - return DataResponse(null, Http::STATUS_NOT_FOUND); - } + $this->mapper->deleteByPollAndUser($pollId, $userId); + $this->logger->debug('Deleting votes from ' . $userId . ' in poll ' . $pollId); + return new DataResponse(null, Http::STATUS_OK); } catch (DoesNotExistException $e) { - return DataResponse(null, Http::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } } diff --git a/src/js/store/modules/subModules/votes.js b/src/js/store/modules/subModules/votes.js index 0a5338f2d0..2a3e22be7e 100644 --- a/src/js/store/modules/subModules/votes.js +++ b/src/js/store/modules/subModules/votes.js @@ -100,7 +100,6 @@ const actions = { const endPoint = 'apps/polls/votes/delete/' return axios.post(generateUrl(endPoint), { pollId: context.rootState.poll.id, - voteId: 0, userId: payload.userId, }) .then(() => { From 93ef72a14a9f6386effe34304882f3b015eecbb0 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 11 Jun 2020 14:55:55 +0200 Subject: [PATCH 009/117] avoid fetching foto fix #912 --- appinfo/routes.php | 2 +- lib/Controller/SystemController.php | 22 +++++++------------ src/js/components/SideBar/SideBarTabShare.vue | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 50a9860c69..658fa24198 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -71,7 +71,7 @@ ['name' => 'acl#getByToken', 'url' => '/acl/get/s/{token}', 'verb' => 'GET'], ['name' => 'acl#get', 'url' => '/acl/get/{id}', 'verb' => 'GET'], - ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get/', 'verb' => 'POST'], + ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get', 'verb' => 'POST'], ['name' => 'system#validate_public_username', 'url' => '/check/username', 'verb' => 'POST'] ] ]; diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index 86051bfb26..894a789329 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -94,6 +94,7 @@ private function isValidEmail($email) { /** * Get a list of NC users, groups and contacts * @NoAdminRequired + * @PublicPage * @NoCSRFRequired * @param string $query * @param bool $getGroups - search in groups @@ -105,7 +106,7 @@ private function isValidEmail($email) { */ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $getContacts = true, $getMail = false, $skipGroups = array(), $skipUsers = array()) { $list = array(); - // if (filter_var($query, FILTER_VALIDATE_EMAIL)) { + if ($this->isValidEmail($query)) { $list[] = [ 'id' => '', @@ -124,10 +125,8 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers ]; } - if ($getGroups) { - $groups = $this->groupManager->search($query); - foreach ($groups as $group) { + foreach ($this->groupManager->search($query) as $group) { if (!in_array($group->getGID(), $skipGroups)) { $list[] = [ 'id' => $group->getGID(), @@ -149,8 +148,7 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers } if ($getUsers) { - $users = $this->userManager->searchDisplayName($query); - foreach ($users as $user) { + foreach ($this->userManager->searchDisplayName($query) as $user) { if (!in_array($user->getUID(), $skipUsers)) { $list[] = [ 'id' => $user->getUID(), @@ -170,13 +168,9 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers } } - $contactsManager = \OC::$server->getContactsManager(); - - - if ($getContacts && $contactsManager->isEnabled()) { - $contacts = $contactsManager->search($query, array('FN', 'EMAIL', 'ORG', 'CATEGORIES')); + if ($getContacts && \OC::$server->getContactsManager()->isEnabled()) { - foreach ($contacts as $contact) { + foreach (\OC::$server->getContactsManager()->search($query, array('FN', 'EMAIL', 'ORG', 'CATEGORIES')) as $contact) { if (!array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact)) { $emailAdresses = $contact['EMAIL']; @@ -199,9 +193,9 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers 'type' => 'contact', 'icon' => 'icon-mail', 'avatarURL' => '', - 'avatar' => isset($contact['PHOTO']) ? $contact['PHOTO'] : '', + 'avatar' => '', 'lastLogin' => '', - 'cloudId' => '' + 'cloudId' => '', ]; } diff --git a/src/js/components/SideBar/SideBarTabShare.vue b/src/js/components/SideBar/SideBarTabShare.vue index 9ffd316129..12ba431432 100644 --- a/src/js/components/SideBar/SideBarTabShare.vue +++ b/src/js/components/SideBar/SideBarTabShare.vue @@ -146,7 +146,7 @@ export default { loadUsersAsync(query) { this.isLoading = false this.siteUsersListOptions.query = query - axios.post(generateUrl('apps/polls/siteusers/get/'), this.siteUsersListOptions) + axios.post(generateUrl('apps/polls/siteusers/get'), this.siteUsersListOptions) .then((response) => { this.users = response.data.siteusers this.isLoading = false From ff1b16124ef335074be901f1e1a021640932dbf2 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 11 Jun 2020 21:00:05 +0200 Subject: [PATCH 010/117] minor fixes --- lib/Controller/ShareController.php | 2 +- lib/Controller/SystemController.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index 15eee19535..99746a786b 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -222,7 +222,7 @@ public function createPersonalShare($token, $userName) { return new DataResponse($publicShare, Http::STATUS_OK); } else { - return new DataResponse(['message'=> 'Wrong share type: ' . $userShare->getType()], Http::STATUS_FORBIDDEN); + return new DataResponse(['message'=> 'Wrong share type: ' . $publicShare->getType()], Http::STATUS_FORBIDDEN); } } catch (DoesNotExistException $e) { diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index 894a789329..9c8326cff5 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -85,7 +85,7 @@ public function __construct( * Validate string as email address * @NoAdminRequired * @param string $query - * @return Boolval + * @return Boolean */ private function isValidEmail($email) { return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $email)) ? false : true; @@ -107,7 +107,7 @@ private function isValidEmail($email) { public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $getContacts = true, $getMail = false, $skipGroups = array(), $skipUsers = array()) { $list = array(); - if ($this->isValidEmail($query)) { + if ($getMail && $this->isValidEmail($query)) { $list[] = [ 'id' => '', 'user' => '', From 6e3792a58903103ecde77d748bc92c2d9dea7aa6 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 11 Jul 2020 16:54:09 +0200 Subject: [PATCH 011/117] Update backend --- appinfo/routes.php | 136 ++++----- lib/Controller/AclController.php | 80 ------ lib/Controller/CommentApiController.php | 16 +- lib/Controller/CommentController.php | 28 +- lib/Controller/OptionApiController.php | 74 +++-- lib/Controller/OptionController.php | 85 +++--- lib/Controller/PageController.php | 1 + lib/Controller/PollApiController.php | 52 ++-- lib/Controller/PollController.php | 114 ++++---- lib/Controller/ShareApiController.php | 44 ++- lib/Controller/ShareController.php | 69 ++--- lib/Controller/SubscriptionApiController.php | 27 +- lib/Controller/SubscriptionController.php | 26 +- lib/Controller/SystemController.php | 37 +-- lib/Controller/VoteApiController.php | 27 +- lib/Controller/VoteController.php | 40 +-- lib/Cron/NotificationCron.php | 5 +- lib/Db/Comment.php | 4 +- lib/Db/Log.php | 8 +- lib/Db/Option.php | 10 +- lib/Db/Poll.php | 30 +- lib/Db/Share.php | 4 +- lib/Db/Subscription.php | 4 +- lib/Db/Vote.php | 4 +- lib/Exceptions/BadRequestException.php | 40 +++ lib/Model/Acl.php | 15 +- lib/Service/AnonymizeService.php | 11 +- lib/Service/CommentService.php | 38 +-- lib/Service/LogService.php | 48 ++-- lib/Service/MailService.php | 33 ++- lib/Service/OptionService.php | 279 ++++++++++++++----- lib/Service/PollService.php | 192 ++++++++----- lib/Service/ShareService.php | 58 ++-- lib/Service/SubscriptionService.php | 18 +- lib/Service/VoteService.php | 50 ++-- 35 files changed, 935 insertions(+), 772 deletions(-) delete mode 100644 lib/Controller/AclController.php create mode 100644 lib/Exceptions/BadRequestException.php diff --git a/appinfo/routes.php b/appinfo/routes.php index 35c44bd669..4ae59333d7 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -23,89 +23,89 @@ return [ 'routes' => [ - ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], + ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'page#index', 'url' => '/not-found', 'verb' => 'GET', 'postfix' => 'notfound'], ['name' => 'page#index', 'url' => '/list/{id}', 'verb' => 'GET', 'postfix' => 'list'], ['name' => 'page#index', 'url' => '/vote/{id}', 'verb' => 'GET', 'postfix' => 'vote'], - ['name' => 'page#vote_public', 'url' => '/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], + + ['name' => 'page#vote_public', 'url' => '/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], ['name' => 'page#vote_public', 'url' => '/poll/{token}', 'verb' => 'GET', 'postfix' => 'oldpublic'], - ['name' => 'subscription#get', 'url' => '/subscription/{pollId}', 'verb' => 'GET'], - ['name' => 'subscription#set', 'url' => '/subscription', 'verb' => 'POST'], - - ['name' => 'comment#getByToken', 'url' => '/comments/s/{token}', 'verb' => 'GET'], - ['name' => 'comment#get', 'url' => '/comments/{pollId}', 'verb' => 'GET'], - ['name' => 'comment#add', 'url' => '/comment/add', 'verb' => 'POST'], - ['name' => 'comment#delete', 'url' => '/comment/delete', 'verb' => 'POST'], - - ['name' => 'vote#getByToken', 'url' => '/votes/get/s/{token}', 'verb' => 'GET'], - ['name' => 'vote#setByToken', 'url' => '/vote/set/s', 'verb' => 'POST'], - ['name' => 'vote#get', 'url' => '/votes/get/{pollId}', 'verb' => 'GET'], - ['name' => 'vote#set', 'url' => '/vote/set', 'verb' => 'POST'], - // ['name' => 'vote#write', 'url' => '/vote/write/', 'verb' => 'POST'], - ['name' => 'vote#delete', 'url' => '/votes/delete', 'verb' => 'POST'], - - ['name' => 'option#get', 'url' => '/options/get/{pollId}', 'verb' => 'GET'], - ['name' => 'option#add', 'url' => '/option/add', 'verb' => 'POST'], - ['name' => 'option#update', 'url' => '/option/update', 'verb' => 'POST'], - ['name' => 'option#reorder', 'url' => '/option/reorder', 'verb' => 'POST'], - ['name' => 'option#remove', 'url' => '/option/remove', 'verb' => 'POST'], - ['name' => 'option#getByToken', 'url' => '/options/get/s/{token}', 'verb' => 'GET'], - - ['name' => 'poll#get', 'url' => '/polls/get/{pollId}', 'verb' => 'GET', 'postfix' => 'auth'], - ['name' => 'poll#get', 'url' => '/polls/get/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], - ['name' => 'poll#add', 'url' => '/polls/add', 'verb' => 'POST'], - ['name' => 'poll#update', 'url' => '/polls/update/{pollId}', 'verb' => 'PUT'], - - ['name' => 'poll#list', 'url' => '/polls/list', 'verb' => 'GET'], - ['name' => 'poll#delete', 'url' => '/polls/delete/{pollId}', 'verb' => 'GET'], + ['name' => 'poll#get', 'url' => '/polls/get/{pollId}', 'verb' => 'GET', 'postfix' => 'auth'], + ['name' => 'poll#get', 'url' => '/polls/get/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], + ['name' => 'poll#add', 'url' => '/polls/add', 'verb' => 'POST'], + ['name' => 'poll#update', 'url' => '/polls/update/{pollId}', 'verb' => 'PUT'], + ['name' => 'poll#list', 'url' => '/polls/list', 'verb' => 'GET'], + ['name' => 'poll#delete', 'url' => '/polls/delete/{pollId}', 'verb' => 'GET'], ['name' => 'poll#deletePermanently', 'url' => '/polls/delete/permanent/{pollId}', 'verb' => 'GET'], - ['name' => 'poll#clone', 'url' => '/polls/clone/{pollId}', 'verb' => 'GET'], + ['name' => 'poll#clone', 'url' => '/polls/clone/{pollId}', 'verb' => 'GET'], + + ['name' => 'option#add', 'url' => '/option', 'verb' => 'POST'], + ['name' => 'option#update', 'url' => '/option/{optionId}', 'verb' => 'PUT'], + ['name' => 'option#delete', 'url' => '/option/{optionId}', 'verb' => 'DELETE'], + ['name' => 'option#confirm', 'url' => '/option/{optionId}/confirm', 'verb' => 'PUT'], + ['name' => 'option#reorder', 'url' => '/option/reorder', 'verb' => 'POST'], + // ['name' => 'option#list', 'url' => '/options/get/{pollId}', 'verb' => 'GET'], + // ['name' => 'option#listByToken', 'url' => '/options/get/s/{token}', 'verb' => 'GET'], + + ['name' => 'vote#set', 'url' => '/vote/set', 'verb' => 'POST'], + ['name' => 'vote#setByToken', 'url' => '/vote/set/s', 'verb' => 'POST'], + ['name' => 'vote#delete', 'url' => '/votes/delete', 'verb' => 'POST'], + // ['name' => 'vote#get', 'url' => '/votes/get/{pollId}', 'verb' => 'GET'], + // ['name' => 'vote#getByToken', 'url' => '/votes/get/s/{token}', 'verb' => 'GET'], + + ['name' => 'share#add', 'url' => '/share/add', 'verb' => 'POST'], + ['name' => 'share#personal', 'url' => '/share/personal', 'verb' => 'POST'], + ['name' => 'share#delete', 'url' => '/share/delete/{token}', 'verb' => 'DELETE'], + ['name' => 'share#sendInvitation', 'url' => '/share/send/{token}', 'verb' => 'POST'], - ['name' => 'share#add', 'url' => '/share/add', 'verb' => 'POST'], - ['name' => 'share#delete', 'url' => '/share/delete', 'verb' => 'POST'], - ['name' => 'share#createPersonalShare', 'url' => '/share/create/s', 'verb' => 'POST'], - ['name' => 'share#sendInvitation', 'url' => '/share/send/{token}', 'verb' => 'POST'], + ['name' => 'subscription#get', 'url' => '/subscription/{pollId}', 'verb' => 'GET'], + ['name' => 'subscription#set', 'url' => '/subscription', 'verb' => 'POST'], - // ['name' => 'share#getShares', 'url' => '/shares/get/{pollId}', 'verb' => 'GET'], - // ['name' => 'share#get', 'url' => '/share/get/{token}', 'verb' => 'GET'], + ['name' => 'comment#add', 'url' => '/comment', 'verb' => 'POST'], + ['name' => 'comment#delete', 'url' => '/comment/{commentId}', 'verb' => 'DELETE'], + // ['name' => 'comment#list', 'url' => '/comments/{pollId}', 'verb' => 'GET'], + // ['name' => 'comment#getByToken', 'url' => '/comments/s/{token}', 'verb' => 'GET'], - ['name' => 'acl#getByToken', 'url' => '/acl/get/s/{token}', 'verb' => 'GET'], - ['name' => 'acl#get', 'url' => '/acl/get/{id}', 'verb' => 'GET'], + // ['name' => 'acl#getByToken', 'url' => '/acl/get/s/{token}', 'verb' => 'GET'], + // ['name' => 'acl#get', 'url' => '/acl/get/{id}', 'verb' => 'GET'], - ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get', 'verb' => 'POST'], - ['name' => 'system#validate_public_username', 'url' => '/check/username', 'verb' => 'POST'], + ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get', 'verb' => 'POST'], + ['name' => 'system#validate_public_username', 'url' => '/check/username', 'verb' => 'POST'], // REST-API calls - ['name' => 'poll_api#get', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'GET'], - ['name' => 'poll_api#list', 'url' => '/api/v1.0/polls', 'verb' => 'GET'], - ['name' => 'poll_api#add', 'url' => '/api/v1.0/poll/add', 'verb' => 'POST'], - ['name' => 'poll_api#clone', 'url' => '/api/v1.0/poll/clone/{pollId}', 'verb' => 'POST'], + ['name' => 'poll_api#list', 'url' => '/api/v1.0/polls', 'verb' => 'GET'], + ['name' => 'poll_api#get', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'GET'], + ['name' => 'poll_api#add', 'url' => '/api/v1.0/poll', 'verb' => 'POST'], ['name' => 'poll_api#update', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'PUT'], ['name' => 'poll_api#delete', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'DELETE'], - ['name' => 'poll_api#delete', 'url' => '/api/v1.0/poll/permanent/{pollId}', 'verb' => 'DELETE'], - ['name' => 'poll_api#enum', 'url' => '/api/v1.0/poll/enum', 'verb' => 'GET'], - - ['name' => 'option_api#list', 'url' => '/api/v1.0/poll/{pollId}/options', 'verb' => 'GET'], - ['name' => 'option_api#add', 'url' => '/api/v1.0/option', 'verb' => 'POST'], - ['name' => 'option_api#update', 'url' => '/api/v1.0/option', 'verb' => 'PUT'], - ['name' => 'option_api#delete', 'url' => '/api/v1.0/option/{optionId}', 'verb' => 'DELETE'], - - ['name' => 'comment_api#list', 'url' => '/api/v1.0/poll/{pollId}/comments', 'verb' => 'GET'], - ['name' => 'comment_api#add', 'url' => '/api/v1.0/comment', 'verb' => 'POST'], - ['name' => 'comment_api#delete', 'url' => '/api/v1.0/comment/{commentId}', 'verb' => 'DELETE'], - - ['name' => 'share_api#list', 'url' => '/api/v1.0/poll/{pollId}/shares', 'verb' => 'GET'], - ['name' => 'share_api#get', 'url' => '/api/v1.0/share/{token}', 'verb' => 'GET'], - ['name' => 'share_api#add', 'url' => '/api/v1.0/share', 'verb' => 'POST'], - ['name' => 'share_api#delete', 'url' => '/api/v1.0/share/{token}', 'verb' => 'DELETE'], - ['name' => 'share_api#sendInvitation', 'url' => '/api/v1.0/share/send/{token}', 'verb' => 'POST'], - - ['name' => 'subscription_api#get', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'GET'], - ['name' => 'subscription_api#subscribe', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'PUT'], - ['name' => 'subscription_api#unsubscribe', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'DELETE'], + ['name' => 'poll_api#clone', 'url' => '/api/v1.0/poll/{pollId}/clone', 'verb' => 'POST'], + ['name' => 'poll_api#trash', 'url' => '/api/v1.0/poll/{pollId}/trash', 'verb' => 'POST'], + ['name' => 'poll_api#enum', 'url' => '/api/v1.0/enum/poll', 'verb' => 'GET'], + + ['name' => 'option_api#list', 'url' => '/api/v1.0/poll/{pollId}/options', 'verb' => 'GET'], + ['name' => 'option_api#add', 'url' => '/api/v1.0/poll/{pollId}/option', 'verb' => 'POST'], + ['name' => 'option_api#update', 'url' => '/api/v1.0/option/{optionId}', 'verb' => 'PUT'], + ['name' => 'option_api#delete', 'url' => '/api/v1.0/option/{optionId}', 'verb' => 'DELETE'], + ['name' => 'option_api#setOrder', 'url' => '/api/v1.0/option/{optionId}/setorder/{order}', 'verb' => 'PUT'], + ['name' => 'option_api#confirm', 'url' => '/api/v1.0/option/{optionId}/confirm', 'verb' => 'PUT'], ['name' => 'vote_api#list', 'url' => '/api/v1.0/poll/{pollId}/votes', 'verb' => 'GET'], - ['name' => 'vote_api#set', 'url' => '/api/v1.0/vote', 'verb' => 'POST'], + ['name' => 'vote_api#set', 'url' => '/api/v1.0/vote', 'verb' => 'POST'], + + ['name' => 'share_api#list', 'url' => '/api/v1.0/poll/{pollId}/shares', 'verb' => 'GET'], + ['name' => 'share_api#get', 'url' => '/api/v1.0/share/{token}', 'verb' => 'GET'], + ['name' => 'share_api#add', 'url' => '/api/v1.0/share', 'verb' => 'POST'], + ['name' => 'share_api#delete', 'url' => '/api/v1.0/share/{token}', 'verb' => 'DELETE'], + ['name' => 'share_api#sendInvitation', 'url' => '/api/v1.0/share/send/{token}', 'verb' => 'POST'], + + ['name' => 'subscription_api#get', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'GET'], + ['name' => 'subscription_api#subscribe', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'PUT'], + ['name' => 'subscription_api#unsubscribe', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'DELETE'], + + ['name' => 'comment_api#list', 'url' => '/api/v1.0/poll/{pollId}/comments', 'verb' => 'GET'], + ['name' => 'comment_api#add', 'url' => '/api/v1.0/comment', 'verb' => 'POST'], + ['name' => 'comment_api#delete', 'url' => '/api/v1.0/comment/{commentId}', 'verb' => 'DELETE'], + ] ]; diff --git a/lib/Controller/AclController.php b/lib/Controller/AclController.php deleted file mode 100644 index 2bb1561f6d..0000000000 --- a/lib/Controller/AclController.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * @author René Gieling - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -namespace OCA\Polls\Controller; - -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\DataResponse; - -use OCP\IRequest; - -use OCA\Polls\Model\Acl; - - -class AclController extends Controller { - - private $acl; - - /** - * PageController constructor. - * @param string $appName - * @param IRequest $request - * @param Acl $acl - */ - public function __construct( - $appName, - IRequest $request, - Acl $acl - ) { - parent::__construct($appName, $request); - $this->acl = $acl; - } - - /** - * Read acl with poll id for current user - * @NoAdminRequired - * @param integer $pollId - * @return array - */ - public function get($id) { - $acl = $this->acl->setPollId($id); - // $acl = $this->acl->setUserId('dartcafe'); - return new DataResponse($acl, Http::STATUS_OK); - } - - /** - * Read acl with share token - * @NoAdminRequired - * @PublicPage - * @NoCSRFRequired - * @param integer $pollId - * @return array - */ - public function getByToken($token) { - $acl = $this->acl->setToken($token); - return new DataResponse($acl, Http::STATUS_OK); - - } - -} diff --git a/lib/Controller/CommentApiController.php b/lib/Controller/CommentApiController.php index 6cc56bba92..16d3b66a68 100644 --- a/lib/Controller/CommentApiController.php +++ b/lib/Controller/CommentApiController.php @@ -25,24 +25,25 @@ use Exception; use OCP\AppFramework\Db\DoesNotExistException; +use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use \OCP\IURLGenerator; +use OCP\IURLGenerator; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; -use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Service\CommentService; class CommentApiController extends ApiController { + /** @var CommentService */ private $commentService; + /** - * CommentApiController constructor. + * CommentApiController constructor * @param string $appName * @param IRequest $request * @param CommentService $commentService @@ -62,12 +63,11 @@ public function __construct( } /** - * get * Read all comments of a poll based on the poll id and return list as array * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function list($pollId) { @@ -81,7 +81,7 @@ public function list($pollId) { } /** - * Write a new comment to the db and returns the new comment as array + * Add comment * @NoAdminRequired * @CORS * @NoCSRFRequired @@ -100,7 +100,7 @@ public function add($pollId, $message) { } /** - * Delete Comment + * Delete comment * @NoAdminRequired * @CORS * @NoCSRFRequired diff --git a/lib/Controller/CommentController.php b/lib/Controller/CommentController.php index 6f240f0531..d68d875e6e 100644 --- a/lib/Controller/CommentController.php +++ b/lib/Controller/CommentController.php @@ -25,25 +25,24 @@ use Exception; use OCP\AppFramework\Db\DoesNotExistException; +use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; -use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Service\CommentService; class CommentController extends Controller { + /** @var CommentService */ private $commentService; /** - * CommentController constructor. + * CommentController constructor * @param string $appName * @param IRequest $request * @param CommentService $commentService @@ -58,28 +57,15 @@ public function __construct( $this->commentService = $commentService; } - /** - * get - * Read all comments of a poll based on the poll id and return list as array - * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId - * @return DataResponse - */ - public function list($pollId) { - return new DataResponse($this->commentService->list($pollId), Http::STATUS_OK); - } - // /** - // * Read all comments of a poll based on a share token and return list as array + // * Read all comments of a poll based on the poll id and return list as array // * @NoAdminRequired - // * @NoCSRFRequired - // * @PublicPage + // * @param int $pollId // * @param string $token // * @return DataResponse // */ - // public function getByToken($token) { - // return new DataResponse($this->commentService->get(0, $token), Http::STATUS_OK); + // public function list($pollId) { + // return new DataResponse($this->commentService->list($pollId), Http::STATUS_OK); // } // /** diff --git a/lib/Controller/OptionApiController.php b/lib/Controller/OptionApiController.php index e3396a3ed7..f08844358f 100644 --- a/lib/Controller/OptionApiController.php +++ b/lib/Controller/OptionApiController.php @@ -23,21 +23,21 @@ namespace OCA\Polls\Controller; -use Exception; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; +use \Exception; +use \Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; + use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; - - use OCA\Polls\Service\OptionService; class OptionApiController extends ApiController { + /** @var OptionService */ private $optionService; /** @@ -65,14 +65,14 @@ public function __construct( * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function list($pollId) { try { return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK); } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND); + return new DataResponse([], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } @@ -80,26 +80,18 @@ public function list($pollId) { /** - * Add a new Option to poll + * Add a new option * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @param string $pollOptionText - * @param integer $timestamp + * @param int $timestamp * @return DataResponse */ - public function add($pollId, $pollOptionText = '', $timestamp = 0) { - $option = [ - 'pollId' => $pollId, - 'pollOptionText' => $pollOptionText, - 'timestamp' => $timestamp - ]; - + public function add($pollId, $timestamp = 0, $pollOptionText = '') { try { - return new DataResponse(['option' => $this->optionService->add($option)], Http::STATUS_CREATED); - } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND); + return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_CREATED); } catch (UniqueConstraintViolationException $e) { return new DataResponse(['error' => 'Option exists'], Http::STATUS_CONFLICT); } catch (NotAuthorizedException $e) { @@ -109,27 +101,27 @@ public function add($pollId, $pollOptionText = '', $timestamp = 0) { /** - * Update poll option + * Update option * @NoAdminRequired * @CORS * @NoCSRFRequired * @param array $option * @return DataResponse */ - public function update($option) { + public function update($optionId, $timestamp = 0 , $pollOptionText = '') { try { - return new DataResponse(['option' => $this->optionService->update($option)], Http::STATUS_OK); + return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText, $order)], Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * Remove a single option + * Delete option * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $optionId + * @param int $optionId * @return DataResponse */ public function delete($optionId) { @@ -141,4 +133,38 @@ public function delete($optionId) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } + + /** + * Switch option confirmation + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * @param int $optionId + * @return DataResponse + */ + public function confirm($optionId) { + try { + return new DataResponse(['option' => $this->optionService->confirm($optionId)], Http::STATUS_OK); + } catch (DoesNotExistException $e) { + return new DataResponse(['error' => 'Option does not exist'], Http::STATUS_NOT_FOUND); + } catch (NotAuthorizedException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } + } + + /** + * Set order position for option + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * @param array $option + * @return DataResponse + */ + public function setOrder($optionId, $order) { + try { + return new DataResponse(['option' => $this->optionService->setOrder($optionId, $order)], Http::STATUS_OK); + } catch (NotAuthorizedException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } + } } diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php index 0ec2409229..1fa382f6c4 100644 --- a/lib/Controller/OptionController.php +++ b/lib/Controller/OptionController.php @@ -26,16 +26,15 @@ use Exception; use OCP\IRequest; + use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; - -use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Service\OptionService; class OptionController extends Controller { + /** @var OptionService */ private $optionService; /** @@ -54,69 +53,73 @@ public function __construct( $this->optionService = $optionService; } - /** - * Get all options of given poll - * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId - * @return DataResponse - */ - public function list($pollId) { - return new DataResponse($this->optionService->list($pollId), Http::STATUS_OK); - } - + // /** + // * Get all options of given poll + // * @NoAdminRequired + // * @param int $pollId + // * @return DataResponse + // */ + // public function list($pollId) { + // return new DataResponse($this->optionService->list($pollId), Http::STATUS_OK); + // } + // + // + // /** + // * Get all options specified by token + // * Read all options of a poll based on a share token and return list as array + // * @NoAdminRequired + // * @PublicPage + // * @param string $token + // * @return DataResponse + // */ + // public function listByToken($token) { + // return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK); + // } /** - * getByToken - * Read all options of a poll based on a share token and return list as array - * @NoAdminRequired - * @PublicPage - * @NoCSRFRequired - * @param string $token - * @return DataResponse - */ - public function getByToken($token) { - return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK); + * Add a new option + * @NoAdminRequired + * @param array $option + * @return DataResponse + */ + public function add($pollId, $timestamp = 0, $pollOptionText = '') { + return new DataResponse($this->optionService->add($pollId, $timestamp, $pollOptionText), Http::STATUS_OK); } /** - * Add a new Option to poll + * Update option * @NoAdminRequired - * @NoCSRFRequired * @param array $option * @return DataResponse */ - public function add($option) { - return new DataResponse($this->optionService->add($option), Http::STATUS_OK); + public function update($optionId, $timestamp, $pollOptionText) { + return new DataResponse($this->optionService->update($optionId, $timestamp, $pollOptionText), Http::STATUS_OK); } /** - * Update poll option + * Delete option * @NoAdminRequired - * @NoCSRFRequired - * @param array $option + * @param Option $option * @return DataResponse */ - public function update($option) { - return new DataResponse($this->optionService->update($option), Http::STATUS_OK); + public function delete($optionId) { + return new DataResponse($this->optionService->delete($optionId), Http::STATUS_OK); } /** - * Remove a single option + * Switch option confirmation * @NoAdminRequired - * @NoCSRFRequired - * @param Option $option + * @param int $optionId * @return DataResponse */ - public function remove($option) { - return new DataResponse($this->optionService->delete($option['id']), Http::STATUS_OK); + public function confirm($optionId) { + return new DataResponse($this->optionService->confirm($optionId), Http::STATUS_OK); } /** - * Set order by order of the given array + * Reorder options * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @param Array $options * @return DataResponse */ diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 71e0a7cde0..587a41846a 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -37,6 +37,7 @@ class PageController extends Controller { + /** @var IURLGenerator */ private $urlGenerator; /** diff --git a/lib/Controller/PollApiController.php b/lib/Controller/PollApiController.php index 3c8acc9dc6..20eb2ea076 100644 --- a/lib/Controller/PollApiController.php +++ b/lib/Controller/PollApiController.php @@ -32,7 +32,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; - use OCP\ILogger; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -41,35 +40,32 @@ class PollApiController extends ApiController { - private $logger; + + /** @var PollService */ private $pollService; /** - * PollController constructor. + * PollApiController constructor * @param string $appName - * @param $userId * @param IRequest $request - * @param ILogger $logger * @param PollService $pollService */ public function __construct( string $appName, IRequest $request, - ILogger $logger, PollService $pollService ) { parent::__construct($appName, $request); - $this->logger = $logger; $this->pollService = $pollService; } /** - * list + * Get list of polls * @NoAdminRequired - * @NoCSRFRequired * @CORS + * @NoCSRFRequired * @return DataResponse */ @@ -85,11 +81,12 @@ public function list() { /** - * get + * get poll configuration * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param integer $pollId - * @return array + * @param int $pollId + * @return DataResponse */ public function get($pollId) { try { @@ -102,9 +99,10 @@ public function get($pollId) { } /** - * write + * Add poll * @NoAdminRequired * @NoCSRFRequired + * @CORS * @param Array $poll * @return DataResponse */ @@ -122,10 +120,12 @@ public function add($type, $title) { } /** - * write + * Update poll configuration * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param Array $poll + * @param int $pollId + * @param array $poll * @return DataResponse */ @@ -146,14 +146,15 @@ public function update($pollId, $poll) { } /** - * delete + * Switch deleted status (move to deleted polls) * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param Array $poll + * @param int $pollId * @return DataResponse */ - public function delete($pollId) { + public function trash($pollId) { try { return new DataResponse(['poll' => $this->pollService->delete($pollId)], Http::STATUS_OK); } catch (DoesNotExistException $e) { @@ -164,14 +165,15 @@ public function delete($pollId) { } /** - * deletePermanently + * Delete poll * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param Array $poll + * @param int $pollId * @return DataResponse */ - public function deletePermanently($pollId) { + public function delete($pollId) { try { return new DataResponse(['poll' => $this->pollService->deletePermanently($pollId)], Http::STATUS_OK); } catch (DoesNotExistException $e) { @@ -183,10 +185,11 @@ public function deletePermanently($pollId) { } /** - * clone + * Clone poll * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function clone($pollId) { @@ -200,8 +203,9 @@ public function clone($pollId) { } /** - * enum + * Get valid values for configuration options * @NoAdminRequired + * @CORS * @NoCSRFRequired * @param Array $poll * @return DataResponse diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 27f9c4be1c..834fb39195 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -21,7 +21,7 @@ * */ - namespace OCA\Polls\Controller; +namespace OCA\Polls\Controller; use Exception; use OCP\AppFramework\Db\DoesNotExistException; @@ -32,7 +32,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -46,19 +45,28 @@ class PollController extends Controller { - private $logger; + /** @var PollService */ private $pollService; + + /** @var CommentService */ private $commentService; + + /** @var OptionService */ private $optionService; + + /** @var ShareService */ private $shareService; + + /** @var VoteService */ private $voteService; + + /** @var Acl */ private $acl; /** * PollController constructor. * @param string $appName * @param IRequest $request - * @param ILogger $logger * @param PollService $pollService * @param CommentService $commentService * @param OptionService $optionService @@ -70,7 +78,6 @@ class PollController extends Controller { public function __construct( string $appName, IRequest $request, - ILogger $logger, PollService $pollService, CommentService $commentService, OptionService $optionService, @@ -79,7 +86,6 @@ public function __construct( Acl $acl ) { parent::__construct($appName, $request); - $this->logger = $logger; $this->pollService = $pollService; $this->commentService = $commentService; $this->optionService = $optionService; @@ -90,9 +96,8 @@ public function __construct( /** - * list + * Get list of polls * @NoAdminRequired - * @NoCSRFRequired * @return DataResponse */ @@ -108,12 +113,12 @@ public function list() { /** - * get + * get complete poll * @NoAdminRequired - * @NoCSRFRequired * @PublicPage - * @param integer $pollId - * @return array + * @param int $pollId + * @param string $token + * @return DataResponse */ public function get($pollId, $token) { try { @@ -125,8 +130,6 @@ public function get($pollId, $token) { $acl = $this->acl->setPollId($pollId); } - // $this->poll = $this->pollService->get($pollId, $token); - // return new DataResponse($this->pollService->get($pollId, $token), Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { @@ -134,25 +137,25 @@ public function get($pollId, $token) { } try { - $comments = $this->commentService->list($this->acl->getPollId(), $token); + $comments = $this->commentService->list($poll->getId(), $token); } catch (Exception $e) { $comments = []; } try { - $options = $this->optionService->list($this->acl->getPollId(), $token); + $options = $this->optionService->list($poll->getId(), $token); } catch (Exception $e) { $options = []; } try { - $votes = $this->voteService->list($this->acl->getPollId(), $token); + $votes = $this->voteService->list($poll->getId(), $token); } catch (Exception $e) { $votes = []; } try { - $shares = $this->shareService->list($this->acl->getPollId()); + $shares = $this->shareService->list($poll->getId()); } catch (Exception $e) { $shares = []; } @@ -168,98 +171,95 @@ public function get($pollId, $token) { } /** - * delete + * Add poll * @NoAdminRequired - * @NoCSRFRequired - * @param Array $poll + * @param string $type + * @param string $title * @return DataResponse */ - public function delete($pollId) { + public function add($type, $title) { try { - return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK); - } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); + return new DataResponse($this->pollService->add($type, $title), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (InvalidPollTypeException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (EmptyTitleException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * deletePermanently + * Update poll configuration * @NoAdminRequired - * @NoCSRFRequired - * @param Array $poll + * @param int $pollId + * @param array $poll * @return DataResponse */ - public function deletePermanently($pollId) { + public function update($pollId, $poll) { try { - return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK); + return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (InvalidAccessException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (InvalidShowResultsException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (EmptyTitleException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } - /** - * add + * Switch deleted status (move to deleted polls) * @NoAdminRequired - * @NoCSRFRequired - * @param string $type - * @param string $title + * @param int $pollId * @return DataResponse */ - public function add($type, $title) { + public function delete($pollId) { try { - return new DataResponse($this->pollService->add($type, $title), Http::STATUS_OK); + return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK); + } catch (DoesNotExistException $e) { + return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (InvalidPollTypeException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (EmptyTitleException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * write + * Delete poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId - * @param array $poll + * @param Array $poll * @return DataResponse */ - public function update($pollId, $poll) { + public function deletePermanently($pollId) { try { - return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK); + return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (InvalidAccessException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (InvalidShowResultsException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (EmptyTitleException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * clone + * Clone poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function clone($pollId) { try { - return new DataResponse($this->pollService->clone($pollId), Http::STATUS_OK); + $poll = $this->pollService->clone($pollId); + $this->optionService->clone($pollId, $poll->getId()); + + return new DataResponse($poll, Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { diff --git a/lib/Controller/ShareApiController.php b/lib/Controller/ShareApiController.php index 3d7912da19..261262b892 100644 --- a/lib/Controller/ShareApiController.php +++ b/lib/Controller/ShareApiController.php @@ -28,7 +28,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\InvalidUsername; - use OCP\IRequest; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; @@ -39,13 +38,15 @@ class ShareApiController extends ApiController { + /** @var ShareService */ private $shareService; + + /** @var MailService */ private $mailService; /** - * ShareController constructor. + * ShareApiController constructor * @param string $appName - * @param string $userId * @param IRequest $request * @param MailService $mailService * @param ShareService $shareService @@ -66,12 +67,11 @@ public function __construct( } /** - * list * Read all shares of a poll based on the poll id and return list as array * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function list($pollId) { @@ -85,11 +85,10 @@ public function list($pollId) { } /** - * get share by token - * Get pollId by token + * Get share by token * @NoAdminRequired - * @NoCSRFRequired * @CORS + * @NoCSRFRequired * @param string $token * @return DataResponse */ @@ -104,7 +103,7 @@ public function get($token) { } /** - * Write a new share to the db and returns the new share as array + * Add share * @NoAdminRequired * @CORS * @NoCSRFRequired @@ -117,47 +116,46 @@ public function get($token) { public function add($pollId, $type, $userId = '', $userEmail = '') { try { return new DataResponse(['share' => $this->shareService->add($pollId, $type, $userId, $userEmail)], Http::STATUS_CREATED); - } catch (\Exception $e) { - return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (Exception $e) { + return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } } /** - * SendInvitation - * Sent invitation mails for a share + * Delete share * @NoAdminRequired * @CORS * @NoCSRFRequired * @param string $token * @return DataResponse */ - public function sendInvitation($token) { + + public function delete($token) { try { - return new DataResponse($this->mailService->sendInvitationMail($token), Http::STATUS_OK); - } catch (Exception $e) { + return new DataResponse(['share' => $this->shareService->delete($token)], Http::STATUS_OK); + } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (DoesNotExistException $e) { + return new DataResponse($e, Http::STATUS_NOT_FOUND); } } /** - * delete share + * Sent invitation mails for a share * @NoAdminRequired * @CORS * @NoCSRFRequired * @param string $token * @return DataResponse */ - - public function delete($token) { + public function sendInvitation($token) { try { - return new DataResponse(['share' => $this->shareService->remove($token)], Http::STATUS_OK); - } catch (NotAuthorizedException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + return new DataResponse($this->mailService->sendInvitationMail($token), Http::STATUS_OK); } catch (Exception $e) { - return new DataResponse($e, Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } } diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index bd3dd187e6..bb55c5b87f 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -30,54 +30,47 @@ use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; - - -use OCA\Polls\Model\Acl; use OCA\Polls\Service\ShareService; use OCA\Polls\Service\MailService; class ShareController extends Controller { - private $logger; + /** @var ShareService */ private $shareService; + + /** @var MailService */ private $mailService; - private $userId; /** * ShareController constructor. * @param string $appName - * @param string $userId * @param IRequest $request - * @param ILogger $logger * @param MailService $mailService * @param ShareService $shareService */ public function __construct( string $appName, - $userId, IRequest $request, - ILogger $logger, MailService $mailService, ShareService $shareService ) { parent::__construct($appName, $request); - $this->logger = $logger; - $this->userId = $userId; $this->shareService = $shareService; $this->mailService = $mailService; } /** - * Write a new share to the db and returns the new share as array + * Add share * @NoAdminRequired - * @NoCSRFRequired * @param int $pollId - * @param Array $share + * @param int $pollId + * @param string $type + * @param string $userId + * @param string $userEmail * @return DataResponse */ public function add($pollId, $type, $userId = '', $userEmail = '') { @@ -91,19 +84,18 @@ public function add($pollId, $type, $userId = '', $userEmail = '') { } /** - * createPersonalShare - * Write a new share to the db and returns the new share as array + * Create a personal share from a public share + * or update an email share with the username * @NoAdminRequired * @PublicPage - * @NoCSRFRequired * @param string $token * @param string $userName * @return DataResponse */ - public function createPersonalShare($token, $userName) { + public function personal($token, $userName) { try { - return new DataResponse($this->shareService->createPersonalShare($token, $userName), Http::STATUS_CREATED); + return new DataResponse($this->shareService->personal($token, $userName), Http::STATUS_CREATED); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } catch (InvalidUsername $e) { @@ -115,43 +107,36 @@ public function createPersonalShare($token, $userName) { } /** - * SendInvitation - * Sent invitation mails for a share + * Delete share * @NoAdminRequired - * @PublicPage - * @NoCSRFRequired * @param string $token * @return DataResponse */ - public function sendInvitation($token) { + + public function delete($token) { try { - $sentResult = $this->mailService->sendInvitationMail($token); - $share = $this->shareService->get($token); - return new DataResponse(['share' => $share, 'sentResult' => $sentResult], Http::STATUS_OK); - } catch (Exception $e) { + return new DataResponse($this->shareService->delete($token), Http::STATUS_OK); + } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (Exception $e) { + return new DataResponse($e, Http::STATUS_NOT_FOUND); } } /** - * remove - * remove share + * Sent invitation mails for a share * @NoAdminRequired - * @NoCSRFRequired - * @param Share $share + * @PublicPage + * @param string $token * @return DataResponse */ - - public function delete($share) { + public function sendInvitation($token) { try { - return new DataResponse(array( - 'action' => 'deleted', - 'shareId' => $this->shareService->remove($share['token'])->getId() - ), Http::STATUS_OK); - } catch (NotAuthorizedException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + $sentResult = $this->mailService->sendInvitationMail($token); + $share = $this->shareService->get($token); + return new DataResponse(['share' => $share, 'sentResult' => $sentResult], Http::STATUS_OK); } catch (Exception $e) { - return new DataResponse($e, Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } } diff --git a/lib/Controller/SubscriptionApiController.php b/lib/Controller/SubscriptionApiController.php index 3a23d403b0..13ffe3eb6b 100644 --- a/lib/Controller/SubscriptionApiController.php +++ b/lib/Controller/SubscriptionApiController.php @@ -28,7 +28,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; @@ -38,25 +37,20 @@ class SubscriptionApiController extends ApiController { - private $userId; + /** @var SubscriptionService */ private $subscriptionService; - private $logger; /** - * SubscriptionController constructor. + * SubscriptionApiController constructor * @param string $appName - * @param $UserId * @param SubscriptionService $subscriptionService * @param IRequest $request - * @param ILogger $logger */ public function __construct( string $appName, - $userId, SubscriptionService $subscriptionService, - IRequest $request, - ILogger $logger + IRequest $request ) { parent::__construct($appName, @@ -64,17 +58,18 @@ public function __construct( 'PUT, GET, DELETE', 'Authorization, Content-Type, Accept', 1728000); - $this->userId = $userId; $this->subscriptionService = $subscriptionService; - $this->logger = $logger; } /** + * Get subscription status * @NoAdminRequired * CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse + * @throws DoesNotExistException + * @throws NotAuthorizedException */ public function get($pollId) { try { @@ -88,10 +83,12 @@ public function get($pollId) { } /** + * Subscribe to poll * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId + * @throws NotAuthorizedException */ public function subscribe($pollId) { try { @@ -102,10 +99,12 @@ public function subscribe($pollId) { } } /** + * Unsubscribe from poll * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId + * @throws NotAuthorizedException */ public function unsubscribe($pollId) { try { diff --git a/lib/Controller/SubscriptionController.php b/lib/Controller/SubscriptionController.php index e90f4a66f8..f2517237be 100644 --- a/lib/Controller/SubscriptionController.php +++ b/lib/Controller/SubscriptionController.php @@ -28,7 +28,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -37,38 +36,32 @@ class SubscriptionController extends Controller { - private $userId; + /** @var SubscriptionService */ private $subscriptionService; - private $logger; /** * SubscriptionController constructor. * @param string $appName - * @param $UserId * @param SubscriptionService $subscriptionService * @param IRequest $request - * @param ILogger $logger */ public function __construct( string $appName, - $userId, SubscriptionService $subscriptionService, - IRequest $request, - ILogger $logger - + IRequest $request ) { parent::__construct($appName, $request); - $this->userId = $userId; $this->subscriptionService = $subscriptionService; - $this->logger = $logger; } /** + * Get subscription status * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse + * @throws DoesNotExistException + * @throws NotAuthorizedException */ public function get($pollId) { try { @@ -81,9 +74,12 @@ public function get($pollId) { } /** + * Switch subscription status * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId + * @param int $subscribed + * @return DataResponse + * @throws NotAuthorizedException */ public function set($pollId, $subscribed) { try { diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index 44dfbf8ab6..b1e2c6060c 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -36,16 +36,25 @@ use OCA\Polls\Db\ShareMapper; use OCA\Polls\Db\Vote; use OCA\Polls\Db\VoteMapper; -use OCP\ILogger; class SystemController extends Controller { + /** @var string */ private $userId; - private $logger; + + /** @var IConfig */ private $systemConfig; + + /** @var IGroupManager */ private $groupManager; + + /** @var IUserManager */ private $userManager; + + /** @var VoteMapper */ private $voteMapper; + + /** @var ShareMapper */ private $shareMapper; /** @@ -53,7 +62,6 @@ class SystemController extends Controller { * @param string $appName * @param $userId * @param IRequest $request - * @param ILogger $logger * @param IConfig $systemConfig * @param IGroupManager $groupManager * @param IUserManager $userManager @@ -64,7 +72,6 @@ public function __construct( string $appName, $userId, IRequest $request, - ILogger $logger, IConfig $systemConfig, IGroupManager $groupManager, IUserManager $userManager, @@ -74,7 +81,6 @@ public function __construct( parent::__construct($appName, $request); $this->voteMapper = $voteMapper; $this->shareMapper = $shareMapper; - $this->logger = $logger; $this->userId = $userId; $this->systemConfig = $systemConfig; $this->groupManager = $groupManager; @@ -85,7 +91,7 @@ public function __construct( * Validate string as email address * @NoAdminRequired * @param string $query - * @return Boolval + * @return boolval */ private function isValidEmail($email) { return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $email)) ? false : true; @@ -207,7 +213,6 @@ public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers } } - } return new DataResponse([ @@ -303,13 +308,13 @@ public function validatePublicUsername($pollId, $userName, $token) { ], 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; - } - } + // 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/Controller/VoteApiController.php b/lib/Controller/VoteApiController.php index 21d7762dca..8f8976ba98 100644 --- a/lib/Controller/VoteApiController.php +++ b/lib/Controller/VoteApiController.php @@ -28,7 +28,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -37,20 +36,18 @@ class VoteApiController extends ApiController { - private $logger; + /** @var VoteService */ private $voteService; /** - * VoteController constructor. + * VoteAPIController constructor * @param string $appName * @param IRequest $request - * @param ILogger $logger * @param VoteService $voteService */ public function __construct( string $appName, IRequest $request, - ILogger $logger, VoteService $voteService ) { parent::__construct($appName, @@ -59,16 +56,14 @@ public function __construct( 'Authorization, Content-Type, Accept', 1728000); $this->voteService = $voteService; - $this->logger = $logger; } /** - * Get all votes of given poll * Read all votes of a poll based on the poll id and return list as array * @NoAdminRequired - * @NoCSRFRequired * @CORS - * @param integer $pollId + * @NoCSRFRequired + * @param int $pollId * @return DataResponse */ public function list($pollId) { @@ -82,21 +77,19 @@ public function list($pollId) { } /** - * set + * Set vote answer * @NoAdminRequired - * @NoCSRFRequired * @CORS - * @param integer $pollId - * @param Array $option - * @param string $userId + * @NoCSRFRequired + * @param int $optionId * @param string $setTo * @return DataResponse */ - public function set($pollId, $pollOptionText, $setTo) { + public function set($optionId, $setTo) { try { - return new DataResponse(['vote' => $this->voteService->set($pollId, $pollOptionText, $setTo)], Http::STATUS_OK); + return new DataResponse(['vote' => $this->voteService->set($optionId, $setTo)], Http::STATUS_OK); } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } diff --git a/lib/Controller/VoteController.php b/lib/Controller/VoteController.php index f666c0046d..02ccc9a040 100644 --- a/lib/Controller/VoteController.php +++ b/lib/Controller/VoteController.php @@ -27,7 +27,6 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; -use OCP\ILogger; use OCP\IRequest; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; @@ -38,34 +37,29 @@ class VoteController extends Controller { + /** @var VoteService */ private $voteService; - private $logger; /** - * VoteController constructor. + * VoteController constructor * @param string $appName * @param IRequest $request - * @param ILogger $logger * @param VoteService $voteService */ public function __construct( string $appName, - ILogger $logger, IRequest $request, VoteService $voteService ) { parent::__construct($appName, $request); - $this->logger = $logger; $this->voteService = $voteService; } /** - * Get all votes of given poll * Read all votes of a poll based on the poll id and return list as array * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function get($pollId) { @@ -82,33 +76,28 @@ public function get($pollId) { * set * @NoAdminRequired * @NoCSRFRequired - * @param integer $pollId - * @param Array $option - * @param string $userId + * @param int $optionId * @param string $setTo * @return DataResponse */ - public function set($pollId, $option, $setTo) { + public function set($optionId, $setTo) { try { - return new DataResponse($this->voteService->set($pollId, $option['pollOptionText'], $setTo), Http::STATUS_OK); + return new DataResponse($this->voteService->set($optionId, $setTo), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND); } } - /** - * delete + * Remove user from poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $voteId * @param string $userId - * @param integer $pollId + * @param int $pollId * @return DataResponse */ - public function delete($userId, $pollId) { + public function delete($pollId, $userId) { try { return new DataResponse($this->voteService->delete($pollId, $userId), Http::STATUS_OK); } catch (NotAuthorizedException $e) { @@ -123,18 +112,17 @@ public function delete($userId, $pollId) { */ /** - * setByToken + * Set vote with token * @NoAdminRequired * @PublicPage - * @NoCSRFRequired * @param Array $option * @param string $setTo * @param string $token * @return DataResponse */ - public function setByToken($option, $setTo, $token) { + public function setByToken($optionId, $setTo, $token) { try { - return new DataResponse($this->voteService->set(0, $option['pollOptionText'], $setTo, $token), Http::STATUS_OK); + return new DataResponse($this->voteService->set($optionId, $setTo, $token), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } catch (DoesNotExistException $e) { @@ -144,11 +132,9 @@ public function setByToken($option, $setTo, $token) { } /** - * getByToken * Read all votes of a poll based on a share token and return list as array * @NoAdminRequired * @PublicPage - * @NoCSRFRequired * @param string $token * @return DataResponse */ diff --git a/lib/Cron/NotificationCron.php b/lib/Cron/NotificationCron.php index e5ddbe13d6..6aa4fb17a6 100644 --- a/lib/Cron/NotificationCron.php +++ b/lib/Cron/NotificationCron.php @@ -28,11 +28,10 @@ class NotificationCron extends TimedJob { - /** @var MailService*/ + /** @var MailService */ private $mailService; - /** @param MailService $mailService - */ + /** @param MailService $mailService */ public function __construct( MailService $mailService ) { diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php index 4935c077d2..56514570be 100644 --- a/lib/Db/Comment.php +++ b/lib/Db/Comment.php @@ -31,9 +31,9 @@ use OCP\AppFramework\Db\Entity; /** - * @method integer getId() + * @method int getId() * @method void setId(integer $value) - * @method integer getPollId() + * @method int getPollId() * @method void setPollId(integer $value) * @method string getUserId() * @method void setUserId(string $value) diff --git a/lib/Db/Log.php b/lib/Db/Log.php index ce2492f346..9205667478 100644 --- a/lib/Db/Log.php +++ b/lib/Db/Log.php @@ -29,13 +29,13 @@ use OCP\AppFramework\Db\Entity; /** - * @method integer getPollId() + * @method int getPollId() * @method void setPollId(integer $value) - * @method integer getCreated() + * @method int getCreated() * @method void setCreated(integer $value) - * @method integer getProcessed() + * @method int getProcessed() * @method void setProcessed(integer $value) - * @method integer getUserId() + * @method int getUserId() * @method void setUserId(string $value) * @method string getDisplayName() * @method void setDisplayName(string $value) diff --git a/lib/Db/Option.php b/lib/Db/Option.php index 8f4d4fcf5b..d02f167ec4 100644 --- a/lib/Db/Option.php +++ b/lib/Db/Option.php @@ -30,17 +30,17 @@ use OCP\AppFramework\Db\Entity; /** - * @method integer getId() + * @method int getId() * @method void setId(integer $value) - * @method integer getPollId() + * @method int getPollId() * @method void setPollId(integer $value) * @method string getPollOptionText() * @method void setPollOptionText(string $value) - * @method integer getTimestamp() + * @method int getTimestamp() * @method void setTimestamp(integer $value) - * @method integer getOrder() + * @method int getOrder() * @method void setOrder(integer $value) - * @method integer getConfirmed() + * @method int getConfirmed() * @method void setConfirmed(integer $value) */ class Option extends Entity implements JsonSerializable { diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php index 8fa2d05695..d574a48154 100644 --- a/lib/Db/Poll.php +++ b/lib/Db/Poll.php @@ -39,29 +39,29 @@ * @method void setDescription(string $value) * @method string getOwner() * @method void setOwner(string $value) - * @method integer getCreated() + * @method int getCreated() * @method void setCreated(integer $value) - * @method integer getExpire() + * @method int getExpire() * @method void setExpire(integer $value) - * @method integer getDeleted() + * @method int getDeleted() * @method void setDeleted(integer $value) * @method string getAccess() * @method void setAccess(string $value) - * @method integer getAnonymous() + * @method int getAnonymous() * @method void setAnonymous(integer $value) - * @method integer getFullAnonymous() + * @method int getFullAnonymous() * @method void setFullAnonymous(integer $value) - * @method integer getAllowMaybe() + * @method int getAllowMaybe() * @method void setAllowMaybe(integer $value) * @method string getOptions() * @method void setOptions(string $value) * @method string getSettings() * @method void setSettings(string $value) - * @method integer getVoteLimit() + * @method int getVoteLimit() * @method void setVoteLimit(integer $value) * @method string getShowResults() * @method void setShowResults(string $value) - * @method integer getAdminAccess() + * @method int getAdminAccess() * @method void setAdminAccess(integer $value) */ class Poll extends Entity implements JsonSerializable { @@ -135,20 +135,6 @@ public function jsonSerialize() { ]; } - public function deserializeArray($array) { - $this->setTitle(isset($array['title']) ? $array['title'] : $this->getTitle()); - $this->setDescription(isset($array['description']) ? $array['description'] : $this->getDescription()); - $this->setAccess(isset($array['access']) ? $array['access'] : $this->getAccess()); - $this->setExpire(isset($array['expire']) ? $array['expire'] : $this->getExpire()); - $this->setAnonymous(isset($array['anonymous']) ? $array['anonymous'] : $this->getAnonymous()); - $this->setAllowMaybe(isset($array['allowMaybe']) ? $array['allowMaybe'] : $this->getAllowMaybe()); - $this->setVoteLimit(isset($array['voteLimit']) ? $array['voteLimit'] : $this->getVoteLimit()); - $this->setShowResults(isset($array['showResults']) ? $array['showResults'] : $this->getShowResults()); - $this->setDeleted(isset($array['deleted']) ? $array['deleted'] : $this->getDeleted()); - $this->setAdminAccess(isset($array['adminAccess']) ? $array['adminAccess'] : $this->getAdminAccess()); - return $this; - } - private function getDisplayName() { if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) { diff --git a/lib/Db/Share.php b/lib/Db/Share.php index 1a3042d22a..04b777335e 100644 --- a/lib/Db/Share.php +++ b/lib/Db/Share.php @@ -35,13 +35,13 @@ * @method void setToken(string $value) * @method string getType() * @method void setType(string $value) - * @method integer getPollId() + * @method int getPollId() * @method void setPollId(integer $value) * @method string getUserId() * @method void setUserId(string $value) * @method string getUserEmail() * @method void setUserEmail(string $value) - * @method integer getInvitationSent() + * @method int getInvitationSent() * @method void setInvitationSent(integer $value) */ class Share extends Entity implements JsonSerializable { diff --git a/lib/Db/Subscription.php b/lib/Db/Subscription.php index 256fcbc15d..ace2ebd509 100644 --- a/lib/Db/Subscription.php +++ b/lib/Db/Subscription.php @@ -29,9 +29,9 @@ use OCP\AppFramework\Db\Entity; /** - * @method integer getId() + * @method int getId() * @method void setId(integer $value) - * @method integer getPollId() + * @method int getPollId() * @method void setPollId(integer $value) * @method string getUserId() * @method void setUserId(string $value) diff --git a/lib/Db/Vote.php b/lib/Db/Vote.php index b601346761..839f154a73 100644 --- a/lib/Db/Vote.php +++ b/lib/Db/Vote.php @@ -30,11 +30,11 @@ use OCP\AppFramework\Db\Entity; /** - * @method integer getPollId() + * @method int getPollId() * @method void setPollId(integer $value) * @method string getUserId() * @method void setUserId(string $value) - * @method integer getVoteOptionId() + * @method int getVoteOptionId() * @method void setVoteOptionId(integer $value) * @method string getVoteOptionText() * @method void setVoteOptionText(string $value) diff --git a/lib/Exceptions/BadRequestException.php b/lib/Exceptions/BadRequestException.php new file mode 100644 index 0000000000..8c0c25c3ee --- /dev/null +++ b/lib/Exceptions/BadRequestException.php @@ -0,0 +1,40 @@ + + * + * @author René Gieling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Polls\Exceptions; + +use OCP\AppFramework\Http; + +class BadRequestException extends \Exception { + /** + * NotAuthorizedException Constructor + * @param string $e exception message + */ + public function __construct($e = 'Not allowed') { + parent::__construct($e); + } + public function getStatus() { + return Http::STATUS_BAD_REQUEST; + } + +} diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php index ebc998f258..7131943604 100644 --- a/lib/Model/Acl.php +++ b/lib/Model/Acl.php @@ -30,7 +30,6 @@ use OCP\IUserManager; use OCP\IGroupManager; -use OCP\ILogger; use OCP\IUser; use OCA\Polls\Db\Poll; use OCA\Polls\Db\Share; @@ -48,9 +47,6 @@ class Acl implements JsonSerializable { /** @var int */ private $pollId = 0; - /** @var ILogger */ - private $logger; - /** @var array */ private $shares = []; @@ -86,7 +82,6 @@ class Acl implements JsonSerializable { * Acl constructor. * @param string $appName * @param string $userId - * @param ILogger $logger * @param IUserManager $userManager * @param IGroupManager $groupManager * @param PollMapper $pollMapper @@ -97,7 +92,6 @@ class Acl implements JsonSerializable { */ public function __construct( $userId, - ILogger $logger, IUserManager $userManager, IGroupManager $groupManager, PollMapper $pollMapper, @@ -106,7 +100,6 @@ public function __construct( Poll $poll ) { $this->userId = $userId; - $this->logger = $logger; $this->userManager = $userManager; $this->groupManager = $groupManager; $this->pollMapper = $pollMapper; @@ -139,7 +132,7 @@ public function getDisplayName() { /** * @NoAdminRequired - * @return boolean + * @return bool */ public function setPollIdOrToken($pollId = 0, $token = '') { @@ -154,7 +147,7 @@ public function setPollIdOrToken($pollId = 0, $token = '') { /** * @NoAdminRequired - * @return boolean + * @return bool */ public function checkAuthorize($pollId = 0, $token = '') { @@ -403,14 +396,14 @@ public function getToken(): string { * @return string */ public function setToken(string $token): Acl { - $this->logger->debug('Share PollId' . $token); + \OC::$server->getLogger()->debug('Share PollId: ' . $token); try { $this->token = $token; $share = $this->shareMapper->findByToken($token); $this->foundByToken = true; $this->setPollId($share->getPollId()); - $this->logger->debug('Share PollId' . $share->getPollId()); + \OC::$server->getLogger()->debug('Share PollId: ' . $share->getPollId()); if (($share->getType() === 'group' || $share->getType() === 'user') && !\OC::$server->getUserSession()->isLoggedIn()) { // User must be logged in for shareType user and group diff --git a/lib/Service/AnonymizeService.php b/lib/Service/AnonymizeService.php index 80f11fa114..27fbdc9bb3 100644 --- a/lib/Service/AnonymizeService.php +++ b/lib/Service/AnonymizeService.php @@ -31,10 +31,19 @@ class AnonymizeService { + /** @var VoteMapper */ private $voteMapper; + + /** @var CommentMapper */ private $commentMapper; + + /** @var array */ private $anonList = array(); + + /** @var string */ private $userId; + + /** @var int */ private $pollId; public function __construct( @@ -74,7 +83,7 @@ private function anonymize($array) { * Initialize anonymizer with pollId and userId * Creates a mapping list with unique Anonymous strings based on the partcipants of a poll * @NoAdminRequired - * @param integer $pollId + * @param int $pollId * @param string $userId - usernames, which will not be anonymized */ diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index a1cd713181..f2c6ef563d 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -23,10 +23,9 @@ namespace OCA\Polls\Service; -use \Exception; -use OCP\ILogger; - +use Exception; use OCA\Polls\Exceptions\NotAuthorizedException; + use OCA\Polls\Db\Comment; use OCA\Polls\Db\CommentMapper; use OCA\Polls\Model\Acl; @@ -36,15 +35,20 @@ class CommentService { - private $comment; + /** @var CommentMapper */ private $commentMapper; - private $logger; + + /** @var Comment */ + private $comment; + + /** @var AnonymizeService */ private $anonymizer; + + /** @var Acl */ private $acl; /** * CommentService constructor. - * @param ILogger $logger * @param CommentMapper $commentMapper * @param Comment $comment * @param AnonymizeService $anonymizer @@ -52,7 +56,6 @@ class CommentService { */ public function __construct( - ILogger $logger, CommentMapper $commentMapper, Comment $comment, AnonymizeService $anonymizer, @@ -60,18 +63,18 @@ public function __construct( ) { $this->commentMapper = $commentMapper; $this->comment = $comment; - $this->logger = $logger; $this->anonymizer = $anonymizer; $this->acl = $acl; } /** - * get + * Get comments * Read all comments of a poll based on the poll id and return list as array * @NoAdminRequired - * @param integer $pollId + * @param int $pollId * @param string $token - * @return Array + * @return array + * @throws NotAuthorizedException */ public function list($pollId = 0, $token = '') { @@ -88,12 +91,13 @@ public function list($pollId = 0, $token = '') { } /** - * Write a new comment to the db and returns the new comment as array + * Add comment * @NoAdminRequired - * @param string $message * @param int $pollId + * @param string $message * @param string $token * @return Comment + * @throws NotAuthorizedException */ public function add($pollId = 0, $message, $token = '') { @@ -114,20 +118,20 @@ public function add($pollId = 0, $message, $token = '') { throw new NotAuthorizedException; } - } catch (\Exception $e) { - $this->logger->alert('Error writing comment for pollId ' . $pollId . ': '. $e); + } catch (Exception $e) { + \OC::$server->getLogger()->alert('Error writing comment for pollId ' . $pollId . ': '. $e); throw new NotAuthorizedException($e); } } /** - * delete - * Delete Comment + * Delete comment * @NoAdminRequired * @param int $commentId * @param string $token * @return Comment + * @throws NotAuthorizedException */ public function delete($commentId, $token = '') { $this->comment = $this->commentMapper->find($commentId); diff --git a/lib/Service/LogService.php b/lib/Service/LogService.php index d6936c04f5..950abf44ac 100644 --- a/lib/Service/LogService.php +++ b/lib/Service/LogService.php @@ -31,36 +31,38 @@ class LogService { - private $mapper; - private $logItem; + /** @var LogMapper */ + private $logMapper; + + /** @var Log */ + private $log; /** * LogService constructor. - * @param LogMapper $mapper - * @param Log $logItem + * @param LogMapper $logMapper + * @param Log $log */ - public function __construct( - LogMapper $mapper, - Log $logItem + LogMapper $logMapper, + Log $log ) { - $this->mapper = $mapper; - $this->logItem = $logItem; + $this->logMapper = $logMapper; + $this->log = $log; } /** * Prevent repetition of the same log event * @NoAdminRequired - * @return Bool + * @return bool */ public function isRepetition() { try { - $lastRecord = $this->mapper->getLastRecord($this->logItem->getPollId()); - return (intval($lastRecord->getPollId()) === intval($this->logItem->getPollId()) - && $lastRecord->getUserId() === $this->logItem->getUserId() - && $lastRecord->getMessageId() === $this->logItem->getMessageId() - && $lastRecord->getMessage() === $this->logItem->getMessage() + $lastRecord = $this->logMapper->getLastRecord($this->log->getPollId()); + return (intval($lastRecord->getPollId()) === intval($this->log->getPollId()) + && $lastRecord->getUserId() === $this->log->getUserId() + && $lastRecord->getMessageId() === $this->log->getMessageId() + && $lastRecord->getMessage() === $this->log->getMessage() ); } catch (DoesNotExistException $e) { return false; @@ -77,23 +79,23 @@ public function isRepetition() { * @return Log */ public function setLog($pollId, $messageId, $userId = null, $message = null) { - $this->logItem = new Log(); - $this->logItem->setPollId($pollId); - $this->logItem->setCreated(time()); - $this->logItem->setMessageId($messageId); - $this->logItem->setMessage($message); + $this->log = new Log(); + $this->log->setPollId($pollId); + $this->log->setCreated(time()); + $this->log->setMessageId($messageId); + $this->log->setMessage($message); if ($userId) { - $this->logItem->setUserId($userId); + $this->log->setUserId($userId); } else { - $this->logItem->setUserId(\OC::$server->getUserSession()->getUser()->getUID()); + $this->log->setUserId(\OC::$server->getUserSession()->getUser()->getUID()); } if ($this->isRepetition()) { return null; } else { - return $this->mapper->insert($this->logItem); + return $this->logMapper->insert($this->log); } } diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index fbd4098428..54fe8a34f3 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -34,7 +34,6 @@ use OCP\L10N\IFactory; use OCP\Mail\IMailer; use OCP\Mail\IEMailTemplate; -use OCP\ILogger; use OCA\Polls\Db\SubscriptionMapper; use OCA\Polls\Db\Subscription; @@ -46,18 +45,37 @@ class MailService { + /** @var IUserManager */ private $userManager; + + /** @var IGroupManager */ private $groupManager; + + /** @var IConfig */ private $config; + + /** @var IURLGenerator */ private $urlGenerator; + + /** @var IL10N */ private $trans; + + /** @var IFactory */ private $transFactory; + + /** @var IMailer */ private $mailer; - private $logger; - private $shareMapper; + /** @var SubscriptionMapper */ private $subscriptionMapper; + + /** @var ShareMapper */ + private $shareMapper; + + /** @var PollMapper */ private $pollMapper; + + /** @var LogMapper */ private $logMapper; /** @@ -69,7 +87,6 @@ class MailService { * @param IL10N $trans * @param IFactory $transFactory * @param IMailer $mailer - * @param ILogger $logger * @param SubscriptionMapper $subscriptionMapper * @param ShareMapper $shareMapper * @param PollMapper $pollMapper @@ -84,7 +101,6 @@ public function __construct( IL10N $trans, IFactory $transFactory, IMailer $mailer, - ILogger $logger, ShareMapper $shareMapper, SubscriptionMapper $subscriptionMapper, PollMapper $pollMapper, @@ -97,7 +113,6 @@ public function __construct( $this->trans = $trans; $this->transFactory = $transFactory; $this->mailer = $mailer; - $this->logger = $logger; $this->shareMapper = $shareMapper; $this->subscriptionMapper = $subscriptionMapper; $this->pollMapper = $pollMapper; @@ -135,7 +150,7 @@ private function sendMail($emailTemplate, $toUserId = '', $toEmail = '', $toDisp return null; } catch (\Exception $e) { - $this->logger->logException($e, ['app' => 'polls']); + \OC::$server->getLogger()->logException($e, ['app' => 'polls']); throw $e; } @@ -305,7 +320,7 @@ public function sendInvitationMail($token) { $sentMails[] = $recipient; } catch (Exception $e) { $abortedMails[] = $recipient; - $this->logger->alert('Error sending Mail to ' . json_encode($recipient)); + \OC::$server->getLogger()->alert('Error sending Mail to ' . json_encode($recipient)); } } return ['sentMails' => $sentMails, 'abortedMails' => $abortedMails]; @@ -428,7 +443,7 @@ public function sendNotifications() { try { $this->sendMail($emailTemplate, $subscription->getUserId()); } catch (Exception $e) { - $this->logger->alert('Error sending Mail to ' . $subscription->getUserId()); + \OC::$server->getLogger()->alert('Error sending Mail to ' . $subscription->getUserId()); } } } diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 0afe4b8c93..2bab49a871 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -26,23 +26,41 @@ use Exception; use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; +use OCA\Polls\Exceptions\BadRequestException; -use OCA\Polls\Db\Option; use OCA\Polls\Db\OptionMapper; +use OCA\Polls\Db\Option; +use OCA\Polls\Db\PollMapper; +use OCA\Polls\Db\Poll; use OCA\Polls\Service\LogService; use OCA\Polls\Model\Acl; class OptionService { + /** @var OptionMapper */ private $optionMapper; + + /** @var Option */ private $option; + + /** @var PollMapper */ + private $pollMapper; + + /** @var Poll */ + private $poll; + + /** @var LogService */ private $logService; + + /** @var Acl */ private $acl; /** * OptionController constructor. * @param OptionMapper $optionMapper * @param Option $option + * @param PollMapper $pollMapper + * @param Poll $poll * @param LogService $logService * @param Acl $acl */ @@ -50,85 +68,94 @@ class OptionService { public function __construct( OptionMapper $optionMapper, Option $option, + PollMapper $pollMapper, + Poll $poll, LogService $logService, Acl $acl ) { $this->optionMapper = $optionMapper; $this->option = $option; + $this->pollMapper = $pollMapper; + $this->poll = $poll; $this->logService = $logService; $this->acl = $acl; } /** - * Set properties from option array + * Get all options of given poll * @NoAdminRequired - * @param Array $option + * @param int $pollId + * @param string $token + * @return array Array of Option objects + * @throws NotAuthorizedException */ - private function set($option) { - - $this->option->setPollId($option['pollId']); - $this->option->setPollOptionText(trim(htmlspecialchars($option['pollOptionText']))); - $this->option->setTimestamp($option['timestamp']); + public function list($pollId = 0, $token = '') { - if ($option['timestamp']) { - $this->option->setOrder($option['timestamp']); - } else { - $this->option->setOrder($option['order']); + if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + throw new NotAuthorizedException; } - if ($option['confirmed']) { - // do not update confirmation date, if option is already confirmed - if (!$this->option->getConfirmed()) { - $this->option->setConfirmed(time()); - } - } else { - $this->option->setConfirmed(0); + try { + return $this->optionMapper->findByPoll($pollId); + } catch (DoesNotExistException $e) { + return []; } } + /** - * Get all options of given poll + * Add a new option * @NoAdminRequired - * @param integer $pollId - * @param string $token - * @return array Array of Option objects + * @param int $pollId + * @param int $timestamp + * @param string $pollOptionText + * @return Option + * @throws NotAuthorizedException */ - public function list($pollId = 0, $token = '') { + public function add($pollId, $timestamp = 0 , $pollOptionText = '') { - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + $this->poll = $this->pollMapper->find($pollId); + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } - return $this->optionMapper->findByPoll($pollId); + $this->option = new Option(); + $this->option->setPollId($pollId); + $this->setOption($timestamp, $pollOptionText, 0); + return $this->optionMapper->insert($this->option); } - /** - * Add a new Option to poll + * Update option * @NoAdminRequired - * @param Array $option + * @param int $optionId + * @param int $timestamp + * @param string $pollOptionText + * @param int $order * @return Option + * @throws NotAuthorizedException */ - public function add($option) { + public function update($optionId, $timestamp = 0 , $pollOptionText = '', $order = 0) { - if (!$this->acl->setPollId($option['pollId'])->getAllowEdit()) { + $this->option = $this->optionMapper->find($optionId); + $this->poll = $this->pollMapper->find($this->option->getPollId()); + + if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } - $this->option = new Option(); - $this->set($option); - $this->optionMapper->insert($this->option); - $this->logService->setLog($option['pollId'], 'addOption'); + $this->setOption($timestamp, $pollOptionText, $order); - return $this->option; + return $this->optionMapper->update($this->option); } /** - * Remove a single option + * Delete option * @NoAdminRequired - * @param Option $option - * @return array Array of Option objects + * @param int $optionId + * @return Option deleted Option + * @throws NotAuthorizedException */ public function delete($optionId) { $this->option = $this->optionMapper->find($optionId); @@ -140,45 +167,79 @@ public function delete($optionId) { $this->optionMapper->delete($this->option); return $this->option; - } /** - * Update poll option + * Switch optoin confirmation * @NoAdminRequired - * @param array $option - * @return Option + * @param int $optionId + * @return Option confirmed Option + * @throws NotAuthorizedException */ - public function update($option) { - if (!$this->acl->setPollId($option['pollId'])->getAllowEdit()) { + public function confirm($optionId) { + $this->option = $this->optionMapper->find($optionId); + + if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } - try { - $this->option = $this->optionMapper->find($option['id']); - $this->set($option); - $this->optionMapper->update($this->option); - $this->logService->setLog($option['pollId'], 'updateOption'); + if ($this->option->setConfirmation()) { + $this->option->setConfirmation(0); + } else { + $this->option->setConfirmation(time()); + } + + return $this->optionMapper->update($this->option); + } + + /** + * Copy options from $fromPoll to $toPoll + * @NoAdminRequired + * @param int $fromPollId + * @param int $toPollId + * @return array Array of Option objects + * @throws NotAuthorizedException + */ + public function clone($fromPollId, $toPollId) { - return $this->option; - } catch (Exception $e) { - return new DoesNotExistException($e); + if (!$this->acl->setPollId($fromPollId)->getAllowView()) { + throw new NotAuthorizedException; } + foreach ($this->optionMapper->findByPoll($fromPollId) as $origin) { + $option = new Option(); + $option->setPollId($toPollId); + $option->setConfirmed(0); + $option->setPollOptionText($origin->getPollOptionText()); + $option->setTimestamp($origin->getTimestamp()); + $option->setOrder($origin->getOrder()); + $this->optionMapper->insert($option); + } + + return $this->optionMapper->findByPoll($toPollId); } /** - * Set order by order of the given array + * Reorder options with the order specified by $options * @NoAdminRequired - * @param array $options + * @param int $pollId + * @param array $options - Array of options * @return array Array of Option objects + * @throws NotAuthorizedException + * @throws BadRequestException */ public function reorder($pollId, $options) { + $this->poll = $this->pollMapper->find($pollId); + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } + if ($this->poll->getType() === 'datePoll') { + throw new BadRequestException("Not allowed in date polls", 1); + } + $i = 0; foreach ($options as $option) { $this->option = $this->optionMapper->find($option['id']); @@ -189,28 +250,116 @@ public function reorder($pollId, $options) { } return $this->optionMapper->findByPoll($pollId); - } /** - * Set order by order of the given array + * Change order for $optionId and reorder the options * @NoAdminRequired - * @param integer $fromPollId - * @param integer $toPollId + * @param int $optionId + * @param int $newOrder * @return array Array of Option objects + * @throws NotAuthorizedException + * @throws BadRequestException */ - public function clone($fromPollId, $toPollId) { + public function setOrder($optionId, $newOrder) { - if (!$this->acl->setPollId($fromPollId)->getAllowView()) { + $this->option = $this->optionMapper->find($optionId); + $pollId = $this->option->getPollId(); + $this->poll = $this->pollMapper->find($pollId); + + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } - foreach ($this->optionMapper->findByPoll($fromPollId) as $option) { - $option->setPollId($toPollId); - $this->optionMapper->insert($option); + if ($this->poll->getType() === 'datePoll') { + throw new BadRequestException("Not allowed in date polls", 1); } - return $this->optionMapper->findByPoll($toPollId); + if ($newOrder < 1) { + $newOrder = 1; + } elseif ($newOrder > getHighestOrder($pollId)) { + $newOrder = getHighestOrder($pollId); + } + + $oldOrder = $this->option->getOrder(); + + foreach ($this->optionMapper->findByPoll($pollId) as $option) { + $currentOrder = $option->getOrder(); + if ( + ($currentOrder < $oldOrder && $currentOrder < $newOrder) + || ($currentOrder > $oldOrder && $currentOrder > $newOrder) + ) { + + continue; + + } elseif ($currentOrder > $oldOrder && $currentOrder <= $newOrder) { + $option->setOrder($currentOrder - 1); + $this->optionMapper->update($option); + + } elseif ( + ($currentOrder < $oldOrder && $currentOrder >= $newOrder) + || ($currentOrder < $oldOrder && $currentOrder = $newOrder) + ) { + + $option->setOrder($currentOrder + 1); + $this->optionMapper->update($option); + + } elseif ($currentOrder === $oldOrder) { + + $option->setOrder($newOrder); + $this->optionMapper->update($option); + + } + } + + return $this->optionMapper->findByPoll($this->option->getPollId()); + } + + /** + * Set option entities validated + * @NoAdminRequired + * @param int $timestamp + * @param string $pollOptionText + * @param int $order + * @throws BadRequestException + */ + private function setOption($timestamp = 0 , $pollOptionText = '', $order = 0) { + if ($this->poll->getType() === 'datePoll') { + if ($timestamp) { + $this->option->setTimestamp($timestamp); + $this->option->setOrder($timestamp); + $this->option->setPollOptionText(date('c', $timestamp)); + } else { + throw new BadRequestException("Date poll must have a timestamp", 1); + } + } elseif ($this->poll->getType() === 'textPoll') { + if ($pollOptionText) { + $this->option->setPollOptionText($pollOptionText); + } else { + throw new BadRequestException("Text poll must have a pollOptionText", 1); + } + + if (!$order && !$this->option->getOrder()) { + $order = $this->getHighestOrder($this->option->getPollId()) + 1; + $this->option->setOrder($order); + } + } + } + + /** + * Get the highest order number in $pollId + * @NoAdminRequired + * @param int $pollId + * @return int Highest order number + */ + private function getHighestOrder($pollId) { + $order = 0; + foreach ($this->optionMapper->findByPoll($pollId) as $option) { + if ($option->getOrder() > $order) { + $order = $option->getOrder(); + } + } + return $order; } } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index d23c859509..946a66d265 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -31,7 +31,6 @@ use OCA\Polls\Exceptions\InvalidPollTypeException; use OCA\Polls\Exceptions\NotAuthorizedException; - use OCP\ILogger; use OCA\Polls\Db\PollMapper; use OCA\Polls\Db\Poll; @@ -40,15 +39,20 @@ class PollService { - private $logger; + /** @var PollMapper */ private $pollMapper; + + /** @var Poll */ private $poll; + + /** @var LogService */ private $logService; + + /** @var Acl */ private $acl; /** * PollController constructor. - * @param ILogger $logger * @param PollMapper $pollMapper * @param Poll $poll * @param LogService $logService @@ -56,13 +60,11 @@ class PollService { */ public function __construct( - ILogger $logger, PollMapper $pollMapper, Poll $poll, LogService $logService, Acl $acl ) { - $this->logger = $logger; $this->pollMapper = $pollMapper; $this->poll = $poll; $this->logService = $logService; @@ -71,9 +73,10 @@ public function __construct( /** - * list + * Get list of polls * @NoAdminRequired - * @return array + * @return array Array of Poll + * @throws NotAuthorizedException */ public function list() { @@ -97,10 +100,11 @@ public function list() { } /** - * get + * get poll configuration * @NoAdminRequired - * @param integer $pollId - * @return array + * @param int $pollId + * @return Poll + * @throws NotAuthorizedException */ public function get($pollId) { @@ -113,10 +117,11 @@ public function get($pollId) { } /** - * get + * get poll configuration by token * @NoAdminRequired - * @param integer $pollId - * @return array + * @param int $pollId + * @return Poll + * @throws NotAuthorizedException */ public function getByToken($token) { @@ -129,57 +134,14 @@ public function getByToken($token) { } /** - * delete + * Add poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId - * @return Poll - */ - - public function delete($pollId) { - $this->poll = $this->pollMapper->find($pollId); - - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { - throw new NotAuthorizedException; - } - - if ($this->poll->getDeleted()) { - $this->poll->setDeleted(0); - } else { - $this->poll->setDeleted(time()); - } - - $this->poll = $this->pollMapper->update($this->poll); - $this->logService->setLog($this->poll->getId(), 'deletePoll'); - - return $this->poll; - } - - /** - * deletePermanently - * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId - * @return Poll - */ - - public function deletePermanently($pollId) { - $this->poll = $this->pollMapper->find($pollId); - - if (!$this->acl->setPollId($pollId)->getAllowEdit() || !$this->poll->getDeleted()) { - throw new NotAuthorizedException; - } - - return $this->pollMapper->delete($this->poll); - } - - /** - * write - * @NoAdminRequired - * @NoCSRFRequired * @param string $type * @param string $title * @return Poll + * @throws NotAuthorizedException + * @throws InvalidPollTypeException + * @throws EmptyTitleException */ public function add($type, $title) { @@ -221,11 +183,15 @@ public function add($type, $title) { } /** - * update + * Update poll configuration * @NoAdminRequired - * @NoCSRFRequired - * @param Array $poll + * @param int $pollId + * @param array $poll * @return Poll + * @throws NotAuthorizedException + * @throws EmptyTitleException + * @throws InvalidShowResultsException + * @throws InvalidAccessException */ public function update($pollId, $poll) { @@ -256,36 +222,93 @@ public function update($pollId, $poll) { return $this->poll; } + /** - * clone + * Switch deleted status (move to deleted polls) * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return Poll + * @throws NotAuthorizedException */ - public function clone($pollId) { - if (!$this->acl->setPollId($this->poll->getId())->getAllowView()) { + public function delete($pollId) { + $this->poll = $this->pollMapper->find($pollId); + + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } + if ($this->poll->getDeleted()) { + $this->poll->setDeleted(0); + } else { + $this->poll->setDeleted(time()); + } + + $this->poll = $this->pollMapper->update($this->poll); + $this->logService->setLog($this->poll->getId(), 'deletePoll'); + + return $this->poll; + } + + /** + * Delete poll + * @NoAdminRequired + * @param int $pollId + * @return Poll the deleted poll + * @throws NotAuthorizedException + */ + + public function deletePermanently($pollId) { $this->poll = $this->pollMapper->find($pollId); - $this->poll->setCreated(time()); - $this->poll->setOwner(\OC::$server->getUserSession()->getUser()->getUID()); - $this->poll->setTitle('Clone of ' . $this->poll->getTitle()); - $this->poll->setDeleted(0); - $this->poll->setId(0); + if (!$this->acl->setPollId($pollId)->getAllowEdit() || !$this->poll->getDeleted()) { + throw new NotAuthorizedException; + } - $this->poll = $this->pollMapper->insert($this->poll); - $this->logService->setLog($this->poll->getId(), 'addPoll'); + return $this->pollMapper->delete($this->poll); + } - $this->optionService->clone($pollId, $this->poll->getId()); + /** + * Clone poll + * @NoAdminRequired + * @param int $pollId + * @return Poll + * @throws NotAuthorizedException + */ + public function clone($pollId) { - return $this->poll; + $origin = $this->pollMapper->find($pollId); + if (!$this->acl->setPollId($origin->getId())->getAllowView()) { + throw new NotAuthorizedException; + } + + $this->poll = new Poll(); + $this->poll->setCreated(time()); + $this->poll->setOwner(\OC::$server->getUserSession()->getUser()->getUID()); + $this->poll->setTitle('Clone of ' . $origin->getTitle()); + $this->poll->setDeleted(0); + $this->poll->setAccess('hidden'); + $this->poll->setType($origin->getType()); + $this->poll->setDescription($origin->getDescription()); + $this->poll->setExpire($origin->getExpire()); + $this->poll->setAnonymous($origin->getAnonymous()); + $this->poll->setFullAnonymous($origin->getFullAnonymous()); + $this->poll->setAllowMaybe($origin->getAllowMaybe()); + $this->poll->setVoteLimit($origin->getVoteLimit()); + $this->poll->setSettings($origin->getSettings()); + $this->poll->setOptions($origin->getOptions()); + $this->poll->setShowResults($origin->getShowResults()); + $this->poll->setAdminAccess($origin->getAdminAccess()); + + return $this->pollMapper->insert($this->poll); } + /** + * Get valid values for configuration options + * @NoAdminRequired + * @return array + */ public function getValidEnum() { return [ 'pollType' => $this->getValidPollType(), @@ -294,14 +317,29 @@ public function getValidEnum() { ]; } + /** + * Get valid values for pollType + * @NoAdminRequired + * @return array + */ private function getValidPollType() { return ['datePoll', 'textPoll']; } + /** + * Get valid values for access + * @NoAdminRequired + * @return array + */ private function getValidAccess() { return ['hidden', 'public']; } + /** + * Get valid values for showResult + * @NoAdminRequired + * @return array + */ private function getValidShowResults() { return ['always', 'expired', 'never']; } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 5d8b47c4bd..1bd9bcb8ac 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -24,54 +24,62 @@ namespace OCA\Polls\Service; use Exception; - -use OCP\Security\ISecureRandom; - use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\InvalidUsername; -use OCA\Polls\Db\Share; +use OCP\Security\ISecureRandom; + +use OCA\Polls\Controller\SystemController; use OCA\Polls\Db\ShareMapper; +use OCA\Polls\Db\Share; use OCA\Polls\Service\MailService; use OCA\Polls\Model\Acl; -use OCA\Polls\Controller\SystemController; class ShareService { + /** @var SystemController */ + private $systemController; + + /** @var ShareMapper */ private $shareMapper; + + /** @var Share */ private $share; - private $systemController; + + /** @var MailService */ private $mailService; + + /** @var Acl */ private $acl; /** * ShareController constructor. + * @param SystemController $systemController * @param ShareMapper $shareMapper * @param Share $share - * @param SystemController $systemController * @param MailService $mailService * @param Acl $acl */ public function __construct( + SystemController $systemController, ShareMapper $shareMapper, Share $share, - SystemController $systemController, MailService $mailService, Acl $acl ) { + $this->systemController = $systemController; $this->shareMapper = $shareMapper; $this->share = $share; - $this->systemController = $systemController; $this->mailService = $mailService; $this->acl = $acl; } /** - * get * Read all shares of a poll based on the poll id and return list as array * @NoAdminRequired - * @param integer $pollId - * @return array + * @param int $pollId + * @return array array of Share + * @throws NotAuthorizedException */ public function list($pollId) { if (!$this->acl->setPollId($pollId)->getAllowEdit()) { @@ -82,8 +90,7 @@ public function list($pollId) { } /** - * getByToken - * Get pollId by token + * Get share by token * @NoAdminRequired * @param string $token * @return Share @@ -93,11 +100,14 @@ public function get($token) { } /** - * Write a new share to the db and returns the new share as array + * Add share * @NoAdminRequired * @param int $pollId - * @param string $share - * @return array + * @param string $type + * @param string $userId + * @param string $userEmail + * @return Share + * @throws NotAuthorizedException */ public function add($pollId, $type, $userId, $userEmail = '') { @@ -122,14 +132,16 @@ public function add($pollId, $type, $userId, $userEmail = '') { } /** - * createPersonalShare - * Write a new share to the db and returns the new share as array + * Create a personal share from a public share + * or update an email share with the username * @NoAdminRequired * @param string $token * @param string $userName * @return Share + * @throws NotAuthorizedException + * @throws InvalidUsername */ - public function createPersonalShare($token, $userName) { + public function personal($token, $userName) { $publicShare = $this->shareMapper->findByToken($token); // Return of validatePublicUsername is a DataResponse @@ -142,7 +154,6 @@ public function createPersonalShare($token, $userName) { if ($publicShare->getType() === 'public') { - $this->share = new Share(); $this->share->setToken(\OC::$server->getSecureRandom()->generate( 16, @@ -169,14 +180,15 @@ public function createPersonalShare($token, $userName) { } /** - * remove + * Delete share * remove share * @NoAdminRequired * @param string $token * @return Share + * @throws NotAuthorizedException */ - public function remove($token) { + public function delete($token) { $this->share = $this->shareMapper->findByToken($token); if (!$this->acl->setPollId($this->share->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php index f378e476c2..8809f79255 100644 --- a/lib/Service/SubscriptionService.php +++ b/lib/Service/SubscriptionService.php @@ -27,7 +27,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\ILogger; use OCA\Polls\Db\Subscription; use OCA\Polls\Db\SubscriptionMapper; @@ -35,30 +34,29 @@ class SubscriptionService { + /** @var Acl */ private $acl; + + /** @var SubscriptionMapper */ private $subscriptionMapper; - private $logger; /** * SubscriptionController constructor. * @param SubscriptionMapper $subscriptionMapper - * @param ILogger $logger * @param Acl $acl */ public function __construct( SubscriptionMapper $subscriptionMapper, - ILogger $logger, Acl $acl ) { $this->subscriptionMapper = $subscriptionMapper; $this->acl = $acl; - $this->logger = $logger; } /** * @NoAdminRequired - * @param integer $pollId + * @param int $pollId * @return array */ public function get($pollId) { @@ -77,7 +75,7 @@ public function get($pollId) { /** * @NoAdminRequired - * @param integer $pollId + * @param int $pollId * @return array */ public function set($pollId, $subscribed) { @@ -111,15 +109,15 @@ public function set($pollId, $subscribed) { } catch (MultipleObjectsReturnedException $e) { // Duplicates should not exist but if found, fix it // unsubscribe from all and resubscribe, if requested - $this->logger->debug('Multiple subscription (dulpicates) found'); + \OC::$server->getLogger()->debug('Multiple subscription (dulpicates) found'); $this->subscriptionMapper->unsubscribe($pollId, $this->acl->getUserId()); - $this->logger->debug('Unsubscribed all for user ' . $this->acl->getUserId() . 'in poll' . $pollId); + \OC::$server->getLogger()->debug('Unsubscribed all for user ' . $this->acl->getUserId() . 'in poll' . $pollId); if ($subscribed) { $subscription = new Subscription(); $subscription->setPollId($pollId); $subscription->setUserId($this->acl->getUserId()); $this->subscriptionMapper->insert($subscription); - $this->logger->debug('Added new subscription'); + \OC::$server->getLogger()->debug('Added new subscription'); return $subscription; } else { return ['status' => 'Unsubscribed from poll ' . $pollId]; diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 4df01c7065..5073b732c0 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -27,8 +27,8 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; -use OCA\Polls\Db\Vote; use OCA\Polls\Db\VoteMapper; +use OCA\Polls\Db\Vote; use OCA\Polls\Db\OptionMapper; use OCA\Polls\Service\AnonymizeService; use OCA\Polls\Service\LogService; @@ -36,11 +36,22 @@ class VoteService { + /** @var VoteMapper */ private $voteMapper; + + /** @var Vote */ private $vote; + + /** @var OptionMapper */ private $optionMapper; + + /** @var AnonymizeService */ private $anonymizer; + + /** @var LogService */ private $logService; + + /** @var Acl */ private $acl; /** @@ -69,12 +80,12 @@ public function __construct( } /** - * Get all votes of given poll * Read all votes of a poll based on the poll id and return list as array * @NoAdminRequired - * @param integer $pollId + * @param int $pollId * @param string $token - * @return Vote + * @return array + * @throws NotAuthorizedException */ public function list($pollId = 0, $token = '') { if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { @@ -92,24 +103,29 @@ public function list($pollId = 0, $token = '') { } /** - * set + * Set vote * @NoAdminRequired - * @param integer $pollId - * @param Array $option + * @param int $optionId * @param string $setTo * @param string $token * @return Vote + * @throws NotAuthorizedException */ - public function set($pollId = 0, $pollOptionText, $setTo, $token = '') { + public function set($optionId, $setTo, $token = '') { + + $option = $this->optionMapper->find($optionId); + $pollId = $option->getPollId(); - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowVote()) { + if (!$this->acl->setPollIdOrToken($option->getPollId(), $token)->getAllowVote()) { throw new NotAuthorizedException; } - $option = $this->optionMapper->findByPollAndText($this->acl->getpollId(), $pollOptionText); + if (!$option->getPollId() === $this->acl->getPollId()) { + throw new NotAuthorizedException; + } try { - $this->vote = $this->voteMapper->findSingleVote($this->acl->getpollId(), $option->getPollOptionText(), $this->acl->getUserId()); + $this->vote = $this->voteMapper->findSingleVote($this->acl->getPollId(), $option->getPollOptionText(), $this->acl->getUserId()); $this->vote->setVoteAnswer($setTo); $this->voteMapper->update($this->vote); @@ -117,7 +133,7 @@ public function set($pollId = 0, $pollOptionText, $setTo, $token = '') { // Vote does not exist, insert as new Vote $this->vote = new Vote(); - $this->vote->setPollId($this->acl->getpollId()); + $this->vote->setPollId($this->acl->getPollId()); $this->vote->setUserId($this->acl->getUserId()); $this->vote->setVoteOptionText($option->getPollOptionText()); $this->vote->setVoteOptionId($option->getId()); @@ -125,19 +141,19 @@ public function set($pollId = 0, $pollOptionText, $setTo, $token = '') { $this->voteMapper->insert($this->vote); } finally { - $this->logService->setLog($this->vote->getPollId(), 'setVote', $this->vote->getUserId()); + $this->logService->setLog($this->acl->getPollId(), 'setVote', $this->vote->getUserId()); return $this->vote; } } /** - * delete + * Remove user from poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $voteId + * @param int $voteId * @param string $userId - * @param integer $pollId + * @param int $pollId * @return Vote + * @throws NotAuthorizedException */ public function delete($pollId, $userId) { From 6fa543b89a5a23df57e20028a829f12817ad2cfb Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 11 Jul 2020 16:54:24 +0200 Subject: [PATCH 012/117] update API docs --- docs/API_v1.0.md | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/docs/API_v1.0.md b/docs/API_v1.0.md index 2f1c3326fe..b26c62f7fe 100644 --- a/docs/API_v1.0.md +++ b/docs/API_v1.0.md @@ -16,27 +16,34 @@ Example calls: ``` # Poll -| Method | Endpoint | Description | Return codes | -| --------- | ----------------------------------- | ---------------------------- | ------------------ | -| GET | /api/v1.0/polls | Get polls list as array | 200, 403, 404 | -| GET | /api/v1.0/poll/{pollId} | Get poll with {pollId} | 200, 403, 404 | -| POST | /api/v1.0/poll/add | Add new poll with payload | 201, 403, 404 | -| POST | /api/v1.0/poll/clone/{pollId} | Clone poll {pollId} | 201, 403, 404 | -| PUT | /api/v1.0/poll/{pollId} | Update poll | 200, 403, 404, 409 | -| DELETE | /api/v1.0/poll/{pollId} | Delete poll logical | 200, 403, 404 | -| DELETE | /api/v1.0/poll/permanent/{pollId} | Delete poll permanently | 200, 403, 404 | -| GET | /api/v1.0/poll/enum | Get valid enums | 200, 403, 404 | - -## Add poll - +## Default functions +| Method | Endpoint | Payload | Description | Return codes | Return value | +| --------- | ------------------------ | ------- | ---------------------- | ------------------ | -------------- | +| GET | /api/v1.0/polls | no | Get array of polls | 200, 403, 404 | array | +| GET | /api/v1.0/poll/{pollId} | no | Get poll with {pollId} | 200, 403, 404 | requested poll | +| POST | /api/v1.0/poll | yes | Add new poll | 201, 403, 404 | added poll | +| PUT | /api/v1.0/poll/{pollId} | yes | Update poll | 200, 403, 404, 409 | updated poll | +| DELETE | /api/v1.0/poll/{pollId} | no | Delete poll | 200, 403, 404 | deleted poll | + + +## Special functions +| Method | Endpoint | Payload | Description | Return codes | Return value | +| --------- | ------------------------------| ------- | ---------------------------- | ------------------ | -------------- | +| POST | /api/v1.0/poll/{pollId}/clone | no | Clone poll from {pollId} | 201, 403, 404 | cloned poll | +| POST | /api/v1.0/poll/{pollId}/trash | no | Move to/remome from trash | 200, 403, 404 | updated poll | +| GET | /api/v1.0/enum/poll | no | Get valid enums | 200, 403, 404 | array | + +## Valid payloads +### Add new poll ```json { "type": "datePoll", - "title": "Test" + "title": "Poll Title" } ``` -## Update poll +### Update poll +send the full or a partial structure ```json { "poll": { @@ -52,54 +59,50 @@ Example calls: } } ``` - ### Keys and values | Key | Type | description | | ------- | ------- | -------------------| | expire | integer | unix timestamp | | deleted | integer | unix timestamp | - - # Options -| Method | Endpoint | Description | Return codes | -| --------- | ----------------------------------- | ---------------------------- | ------------------ | -| GET | /api/v1.0/poll/{pollId}/options | Get options as array | 200, 403, 404 | -| POST | /api/v1.0/option | Add new option with Payload | 201, 403, 404, 409 | -| PUT | /api/v1.0/option | Update option with Payload | 200, 403, 404 | -| DELETE | /api/v1.0/option/{optionId} | Delete option | 200, 403, 404 | +## Default functions +| Method | Endpoint | Payload | Description | Return codes | Return value | +| --------- | ------------------------------- | ------- | ----------------- | ------------------ | -------------- | +| GET | /api/v1.0/poll/{pollId}/options | no | Get poll options | 200, 403, 404 | array | +| POST | /api/v1.0/poll/{pollId}/option | yes | Add new option | 201, 403, 404, 409 | added option | +| PUT | /api/v1.0/option/{optionId} | yes | Update option | 200, 403, 404 | updated option | +| DELETE | /api/v1.0/option/{optionId} | no | Delete option | 200, 403, 404 | deleted option | + +## Special functions (no payloads) +| Method | Endpoint | Description | Return codes | Return value | +| --------- | -------------------------------------------- | ----------------------------- | ------------------ | ---------------- | +| PUT | /api/v1.0/option/{optionId}/confirm | Confirm/unconfirm option | 200, 403, 404 | confirmed option | +| PUT | /api/v1.0/option/{optionId}/setorder/{order} | Set order (text poll) | 200, 403, 404 | array | + +## Valid payloads +### Add/update option (text poll) -## add option ```json { - "pollId": 139, - "pollOptionText": "19-06-2020 17:00:00", - "timestamp": 0, + "pollOptionText": "Text of new option" } ``` -## Update option +### Add/update option (date poll) ```json { - "id": 17, - "pollId": 1, - "pollOptionText": "poll option", - "timestamp": 0, - "order": 1, - "confirmed": 1590762104 -}, + "timestamp": 1589195823 +} ``` ### Keys and values -| Key | Type | description | -| -------------- | ------- | ------------------------------------- | -| id | String | id overrides optionID if used | -| pollOptionText | String | poll text or date option in UTC | -| confirmed | Integer | unix timestamp | -| timestamp | Integer | unix timestamp for date option | -| order | Integer | position on option order for textpolls | +| Key | Type | description | +| -------------- | ------- | ----------------------- | +| pollOptionText | String | poll text | +| timestamp | Integer | 10 digit unix timestamp | + -* if timestamp is given in a date poll, the poll option text is ignored # Votes | Method | Endpoint | Description | Return codes | @@ -110,8 +113,7 @@ Example calls: ## set vote ```json { - "pollId": 1, - "pollOptionText": "Saturn", + "optionId": 1, "setTo" :"yes" } ``` From 255a36387351e40f2377a649156c3b0bf90f3ab5 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 11 Jul 2020 16:54:39 +0200 Subject: [PATCH 013/117] Update Frontend store --- src/js/components/Base/OptionAddDate.vue | 5 +- src/js/components/Navigation/Navigation.vue | 2 +- src/js/store/modules/subModules/comments.js | 9 +-- src/js/store/modules/subModules/options.js | 79 +++++++++++---------- src/js/store/modules/subModules/shares.js | 30 ++++---- src/js/store/modules/subModules/votes.js | 39 +++++----- 6 files changed, 81 insertions(+), 83 deletions(-) diff --git a/src/js/components/Base/OptionAddDate.vue b/src/js/components/Base/OptionAddDate.vue index 60b3440a3f..a7c363c3b7 100644 --- a/src/js/components/Base/OptionAddDate.vue +++ b/src/js/components/Base/OptionAddDate.vue @@ -75,7 +75,10 @@ export default { methods: { addOption(pollOptionText) { if (moment(pollOptionText).isValid()) { - this.$store.dispatch('poll/options/add', { pollOptionText: pollOptionText }) + this.$store.dispatch('poll/options/add', { + pollOptionText: pollOptionText, + timestamp: moment(pollOptionText).unix(), + }) } }, }, diff --git a/src/js/components/Navigation/Navigation.vue b/src/js/components/Navigation/Navigation.vue index 5aaf339ade..9e1226b0ac 100644 --- a/src/js/components/Navigation/Navigation.vue +++ b/src/js/components/Navigation/Navigation.vue @@ -145,7 +145,7 @@ export default { emit('update-polls') this.$router.push({ name: 'vote', params: { id: response.pollId } }) }) - .error(() => { + .catch(() => { OC.Notification.showTemporary(t('polls', 'Error cloning poll.'), { type: 'error' }) }) }, diff --git a/src/js/store/modules/subModules/comments.js b/src/js/store/modules/subModules/comments.js index 739acc4025..5d10423171 100644 --- a/src/js/store/modules/subModules/comments.js +++ b/src/js/store/modules/subModules/comments.js @@ -63,7 +63,7 @@ const getters = { const actions = { add(context, payload) { - const endPoint = 'apps/polls/comment/add' + const endPoint = 'apps/polls/comment' return axios.post(generateUrl(endPoint), { message: payload.message, pollId: context.rootState.poll.id, @@ -80,12 +80,9 @@ const actions = { }, delete(context, payload) { - const endPoint = 'apps/polls/comment/delete' + const endPoint = 'apps/polls/comment' context.commit('delete', { comment: payload.comment }) - return axios.post(generateUrl(endPoint), { - token: context.rootState.poll.acl.token, - commentId: payload.comment.id, - }) + return axios.delete(generateUrl(endPoint.concat('/', payload.comment.id)), { token: context.rootState.poll.acl.token }) .then((response) => { context.commit('delete', { comment: response.data.comment }) return response.data diff --git a/src/js/store/modules/subModules/options.js b/src/js/store/modules/subModules/options.js index d152c3d301..9d01d930a1 100644 --- a/src/js/store/modules/subModules/options.js +++ b/src/js/store/modules/subModules/options.js @@ -22,7 +22,6 @@ import axios from '@nextcloud/axios' import orderBy from 'lodash/orderBy' -import moment from '@nextcloud/moment' import { generateUrl } from '@nextcloud/router' const defaultOptions = () => { @@ -100,67 +99,54 @@ const getters = { } const actions = { - reorder(context, payload) { - const endPoint = 'apps/polls/option/reorder' - return axios.post(generateUrl(endPoint), { pollId: context.rootState.poll.id, options: payload }) + add(context, payload) { + const endPoint = 'apps/polls/option' + return axios.post(generateUrl(endPoint), { + pollId: context.rootState.poll.id, + timestamp: payload.timestamp, + pollOptionText: payload.pollOptionText, + }) .then((response) => { - context.commit('set', { options: response.data }) + context.commit('setItem', { option: response.data }) }) .catch((error) => { - console.error('Error reordering option', { error: error.response }, { payload: payload }) + console.error('Error adding option', { error: error.response }, { payload: payload }) throw error }) }, - add(context, payload) { - const endPoint = 'apps/polls/option/add' - const option = {} - - option.id = 0 - option.pollId = context.rootState.poll.id - - if (context.rootState.poll.type === 'datePoll') { - if (payload.timestamp) { - option.timestamp = payload.timestamp - } else { - option.timestamp = moment(payload.pollOptionText).unix() - } - option.order = option.timestamp - option.pollOptionText = moment.utc(payload.pollOptionText).format('YYYY-MM-DD HH:mm:ss') - - } else if (context.rootState.poll.type === 'textPoll') { - option.timestamp = 0 - option.order = state.list.length + 1 - option.pollOptionText = payload.pollOptionText - } - - return axios.post(generateUrl(endPoint), { option: option }) + update(context, payload) { + const endPoint = 'apps/polls/option' + return axios.put(generateUrl(endPoint.concat('/', payload.option.id)), { + timestamp: payload.option.timestamp, + pollOptionText: payload.option.timeStamp, + }) .then((response) => { context.commit('setItem', { option: response.data }) }) .catch((error) => { - console.error('Error adding option', { error: error.response }, { payload: option }) + console.error('Error updating option', { error: error.response }, { payload: payload }) throw error }) }, - update(context, payload) { - const endPoint = 'apps/polls/option/update' + delete(context, payload) { + const endPoint = 'apps/polls/option' - return axios.post(generateUrl(endPoint), { option: payload.option }) - .then((response) => { - context.commit('setItem', { option: response.data }) + return axios.delete(generateUrl(endPoint.concat('/', payload.option.id))) + .then(() => { + context.commit('delete', { option: payload.option }) }) .catch((error) => { - console.error('Error updating option', { error: error.response }, { payload: payload }) + console.error('Error removing option', { error: error.response }, { payload: payload }) throw error }) }, - delete(context, payload) { - const endPoint = 'apps/polls/option/remove' + confirm(context, payload) { + const endPoint = 'apps/polls/option' - return axios.post(generateUrl(endPoint), { option: payload.option }) + return axios.put(generateUrl(endPoint.concat('/', payload.option.id, '/confirm'))) .then(() => { context.commit('delete', { option: payload.option }) }) @@ -169,6 +155,21 @@ const actions = { throw error }) }, + + reorder(context, payload) { + const endPoint = 'apps/polls/option/reorder' + return axios.post(generateUrl(endPoint), { + pollId: context.rootState.poll.id, + options: payload, + }) + .then((response) => { + context.commit('set', { options: response.data }) + }) + .catch((error) => { + console.error('Error reordering option', { error: error.response }, { payload: payload }) + throw error + }) + }, } export default { state, mutations, getters, actions, namespaced } diff --git a/src/js/store/modules/subModules/shares.js b/src/js/store/modules/subModules/shares.js index 6332930263..d3f5b5c737 100644 --- a/src/js/store/modules/subModules/shares.js +++ b/src/js/store/modules/subModules/shares.js @@ -102,9 +102,23 @@ const actions = { }) }, + addPersonal(context, payload) { + const endPoint = 'apps/polls/share/personal' + + return axios.post(generateUrl(endPoint), { token: payload.token, userName: payload.userName }) + .then((response) => { + return { token: response.data.token } + }) + .catch((error) => { + console.error('Error writing personal share', { error: error.response }, { payload: payload }) + throw error + }) + + }, + delete(context, payload) { const endPoint = 'apps/polls/share/delete' - return axios.post(generateUrl(endPoint), { share: payload.share }) + return axios.delete(generateUrl(endPoint.concat('/', payload.share.token))) .then(() => { context.commit('delete', { share: payload.share }) }) @@ -126,20 +140,6 @@ const actions = { throw error }) }, - - addPersonal(context, payload) { - const endPoint = 'apps/polls/share/create/s' - - return axios.post(generateUrl(endPoint), { token: payload.token, userName: payload.userName }) - .then((response) => { - return { token: response.data.token } - }) - .catch((error) => { - console.error('Error writing share', { error: error.response }, { payload: payload }) - throw error - }) - - }, } export default { namespaced, state, mutations, actions, getters } diff --git a/src/js/store/modules/subModules/votes.js b/src/js/store/modules/subModules/votes.js index 06da10cd05..012e7d7250 100644 --- a/src/js/store/modules/subModules/votes.js +++ b/src/js/store/modules/subModules/votes.js @@ -114,23 +114,6 @@ const getters = { } const actions = { - delete(context, payload) { - const endPoint = 'apps/polls/votes/delete' - return axios.post(generateUrl(endPoint), { - pollId: context.rootState.poll.id, - voteId: 0, - userId: payload.userId, - }) - .then(() => { - context.commit('deleteVotes', payload) - OC.Notification.showTemporary(t('polls', 'User {userId} removed', payload), { type: 'success' }) - }) - .catch((error) => { - console.error('Error deleting votes', { error: error.response }, { payload: payload }) - throw error - }) - }, - set(context, payload) { let endPoint = 'apps/polls/vote/set' @@ -138,11 +121,9 @@ const actions = { endPoint = endPoint.concat('/s') } return axios.post(generateUrl(endPoint), { - pollId: context.rootState.poll.id, - token: context.rootState.poll.acl.token, - option: payload.option, - userId: payload.userId, + optionId: payload.option.id, setTo: payload.setTo, + token: context.rootState.poll.acl.token, }) .then((response) => { context.commit('setItem', { option: payload.option, pollId: context.rootState.poll.id, vote: response.data }) @@ -154,6 +135,22 @@ const actions = { }) }, + delete(context, payload) { + const endPoint = 'apps/polls/votes/delete' + return axios.post(generateUrl(endPoint), { + pollId: context.rootState.poll.id, + userId: payload.userId, + }) + .then(() => { + context.commit('deleteVotes', payload) + OC.Notification.showTemporary(t('polls', 'User {userId} removed', payload), { type: 'success' }) + }) + .catch((error) => { + console.error('Error deleting votes', { error: error.response }, { payload: payload }) + throw error + }) + }, + } export default { namespaced, state, mutations, getters, actions } From cf4fe7174164f6a168bcd60ecf26896e0ea65848 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 11 Jul 2020 17:32:57 +0200 Subject: [PATCH 014/117] code fixes and bugs --- lib/Controller/OptionApiController.php | 4 +-- lib/Controller/OptionController.php | 10 ++++---- lib/Controller/PollController.php | 10 ++++---- lib/Controller/ShareApiController.php | 2 +- lib/Controller/ShareController.php | 2 +- lib/Controller/SubscriptionApiController.php | 4 +-- lib/Controller/SystemController.php | 2 +- lib/Controller/VoteController.php | 1 - lib/Db/Poll.php | 14 +++++++++++ lib/Service/CommentService.php | 2 +- lib/Service/OptionService.php | 26 ++++++++++---------- lib/Service/PollService.php | 2 +- lib/Service/SubscriptionService.php | 4 +-- lib/Service/VoteService.php | 5 ++-- 14 files changed, 50 insertions(+), 38 deletions(-) diff --git a/lib/Controller/OptionApiController.php b/lib/Controller/OptionApiController.php index f08844358f..5c3e6f3c4e 100644 --- a/lib/Controller/OptionApiController.php +++ b/lib/Controller/OptionApiController.php @@ -108,9 +108,9 @@ public function add($pollId, $timestamp = 0, $pollOptionText = '') { * @param array $option * @return DataResponse */ - public function update($optionId, $timestamp = 0 , $pollOptionText = '') { + public function update($optionId, $timestamp = 0, $pollOptionText = '') { try { - return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText, $order)], Http::STATUS_OK); + return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php index 1fa382f6c4..ea58c79cc4 100644 --- a/lib/Controller/OptionController.php +++ b/lib/Controller/OptionController.php @@ -77,11 +77,11 @@ public function __construct( // } /** - * Add a new option - * @NoAdminRequired - * @param array $option - * @return DataResponse - */ + * Add a new option + * @NoAdminRequired + * @param array $option + * @return DataResponse + */ public function add($pollId, $timestamp = 0, $pollOptionText = '') { return new DataResponse($this->optionService->add($pollId, $timestamp, $pollOptionText), Http::STATUS_OK); } diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 834fb39195..73c0734771 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -67,12 +67,12 @@ class PollController extends Controller { * PollController constructor. * @param string $appName * @param IRequest $request - * @param PollService $pollService + * @param PollService $pollService * @param CommentService $commentService - * @param OptionService $optionService - * @param ShareService $shareService - * @param VoteService $voteService - * @param Acl $acl + * @param OptionService $optionService + * @param ShareService $shareService + * @param VoteService $voteService + * @param Acl $acl */ public function __construct( diff --git a/lib/Controller/ShareApiController.php b/lib/Controller/ShareApiController.php index 261262b892..e2d8b465e5 100644 --- a/lib/Controller/ShareApiController.php +++ b/lib/Controller/ShareApiController.php @@ -155,7 +155,7 @@ public function sendInvitation($token) { try { return new DataResponse($this->mailService->sendInvitationMail($token), Http::STATUS_OK); } catch (Exception $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } } } diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index bb55c5b87f..4810ed23a8 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -136,7 +136,7 @@ public function sendInvitation($token) { $share = $this->shareService->get($token); return new DataResponse(['share' => $share, 'sentResult' => $sentResult], Http::STATUS_OK); } catch (Exception $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } } } diff --git a/lib/Controller/SubscriptionApiController.php b/lib/Controller/SubscriptionApiController.php index 13ffe3eb6b..b8a87d1605 100644 --- a/lib/Controller/SubscriptionApiController.php +++ b/lib/Controller/SubscriptionApiController.php @@ -56,8 +56,8 @@ public function __construct( parent::__construct($appName, $request, 'PUT, GET, DELETE', - 'Authorization, Content-Type, Accept', - 1728000); + 'Authorization, Content-Type, Accept', + 1728000); $this->subscriptionService = $subscriptionService; } diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index b1e2c6060c..ef69593200 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -91,7 +91,7 @@ public function __construct( * Validate string as email address * @NoAdminRequired * @param string $query - * @return boolval + * @return bool */ private function isValidEmail($email) { return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $email)) ? false : true; diff --git a/lib/Controller/VoteController.php b/lib/Controller/VoteController.php index 02ccc9a040..32fc89a28d 100644 --- a/lib/Controller/VoteController.php +++ b/lib/Controller/VoteController.php @@ -45,7 +45,6 @@ class VoteController extends Controller { * @param string $appName * @param IRequest $request * @param VoteService $voteService - */ public function __construct( string $appName, diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php index d574a48154..5674d0f3a6 100644 --- a/lib/Db/Poll.php +++ b/lib/Db/Poll.php @@ -135,6 +135,20 @@ public function jsonSerialize() { ]; } + public function deserializeArray($array) { + $this->setTitle(isset($array['title']) ? $array['title'] : $this->getTitle()); + $this->setDescription(isset($array['description']) ? $array['description'] : $this->getDescription()); + $this->setAccess(isset($array['access']) ? $array['access'] : $this->getAccess()); + $this->setExpire(isset($array['expire']) ? $array['expire'] : $this->getExpire()); + $this->setAnonymous(isset($array['anonymous']) ? $array['anonymous'] : $this->getAnonymous()); + $this->setAllowMaybe(isset($array['allowMaybe']) ? $array['allowMaybe'] : $this->getAllowMaybe()); + $this->setVoteLimit(isset($array['voteLimit']) ? $array['voteLimit'] : $this->getVoteLimit()); + $this->setShowResults(isset($array['showResults']) ? $array['showResults'] : $this->getShowResults()); + $this->setDeleted(isset($array['deleted']) ? $array['deleted'] : $this->getDeleted()); + $this->setAdminAccess(isset($array['adminAccess']) ? $array['adminAccess'] : $this->getAdminAccess()); + return $this; + } + private function getDisplayName() { if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) { diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index f2c6ef563d..6c5f89b6a4 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -119,7 +119,7 @@ public function add($pollId = 0, $message, $token = '') { } } catch (Exception $e) { - \OC::$server->getLogger()->alert('Error writing comment for pollId ' . $pollId . ': '. $e); + \OC::$server->getLogger()->alert('Error writing comment for pollId ' . $pollId . ': ' . $e); throw new NotAuthorizedException($e); } diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 2bab49a871..84fb9822ec 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -35,7 +35,7 @@ use OCA\Polls\Service\LogService; use OCA\Polls\Model\Acl; -class OptionService { +class OptionService { /** @var OptionMapper */ private $optionMapper; @@ -112,7 +112,7 @@ public function list($pollId = 0, $token = '') { * @return Option * @throws NotAuthorizedException */ - public function add($pollId, $timestamp = 0 , $pollOptionText = '') { + public function add($pollId, $timestamp = 0, $pollOptionText = '') { $this->poll = $this->pollMapper->find($pollId); if (!$this->acl->setPollId($pollId)->getAllowEdit()) { @@ -136,7 +136,7 @@ public function add($pollId, $timestamp = 0 , $pollOptionText = '') { * @return Option * @throws NotAuthorizedException */ - public function update($optionId, $timestamp = 0 , $pollOptionText = '', $order = 0) { + public function update($optionId, $timestamp = 0, $pollOptionText = '', $order = 0) { $this->option = $this->optionMapper->find($optionId); $this->poll = $this->pollMapper->find($this->option->getPollId()); @@ -183,10 +183,10 @@ public function confirm($optionId) { throw new NotAuthorizedException; } - if ($this->option->setConfirmation()) { - $this->option->setConfirmation(0); + if ($this->option->getConfirmed()) { + $this->option->setConfirmed(0); } else { - $this->option->setConfirmation(time()); + $this->option->setConfirmed(time()); } return $this->optionMapper->update($this->option); @@ -237,7 +237,7 @@ public function reorder($pollId, $options) { } if ($this->poll->getType() === 'datePoll') { - throw new BadRequestException("Not allowed in date polls", 1); + throw new BadRequestException("Not allowed in date polls"); } $i = 0; @@ -272,13 +272,13 @@ public function setOrder($optionId, $newOrder) { } if ($this->poll->getType() === 'datePoll') { - throw new BadRequestException("Not allowed in date polls", 1); + throw new BadRequestException("Not allowed in date polls"); } if ($newOrder < 1) { $newOrder = 1; - } elseif ($newOrder > getHighestOrder($pollId)) { - $newOrder = getHighestOrder($pollId); + } elseif ($newOrder > $this->getHighestOrder($pollId)) { + $newOrder = $this->getHighestOrder($pollId); } $oldOrder = $this->option->getOrder(); @@ -324,20 +324,20 @@ public function setOrder($optionId, $newOrder) { * @param int $order * @throws BadRequestException */ - private function setOption($timestamp = 0 , $pollOptionText = '', $order = 0) { + private function setOption($timestamp = 0, $pollOptionText = '', $order = 0) { if ($this->poll->getType() === 'datePoll') { if ($timestamp) { $this->option->setTimestamp($timestamp); $this->option->setOrder($timestamp); $this->option->setPollOptionText(date('c', $timestamp)); } else { - throw new BadRequestException("Date poll must have a timestamp", 1); + throw new BadRequestException("Date poll must have a timestamp"); } } elseif ($this->poll->getType() === 'textPoll') { if ($pollOptionText) { $this->option->setPollOptionText($pollOptionText); } else { - throw new BadRequestException("Text poll must have a pollOptionText", 1); + throw new BadRequestException("Text poll must have a pollOptionText"); } if (!$order && !$this->option->getOrder()) { diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 946a66d265..e730b575d9 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -208,7 +208,7 @@ public function update($pollId, $poll) { } if (isset($poll['access']) && !in_array($poll['access'], $this->getValidAccess())) { - throw new InvalidAccessException('Invalid value for prop access '. $poll['access']); + throw new InvalidAccessException('Invalid value for prop access ' . $poll['access']); } if (isset($poll['title']) && !$poll['title']) { diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php index 8809f79255..0f7d82a771 100644 --- a/lib/Service/SubscriptionService.php +++ b/lib/Service/SubscriptionService.php @@ -32,7 +32,7 @@ use OCA\Polls\Db\SubscriptionMapper; use OCA\Polls\Model\Acl; -class SubscriptionService { +class SubscriptionService { /** @var Acl */ private $acl; @@ -92,7 +92,7 @@ public function set($pollId, $subscribed) { return ['status' => 'Subscribed to poll ' . $pollId]; } - } catch (DoesNotExistException $e){ + } catch (DoesNotExistException $e) { if ($subscribed) { $subscription = new Subscription(); diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 5073b732c0..7534b258d6 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -34,7 +34,7 @@ use OCA\Polls\Service\LogService; use OCA\Polls\Model\Acl; -class VoteService { +class VoteService { /** @var VoteMapper */ private $voteMapper; @@ -114,13 +114,12 @@ public function list($pollId = 0, $token = '') { public function set($optionId, $setTo, $token = '') { $option = $this->optionMapper->find($optionId); - $pollId = $option->getPollId(); if (!$this->acl->setPollIdOrToken($option->getPollId(), $token)->getAllowVote()) { throw new NotAuthorizedException; } - if (!$option->getPollId() === $this->acl->getPollId()) { + if ($option->getPollId() !== $this->acl->getPollId()) { throw new NotAuthorizedException; } From 0cacb217119e4ecadbc3b2a567a1554d513fa4a5 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Sat, 11 Jul 2020 16:58:15 +0000 Subject: [PATCH 015/117] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- appinfo/routes.php | 98 +++++++++++++-------------- lib/Controller/PollController.php | 14 ++-- lib/Controller/ShareApiController.php | 18 ++--- lib/Controller/VoteApiController.php | 4 +- 4 files changed, 67 insertions(+), 67 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 4ae59333d7..24078de303 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -23,89 +23,89 @@ return [ 'routes' => [ - ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], + ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'page#index', 'url' => '/not-found', 'verb' => 'GET', 'postfix' => 'notfound'], ['name' => 'page#index', 'url' => '/list/{id}', 'verb' => 'GET', 'postfix' => 'list'], ['name' => 'page#index', 'url' => '/vote/{id}', 'verb' => 'GET', 'postfix' => 'vote'], - ['name' => 'page#vote_public', 'url' => '/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], + ['name' => 'page#vote_public', 'url' => '/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], ['name' => 'page#vote_public', 'url' => '/poll/{token}', 'verb' => 'GET', 'postfix' => 'oldpublic'], - ['name' => 'poll#get', 'url' => '/polls/get/{pollId}', 'verb' => 'GET', 'postfix' => 'auth'], - ['name' => 'poll#get', 'url' => '/polls/get/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], - ['name' => 'poll#add', 'url' => '/polls/add', 'verb' => 'POST'], - ['name' => 'poll#update', 'url' => '/polls/update/{pollId}', 'verb' => 'PUT'], - ['name' => 'poll#list', 'url' => '/polls/list', 'verb' => 'GET'], - ['name' => 'poll#delete', 'url' => '/polls/delete/{pollId}', 'verb' => 'GET'], + ['name' => 'poll#get', 'url' => '/polls/get/{pollId}', 'verb' => 'GET', 'postfix' => 'auth'], + ['name' => 'poll#get', 'url' => '/polls/get/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], + ['name' => 'poll#add', 'url' => '/polls/add', 'verb' => 'POST'], + ['name' => 'poll#update', 'url' => '/polls/update/{pollId}', 'verb' => 'PUT'], + ['name' => 'poll#list', 'url' => '/polls/list', 'verb' => 'GET'], + ['name' => 'poll#delete', 'url' => '/polls/delete/{pollId}', 'verb' => 'GET'], ['name' => 'poll#deletePermanently', 'url' => '/polls/delete/permanent/{pollId}', 'verb' => 'GET'], - ['name' => 'poll#clone', 'url' => '/polls/clone/{pollId}', 'verb' => 'GET'], + ['name' => 'poll#clone', 'url' => '/polls/clone/{pollId}', 'verb' => 'GET'], - ['name' => 'option#add', 'url' => '/option', 'verb' => 'POST'], - ['name' => 'option#update', 'url' => '/option/{optionId}', 'verb' => 'PUT'], - ['name' => 'option#delete', 'url' => '/option/{optionId}', 'verb' => 'DELETE'], - ['name' => 'option#confirm', 'url' => '/option/{optionId}/confirm', 'verb' => 'PUT'], - ['name' => 'option#reorder', 'url' => '/option/reorder', 'verb' => 'POST'], + ['name' => 'option#add', 'url' => '/option', 'verb' => 'POST'], + ['name' => 'option#update', 'url' => '/option/{optionId}', 'verb' => 'PUT'], + ['name' => 'option#delete', 'url' => '/option/{optionId}', 'verb' => 'DELETE'], + ['name' => 'option#confirm', 'url' => '/option/{optionId}/confirm', 'verb' => 'PUT'], + ['name' => 'option#reorder', 'url' => '/option/reorder', 'verb' => 'POST'], // ['name' => 'option#list', 'url' => '/options/get/{pollId}', 'verb' => 'GET'], // ['name' => 'option#listByToken', 'url' => '/options/get/s/{token}', 'verb' => 'GET'], - ['name' => 'vote#set', 'url' => '/vote/set', 'verb' => 'POST'], - ['name' => 'vote#setByToken', 'url' => '/vote/set/s', 'verb' => 'POST'], - ['name' => 'vote#delete', 'url' => '/votes/delete', 'verb' => 'POST'], + ['name' => 'vote#set', 'url' => '/vote/set', 'verb' => 'POST'], + ['name' => 'vote#setByToken', 'url' => '/vote/set/s', 'verb' => 'POST'], + ['name' => 'vote#delete', 'url' => '/votes/delete', 'verb' => 'POST'], // ['name' => 'vote#get', 'url' => '/votes/get/{pollId}', 'verb' => 'GET'], // ['name' => 'vote#getByToken', 'url' => '/votes/get/s/{token}', 'verb' => 'GET'], - ['name' => 'share#add', 'url' => '/share/add', 'verb' => 'POST'], - ['name' => 'share#personal', 'url' => '/share/personal', 'verb' => 'POST'], - ['name' => 'share#delete', 'url' => '/share/delete/{token}', 'verb' => 'DELETE'], - ['name' => 'share#sendInvitation', 'url' => '/share/send/{token}', 'verb' => 'POST'], + ['name' => 'share#add', 'url' => '/share/add', 'verb' => 'POST'], + ['name' => 'share#personal', 'url' => '/share/personal', 'verb' => 'POST'], + ['name' => 'share#delete', 'url' => '/share/delete/{token}', 'verb' => 'DELETE'], + ['name' => 'share#sendInvitation', 'url' => '/share/send/{token}', 'verb' => 'POST'], ['name' => 'subscription#get', 'url' => '/subscription/{pollId}', 'verb' => 'GET'], - ['name' => 'subscription#set', 'url' => '/subscription', 'verb' => 'POST'], + ['name' => 'subscription#set', 'url' => '/subscription', 'verb' => 'POST'], - ['name' => 'comment#add', 'url' => '/comment', 'verb' => 'POST'], - ['name' => 'comment#delete', 'url' => '/comment/{commentId}', 'verb' => 'DELETE'], + ['name' => 'comment#add', 'url' => '/comment', 'verb' => 'POST'], + ['name' => 'comment#delete', 'url' => '/comment/{commentId}', 'verb' => 'DELETE'], // ['name' => 'comment#list', 'url' => '/comments/{pollId}', 'verb' => 'GET'], // ['name' => 'comment#getByToken', 'url' => '/comments/s/{token}', 'verb' => 'GET'], // ['name' => 'acl#getByToken', 'url' => '/acl/get/s/{token}', 'verb' => 'GET'], // ['name' => 'acl#get', 'url' => '/acl/get/{id}', 'verb' => 'GET'], - ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get', 'verb' => 'POST'], - ['name' => 'system#validate_public_username', 'url' => '/check/username', 'verb' => 'POST'], + ['name' => 'system#get_site_users_and_groups', 'url' => '/siteusers/get', 'verb' => 'POST'], + ['name' => 'system#validate_public_username', 'url' => '/check/username', 'verb' => 'POST'], // REST-API calls - ['name' => 'poll_api#list', 'url' => '/api/v1.0/polls', 'verb' => 'GET'], - ['name' => 'poll_api#get', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'GET'], - ['name' => 'poll_api#add', 'url' => '/api/v1.0/poll', 'verb' => 'POST'], + ['name' => 'poll_api#list', 'url' => '/api/v1.0/polls', 'verb' => 'GET'], + ['name' => 'poll_api#get', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'GET'], + ['name' => 'poll_api#add', 'url' => '/api/v1.0/poll', 'verb' => 'POST'], ['name' => 'poll_api#update', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'PUT'], ['name' => 'poll_api#delete', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'DELETE'], - ['name' => 'poll_api#clone', 'url' => '/api/v1.0/poll/{pollId}/clone', 'verb' => 'POST'], - ['name' => 'poll_api#trash', 'url' => '/api/v1.0/poll/{pollId}/trash', 'verb' => 'POST'], - ['name' => 'poll_api#enum', 'url' => '/api/v1.0/enum/poll', 'verb' => 'GET'], - - ['name' => 'option_api#list', 'url' => '/api/v1.0/poll/{pollId}/options', 'verb' => 'GET'], - ['name' => 'option_api#add', 'url' => '/api/v1.0/poll/{pollId}/option', 'verb' => 'POST'], - ['name' => 'option_api#update', 'url' => '/api/v1.0/option/{optionId}', 'verb' => 'PUT'], - ['name' => 'option_api#delete', 'url' => '/api/v1.0/option/{optionId}', 'verb' => 'DELETE'], + ['name' => 'poll_api#clone', 'url' => '/api/v1.0/poll/{pollId}/clone', 'verb' => 'POST'], + ['name' => 'poll_api#trash', 'url' => '/api/v1.0/poll/{pollId}/trash', 'verb' => 'POST'], + ['name' => 'poll_api#enum', 'url' => '/api/v1.0/enum/poll', 'verb' => 'GET'], + + ['name' => 'option_api#list', 'url' => '/api/v1.0/poll/{pollId}/options', 'verb' => 'GET'], + ['name' => 'option_api#add', 'url' => '/api/v1.0/poll/{pollId}/option', 'verb' => 'POST'], + ['name' => 'option_api#update', 'url' => '/api/v1.0/option/{optionId}', 'verb' => 'PUT'], + ['name' => 'option_api#delete', 'url' => '/api/v1.0/option/{optionId}', 'verb' => 'DELETE'], ['name' => 'option_api#setOrder', 'url' => '/api/v1.0/option/{optionId}/setorder/{order}', 'verb' => 'PUT'], - ['name' => 'option_api#confirm', 'url' => '/api/v1.0/option/{optionId}/confirm', 'verb' => 'PUT'], + ['name' => 'option_api#confirm', 'url' => '/api/v1.0/option/{optionId}/confirm', 'verb' => 'PUT'], ['name' => 'vote_api#list', 'url' => '/api/v1.0/poll/{pollId}/votes', 'verb' => 'GET'], - ['name' => 'vote_api#set', 'url' => '/api/v1.0/vote', 'verb' => 'POST'], + ['name' => 'vote_api#set', 'url' => '/api/v1.0/vote', 'verb' => 'POST'], - ['name' => 'share_api#list', 'url' => '/api/v1.0/poll/{pollId}/shares', 'verb' => 'GET'], - ['name' => 'share_api#get', 'url' => '/api/v1.0/share/{token}', 'verb' => 'GET'], - ['name' => 'share_api#add', 'url' => '/api/v1.0/share', 'verb' => 'POST'], - ['name' => 'share_api#delete', 'url' => '/api/v1.0/share/{token}', 'verb' => 'DELETE'], - ['name' => 'share_api#sendInvitation', 'url' => '/api/v1.0/share/send/{token}', 'verb' => 'POST'], + ['name' => 'share_api#list', 'url' => '/api/v1.0/poll/{pollId}/shares', 'verb' => 'GET'], + ['name' => 'share_api#get', 'url' => '/api/v1.0/share/{token}', 'verb' => 'GET'], + ['name' => 'share_api#add', 'url' => '/api/v1.0/share', 'verb' => 'POST'], + ['name' => 'share_api#delete', 'url' => '/api/v1.0/share/{token}', 'verb' => 'DELETE'], + ['name' => 'share_api#sendInvitation', 'url' => '/api/v1.0/share/send/{token}', 'verb' => 'POST'], - ['name' => 'subscription_api#get', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'GET'], - ['name' => 'subscription_api#subscribe', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'PUT'], + ['name' => 'subscription_api#get', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'GET'], + ['name' => 'subscription_api#subscribe', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'PUT'], ['name' => 'subscription_api#unsubscribe', 'url' => '/api/v1.0/poll/{pollId}/subscription', 'verb' => 'DELETE'], - ['name' => 'comment_api#list', 'url' => '/api/v1.0/poll/{pollId}/comments', 'verb' => 'GET'], - ['name' => 'comment_api#add', 'url' => '/api/v1.0/comment', 'verb' => 'POST'], - ['name' => 'comment_api#delete', 'url' => '/api/v1.0/comment/{commentId}', 'verb' => 'DELETE'], + ['name' => 'comment_api#list', 'url' => '/api/v1.0/poll/{pollId}/comments', 'verb' => 'GET'], + ['name' => 'comment_api#add', 'url' => '/api/v1.0/comment', 'verb' => 'POST'], + ['name' => 'comment_api#delete', 'url' => '/api/v1.0/comment/{commentId}', 'verb' => 'DELETE'], ] ]; diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 73c0734771..d1b4945be0 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -67,13 +67,13 @@ class PollController extends Controller { * PollController constructor. * @param string $appName * @param IRequest $request - * @param PollService $pollService - * @param CommentService $commentService - * @param OptionService $optionService - * @param ShareService $shareService - * @param VoteService $voteService - * @param Acl $acl - */ + * @param PollService $pollService + * @param CommentService $commentService + * @param OptionService $optionService + * @param ShareService $shareService + * @param VoteService $voteService + * @param Acl $acl + */ public function __construct( string $appName, diff --git a/lib/Controller/ShareApiController.php b/lib/Controller/ShareApiController.php index e2d8b465e5..57c65033e2 100644 --- a/lib/Controller/ShareApiController.php +++ b/lib/Controller/ShareApiController.php @@ -60,8 +60,8 @@ public function __construct( parent::__construct($appName, $request, 'POST, PUT, GET, DELETE', - 'Authorization, Content-Type, Accept', - 1728000); + 'Authorization, Content-Type, Accept', + 1728000); $this->shareService = $shareService; $this->mailService = $mailService; } @@ -85,13 +85,13 @@ public function list($pollId) { } /** - * Get share by token - * @NoAdminRequired - * @CORS - * @NoCSRFRequired - * @param string $token - * @return DataResponse - */ + * Get share by token + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * @param string $token + * @return DataResponse + */ public function get($token) { try { return new DataResponse(['share' => $this->shareService->get($token)], Http::STATUS_OK); diff --git a/lib/Controller/VoteApiController.php b/lib/Controller/VoteApiController.php index 8f8976ba98..28b1ededc4 100644 --- a/lib/Controller/VoteApiController.php +++ b/lib/Controller/VoteApiController.php @@ -53,8 +53,8 @@ public function __construct( parent::__construct($appName, $request, 'PUT, GET, DELETE', - 'Authorization, Content-Type, Accept', - 1728000); + 'Authorization, Content-Type, Accept', + 1728000); $this->voteService = $voteService; } From a2197adf6775c9a387d2b192d033ab780f4da236 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sun, 12 Jul 2020 10:55:00 +0200 Subject: [PATCH 016/117] reduced latency on option confirmation and enhanced error handling --- appinfo/routes.php | 4 +- lib/Controller/OptionController.php | 33 +++++++------- src/js/mixins/optionMixins.js | 2 +- src/js/store/modules/subModules/options.js | 50 +++++++++++++++++----- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 24078de303..d5659af795 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -44,8 +44,8 @@ ['name' => 'option#update', 'url' => '/option/{optionId}', 'verb' => 'PUT'], ['name' => 'option#delete', 'url' => '/option/{optionId}', 'verb' => 'DELETE'], ['name' => 'option#confirm', 'url' => '/option/{optionId}/confirm', 'verb' => 'PUT'], - ['name' => 'option#reorder', 'url' => '/option/reorder', 'verb' => 'POST'], - // ['name' => 'option#list', 'url' => '/options/get/{pollId}', 'verb' => 'GET'], + ['name' => 'option#reorder', 'url' => '/options/reorder', 'verb' => 'POST'], + ['name' => 'option#list', 'url' => '/polls/{pollId}/options', 'verb' => 'GET'], // ['name' => 'option#listByToken', 'url' => '/options/get/s/{token}', 'verb' => 'GET'], ['name' => 'vote#set', 'url' => '/vote/set', 'verb' => 'POST'], diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php index ea58c79cc4..9fc748896a 100644 --- a/lib/Controller/OptionController.php +++ b/lib/Controller/OptionController.php @@ -53,16 +53,16 @@ public function __construct( $this->optionService = $optionService; } - // /** - // * Get all options of given poll - // * @NoAdminRequired - // * @param int $pollId - // * @return DataResponse - // */ - // public function list($pollId) { - // return new DataResponse($this->optionService->list($pollId), Http::STATUS_OK); - // } - // + /** + * Get all options of given poll + * @NoAdminRequired + * @param int $pollId + * @return DataResponse + */ + public function list($pollId) { + return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK); + } + // // /** // * Get all options specified by token @@ -76,6 +76,9 @@ public function __construct( // return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK); // } + + + /** * Add a new option * @NoAdminRequired @@ -83,7 +86,7 @@ public function __construct( * @return DataResponse */ public function add($pollId, $timestamp = 0, $pollOptionText = '') { - return new DataResponse($this->optionService->add($pollId, $timestamp, $pollOptionText), Http::STATUS_OK); + return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_OK); } /** @@ -93,7 +96,7 @@ public function add($pollId, $timestamp = 0, $pollOptionText = '') { * @return DataResponse */ public function update($optionId, $timestamp, $pollOptionText) { - return new DataResponse($this->optionService->update($optionId, $timestamp, $pollOptionText), Http::STATUS_OK); + return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK); } /** @@ -103,7 +106,7 @@ public function update($optionId, $timestamp, $pollOptionText) { * @return DataResponse */ public function delete($optionId) { - return new DataResponse($this->optionService->delete($optionId), Http::STATUS_OK); + return new DataResponse(['option' => $this->optionService->delete($optionId)], Http::STATUS_OK); } /** @@ -113,7 +116,7 @@ public function delete($optionId) { * @return DataResponse */ public function confirm($optionId) { - return new DataResponse($this->optionService->confirm($optionId), Http::STATUS_OK); + return new DataResponse(['option' => $this->optionService->confirm($optionId)], Http::STATUS_OK); } /** @@ -124,6 +127,6 @@ public function confirm($optionId) { * @return DataResponse */ public function reorder($pollId, $options) { - return new DataResponse($this->optionService->reorder($pollId, $options), Http::STATUS_OK); + return new DataResponse(['options' => $this->optionService->reorder($pollId, $options)], Http::STATUS_OK); } } diff --git a/src/js/mixins/optionMixins.js b/src/js/mixins/optionMixins.js index 7a0b1a8eaf..58fc6eb6d5 100644 --- a/src/js/mixins/optionMixins.js +++ b/src/js/mixins/optionMixins.js @@ -1,7 +1,7 @@ export const confirmOption = { methods: { confirmOption(option) { - this.$store.dispatch('poll/options/update', { option: { ...option, confirmed: !option.confirmed } }) + this.$store.dispatch('poll/options/confirm', { option: option }) }, }, } diff --git a/src/js/store/modules/subModules/options.js b/src/js/store/modules/subModules/options.js index 9d01d930a1..e25367108e 100644 --- a/src/js/store/modules/subModules/options.js +++ b/src/js/store/modules/subModules/options.js @@ -49,6 +49,14 @@ const mutations = { }) }, + confirm(state, payload) { + const index = state.list.findIndex((option) => { + return option.id === payload.option.id + }) + + state.list[index].confirmed = !state.list[index].confirmed + }, + setItem(state, payload) { const index = state.list.findIndex((option) => { return option.id === payload.option.id @@ -99,6 +107,20 @@ const getters = { } const actions = { + + reload(context) { + const endPoint = 'apps/polls/polls' + console.error('Reloading options') + return axios.get(generateUrl(endPoint.concat('/', context.rootState.poll.id, '/options'))) + .then((response) => { + context.commit('set', { options: response.data.options }) + }) + .catch((error) => { + console.error('Error loding options', { error: error.response }, { pollId: context.rootState.poll.id }) + throw error + }) + }, + add(context, payload) { const endPoint = 'apps/polls/option' return axios.post(generateUrl(endPoint), { @@ -107,10 +129,11 @@ const actions = { pollOptionText: payload.pollOptionText, }) .then((response) => { - context.commit('setItem', { option: response.data }) + context.commit('setItem', { option: response.data.option }) }) .catch((error) => { console.error('Error adding option', { error: error.response }, { payload: payload }) + context.dispatch('reload') throw error }) }, @@ -122,10 +145,11 @@ const actions = { pollOptionText: payload.option.timeStamp, }) .then((response) => { - context.commit('setItem', { option: response.data }) + context.commit('setItem', { option: response.data.option }) }) .catch((error) => { console.error('Error updating option', { error: error.response }, { payload: payload }) + context.dispatch('reload') throw error }) }, @@ -134,39 +158,43 @@ const actions = { const endPoint = 'apps/polls/option' return axios.delete(generateUrl(endPoint.concat('/', payload.option.id))) - .then(() => { - context.commit('delete', { option: payload.option }) + .then((response) => { + context.commit('delete', { option: response.data.option }) }) .catch((error) => { - console.error('Error removing option', { error: error.response }, { payload: payload }) + console.error('Error deleting option', { error: error.response }, { payload: payload }) + context.dispatch('reload') throw error }) }, confirm(context, payload) { - const endPoint = 'apps/polls/option' + context.commit('confirm', { option: payload.option }) + const endPoint = 'apps/polls/option' return axios.put(generateUrl(endPoint.concat('/', payload.option.id, '/confirm'))) - .then(() => { - context.commit('delete', { option: payload.option }) + .then((response) => { + context.commit('setItem', { option: response.data.option }) }) .catch((error) => { - console.error('Error removing option', { error: error.response }, { payload: payload }) + console.error('Error confirming option', { error: error.response }, { payload: payload }) + context.dispatch('reload') throw error }) }, reorder(context, payload) { - const endPoint = 'apps/polls/option/reorder' + const endPoint = 'apps/polls/options/reorder' return axios.post(generateUrl(endPoint), { pollId: context.rootState.poll.id, options: payload, }) .then((response) => { - context.commit('set', { options: response.data }) + context.commit('set', { options: response.data.options }) }) .catch((error) => { console.error('Error reordering option', { error: error.response }, { payload: payload }) + context.dispatch('reload') throw error }) }, From e11022004cf8c6e7daf9bd8d0cbc5c414587e99a Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sun, 12 Jul 2020 13:39:24 +0200 Subject: [PATCH 017/117] fix voting --- lib/Service/VoteService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 7534b258d6..32076289b9 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -119,7 +119,7 @@ public function set($optionId, $setTo, $token = '') { throw new NotAuthorizedException; } - if ($option->getPollId() !== $this->acl->getPollId()) { + if (intval($option->getPollId()) !== $this->acl->getPollId()) { throw new NotAuthorizedException; } From 5151f1fcff7dfc36a3ec5fba8ed423d5e46fdb07 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sun, 12 Jul 2020 22:01:19 +0200 Subject: [PATCH 018/117] Avoid avatar errors and tidy acl model --- lib/Db/Comment.php | 9 ++- lib/Db/Share.php | 8 +- lib/Db/Vote.php | 8 +- lib/Model/Acl.php | 77 ++++--------------- src/js/components/Base/ParticipantsList.vue | 3 +- src/js/components/Base/UserItem.vue | 6 +- src/js/components/Comments/Comments.vue | 2 +- .../components/VoteTable/VoteHeaderPublic.vue | 2 +- src/js/store/modules/poll.js | 3 + src/js/store/modules/subModules/acl.js | 3 +- src/js/store/modules/subModules/votes.js | 2 +- 11 files changed, 47 insertions(+), 76 deletions(-) diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php index 56514570be..4165996f3d 100644 --- a/lib/Db/Comment.php +++ b/lib/Db/Comment.php @@ -78,16 +78,21 @@ public function jsonSerialize() { 'dt' => $this->dt, 'timestamp' => intval($timestamp), 'comment' => $this->comment, - 'displayName' => $this->getDisplayName() + 'displayName' => $this->getDisplayName(), + 'externalUser' => $this->externalUser() ]; } private function getDisplayName() { - if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); } else { return $this->userId; } } + + private function externalUser() { + return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser); + } + } diff --git a/lib/Db/Share.php b/lib/Db/Share.php index 04b777335e..84ae4ea29a 100644 --- a/lib/Db/Share.php +++ b/lib/Db/Share.php @@ -73,8 +73,9 @@ public function jsonSerialize() { 'pollId' => intval($this->pollId), 'userId' => $this->userId, 'userEmail' => $this->userEmail, + 'invitationSent' => intval($this->invitationSent), 'displayName' => $this->getDisplayName(), - 'invitationSent' => intval($this->invitationSent) + 'externalUser' => $this->externalUser() ]; } @@ -86,4 +87,9 @@ private function getDisplayName() { return $this->userId; } } + + private function externalUser() { + return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser); + } + } diff --git a/lib/Db/Vote.php b/lib/Db/Vote.php index 839f154a73..85b63c09c1 100644 --- a/lib/Db/Vote.php +++ b/lib/Db/Vote.php @@ -66,16 +66,20 @@ public function jsonSerialize() { 'voteOptionId' => intval($this->voteOptionId), 'voteOptionText' => $this->voteOptionText, 'voteAnswer' => $this->voteAnswer, - 'displayName' => $this->getDisplayName() + 'displayName' => $this->getDisplayName(), + 'externalUser' => $this->externalUser() ]; } private function getDisplayName() { - if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); } else { return $this->userId; } } + + private function externalUser() { + return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser); + } } diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php index 7131943604..1076000831 100644 --- a/lib/Model/Acl.php +++ b/lib/Model/Acl.php @@ -53,9 +53,6 @@ class Acl implements JsonSerializable { /** @var string */ private $token = ''; - /** @var bool */ - private $foundByToken = false; - /** @var string */ private $userId; @@ -77,7 +74,6 @@ class Acl implements JsonSerializable { /** @var Poll */ private $poll; - /** * Acl constructor. * @param string $appName @@ -129,27 +125,20 @@ public function getDisplayName() { } } - /** * @NoAdminRequired - * @return bool + * @return string */ - public function setPollIdOrToken($pollId = 0, $token = '') { - - if ($token) { - $this->setToken($token); - } elseif ($pollId) { - $this->setPollId($pollId); - } - - return $this; + public function getIsExternalUser() { + return !($this->userManager->get($this->userId) instanceof IUser); } + /** * @NoAdminRequired * @return bool */ - public function checkAuthorize($pollId = 0, $token = '') { + public function setPollIdOrToken($pollId = 0, $token = '') { if ($token) { $this->setToken($token); @@ -157,7 +146,7 @@ public function checkAuthorize($pollId = 0, $token = '') { $this->setPollId($pollId); } - return ($this->userId && $this->poll->getId()); + return $this; } /** @@ -309,17 +298,10 @@ public function getExpired(): bool { * @return bool */ public function getAllowVote(): bool { - if ( - ($this->getAllowView() || $this->getFoundByToken()) + return ($this->getAllowView() || $this->getToken()) && !$this->getExpired() && !$this->poll->getDeleted() - && $this->userId - - ) { - return true; - } else { - return false; - } + && $this->userId; } /** @@ -343,15 +325,9 @@ public function getAllowEdit(): bool { * @return bool */ public function getAllowSeeResults(): bool { - if ($this->poll->getShowResults() === 'always' || $this->getIsOwner()) { - return true; - } elseif ($this->poll->getShowResults() === 'never') { - return false; - } elseif ($this->poll->getShowResults() === 'expired') { - return $this->getExpired(); - } else { - return false; - } + return $this->poll->getShowResults() === 'always' + || ($this->poll->getShowResults() === 'expired' && $this->getExpired()) + || $this->getIsOwner(); } /** @@ -359,28 +335,7 @@ public function getAllowSeeResults(): bool { * @return bool */ public function getAllowSeeUsernames(): bool { - return !($this->poll->getAnonymous() && !$this->getIsOwner()); ; - } - - /** - * @NoAdminRequired - * @return bool - */ - public function getAllowSeeAllVotes(): bool { - // TODO: preparation for polls without displaying other votes - if ($this->pollId) { - return true; - } else { - return false; - } - } - - /** - * @NoAdminRequired - * @return bool - */ - public function getFoundByToken(): bool { - return $this->foundByToken; + return !$this->poll->getAnonymous() || $this->getIsOwner(); } /** @@ -401,7 +356,6 @@ public function setToken(string $token): Acl { $this->token = $token; $share = $this->shareMapper->findByToken($token); - $this->foundByToken = true; $this->setPollId($share->getPollId()); \OC::$server->getLogger()->debug('Share PollId: ' . $share->getPollId()); @@ -410,7 +364,6 @@ public function setToken(string $token): Acl { $this->setPollId(0); $this->setUserId(null); $this->token = ''; - $this->foundByToken = false; } else if (($share->getType() === 'group' || $share->getType() === 'public') && \OC::$server->getUserSession()->isLoggedIn()) { // Use user name of authorized user shareType public and group if user is logged in $this->setUserId($this->userId); @@ -423,7 +376,6 @@ public function setToken(string $token): Acl { $this->setPollId(0); $this->setUserId(null); $this->token = ''; - $this->foundByToken = false; } return $this; } @@ -436,6 +388,7 @@ public function jsonSerialize(): array { 'userId' => $this->getUserId(), 'displayName' => $this->getDisplayName(), 'loggedIn' => $this->getLoggedIn(), + 'externalUser' => $this->getIsExternalUser(), 'pollId' => $this->getPollId(), 'token' => $this->getToken(), 'isOwner' => $this->getIsOwner(), @@ -446,12 +399,10 @@ public function jsonSerialize(): array { 'allowEdit' => $this->getAllowEdit(), 'allowSeeResults' => $this->getAllowSeeResults(), 'allowSeeUsernames' => $this->getAllowSeeUsernames(), - 'allowSeeAllVotes' => $this->getAllowSeeAllVotes(), 'userHasVoted' => $this->getUserHasVoted(), 'groupShare' => $this->getGroupShare(), 'personalShare' => $this->getPersonalShare(), - 'publicShare' => $this->getPublicShare(), - 'foundByToken' => $this->getFoundByToken() + 'publicShare' => $this->getPublicShare() ]; } } diff --git a/src/js/components/Base/ParticipantsList.vue b/src/js/components/Base/ParticipantsList.vue index dafbadd4d5..35f8f34256 100644 --- a/src/js/components/Base/ParticipantsList.vue +++ b/src/js/components/Base/ParticipantsList.vue @@ -29,8 +29,7 @@ {{ t('polls','No Participants until now') }}
- diff --git a/src/js/components/Base/UserItem.vue b/src/js/components/Base/UserItem.vue index babeadb964..b0889c502d 100644 --- a/src/js/components/Base/UserItem.vue +++ b/src/js/components/Base/UserItem.vue @@ -26,7 +26,7 @@ class="user-item__avatar" :menu-position="menuPosition" :user="userId" - :is-guest="!Boolean(getCurrentUser())" + :is-guest="!Boolean(getCurrentUser()) || externalUser" :display-name="resolveDisplayName" :is-no-user="isNoUser" /> @@ -84,6 +84,10 @@ export default { type: Boolean, default: false, }, + externalUser: { + type: Boolean, + default: false, + }, }, data() { diff --git a/src/js/components/Comments/Comments.vue b/src/js/components/Comments/Comments.vue index 18ced5a43c..280d9de5dd 100644 --- a/src/js/components/Comments/Comments.vue +++ b/src/js/components/Comments/Comments.vue @@ -27,7 +27,7 @@ tag="ul">
  • - + {{ t('polls', 'Delete comment') }} diff --git a/src/js/components/VoteTable/VoteHeaderPublic.vue b/src/js/components/VoteTable/VoteHeaderPublic.vue index 2d2f56f0ed..e60fc480d1 100644 --- a/src/js/components/VoteTable/VoteHeaderPublic.vue +++ b/src/js/components/VoteTable/VoteHeaderPublic.vue @@ -110,7 +110,7 @@ export default { }, displayLink() { - return (this.acl.userId !== '' && this.acl.userId !== null && this.acl.foundByToken) + return (this.acl.userId !== '' && this.acl.userId !== null && this.acl.token) }, isValidUser() { diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index 653a55c4ab..ee8cbc1881 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -89,6 +89,7 @@ const getters = { participants.push({ userId: item.userId, displayName: item.displayName, + externalUser: item.externalUser, voted: true, }) } @@ -98,6 +99,7 @@ const getters = { participants.push({ userId: state.acl.userId, displayName: state.acl.displayName, + externalUser: state.externalUser, voted: false, }) } @@ -113,6 +115,7 @@ const getters = { participantsVoted.push({ userId: item.userId, displayName: item.displayName, + externalUser: item.externalUser, }) } } diff --git a/src/js/store/modules/subModules/acl.js b/src/js/store/modules/subModules/acl.js index 5c7be05061..1959b07133 100644 --- a/src/js/store/modules/subModules/acl.js +++ b/src/js/store/modules/subModules/acl.js @@ -26,13 +26,12 @@ const defaultAcl = () => { accessLevel: '', allowComment: false, allowEdit: false, - allowSeeAllVotes: false, allowSeeResults: false, allowSeeUsernames: false, allowView: false, allowVote: false, displayName: '', - foundByToken: false, + externalUser: false, groupShare: false, isAdmin: false, isOwner: false, diff --git a/src/js/store/modules/subModules/votes.js b/src/js/store/modules/subModules/votes.js index 012e7d7250..8eaa9280dc 100644 --- a/src/js/store/modules/subModules/votes.js +++ b/src/js/store/modules/subModules/votes.js @@ -117,7 +117,7 @@ const actions = { set(context, payload) { let endPoint = 'apps/polls/vote/set' - if (context.rootState.poll.acl.foundByToken) { + if (context.rootState.poll.acl.token) { endPoint = endPoint.concat('/s') } return axios.post(generateUrl(endPoint), { From 1a165ec44c004b259b9ebdbd5b50aed5d9a50638 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Mon, 13 Jul 2020 13:22:37 +0200 Subject: [PATCH 019/117] Drop support for NC16 --- .travis.yml | 1 + CHANGELOG.md | 3 +-- appinfo/info.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b9a423a96..91bae7e2ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ services: php: - 7.2 - 7.3 + - 7.4 addons: apt: diff --git a/CHANGELOG.md b/CHANGELOG.md index bc8a63481f..8597a5f61e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## [1.5.0] - tbd + - Drop support for Nextcloud 16 - Stop immediatley sending of invitation mails after adding a share #1007 #935 - Fix: Hide usernames in notification mail, if results in poll are hidden #990 #980 - Adding a REST-API #966 @@ -14,8 +15,6 @@ All notable changes to this project will be documented in this file. - Added the ability to confirm options #939 #136 - A lot of refactoring - - ## [1.4.3] - 2020-05-03 - fix #909 - fix #910 diff --git a/appinfo/info.xml b/appinfo/info.xml index 37665b1dc7..9a3b1e4280 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -23,7 +23,7 @@ https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/vote.png https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/edit-poll.png - + OCA\Polls\Cron\NotificationCron From 1f906b431b3a1b45a442545544d0b72dc7356af4 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Fri, 24 Jul 2020 08:11:05 +0200 Subject: [PATCH 020/117] Code maintenance --- lib/Service/OptionService.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 84fb9822ec..3cabc5ae86 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -285,14 +285,7 @@ public function setOrder($optionId, $newOrder) { foreach ($this->optionMapper->findByPoll($pollId) as $option) { $currentOrder = $option->getOrder(); - if ( - ($currentOrder < $oldOrder && $currentOrder < $newOrder) - || ($currentOrder > $oldOrder && $currentOrder > $newOrder) - ) { - - continue; - - } elseif ($currentOrder > $oldOrder && $currentOrder <= $newOrder) { + if ($currentOrder > $oldOrder && $currentOrder <= $newOrder) { $option->setOrder($currentOrder - 1); $this->optionMapper->update($option); @@ -310,6 +303,8 @@ public function setOrder($optionId, $newOrder) { $option->setOrder($newOrder); $this->optionMapper->update($option); + } else { + continue; } } From f95294393895877cd7b6212cb0432e66bfc3eaa1 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 25 Jul 2020 09:07:03 +0200 Subject: [PATCH 021/117] dev updates --- package-lock.json | 466 +++++++++++++++++++++++++++++++++++++--------- package.json | 6 +- 2 files changed, 385 insertions(+), 87 deletions(-) diff --git a/package-lock.json b/package-lock.json index e719637626..494797d111 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3555,6 +3555,27 @@ } } }, + "@babel/polyfill": { + "version": "7.2.5", + "resolved": "https://registry.npmjs.org/@babel/polyfill/-/polyfill-7.2.5.tgz", + "integrity": "sha512-8Y/t3MWThtMLYr0YNC/Q76tqN1w30+b0uQMeFUYauG2UGTR19zyUtFrAzT23zNtBxPp+LbE5E/nwV/q/r3y6ug==", + "requires": { + "core-js": "^2.5.7", + "regenerator-runtime": "^0.12.0" + }, + "dependencies": { + "core-js": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", + "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" + }, + "regenerator-runtime": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", + "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" + } + } + }, "@babel/preset-env": { "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.10.4.tgz", @@ -3883,9 +3904,9 @@ } }, "@nextcloud/vue": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/@nextcloud/vue/-/vue-2.2.1.tgz", - "integrity": "sha512-A2vrP+8cMM67Q9q5ZhUriNn4WDb/X6Q7zNqUT6iCQWI5pf/aun0DbWatZQRtH9OIDfdoj5seUlpNXlPFd8eccg==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@nextcloud/vue/-/vue-2.3.0.tgz", + "integrity": "sha512-6uf7Hu4Obaet7BOs9H/Ng63xAYqks9CL7hsOOHGUzWFYrPPBxgt79iD9OOPpPfJuLQ3Nnuibh942X1QreCBRkw==", "requires": { "@nextcloud/auth": "^1.2.3", "@nextcloud/axios": "^1.3.2", @@ -3895,6 +3916,7 @@ "@nextcloud/router": "^1.0.2", "core-js": "^3.6.5", "debounce": "1.2.0", + "emoji-mart-vue-fast": "^7.0.2", "hammerjs": "^2.0.8", "md5": "^2.2.1", "regenerator-runtime": "^0.13.5", @@ -4331,6 +4353,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz", "integrity": "sha512-5teOsQWABXHHBFP9y3skS5P3d/WfWXpv3FUpy+LorMrNYaT9pI4oLMQX7jzQ2KklNpGpWHzdCXTDT2Y3XGlZBw==", + "optional": true, "requires": { "micromatch": "^3.1.4", "normalize-path": "^2.1.1" @@ -4340,6 +4363,7 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", + "optional": true, "requires": { "remove-trailing-separator": "^1.0.1" } @@ -4448,6 +4472,14 @@ "bn.js": "^4.0.0", "inherits": "^2.0.1", "minimalistic-assert": "^1.0.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "dev": true + } } }, "assert": { @@ -4497,7 +4529,8 @@ "async-each": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz", - "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==" + "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==", + "optional": true }, "async-foreach": { "version": "0.1.3", @@ -4705,7 +4738,8 @@ "binary-extensions": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz", - "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==" + "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==", + "optional": true }, "bindings": { "version": "1.5.0", @@ -4732,9 +4766,9 @@ "dev": true }, "bn.js": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.1.2.tgz", + "integrity": "sha512-40rZaf3bUNKTVYu9sIeeEGOg7g14Yvnj9kH7b50EiwX0Q7A6umbvfI5tvHaOERH0XigqKkfLkFQxzb4e6CIXnA==", "dev": true }, "brace-expansion": { @@ -4824,21 +4858,50 @@ "requires": { "bn.js": "^4.1.0", "randombytes": "^2.0.1" + }, + "dependencies": { + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "dev": true + } } }, "browserify-sign": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.0.4.tgz", - "integrity": "sha1-qk62jl17ZYuqa/alfmMMvXqT0pg=", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.2.0.tgz", + "integrity": "sha512-hEZC1KEeYuoHRqhGhTy6gWrpJA3ZDjFWv0DE61643ZnOXAKJb3u7yWcrU0mMc9SwAqK1n7myPGndkp0dFG7NFA==", "dev": true, "requires": { - "bn.js": "^4.1.1", - "browserify-rsa": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.2", - "elliptic": "^6.0.0", - "inherits": "^2.0.1", - "parse-asn1": "^5.0.0" + "bn.js": "^5.1.1", + "browserify-rsa": "^4.0.1", + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "elliptic": "^6.5.2", + "inherits": "^2.0.4", + "parse-asn1": "^5.1.5", + "readable-stream": "^3.6.0", + "safe-buffer": "^5.2.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + } } }, "browserify-zlib": { @@ -5073,6 +5136,7 @@ "version": "2.1.8", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz", "integrity": "sha512-ZmZUazfOzf0Nve7duiCKD23PFSCs4JPoYyccjUFF3aQkQadqBhfzhjkwBH2mNOG9cTBwhamM37EIsIkZw3nRgg==", + "optional": true, "requires": { "anymatch": "^2.0.0", "async-each": "^1.0.1", @@ -5414,6 +5478,14 @@ "requires": { "bn.js": "^4.1.0", "elliptic": "^6.0.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "dev": true + } } }, "create-hash": { @@ -5596,9 +5668,9 @@ } }, "date-fns": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.14.0.tgz", - "integrity": "sha512-1zD+68jhFgDIM0rF05rcwYO8cExdNqxjq4xP1QKM60Q45mnO6zaMWB4tOzrIr4M4GSLntsKeE4c9Bdl2jhL/yw==" + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.15.0.tgz", + "integrity": "sha512-ZCPzAMJZn3rNUvvQIMlXhDr4A+Ar07eLeGsGREoWU19a3Pqf5oYa+ccd+B3F6XVtQY6HANMFdOQ8A+ipFnvJdQ==" }, "date-format-parse": { "version": "0.2.5", @@ -5738,6 +5810,14 @@ "bn.js": "^4.1.0", "miller-rabin": "^4.0.0", "randombytes": "^2.0.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "dev": true + } } }, "dir-glob": { @@ -5849,9 +5929,9 @@ "integrity": "sha512-IQbCfjJR0NDDn/+vojTlq7fPSREcALtF8M1n01gw7nQghCtfFYrJ2dfhsp8APr8bANoFC8vRTFVXMOGpT0eetw==" }, "elliptic": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz", - "integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", + "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", "dev": true, "requires": { "bn.js": "^4.4.0", @@ -5861,6 +5941,39 @@ "inherits": "^2.0.1", "minimalistic-assert": "^1.0.0", "minimalistic-crypto-utils": "^1.0.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "dev": true + } + } + }, + "emoji-mart-vue-fast": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/emoji-mart-vue-fast/-/emoji-mart-vue-fast-7.0.2.tgz", + "integrity": "sha512-7OftneG98Jb9wkJgPBeUdEWrMMdGvd08erHMjNviKSuQSBsBAIFnQyW7lroBZ+dLT7uTZKuZfWdWwUfWpk965w==", + "requires": { + "@babel/polyfill": "7.2.5", + "@babel/runtime": "7.3.4", + "vue-virtual-scroller": "^1.0.0-rc.2" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.3.4.tgz", + "integrity": "sha512-IvfvnMdSaLBateu0jfsYIpZTxAc2cKEXEMiezGGN75QcBcecDUKd3PgLAncT0oOgxKy8dd8hrJKj9MfzgfZd6g==", + "requires": { + "regenerator-runtime": "^0.12.0" + } + }, + "regenerator-runtime": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", + "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" + } } }, "emoji-regex": { @@ -5976,9 +6089,9 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.4.0.tgz", - "integrity": "sha512-gU+lxhlPHu45H3JkEGgYhWhkR9wLHHEXC9FbWFnTlEkbKyZKWgWRLgf61E8zWmBuI6g5xKBph9ltg3NtZMVF8g==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.5.0.tgz", + "integrity": "sha512-vlUP10xse9sWt9SGRtcr1LAC67BENcQMFeV+w5EvLEoFe3xJ8cF1Skd0msziRx/VMC+72B4DxreCE+OR12OA6Q==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -5989,9 +6102,9 @@ "doctrine": "^3.0.0", "enquirer": "^2.3.5", "eslint-scope": "^5.1.0", - "eslint-utils": "^2.0.0", - "eslint-visitor-keys": "^1.2.0", - "espree": "^7.1.0", + "eslint-utils": "^2.1.0", + "eslint-visitor-keys": "^1.3.0", + "espree": "^7.2.0", "esquery": "^1.2.0", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", @@ -6005,7 +6118,7 @@ "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", - "lodash": "^4.17.14", + "lodash": "^4.17.19", "minimatch": "^3.0.4", "natural-compare": "^1.4.0", "optionator": "^0.9.1", @@ -6086,14 +6199,14 @@ "dev": true }, "espree": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-7.1.0.tgz", - "integrity": "sha512-dcorZSyfmm4WTuTnE5Y7MEN1DyoPYy1ZR783QW1FJoenn7RailyWFsq/UL6ZAAA7uXurN9FIpYyUs3OfiIW+Qw==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.2.0.tgz", + "integrity": "sha512-H+cQ3+3JYRMEIOl87e7QdHX70ocly5iW4+dttuR8iYSPr/hXKFb+7dBsZ7+u1adC4VrnPlTkv0+OwuPnDop19g==", "dev": true, "requires": { - "acorn": "^7.2.0", + "acorn": "^7.3.1", "acorn-jsx": "^5.2.0", - "eslint-visitor-keys": "^1.2.0" + "eslint-visitor-keys": "^1.3.0" } }, "glob-parent": { @@ -6508,9 +6621,9 @@ "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" }, "events": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.1.0.tgz", - "integrity": "sha512-Rv+u8MLHNOdMjTAFeT3nCjHn2aGlx435FP/sDHNaRhDEMwyI/aB22Kj2qIN8R0cw3z28psEQLYwxVKLsKrMgWg==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.2.0.tgz", + "integrity": "sha512-/46HWwbfCX2xTawVfkKLGxMifJYQBWMwY1mjywRtb4c9x8l5NP3KoJtnIOiL1hfdRkIuYhETxQlo62IF8tcnlg==", "dev": true }, "evp_bytestokey": { @@ -7598,6 +7711,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz", "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", + "optional": true, "requires": { "is-glob": "^3.1.0", "path-dirname": "^1.0.0" @@ -7607,6 +7721,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", + "optional": true, "requires": { "is-extglob": "^2.1.0" } @@ -7837,9 +7952,9 @@ } }, "safe-buffer": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", - "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "dev": true } } @@ -8112,6 +8227,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz", "integrity": "sha1-dfFmQrSA8YenEcgUFh/TpKdlWJg=", + "optional": true, "requires": { "binary-extensions": "^1.0.0" } @@ -8921,6 +9037,14 @@ "requires": { "bn.js": "^4.0.0", "brorand": "^1.0.1" + }, + "dependencies": { + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "dev": true + } } }, "mime-db": { @@ -9663,7 +9787,8 @@ "path-dirname": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", - "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=" + "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=", + "optional": true }, "path-exists": { "version": "3.0.0", @@ -9704,9 +9829,9 @@ } }, "pbkdf2": { - "version": "3.0.17", - "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz", - "integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.1.tgz", + "integrity": "sha512-4Ejy1OPxi9f2tt1rRV7Go7zmfDQ+ZectEQz3VGUQhgq62HtIRPDyG/JtnwIxs6x3uNMwo2V7q1fMvKjb+Tnpqg==", "dev": true, "requires": { "create-hash": "^1.1.2", @@ -10059,6 +10184,14 @@ "parse-asn1": "^5.0.0", "randombytes": "^2.0.1", "safe-buffer": "^5.1.2" + }, + "dependencies": { + "bn.js": { + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "dev": true + } } }, "pump": { @@ -10182,6 +10315,7 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", "integrity": "sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ==", + "optional": true, "requires": { "graceful-fs": "^4.1.11", "micromatch": "^3.1.10", @@ -10332,7 +10466,8 @@ "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", - "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=" + "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=", + "optional": true }, "repeat-element": { "version": "1.1.3", @@ -10627,6 +10762,11 @@ "ajv-keywords": "^3.4.1" } }, + "scrollparent": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/scrollparent/-/scrollparent-2.0.1.tgz", + "integrity": "sha1-cV1bnMV3YPsivczDvvtb/gaxoxc=" + }, "scss-tokenizer": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/scss-tokenizer/-/scss-tokenizer-0.2.3.tgz", @@ -11159,9 +11299,9 @@ } }, "strip-json-comments": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.0.tgz", - "integrity": "sha512-e6/d0eBu7gHtdCqFt0xJr642LdToM5/cN4Qb9DbHjVx1CP5RyeM+zH7pbecEmDv/lBqb0QH+6Uqq75rxFPkM0w==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, "style-search": { @@ -11768,9 +11908,9 @@ } }, "terser": { - "version": "4.6.13", - "resolved": "https://registry.npmjs.org/terser/-/terser-4.6.13.tgz", - "integrity": "sha512-wMvqukYgVpQlymbnNbabVZbtM6PN63AzqexpwJL8tbh/mRT9LE5o+ruVduAGL7D6Fpjl+Q+06U5I9Ul82odAhw==", + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-4.8.0.tgz", + "integrity": "sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==", "dev": true, "requires": { "commander": "^2.20.0", @@ -12108,9 +12248,9 @@ } }, "tslib": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", - "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", + "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", "dev": true }, "tty-browserify": { @@ -12354,7 +12494,8 @@ "upath": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/upath/-/upath-1.2.0.tgz", - "integrity": "sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==" + "integrity": "sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==", + "optional": true }, "uri-js": { "version": "4.2.2", @@ -12590,6 +12731,11 @@ "resolved": "https://registry.npmjs.org/vue-multiselect/-/vue-multiselect-2.1.6.tgz", "integrity": "sha512-s7jmZPlm9FeueJg1RwJtnE9KNPtME/7C8uRWSfp9/yEN4M8XcS/d+bddoyVwVnvFyRh9msFo0HWeW0vTL8Qv+w==" }, + "vue-observe-visibility": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/vue-observe-visibility/-/vue-observe-visibility-0.4.6.tgz", + "integrity": "sha512-xo0CEVdkjSjhJoDdLSvoZoQrw/H2BlzB5jrCBKGZNXN2zdZgMuZ9BKrxXDjNP2AxlcCoKc8OahI3F3r3JGLv2Q==" + }, "vue-resize": { "version": "0.4.5", "resolved": "https://registry.npmjs.org/vue-resize/-/vue-resize-0.4.5.tgz", @@ -12626,15 +12772,25 @@ "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "dev": true }, + "vue-virtual-scroller": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/vue-virtual-scroller/-/vue-virtual-scroller-1.0.10.tgz", + "integrity": "sha512-Hn4qSBDhRY4XdngPioYy/ykDjrLX/NMm1fQXm/4UQQ/Xv1x8JbHGFZNftQowTcfICgN7yc31AKnUk1UGLJ2ndA==", + "requires": { + "scrollparent": "^2.0.1", + "vue-observe-visibility": "^0.4.4", + "vue-resize": "^0.4.5" + } + }, "vue-visible": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/vue-visible/-/vue-visible-1.0.2.tgz", "integrity": "sha512-yaX2its9XAJKGuQqf7LsiZHHSkxsIK8rmCOQOvEGEoF41blKRK8qr9my4qYoD6ikdLss4n8tKqYBecmaY0+WJg==" }, "vue2-datepicker": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/vue2-datepicker/-/vue2-datepicker-3.6.0.tgz", - "integrity": "sha512-PDGkOIU2LCripjsWsosrHpxUSmR3itkdAHwhh5YU8aEOsc4kUKwR/aBqwn89PYophi1EwNcsPreeY1b8WhiSGg==", + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/vue2-datepicker/-/vue2-datepicker-3.6.1.tgz", + "integrity": "sha512-U6iQWSDsNoq/u6QJCtAMcyWlcZSx0rmPmqaJ8LQtGvwu9x12jXDoe3YNeG4y7E45OYAMLXs9WzGkDqDmNj3jkw==", "requires": { "date-fns": "^2.0.1", "date-format-parse": "^0.2.5" @@ -12654,20 +12810,142 @@ "integrity": "sha512-w7oJzmHQs0FM9LXodfskhw9wgKBiaB+totOdb8sNzbTB2KDCEEwEs29NzBZFh/lmEK1t5tDmM1vtsO7ubG1DFw==" }, "watchpack": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.1.tgz", - "integrity": "sha512-+IF9hfUFOrYOOaKyfaI7h7dquUIOgyEMoQMLA7OP5FxegKA2+XdXThAZ9TU2kucfhDH7rfMHs1oPYziVGWRnZA==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.7.4.tgz", + "integrity": "sha512-aWAgTW4MoSJzZPAicljkO1hsi1oKj/RRq/OJQh2PKI2UKL04c2Bs+MBOB+BBABHTXJpf9mCwHN7ANCvYsvY2sg==", "dev": true, "requires": { - "chokidar": "^2.1.8", + "chokidar": "^3.4.1", "graceful-fs": "^4.1.2", - "neo-async": "^2.5.0" + "neo-async": "^2.5.0", + "watchpack-chokidar2": "^2.0.0" + }, + "dependencies": { + "anymatch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", + "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "dev": true, + "optional": true, + "requires": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + } + }, + "binary-extensions": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz", + "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==", + "dev": true, + "optional": true + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "optional": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "chokidar": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.4.1.tgz", + "integrity": "sha512-TQTJyr2stihpC4Sya9hs2Xh+O2wf+igjL36Y75xx2WdHuiICcn/XJza46Jwt0eT5hVpQOzo3FpY3cj3RVYLX0g==", + "dev": true, + "optional": true, + "requires": { + "anymatch": "~3.1.1", + "braces": "~3.0.2", + "fsevents": "~2.1.2", + "glob-parent": "~5.1.0", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.4.0" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "optional": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "dev": true, + "optional": true + }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "optional": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "optional": true, + "requires": { + "binary-extensions": "^2.0.0" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "optional": true + }, + "readdirp": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.4.0.tgz", + "integrity": "sha512-0xe001vZBnJEK+uKcj8qOhyAKPzIT+gStxWr3LCB0DwcXR5NZJ3IaC+yGnHCYzB/S7ov3m3EEbZI2zeNvX+hGQ==", + "dev": true, + "optional": true, + "requires": { + "picomatch": "^2.2.1" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "optional": true, + "requires": { + "is-number": "^7.0.0" + } + } + } + }, + "watchpack-chokidar2": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/watchpack-chokidar2/-/watchpack-chokidar2-2.0.0.tgz", + "integrity": "sha512-9TyfOyN/zLUbA288wZ8IsMZ+6cbzvsNyEzSBp6e/zkifi6xxbl8SmQ/CxQq32k8NNqrdVEVUVSEf56L4rQ/ZxA==", + "dev": true, + "optional": true, + "requires": { + "chokidar": "^2.1.8" } }, "webpack": { - "version": "4.43.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.43.0.tgz", - "integrity": "sha512-GW1LjnPipFW2Y78OOab8NJlCflB7EFskMih2AHdvjbpKMeDJqEgSx24cXXXiPS65+WSwVyxtDsJH6jGX2czy+g==", + "version": "4.44.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.44.0.tgz", + "integrity": "sha512-wAuJxK123sqAw31SpkPiPW3iKHgFUiKvO7E7UZjtdExcsRe3fgav4mvoMM7vvpjLHVoJ6a0Mtp2fzkoA13e0Zw==", "dev": true, "requires": { "@webassemblyjs/ast": "1.9.0", @@ -12678,7 +12956,7 @@ "ajv": "^6.10.2", "ajv-keywords": "^3.4.1", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^4.1.0", + "enhanced-resolve": "^4.3.0", "eslint-scope": "^4.0.3", "json-parse-better-errors": "^1.0.2", "loader-runner": "^2.4.0", @@ -12691,7 +12969,7 @@ "schema-utils": "^1.0.0", "tapable": "^1.1.3", "terser-webpack-plugin": "^1.4.3", - "watchpack": "^1.6.1", + "watchpack": "^1.7.4", "webpack-sources": "^1.4.1" }, "dependencies": { @@ -12724,6 +13002,29 @@ "y18n": "^4.0.0" } }, + "enhanced-resolve": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-4.3.0.tgz", + "integrity": "sha512-3e87LvavsdxyoCfGusJnrZ5G8SLPOFeHSNpZI/ATL9a5leXo2k0w6MKnbqhdBad9qTobSfB20Ld7UmgoNbAZkQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "memory-fs": "^0.5.0", + "tapable": "^1.0.0" + }, + "dependencies": { + "memory-fs": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.5.0.tgz", + "integrity": "sha512-jA0rdU5KoQMC0e6ppoNRtpp6vjFq6+NY7r8hywnC7V+1Xj/MtHwGIbB1QaK/dunyjWteJzmkpd7ooeWg10T7GA==", + "dev": true, + "requires": { + "errno": "^0.1.3", + "readable-stream": "^2.0.1" + } + } + } + }, "eslint-scope": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", @@ -12755,10 +13056,13 @@ } }, "serialize-javascript": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-2.1.2.tgz", - "integrity": "sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==", - "dev": true + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-3.1.0.tgz", + "integrity": "sha512-JIJT1DGiWmIKhzRsG91aS6Ze4sFUrYbltlkg2onR5OrnNM02Kl/hnY/T4FN2omvyeBbQmMJv+K4cPOpGzOTFBg==", + "dev": true, + "requires": { + "randombytes": "^2.1.0" + } }, "source-map": { "version": "0.6.1", @@ -12776,28 +13080,22 @@ } }, "terser-webpack-plugin": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.4.3.tgz", - "integrity": "sha512-QMxecFz/gHQwteWwSo5nTc6UaICqN1bMedC5sMtUc7y3Ha3Q8y6ZO0iCR8pq4RJC8Hjf0FEPEHZqcMB/+DFCrA==", + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.4.4.tgz", + "integrity": "sha512-U4mACBHIegmfoEe5fdongHESNJWqsGU+W0S/9+BmYGVQDw1+c2Ow05TpMhxjPK1sRb7cuYq1BPl1e5YHJMTCqA==", "dev": true, "requires": { "cacache": "^12.0.2", "find-cache-dir": "^2.1.0", "is-wsl": "^1.1.0", "schema-utils": "^1.0.0", - "serialize-javascript": "^2.1.2", + "serialize-javascript": "^3.1.0", "source-map": "^0.6.1", "terser": "^4.1.2", "webpack-sources": "^1.4.0", "worker-farm": "^1.7.0" } }, - "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", - "dev": true - }, "yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index 0e2b1dd747..1e23e9a347 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@nextcloud/event-bus": "^1.1.4", "@nextcloud/moment": "^1.1.1", "@nextcloud/router": "^1.1.0", - "@nextcloud/vue": "^2.2.1", + "@nextcloud/vue": "^2.3.0", "core-js": "^3.6.5", "lodash": "^4.17.19", "moment": "^2.27.0", @@ -69,7 +69,7 @@ "babel-loader": "^8.0.6", "cross-env": "^7.0.0", "css-loader": "^3.6.0", - "eslint": "^7.4.0", + "eslint": "^7.5.0", "eslint-config-standard": "^14.1.0", "eslint-loader": "^4.0.2", "eslint-plugin-import": "^2.22.0", @@ -87,7 +87,7 @@ "vue-loader": "^15.9.3", "vue-style-loader": "^4.1.2", "vue-template-compiler": "^2.6.11", - "webpack": "^4.43.0", + "webpack": "^4.44.0", "webpack-cli": "^3.3.12", "webpack-merge": "^5.0.9" } From b362d0a86fd1270e411beccd850c53c68119eb3a Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 25 Jul 2020 10:15:26 +0200 Subject: [PATCH 022/117] remove php 7.4 from travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 91bae7e2ce..7b9a423a96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ services: php: - 7.2 - 7.3 - - 7.4 addons: apt: From e857f1450b8e916b675a907fe75f236ad5cd9c99 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sun, 26 Jul 2020 19:35:11 +0200 Subject: [PATCH 023/117] copy participants addresses to clipboard --- appinfo/routes.php | 2 + lib/Controller/PollApiController.php | 19 ++++++ lib/Controller/PollController.php | 17 +++++ lib/Db/ShareMapper.php | 22 +++++++ lib/Db/Vote.php | 2 +- lib/Service/MailService.php | 29 ++++++++- lib/Service/PollService.php | 72 ++++++++++++++++----- src/js/components/Base/ParticipantsList.vue | 33 +++++++++- src/js/store/modules/poll.js | 11 ++++ 9 files changed, 189 insertions(+), 18 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index d5659af795..a2b38130fe 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -39,6 +39,7 @@ ['name' => 'poll#delete', 'url' => '/polls/delete/{pollId}', 'verb' => 'GET'], ['name' => 'poll#deletePermanently', 'url' => '/polls/delete/permanent/{pollId}', 'verb' => 'GET'], ['name' => 'poll#clone', 'url' => '/polls/clone/{pollId}', 'verb' => 'GET'], + ['name' => 'poll#getParticipantsEmailAddresses', 'url' => '/polls/addresses/{pollId}', 'verb' => 'GET'], ['name' => 'option#add', 'url' => '/option', 'verb' => 'POST'], ['name' => 'option#update', 'url' => '/option/{optionId}', 'verb' => 'PUT'], @@ -81,6 +82,7 @@ ['name' => 'poll_api#delete', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'DELETE'], ['name' => 'poll_api#clone', 'url' => '/api/v1.0/poll/{pollId}/clone', 'verb' => 'POST'], ['name' => 'poll_api#trash', 'url' => '/api/v1.0/poll/{pollId}/trash', 'verb' => 'POST'], + ['name' => 'poll_api#getParticipantsEmailAddresses', 'url' => '/api/v1.0/poll/{pollId}/addresses', 'verb' => 'GET'], ['name' => 'poll_api#enum', 'url' => '/api/v1.0/enum/poll', 'verb' => 'GET'], ['name' => 'option_api#list', 'url' => '/api/v1.0/poll/{pollId}/options', 'verb' => 'GET'], diff --git a/lib/Controller/PollApiController.php b/lib/Controller/PollApiController.php index 20eb2ea076..c2e4750ff9 100644 --- a/lib/Controller/PollApiController.php +++ b/lib/Controller/PollApiController.php @@ -202,6 +202,25 @@ public function clone($pollId) { } } + /** + * Collect email addresses from particitipants + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * @param Array $poll + * @return DataResponse + */ + + public function getParticipantsEmailAddresses($pollId) { + try { + return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK); + } catch (DoesNotExistException $e) { + return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); + } catch (NotAuthorizedException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } + } + /** * Get valid values for configuration options * @NoAdminRequired diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index d1b4945be0..04445482fa 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -267,4 +267,21 @@ public function clone($pollId) { } } + /** + * Collect email addresses from particitipants + * @NoAdminRequired + * @param Array $poll + * @return DataResponse + */ + + public function getParticipantsEmailAddresses($pollId) { + try { + return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK); + } catch (DoesNotExistException $e) { + return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); + } catch (NotAuthorizedException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } + } + } diff --git a/lib/Db/ShareMapper.php b/lib/Db/ShareMapper.php index 3a4408f369..87df1051a8 100644 --- a/lib/Db/ShareMapper.php +++ b/lib/Db/ShareMapper.php @@ -70,6 +70,28 @@ public function findByPoll($pollId) { return $this->findEntities($qb); } + /** + * @param int $pollId + * @param string $userId + * @throws \OCP\AppFramework\Db\DoesNotExistException if not found + * @return array + */ + + public function findByPollAndUser($pollId, $userId) { + $qb = $this->db->getQueryBuilder(); + + $qb->select('*') + ->from($this->getTableName()) + ->where( + $qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId, IQueryBuilder::PARAM_INT)) + ) + ->andWhere( + $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) + ); + + return $this->findEntity($qb); + } + /** * @param string $token * @throws \OCP\AppFramework\Db\DoesNotExistException if not found diff --git a/lib/Db/Vote.php b/lib/Db/Vote.php index 85b63c09c1..b304c149cd 100644 --- a/lib/Db/Vote.php +++ b/lib/Db/Vote.php @@ -71,7 +71,7 @@ public function jsonSerialize() { ]; } - private function getDisplayName() { + public function getDisplayName() { if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); } else { diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 54fe8a34f3..2456fb84f8 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -156,6 +156,32 @@ private function sendMail($emailTemplate, $toUserId = '', $toEmail = '', $toDisp } + + /** + * @param integer $pollId + * @param string $userId + * @return string + */ + public function resolveEmailAddress($pollId, $userId) { + $contactsManager = \OC::$server->getContactsManager(); + + if ($this->userManager->get($userId) instanceof IUser) { + return \OC::$server->getConfig()->getUserValue($userId, 'settings', 'email'); + } + + // if $userId is no site user, eval via shares + try { + $share = $this->shareMapper->findByPollAndUser($pollId, $userId); + if ($share->getUserEmail()) { + return $share->getUserEmail(); + } + } catch (\Exception $e) { + // catch silently + } + return $userId; + } + + /** * @param Share $share * @param String $defaultLang @@ -219,7 +245,7 @@ private function getRecipientsByShare($share, $defaultLang = 'en', $skipUser = n return; } - } elseif ($share->getType() === 'external' || $share->getType() === 'email') { + } elseif ($share->getType() === 'external') { $recipients[] = array( 'userId' => $share->getUserId(), 'eMailAddress' => $share->getUserEmail(), @@ -341,6 +367,7 @@ public function sendNotifications() { if ($this->userManager->get($subscription->getUserId()) instanceof IUser) { $lang = $this->config->getUserValue($subscription->getUserId(), 'core', 'lang'); } else { + $lang = $this->config->getUserValue($poll->getOwner(), 'core', 'lang'); continue; } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index e730b575d9..73b2044c2d 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -21,23 +21,26 @@ * */ - namespace OCA\Polls\Service; +namespace OCA\Polls\Service; - use Exception; - use OCP\AppFramework\Db\DoesNotExistException; - use OCA\Polls\Exceptions\EmptyTitleException; - use OCA\Polls\Exceptions\InvalidAccessException; - use OCA\Polls\Exceptions\InvalidShowResultsException; - use OCA\Polls\Exceptions\InvalidPollTypeException; - use OCA\Polls\Exceptions\NotAuthorizedException; +use Exception; +use OCP\AppFramework\Db\DoesNotExistException; +use OCA\Polls\Exceptions\EmptyTitleException; +use OCA\Polls\Exceptions\InvalidAccessException; +use OCA\Polls\Exceptions\InvalidShowResultsException; +use OCA\Polls\Exceptions\InvalidPollTypeException; +use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Db\PollMapper; - use OCA\Polls\Db\Poll; - use OCA\Polls\Service\LogService; - use OCA\Polls\Model\Acl; +use OCA\Polls\Db\PollMapper; +use OCA\Polls\Db\Poll; +use OCA\Polls\Db\VoteMapper; +use OCA\Polls\Db\Vote; +use OCA\Polls\Service\LogService; +use OCA\Polls\Service\MailService; +use OCA\Polls\Model\Acl; - class PollService { +class PollService { /** @var PollMapper */ private $pollMapper; @@ -45,9 +48,18 @@ class PollService { /** @var Poll */ private $poll; + /** @var VoteMapper */ + private $voteMapper; + + /** @var Vote */ + private $vote; + /** @var LogService */ private $logService; + /** @var MailService */ + private $mailService; + /** @var Acl */ private $acl; @@ -55,19 +67,28 @@ class PollService { * PollController constructor. * @param PollMapper $pollMapper * @param Poll $poll + * @param VoteMapper $voteMapper + * @param Vote $vote * @param LogService $logService + * @param MailService $mailService * @param Acl $acl */ public function __construct( PollMapper $pollMapper, Poll $poll, - LogService $logService, + VoteMapper $voteMapper, + Vote $vote, + LogService $logService, + MailService $mailService, Acl $acl ) { $this->pollMapper = $pollMapper; $this->poll = $poll; - $this->logService = $logService; + $this->voteMapper = $voteMapper; + $this->vote = $vote; + $this->logService = $logService; + $this->mailService = $mailService; $this->acl = $acl; } @@ -304,6 +325,27 @@ public function clone($pollId) { return $this->pollMapper->insert($this->poll); } + /** + * Collect email addresses from particitipants + * @NoAdminRequired + * @param Array $poll + * @return DataResponse + */ + + public function getParticipantsEmailAddresses($pollId) { + $this->poll = $this->pollMapper->find($pollId); + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + return []; + } + + $votes = $this->voteMapper->findParticipantsByPoll($pollId); + foreach ($votes as $vote) { + $list[] = $vote->getDisplayName() . ' <' . $this->mailService->resolveEmailAddress($pollId, $vote->getUserId()) . '>'; + } + return array_unique($list); + } + + /** * Get valid values for configuration options * @NoAdminRequired diff --git a/src/js/components/Base/ParticipantsList.vue b/src/js/components/Base/ParticipantsList.vue index 35f8f34256..e8542d17da 100644 --- a/src/js/components/Base/ParticipantsList.vue +++ b/src/js/components/Base/ParticipantsList.vue @@ -33,20 +33,51 @@ v-bind="participant" :hide-names="true" type="user" /> + + + {{ t('polls', 'Copy list of email addresses to clipboard') }} + +
  • diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index 07d6c38ced..8bbdb9479b 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -230,6 +230,17 @@ const actions = { }) }, + getParticipantsEmailAddresses(context, payload) { + const endPoint = 'apps/polls/polls/addresses' + return axios.get(generateUrl(endPoint.concat('/', payload.pollId))) + .then((response) => { + return response + }) + .catch((error) => { + console.error('Error retrieving email addresses', { error: error.response }, { payload: payload }) + }) + }, + } export default { namespaced, state, mutations, getters, actions, modules } From c145b5e4beb4f7ff34e5ebe230b8683ba19d6ca5 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 1 Aug 2020 11:01:34 +0200 Subject: [PATCH 024/117] implement sending to a share's mail address --- lib/Service/MailService.php | 38 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 2456fb84f8..543bafa00f 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -122,28 +122,28 @@ public function __construct( /** * sendMail - Send eMail and evaluate recipient's mail address - * and displayname if $toUserId is a site user + * and displayname if $userId is a site user * @param IEmailTemplate $emailTemplate - * @param String $toUserId - * @param String $toEmail - * @param String $toDisplayName + * @param String $userId + * @param String $emailAddress, ignored, when $userId is set + * @param String $displayName, ignored, when $userId is set * @return String */ - private function sendMail($emailTemplate, $toUserId = '', $toEmail = '', $toDisplayName = '') { + private function sendMail($emailTemplate, $userId = '', $emailAddress = '', $displayName = '') { - if ($this->userManager->get($toUserId) instanceof IUser && !$toEmail) { - $toEmail = \OC::$server->getConfig()->getUserValue($toUserId, 'settings', 'email'); - $toDisplayName = $this->userManager->get($toUserId)->getDisplayName(); + if ($this->userManager->get($userId) instanceof IUser) { + $emailAddress = \OC::$server->getConfig()->getUserValue($userId, 'settings', 'email'); + $displayName = $this->userManager->get($userId)->getDisplayName(); } - if (!$toEmail || !filter_var($toEmail, FILTER_VALIDATE_EMAIL)) { - throw new Exception('Invalid email address (' . $toEmail . ')'); + if (!$emailAddress || !filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { + throw new Exception('Invalid email address (' . $emailAddress . ')'); } try { $message = $this->mailer->createMessage(); - $message->setTo([$toEmail => $toDisplayName]); + $message->setTo([$emailAddress => $displayName]); $message->useTemplate($emailTemplate); $this->mailer->send($message); @@ -363,15 +363,23 @@ public function sendNotifications() { $log = $this->logMapper->findUnprocessed(); foreach ($subscriptions as $subscription) { + $poll = $this->pollMapper->find($subscription->getPollId()); + $emailAddress = ''; + $displayName = ''; if ($this->userManager->get($subscription->getUserId()) instanceof IUser) { $lang = $this->config->getUserValue($subscription->getUserId(), 'core', 'lang'); } else { - $lang = $this->config->getUserValue($poll->getOwner(), 'core', 'lang'); - continue; + try { + $emailAddress = $this->shareMapper->findByPollAndUser($subscription->getPollId(), $subscription->getUserId())->getUserEmail(); + $displayName = $subscription->getUserId(); + $lang = $this->config->getUserValue($poll->getOwner(), 'core', 'lang'); + } catch (\Exception $e) { + continue; + } + } - $poll = $this->pollMapper->find($subscription->getPollId()); $trans = $this->transFactory->get('polls', $lang); $url = $this->urlGenerator->getAbsoluteURL( @@ -468,7 +476,7 @@ public function sendNotifications() { $emailTemplate->addFooter($trans->t('This email is sent to you, because you subscribed to notifications of this poll. To opt out, visit the poll and remove your subscription.')); try { - $this->sendMail($emailTemplate, $subscription->getUserId()); + $this->sendMail($emailTemplate, $subscription->getUserId(), $emailAddress, $displayName); } catch (Exception $e) { \OC::$server->getLogger()->alert('Error sending Mail to ' . $subscription->getUserId()); } From d93709f55bd173a9a3919863da922cf5996bfbd8 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 1 Aug 2020 20:05:18 +0200 Subject: [PATCH 025/117] mobile view indicate votes via bar --- src/js/components/Base/Counter.vue | 57 +++++++++++++++---- .../VoteTable/VoteTableHeaderItem.vue | 9 ++- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/js/components/Base/Counter.vue b/src/js/components/Base/Counter.vue index e263bb162b..6dbf1c1e27 100644 --- a/src/js/components/Base/Counter.vue +++ b/src/js/components/Base/Counter.vue @@ -22,7 +22,7 @@ @@ -60,9 +74,9 @@ export default { type: Object, default: undefined, }, - bubbleStyle: { - type: Boolean, - default: false, + counterStyle: { + type: String, + default: 'iconStyle', }, showMaybe: { type: Boolean, @@ -73,11 +87,6 @@ export default { default: false, }, }, - computed: { - iconStyle() { - return !this.bubbleStyle - }, - }, } @@ -135,9 +144,35 @@ export default { } .no { - // background-color: var(--color-polls-foreground-no); background-color: transparent; } +} + +.counter--bar { + display: flex; + width: 100%; + flex: 1; + height: 4px; + + > * { + text-align: center; + } + + .yes { + background-color: var(--color-polls-foreground-yes); + order: 1; + } + + .maybe { + background-color: var(--color-polls-foreground-maybe); + order: 2; + } + + .no { + background-color: transparent; + order: 3; + } + } diff --git a/src/js/components/VoteTable/VoteTableHeaderItem.vue b/src/js/components/VoteTable/VoteTableHeaderItem.vue index 0b94294336..a84add374b 100644 --- a/src/js/components/VoteTable/VoteTableHeaderItem.vue +++ b/src/js/components/VoteTable/VoteTableHeaderItem.vue @@ -27,7 +27,7 @@ @@ -104,10 +104,15 @@ export default { } .mobile { + .vote-table-header-item { + flex-direction: column; + &.confirmed { + flex-direction: row; + } + } .counter { flex: 1; order: 2; - width: 130px; } .confirmation { From 417d6286d593cb1b31d9523701e6298695ed3c89 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 1 Aug 2020 20:07:44 +0200 Subject: [PATCH 026/117] fix sidebar --- src/js/App.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/js/App.vue b/src/js/App.vue index 6ce6cc6eb9..ec94d14a29 100644 --- a/src/js/App.vue +++ b/src/js/App.vue @@ -279,6 +279,7 @@ input { display: flex; flex-direction: column; padding: 0 8px; + min-width: 320px; } [class*='area__'] { @@ -286,6 +287,7 @@ input { background-color: var(--color-main-background); border-radius: var(--border-radius); margin: 12px 0; + min-width: 320px; } From db579c72b6315944e6e6b2170acc17f973f8e7f8 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sun, 2 Aug 2020 10:24:14 +0200 Subject: [PATCH 027/117] set email address in external share --- lib/Controller/ShareController.php | 23 +++++++++++++++++ lib/Exceptions/InvalidShareType.php | 40 +++++++++++++++++++++++++++++ lib/Service/ShareService.php | 23 +++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 lib/Exceptions/InvalidShareType.php diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index 4810ed23a8..9cd5f55456 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -27,6 +27,7 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\InvalidUsername; +use OCA\Polls\Exceptions\InvalidShareType; use OCP\IRequest; @@ -83,6 +84,28 @@ public function add($pollId, $type, $userId = '', $userEmail = '') { } } + /** + * Add share + * @NoAdminRequired + * @param int $pollId + * @param int $pollId + * @param string $type + * @param string $userId + * @param string $userEmail + * @return DataResponse + */ + public function setEmailAddress($token, $userEmail) { + try { + return new DataResponse(['share' => $this->shareService->setEmailAddress($token, $userEmail)], Http::STATUS_OK); + } catch (NotAuthorizedException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (InvalidShareType $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (\Exception $e) { + return new DataResponse($e, Http::STATUS_CONFLICT); + } + } + /** * Create a personal share from a public share * or update an email share with the username diff --git a/lib/Exceptions/InvalidShareType.php b/lib/Exceptions/InvalidShareType.php new file mode 100644 index 0000000000..056c4c9b57 --- /dev/null +++ b/lib/Exceptions/InvalidShareType.php @@ -0,0 +1,40 @@ + + * + * @author René Gieling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Polls\Exceptions; + +use OCP\AppFramework\Http; + +class InvalidShareType extends \Exception { + /** + * InvalidShareType Constructor + * @param string $e exception message + */ + public function __construct($e = 'Invalid share type') { + parent::__construct($e); + } + public function getStatus() { + return Http::STATUS_CONFLICT; + } + +} diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 1bd9bcb8ac..aaddefb8ce 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -26,6 +26,7 @@ use Exception; use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\InvalidUsername; +use OCA\Polls\Exceptions\InvalidShareType; use OCP\Security\ISecureRandom; @@ -131,6 +132,28 @@ public function add($pollId, $type, $userId, $userEmail = '') { return $this->shareMapper->insert($this->share); } + /** + * Set emailAddress to personal share + * or update an email share with the username + * @NoAdminRequired + * @param string $token + * @param string $emailAddress + * @return Share + * @throws NotAuthorizedException + */ + public function setEmailAddress($token, $emailAddress) { + + $this->share = $this->shareMapper->findByToken($token); + if ($this->share->getType() === 'external') { + // TODO: Simple validate email address + $this->share->setUserEmail($emailAddress); + // TODO: Send confirmation + return $this->shareMapper->update($this->share); + } else { + throw new InvalidShareType('Email address can only be set in external shares.'); + } + } + /** * Create a personal share from a public share * or update an email share with the username From 8880f12f89b089f569e43e664dacc4755585da71 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 5 Aug 2020 07:49:12 +0200 Subject: [PATCH 028/117] hack for hyphenating options in text polls --- src/js/components/VoteTable/VoteTable.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/components/VoteTable/VoteTable.vue b/src/js/components/VoteTable/VoteTable.vue index f606397693..9f85a58854 100644 --- a/src/js/components/VoteTable/VoteTable.vue +++ b/src/js/components/VoteTable/VoteTable.vue @@ -380,10 +380,13 @@ export default { hyphens: auto; text-align: center; align-items: center; + // hack for the hyphens, because hyphenating works different + // in different browsers and with different languages. + min-width: 160px; } } - // some littlehacks + // some little hacks .user-item { max-width: 280px; } From dad6b97a38348f620d20e5d20108a628269645ee Mon Sep 17 00:00:00 2001 From: dartcafe Date: Fri, 7 Aug 2020 22:47:10 +0200 Subject: [PATCH 029/117] public subscription for shares with mail address --- appinfo/routes.php | 3 +- lib/Controller/PollController.php | 18 ++- lib/Controller/SubscriptionController.php | 10 +- lib/Model/Acl.php | 110 +++++++----------- lib/Service/CommentService.php | 6 +- lib/Service/OptionService.php | 19 +-- lib/Service/PollService.php | 36 ++---- lib/Service/ShareService.php | 12 +- lib/Service/SubscriptionService.php | 34 +++--- lib/Service/VoteService.php | 6 +- .../components/Subscription/Subscription.vue | 6 +- .../components/VoteTable/VoteHeaderPublic.vue | 37 +++++- src/js/store/modules/subscription.js | 17 ++- src/js/views/Vote.vue | 7 +- 14 files changed, 162 insertions(+), 159 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index a2b38130fe..a2ba77ad7a 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -60,7 +60,8 @@ ['name' => 'share#delete', 'url' => '/share/delete/{token}', 'verb' => 'DELETE'], ['name' => 'share#sendInvitation', 'url' => '/share/send/{token}', 'verb' => 'POST'], - ['name' => 'subscription#get', 'url' => '/subscription/{pollId}', 'verb' => 'GET'], + ['name' => 'subscription#get', 'url' => '/subscription/{pollId}', 'verb' => 'GET', 'postfix' => 'auth'], + ['name' => 'subscription#get', 'url' => '/subscription/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], ['name' => 'subscription#set', 'url' => '/subscription', 'verb' => 'POST'], ['name' => 'comment#add', 'url' => '/comment', 'verb' => 'POST'], diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 04445482fa..a564fe4017 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -121,14 +121,10 @@ public function list() { * @return DataResponse */ public function get($pollId, $token) { + try { - if ($token) { - $poll = $this->pollService->getByToken($token); - $acl = $this->acl->setToken($token); - } else { - $poll = $this->pollService->get($pollId); - $acl = $this->acl->setPollId($pollId); - } + $acl = $this->acl->set($pollId, $token); + $poll = $this->pollService->get($pollId, $token); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND); @@ -137,25 +133,25 @@ public function get($pollId, $token) { } try { - $comments = $this->commentService->list($poll->getId(), $token); + $comments = $this->commentService->list($pollId, $token); } catch (Exception $e) { $comments = []; } try { - $options = $this->optionService->list($poll->getId(), $token); + $options = $this->optionService->list($pollId, $token); } catch (Exception $e) { $options = []; } try { - $votes = $this->voteService->list($poll->getId(), $token); + $votes = $this->voteService->list($pollId, $token); } catch (Exception $e) { $votes = []; } try { - $shares = $this->shareService->list($poll->getId()); + $shares = $this->shareService->list($pollId, $token); } catch (Exception $e) { $shares = []; } diff --git a/lib/Controller/SubscriptionController.php b/lib/Controller/SubscriptionController.php index f2517237be..ea1e9e49ad 100644 --- a/lib/Controller/SubscriptionController.php +++ b/lib/Controller/SubscriptionController.php @@ -57,15 +57,16 @@ public function __construct( /** * Get subscription status + * @PublicPage * @NoAdminRequired * @param int $pollId * @return DataResponse * @throws DoesNotExistException * @throws NotAuthorizedException */ - public function get($pollId) { + public function get($pollId, $token) { try { - return new DataResponse($this->subscriptionService->get($pollId), Http::STATUS_OK); + return new DataResponse($this->subscriptionService->get($pollId, $token), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } catch (DoesNotExistException $e) { @@ -75,15 +76,16 @@ public function get($pollId) { /** * Switch subscription status + * @PublicPage * @NoAdminRequired * @param int $pollId * @param int $subscribed * @return DataResponse * @throws NotAuthorizedException */ - public function set($pollId, $subscribed) { + public function set($pollId, $token, $subscribed) { try { - return new DataResponse($this->subscriptionService->set($pollId, $subscribed), Http::STATUS_OK); + return new DataResponse($this->subscriptionService->set($pollId, $token, $subscribed), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php index 1076000831..ee7b627be9 100644 --- a/lib/Model/Acl.php +++ b/lib/Model/Acl.php @@ -27,6 +27,7 @@ use JsonSerializable; use Exception; use OCP\AppFramework\Db\DoesNotExistException; +use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IUserManager; use OCP\IGroupManager; @@ -104,6 +105,44 @@ public function __construct( $this->poll = $poll; } + /** + * @NoAdminRequired + * @return bool + */ + public function set($pollId = 0, $token = ''): Acl { + + if ($token) { + \OC::$server->getLogger()->debug('Share token: ' . $token); + + $this->token = $token; + $this->pollId = 0; + $this->userId = null; + $share = $this->shareMapper->findByToken($token); + + if (\OC::$server->getUserSession()->isLoggedIn()) { + if ($share->getType() !== 'group' && $share->getType() !== 'public') { + throw new NotAuthorizedException; + } + + $this->userId = \OC::$server->getUserSession()->getUser()->getUID(); + } else { + if ($share->getType() === 'group' || $share->getType() === 'user') { + throw new NotAuthorizedException; + } + + $this->userId = $share->getUserId(); + } + + $this->pollId = $share->getPollId(); + } elseif ($pollId) { + $this->user = \OC::$server->getUserSession()->getUser()->getUID(); + $this->pollId = $pollId; + } + + $this->poll = $this->pollMapper->find($this->pollId); + + return $this; + } /** * @NoAdminRequired @@ -133,31 +172,6 @@ public function getIsExternalUser() { return !($this->userManager->get($this->userId) instanceof IUser); } - - /** - * @NoAdminRequired - * @return bool - */ - public function setPollIdOrToken($pollId = 0, $token = '') { - - if ($token) { - $this->setToken($token); - } elseif ($pollId) { - $this->setPollId($pollId); - } - - return $this; - } - - /** - * @NoAdminRequired - * @return string - */ - public function setUserId($userId): Acl { - $this->userId = $userId; - return $this; - } - /** * @NoAdminRequired * @return string @@ -174,18 +188,6 @@ public function getPollId(): int { return $this->pollId; } - /** - * @NoAdminRequired - * @return int - */ - public function setPollId(int $pollId): Acl { - $this->pollId = $pollId; - $this->poll = $this->pollMapper->find($this->pollId); - $this->shares = $this->shareMapper->findByPoll($this->pollId); - - return $this; - } - /** * @NoAdminRequired * @return bool @@ -346,40 +348,6 @@ public function getToken(): string { return $this->token; } - /** - * @NoAdminRequired - * @return string - */ - public function setToken(string $token): Acl { - \OC::$server->getLogger()->debug('Share PollId: ' . $token); - try { - - $this->token = $token; - $share = $this->shareMapper->findByToken($token); - $this->setPollId($share->getPollId()); - \OC::$server->getLogger()->debug('Share PollId: ' . $share->getPollId()); - - if (($share->getType() === 'group' || $share->getType() === 'user') && !\OC::$server->getUserSession()->isLoggedIn()) { - // User must be logged in for shareType user and group - $this->setPollId(0); - $this->setUserId(null); - $this->token = ''; - } else if (($share->getType() === 'group' || $share->getType() === 'public') && \OC::$server->getUserSession()->isLoggedIn()) { - // Use user name of authorized user shareType public and group if user is logged in - $this->setUserId($this->userId); - } else { - $this->setUserId($share->getUserId()); - } - - - } catch (DoesNotExistException $e) { - $this->setPollId(0); - $this->setUserId(null); - $this->token = ''; - } - return $this; - } - /** * @return array */ diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index 6c5f89b6a4..cdb2616a18 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -78,7 +78,7 @@ public function __construct( */ public function list($pollId = 0, $token = '') { - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + if (!$this->acl->set($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } @@ -101,7 +101,7 @@ public function list($pollId = 0, $token = '') { */ public function add($pollId = 0, $message, $token = '') { - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowComment()) { + if (!$this->acl->set($pollId, $token)->getAllowComment()) { throw new NotAuthorizedException; } @@ -136,7 +136,7 @@ public function add($pollId = 0, $message, $token = '') { public function delete($commentId, $token = '') { $this->comment = $this->commentMapper->find($commentId); - if ($this->acl->setPollIdOrToken($this->comment->getPollId(), $token)->getUserId() !== $this->acl->getUserId()) { + if ($this->acl->set($this->comment->getPollId(), $token)->getUserId() !== $this->acl->getUserId()) { throw new NotAuthorizedException; } diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 3cabc5ae86..c598073e2f 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -90,13 +90,14 @@ public function __construct( * @throws NotAuthorizedException */ public function list($pollId = 0, $token = '') { + $acl = $this->acl->set($pollId, $token); - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + if (!$acl->getAllowView()) { throw new NotAuthorizedException; } try { - return $this->optionMapper->findByPoll($pollId); + return $this->optionMapper->findByPoll($acl->getPollId()); } catch (DoesNotExistException $e) { return []; } @@ -115,7 +116,7 @@ public function list($pollId = 0, $token = '') { public function add($pollId, $timestamp = 0, $pollOptionText = '') { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -141,7 +142,7 @@ public function update($optionId, $timestamp = 0, $pollOptionText = '', $order = $this->option = $this->optionMapper->find($optionId); $this->poll = $this->pollMapper->find($this->option->getPollId()); - if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -160,7 +161,7 @@ public function update($optionId, $timestamp = 0, $pollOptionText = '', $order = public function delete($optionId) { $this->option = $this->optionMapper->find($optionId); - if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -179,7 +180,7 @@ public function delete($optionId) { public function confirm($optionId) { $this->option = $this->optionMapper->find($optionId); - if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -202,7 +203,7 @@ public function confirm($optionId) { */ public function clone($fromPollId, $toPollId) { - if (!$this->acl->setPollId($fromPollId)->getAllowView()) { + if (!$this->acl->set($fromPollId)->getAllowView()) { throw new NotAuthorizedException; } @@ -232,7 +233,7 @@ public function reorder($pollId, $options) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -267,7 +268,7 @@ public function setOrder($optionId, $newOrder) { $pollId = $this->option->getPollId(); $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 73b2044c2d..b9fdbdef95 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -111,7 +111,7 @@ public function list() { // TODO: Not the elegant way. Improvement neccessary foreach ($polls as $poll) { $combinedPoll = (object) array_merge( - (array) json_decode(json_encode($poll)), (array) json_decode(json_encode($this->acl->setPollId($poll->getId())))); + (array) json_decode(json_encode($poll)), (array) json_decode(json_encode($this->acl->set($poll->getId())))); if ($combinedPoll->allowView) { $pollList[] = $combinedPoll; } @@ -127,30 +127,14 @@ public function list() { * @return Poll * @throws NotAuthorizedException */ - public function get($pollId) { + public function get($pollId, $token) { + $acl = $this->acl->set($pollId, $token); - if (!$this->acl->setPollId($pollId)->getAllowView()) { + if (!$acl->getAllowView()) { throw new NotAuthorizedException; } - return $this->pollMapper->find($pollId); - - } - - /** - * get poll configuration by token - * @NoAdminRequired - * @param int $pollId - * @return Poll - * @throws NotAuthorizedException - */ - public function getByToken($token) { - - if (!$this->acl->setToken($token)->getAllowView()) { - throw new NotAuthorizedException; - } - - return $this->pollMapper->find($this->acl->getPollId()); + return $this->pollMapper->find($acl->getPollId()); } @@ -219,7 +203,7 @@ public function update($pollId, $poll) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($this->poll->getId())->getAllowEdit()) { + if (!$this->acl->set($this->poll->getId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -255,7 +239,7 @@ public function update($pollId, $poll) { public function delete($pollId) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -282,7 +266,7 @@ public function delete($pollId) { public function deletePermanently($pollId) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit() || !$this->poll->getDeleted()) { + if (!$this->acl->set($pollId)->getAllowEdit() || !$this->poll->getDeleted()) { throw new NotAuthorizedException; } @@ -299,7 +283,7 @@ public function deletePermanently($pollId) { public function clone($pollId) { $origin = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($origin->getId())->getAllowView()) { + if (!$this->acl->set($origin->getId())->getAllowView()) { throw new NotAuthorizedException; } @@ -334,7 +318,7 @@ public function clone($pollId) { public function getParticipantsEmailAddresses($pollId) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { return []; } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index aaddefb8ce..70881cf92a 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -82,8 +82,12 @@ public function __construct( * @return array array of Share * @throws NotAuthorizedException */ - public function list($pollId) { - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + public function list($pollId, $token) { + if ($token) { + return array($this->get($token)); + } + + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -112,7 +116,7 @@ public function get($token) { */ public function add($pollId, $type, $userId, $userEmail = '') { - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -213,7 +217,7 @@ public function personal($token, $userName) { public function delete($token) { $this->share = $this->shareMapper->findByToken($token); - if (!$this->acl->setPollId($this->share->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->share->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php index 0f7d82a771..8678817e0f 100644 --- a/lib/Service/SubscriptionService.php +++ b/lib/Service/SubscriptionService.php @@ -59,16 +59,16 @@ public function __construct( * @param int $pollId * @return array */ - public function get($pollId) { - if (!$this->acl->setPollId($pollId)->getAllowView()) { + public function get($pollId, $token) { + if (!$this->acl->set($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } try { - return $this->subscriptionMapper->findByUserAndPoll($pollId, $this->acl->getUserId()); + return $this->subscriptionMapper->findByUserAndPoll($this->acl->getPollId(), $this->acl->getUserId()); } catch (MultipleObjectsReturnedException $e) { // subscription should be unique. If duplicates are found resubscribe // duplicates are removed in $this->set() - return $this->set($pollId, true); + return $this->set($pollId, $token, true); } } @@ -76,51 +76,55 @@ public function get($pollId) { /** * @NoAdminRequired * @param int $pollId + * @param string $token + * @param bool $subscribed * @return array */ - public function set($pollId, $subscribed) { - if (!$this->acl->setPollId($pollId)->getAllowView()) { + public function set($pollId, $token, $subscribed) { + if (!$this->acl->set($pollId, $token)->getAllowView()) { + \OC::$server->getLogger()->alert('Share token: ' . $token); + \OC::$server->getLogger()->alert('Share PollId: ' . $pollId); throw new NotAuthorizedException; } try { - $subscription = $this->subscriptionMapper->findByUserAndPoll($pollId, $this->acl->getUserId()); + $subscription = $this->subscriptionMapper->findByUserAndPoll($this->acl->getPollId(), $this->acl->getUserId()); if (!$subscribed) { $this->subscriptionMapper->delete($subscription); - return ['status' => 'Unsubscribed from poll ' . $pollId]; + return ['status' => 'Unsubscribed from poll ' . $this->acl->getPollId()]; } else { // subscription already exists, just return the existing subscription - return ['status' => 'Subscribed to poll ' . $pollId]; + return ['status' => 'Subscribed to poll ' . $this->acl->getPollId()]; } } catch (DoesNotExistException $e) { if ($subscribed) { $subscription = new Subscription(); - $subscription->setPollId($pollId); + $subscription->setPollId($this->acl->getPollId()); $subscription->setUserId($this->acl->getUserId()); $this->subscriptionMapper->insert($subscription); - return ['status' => 'Subscribed to poll ' . $pollId]; + return ['status' => 'Subscribed to poll ' . $this->acl->getPollId()]; } else { // subscription is not found, just approve the unsubscription - return ['status' => 'Unsubscribed from poll ' . $pollId]; + return ['status' => 'Unsubscribed from poll ' . $this->acl->getPollId()]; } } catch (MultipleObjectsReturnedException $e) { // Duplicates should not exist but if found, fix it // unsubscribe from all and resubscribe, if requested \OC::$server->getLogger()->debug('Multiple subscription (dulpicates) found'); - $this->subscriptionMapper->unsubscribe($pollId, $this->acl->getUserId()); + $this->subscriptionMapper->unsubscribe($this->acl->getPollId(), $this->acl->getUserId()); \OC::$server->getLogger()->debug('Unsubscribed all for user ' . $this->acl->getUserId() . 'in poll' . $pollId); if ($subscribed) { $subscription = new Subscription(); - $subscription->setPollId($pollId); + $subscription->setPollId($this->acl->getPollId()); $subscription->setUserId($this->acl->getUserId()); $this->subscriptionMapper->insert($subscription); \OC::$server->getLogger()->debug('Added new subscription'); return $subscription; } else { - return ['status' => 'Unsubscribed from poll ' . $pollId]; + return ['status' => 'Unsubscribed from poll ' . $this->acl->getPollId()]; } } diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 32076289b9..cbedb1ade1 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -88,7 +88,7 @@ public function __construct( * @throws NotAuthorizedException */ public function list($pollId = 0, $token = '') { - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + if (!$this->acl->set($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } @@ -115,7 +115,7 @@ public function set($optionId, $setTo, $token = '') { $option = $this->optionMapper->find($optionId); - if (!$this->acl->setPollIdOrToken($option->getPollId(), $token)->getAllowVote()) { + if (!$this->acl->set($option->getPollId(), $token)->getAllowVote()) { throw new NotAuthorizedException; } @@ -156,7 +156,7 @@ public function set($optionId, $setTo, $token = '') { */ public function delete($pollId, $userId) { - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } diff --git a/src/js/components/Subscription/Subscription.vue b/src/js/components/Subscription/Subscription.vue index b961a96471..78d4a55213 100644 --- a/src/js/components/Subscription/Subscription.vue +++ b/src/js/components/Subscription/Subscription.vue @@ -45,19 +45,19 @@ export default { }, set(value) { this.$store.commit('setSubscription', value) - this.$store.dispatch('writeSubscriptionPromise', { pollId: this.poll.id }) + this.$store.dispatch('writeSubscriptionPromise') }, }, }, watch: { $route() { - this.$store.dispatch('getSubscription', { pollId: this.$route.params.id }) + this.$store.dispatch('getSubscription', { pollId: this.$route.params.id, token: this.$route.params.token }) }, }, created() { - this.$store.dispatch('getSubscription', { pollId: this.$route.params.id }) + this.$store.dispatch('getSubscription', { pollId: this.$route.params.id, token: this.$route.params.token }) }, } diff --git a/src/js/components/VoteTable/VoteHeaderPublic.vue b/src/js/components/VoteTable/VoteHeaderPublic.vue index e60fc480d1..052a73399e 100644 --- a/src/js/components/VoteTable/VoteHeaderPublic.vue +++ b/src/js/components/VoteTable/VoteHeaderPublic.vue @@ -23,8 +23,22 @@ @@ -37,6 +38,7 @@ export default { ...mapState({ subscription: state => state.subscription, poll: state => state.poll, + share: state => state.poll.share, }), subscribe: { diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index 8bbdb9479b..3a8b0f31d6 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -28,6 +28,7 @@ import acl from './subModules/acl.js' import comments from './subModules/comments.js' import options from './subModules/options.js' import shares from './subModules/shares.js' +import share from './subModules/share.js' import votes from './subModules/votes.js' const defaultPoll = () => { @@ -58,7 +59,9 @@ const modules = { options: options, shares: shares, votes: votes, + share: share, } + const mutations = { set(state, payload) { Object.assign(state, payload.poll) @@ -148,6 +151,7 @@ const actions = { context.commit('comments/reset') context.commit('options/reset') context.commit('shares/reset') + context.commit('share/reset') context.commit('votes/reset') return } @@ -158,13 +162,12 @@ const actions = { context.commit('comments/set', response.data) context.commit('options/set', response.data) context.commit('shares/set', response.data) + context.commit('share/set', response.data) context.commit('votes/set', response.data) return response - }, (error) => { - if (error.response.status !== '404' && error.response.status !== '401') { - console.debug('Error loading poll', { error: error.response }, { payload: payload }) - return error.response - } + }) + .catch((error) => { + console.debug('Error loading poll', { error: error.response }, { payload: payload }) throw error }) }, diff --git a/src/js/store/modules/subModules/share.js b/src/js/store/modules/subModules/share.js new file mode 100644 index 0000000000..1e92b655dd --- /dev/null +++ b/src/js/store/modules/subModules/share.js @@ -0,0 +1,84 @@ +/* + * @copyright Copyright (c) 2019 Rene Gieling + * + * @author Rene Gieling + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import axios from '@nextcloud/axios' +import { generateUrl } from '@nextcloud/router' + +const defaultShares = () => { + return { + displayName: '', + externalUser: false, + id: null, + invitationSent: 0, + pollId: null, + token: '', + type: '', + userEmail: '', + userId: '', + } +} + +const state = defaultShares() + +const namespaced = true + +const mutations = { + set(state, payload) { + Object.assign(state, payload.share) + }, + + reset(state) { + Object.assign(state, defaultShares()) + }, + +} + +const actions = { + get(context, payload) { + const endPoint = 'apps/polls/share' + return axios.get(generateUrl(endPoint.concat('/', payload.token))) + .then((response) => { + context.commit('set', { share: response.data.share }) + return response.data + }) + .catch((error) => { + console.error('Error retrieving share', { error: error.response }, { payload: payload }) + throw error + }) + }, + + sendInvitation(context, payload) { + const endPoint = 'apps/polls/share/send' + return axios.post(generateUrl(endPoint.concat('/', context.state.token))) + .then((response) => { + context.commit('set', { share: response.data.share }) + return response + }) + .catch((error) => { + console.error('Error sending invitation', { error: error.response }, { payload: payload }) + throw error + }) + }, +} + +export default { namespaced, state, mutations, actions } diff --git a/src/js/store/modules/subModules/shares.js b/src/js/store/modules/subModules/shares.js index d3f5b5c737..c684e29762 100644 --- a/src/js/store/modules/subModules/shares.js +++ b/src/js/store/modules/subModules/shares.js @@ -64,7 +64,7 @@ const getters = { invitation: state => { const invitationTypes = ['user', 'group', 'email', 'external', 'contact'] return state.list.filter(share => { - return invitationTypes.includes(share.type) + return invitationTypes.includes(share.type) && share.invitationSent }) }, @@ -105,7 +105,7 @@ const actions = { addPersonal(context, payload) { const endPoint = 'apps/polls/share/personal' - return axios.post(generateUrl(endPoint), { token: payload.token, userName: payload.userName }) + return axios.post(generateUrl(endPoint), { token: payload.token, userName: payload.userName, emailAddress: payload.emailAddress }) .then((response) => { return { token: response.data.token } }) diff --git a/src/js/views/Vote.vue b/src/js/views/Vote.vue index 585f817626..0f110a42e1 100644 --- a/src/js/views/Vote.vue +++ b/src/js/views/Vote.vue @@ -62,8 +62,8 @@ -
    - +
    +
    @@ -80,10 +80,14 @@
    + +
    + +
    @@ -92,11 +96,13 @@ import { Actions, ActionButton, AppContent } from '@nextcloud/vue' import Subscription from '../components/Subscription/Subscription' import Badge from '../components/Base/Badge' import ParticipantsList from '../components/Base/ParticipantsList' +import PersonalLink from '../components/Base/PersonalLink' import PollInformation from '../components/Base/PollInformation' import LoadingOverlay from '../components/Base/LoadingOverlay' -import VoteHeaderPublic from '../components/VoteTable/VoteHeaderPublic' +import PublicRegisterModal from '../components/Base/PublicRegisterModal' import VoteTable from '../components/VoteTable/VoteTable' import { mapState, mapGetters } from 'vuex' +import { getCurrentUser } from '@nextcloud/auth' import { emit } from '@nextcloud/event-bus' import moment from '@nextcloud/moment' @@ -107,11 +113,12 @@ export default { ActionButton, AppContent, Badge, - Subscription, + LoadingOverlay, ParticipantsList, + PersonalLink, PollInformation, - LoadingOverlay, - VoteHeaderPublic, + PublicRegisterModal, + Subscription, VoteTable, }, @@ -130,6 +137,7 @@ export default { poll: state => state.poll, acl: state => state.poll.acl, options: state => state.poll.options.list, + share: state => state.poll.share, }), ...mapGetters({ @@ -181,8 +189,19 @@ export default { }, created() { - this.loadPoll() - emit('toggle-sidebar', { open: (window.innerWidth > 920) }) + if (getCurrentUser() && this.$route.params.token) { + // reroute to the internal vote page, if the user is logged in + this.$store.dispatch('poll/shares/get', { token: this.$route.params.token }) + .then((response) => { + this.$router.replace({ name: 'vote', params: { id: response.share.pollId } }) + }) + .catch(() => { + this.$router.replace({ name: 'notfound' }) + }) + } else { + this.loadPoll() + emit('toggle-sidebar', { open: (window.innerWidth > 920) }) + } }, beforeDestroy() { @@ -210,8 +229,7 @@ export default { this.isLoading = false window.document.title = this.windowTitle }) - .catch((error) => { - console.error(error) + .catch(() => { this.isLoading = false this.$router.replace({ name: 'notfound' }) }) From ab6c0fe12c00a569bbb4252c76cb37a924ef9100 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 12 Aug 2020 21:48:54 +0200 Subject: [PATCH 031/117] added sharing to contact groups --- appinfo/routes.php | 1 + lib/Controller/OptionController.php | 16 - lib/Controller/ShareController.php | 30 +- lib/Controller/SystemController.php | 300 +++---------- lib/Exceptions/TooShortException.php | 40 ++ lib/Exceptions/UsernameInvalidException.php | 40 ++ lib/Service/MailService.php | 4 +- lib/Service/OptionService.php | 2 +- lib/Service/ShareService.php | 9 +- lib/Service/SystemService.php | 414 ++++++++++++++++++ src/js/components/Base/UserItem.vue | 4 + src/js/components/SideBar/SideBarTabShare.vue | 18 + src/js/store/modules/subModules/shares.js | 24 +- src/js/views/Vote.vue | 13 +- 14 files changed, 644 insertions(+), 271 deletions(-) create mode 100644 lib/Exceptions/TooShortException.php create mode 100644 lib/Exceptions/UsernameInvalidException.php create mode 100644 lib/Service/SystemService.php diff --git a/appinfo/routes.php b/appinfo/routes.php index b4a23685e1..1a3ff5c3f4 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -60,6 +60,7 @@ ['name' => 'share#personal', 'url' => '/share/personal', 'verb' => 'POST'], ['name' => 'share#delete', 'url' => '/share/delete/{token}', 'verb' => 'DELETE'], ['name' => 'share#sendInvitation', 'url' => '/share/send/{token}', 'verb' => 'POST'], + ['name' => 'share#resolveContactGroup', 'url' => '/share/resolveContactGroup/{token}', 'verb' => 'POST'], ['name' => 'subscription#get', 'url' => '/subscription/{pollId}', 'verb' => 'GET', 'postfix' => 'auth'], ['name' => 'subscription#get', 'url' => '/subscription/s/{token}', 'verb' => 'GET', 'postfix' => 'public'], diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php index 9fc748896a..3b1e7f1ead 100644 --- a/lib/Controller/OptionController.php +++ b/lib/Controller/OptionController.php @@ -63,22 +63,6 @@ public function list($pollId) { return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK); } - // - // /** - // * Get all options specified by token - // * Read all options of a poll based on a share token and return list as array - // * @NoAdminRequired - // * @PublicPage - // * @param string $token - // * @return DataResponse - // */ - // public function listByToken($token) { - // return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK); - // } - - - - /** * Add a new option * @NoAdminRequired diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index 0c50b4c7ee..9c56621486 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -37,6 +37,7 @@ use OCA\Polls\Service\ShareService; use OCA\Polls\Service\MailService; +use OCA\Polls\Service\SystemService; class ShareController extends Controller { @@ -46,22 +47,28 @@ class ShareController extends Controller { /** @var MailService */ private $mailService; + /** @var SystemService */ + private $systemService; + /** * ShareController constructor. * @param string $appName * @param IRequest $request * @param MailService $mailService * @param ShareService $shareService + * @param SystemService $systemService */ public function __construct( string $appName, IRequest $request, MailService $mailService, - ShareService $shareService + ShareService $shareService, + SystemService $systemService ) { parent::__construct($appName, $request); $this->shareService = $shareService; $this->mailService = $mailService; + $this->systemService = $systemService; } /** @@ -182,4 +189,25 @@ public function sendInvitation($token) { return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } } + + /** + * resolve Contact groupe to individual shares + * @NoAdminRequired + * @param string $token + * @return DataResponse + */ + public function resolveContactGroup($token) { + $shares = []; + try { + $share = $this->shareService->get($token); + \OC::$server->getLogger()->alert('Suche nach Gruppe: ' . $share->getUserId()); + foreach ($this->systemService->getContactsGroupMembers($share->getUserId()) as $member) { + $shares[] = $this->shareService->add($share->getpollId(), 'contact', $member['user'], $member['emailAddress']) ; + } + + return new DataResponse(['shares' => $shares], Http::STATUS_OK); + } catch (Exception $e) { + return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); + } + } } diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index 67b9bbc272..45e5afba86 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -23,293 +23,115 @@ namespace OCA\Polls\Controller; +use Exception; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCA\Polls\Service\SystemService; -use OCP\IGroupManager; -use OCP\IUser; -use OCP\IUserManager; -use OCP\IConfig; use OCP\IRequest; -use OCA\Polls\Db\Share; -use OCA\Polls\Db\ShareMapper; -use OCA\Polls\Db\Vote; -use OCA\Polls\Db\VoteMapper; class SystemController extends Controller { - /** @var string */ - private $userId; - - /** @var IConfig */ - private $systemConfig; - - /** @var IGroupManager */ - private $groupManager; - - /** @var IUserManager */ - private $userManager; - - /** @var VoteMapper */ - private $voteMapper; - - /** @var ShareMapper */ - private $shareMapper; + /** @var SystemService */ + private $systemService; /** * SystemController constructor. * @param string $appName - * @param $userId * @param IRequest $request - * @param IConfig $systemConfig - * @param IGroupManager $groupManager - * @param IUserManager $userManager - * @param VoteMapper $voteMapper - * @param ShareMapper $shareMapper + * @param SystemService $systemService */ + public function __construct( string $appName, - $userId, IRequest $request, - IConfig $systemConfig, - IGroupManager $groupManager, - IUserManager $userManager, - VoteMapper $voteMapper, - ShareMapper $shareMapper + SystemService $systemService ) { parent::__construct($appName, $request); - $this->voteMapper = $voteMapper; - $this->shareMapper = $shareMapper; - $this->userId = $userId; - $this->systemConfig = $systemConfig; - $this->groupManager = $groupManager; - $this->userManager = $userManager; + $this->systemService = $systemService; } + /** + * Get a list of users + * @NoAdminRequired + * @param string $query + * @param array $skipUsers - usernames to skip in return array + * @return DataResponse + */ + public function getSiteUsers($query = '', $skipUsers = array()) { + return new DataResponse(['users' => $this->systemService->getSiteUsers($query, $skipUsers)], Http::STATUS_OK); + } + + /** + * Get a list of user groups + * @NoAdminRequired + * @param string $query + * @param array $skipGroups - group names to skip in return array + * @return DataResponse + */ + public function getSiteGroups($query = '', $skipGroups = array()) { + return new DataResponse(['groups' => $this->systemService->getSiteGroups($query, $skipGroups)], Http::STATUS_OK); + } + /** - * Validate string as email address + * Get a list of contacts * @NoAdminRequired * @param string $query - * @return bool + * @return DataResponse */ - private function isValidEmail($email) { - return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $email)) ? false : true; - } + public function getContacts($query = '') { + return new DataResponse(['contacts' => $this->systemService->getContacts($query)], Http::STATUS_OK); + } /** - * Get a list of NC users, groups and contacts + * Get a list of contact groups + * @NoAdminRequired + * @param string $query + * @return DataResponse + */ + public function getContactsGroups($query = '') { + return new DataResponse(['contactGroups' => $this->systemService->getContactsGroups($query)], Http::STATUS_OK); + } + + + /** + * Get a combined list of NC users, groups and contacts * @NoAdminRequired - * @PublicPage - * @NoCSRFRequired * @param string $query * @param bool $getGroups - search in groups * @param bool $getUsers - search in site users * @param bool $getContacts - search in contacs + * @param bool $getContactGroups - search in contacs * @param array $skipGroups - group names to skip in return array * @param array $skipUsers - user names to skip in return array * @return DataResponse */ - public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $getContacts = true, $getMail = false, $skipGroups = array(), $skipUsers = array()) { - $list = array(); - - if ($getMail && $this->isValidEmail($query)) { - $list[] = [ - 'id' => '', - 'user' => '', - 'organisation' => '', - 'displayName' => '', - 'emailAddress' => $query, - 'desc' => $query, - 'type' => 'email', - 'icon' => 'icon-mail', - 'avatarURL' => '', - 'avatar' => '', - 'lastLogin' => '', - 'cloudId' => '' - - ]; - } - - if ($getGroups) { - foreach ($this->groupManager->search($query) as $group) { - if (!in_array($group->getGID(), $skipGroups)) { - $list[] = [ - 'id' => $group->getGID(), - 'user' => $group->getGID(), - 'organisation' => '', - 'displayName' => $group->getGID(), - 'emailAddress' => '', - 'desc' => 'Group', - 'type' => 'group', - 'icon' => 'icon-group', - 'avatarURL' => '', - 'avatar' => '', - 'lastLogin' => '', - 'cloudId' => '' - - ]; - } - } - } - - if ($getUsers) { - $users = $this->userManager->searchDisplayName($query); - foreach ($users as $user) { - if (!in_array($user->getUID(), $skipUsers) && $user->isEnabled()) { - $list[] = [ - 'id' => $user->getUID(), - 'user' => $user->getUID(), - 'displayName' => $user->getDisplayName(), - 'organisation' => '', - 'emailAddress' => $user->getEMailAddress(), - 'desc' => 'User', - 'type' => 'user', - 'icon' => 'icon-user', - 'avatarURL' => '', - 'avatar' => '', - 'lastLogin' => $user->getLastLogin(), - 'cloudId' => $user->getCloudId() - ]; - } - } - } - - if ($getContacts && \OC::$server->getContactsManager()->isEnabled()) { - - foreach (\OC::$server->getContactsManager()->search($query, array('FN', 'EMAIL', 'ORG', 'CATEGORIES')) as $contact) { - if (!array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact)) { - - $emailAdresses = $contact['EMAIL']; - - if (!is_array($emailAdresses)) { - $emailAdresses = array($emailAdresses); - } else { - // take the first eMail address for now - $emailAdresses = array($emailAdresses[0]); - } - - foreach ($emailAdresses as $emailAddress) { - $list[] = [ - 'id' => $contact['UID'], - 'user' => $contact['FN'], - 'displayName' => $contact['FN'], - 'organisation' => isset($contact['ORG']) ? $contact['ORG'] : '', - 'emailAddress' => $emailAddress, - 'desc' => 'Contact', - 'type' => 'contact', - 'icon' => 'icon-mail', - 'avatarURL' => '', - 'avatar' => '', - 'lastLogin' => '', - 'cloudId' => '', - ]; - } - - } - } - } - - return new DataResponse([ - 'siteusers' => $list - ], Http::STATUS_OK); + public function getSiteUsersAndGroups( + $query = '', + $getGroups = true, + $getUsers = true, + $getContacts = true, + $getContactGroups = true, + $getMail = false, + $skipGroups = array(), + $skipUsers = array() + ) { + return new DataResponse(['siteusers' => $this->systemService->getSiteUsersAndGroups( + $query, $getGroups, $getUsers, $getContacts, $getContactGroups, $getMail, $skipGroups, $skipUsers )], Http::STATUS_OK); } /** * Validate it the user name is reservrd * return false, if this username already exists as a user or as * a participant of the poll - * @NoCSRFRequired * @NoAdminRequired * @PublicPage * @return DataResponse */ public function validatePublicUsername($pollId, $userName, $token) { + return new DataResponse(['result' => true, 'name' => $userName], Http::STATUS_OK); - // return forbidden, if $pollId does not match the share's pollId, force int compare - if (intval($this->shareMapper->findByToken($token)->getPollId()) !== intVal($pollId)) { - return new DataResponse(['result' => false, 'error' => 'wrong token'], Http::STATUS_FORBIDDEN); - } - - // return forbidden, if the length of the userame is lower than 3 characters - if (strlen(trim($userName)) < 3) { - return new DataResponse(['result' => false, 'error' => 'userName too short'], Http::STATUS_FORBIDDEN); - } - - $list = array(); - - // get all groups - $groups = $this->groupManager->search(''); - foreach ($groups as $group) { - $list[] = [ - 'id' => $group->getGID(), - 'user' => $group->getGID(), - 'type' => 'group', - 'displayName' => $group->getGID(), - ]; - } - - // get all users - $users = $this->userManager->searchDisplayName(''); - foreach ($users as $user) { - $list[] = [ - 'id' => $user->getUID(), - 'user' => $user->getUID(), - 'type' => 'user', - 'displayName' => $user->getDisplayName(), - ]; - } - - // get all participants - $votes = $this->voteMapper->findParticipantsByPoll($pollId); - foreach ($votes as $vote) { - if ($vote->getUserId() !== '' && $vote->getUserId() !== null) { - $list[] = [ - 'id' => $vote->getUserId(), - 'user' => $vote->getUserId(), - 'type' => 'participant', - 'displayName' => $vote->getUserId(), - ]; - } - } - - // get all shares for this poll - $shares = $this->shareMapper->findByPoll($pollId); - foreach ($shares as $share) { - if ($share->getUserId() !== '' && $share->getUserId() !== null) { - $list[] = [ - 'id' => $share->getUserId(), - 'user' => $share->getUserId(), - 'type' => 'share', - 'displayName' => $share->getUserId(), - ]; - } - } - - // check if the username is contained inside the generated list - // return forbidden, if list contains requested username - foreach ($list as $element) { - if (strtolower(trim($userName)) === strtolower(trim($element['id'])) || strtolower(trim($userName)) === strtolower(trim($element['displayName']))) { - return new DataResponse([ - 'result' => false - ], Http::STATUS_FORBIDDEN); - } - } - - // return OK, if username is allowed - return new DataResponse([ - 'result' => true, - 'name' => $userName - ], 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/Exceptions/TooShortException.php b/lib/Exceptions/TooShortException.php new file mode 100644 index 0000000000..8b497d2819 --- /dev/null +++ b/lib/Exceptions/TooShortException.php @@ -0,0 +1,40 @@ + + * + * @author René Gieling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Polls\Exceptions; + +use OCP\AppFramework\Http; + +class TooShortException extends \Exception { + /** + * TooShortException Constructor + * @param string $e exception message + */ + public function __construct($e = 'String too short') { + parent::__construct($e); + } + public function getStatus() { + return Http::STATUS_FORBIDDEN; + } + +} diff --git a/lib/Exceptions/UsernameInvalidException.php b/lib/Exceptions/UsernameInvalidException.php new file mode 100644 index 0000000000..4c7c4e1adb --- /dev/null +++ b/lib/Exceptions/UsernameInvalidException.php @@ -0,0 +1,40 @@ + + * + * @author René Gieling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Polls\Exceptions; + +use OCP\AppFramework\Http; + +class UsernameInvalidException extends \Exception { + /** + * UsernameInvalidException Constructor + * @param string $e exception message + */ + public function __construct($e = 'Username not allowed') { + parent::__construct($e); + } + public function getStatus() { + return Http::STATUS_FORBIDDEN; + } + +} diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 543bafa00f..73ccbcfd51 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -231,8 +231,8 @@ private function getRecipientsByShare($share, $defaultLang = 'en', $skipUser = n $recipients[] = array( 'userId' => $share->getUserId(), - 'eMailAddress' => $contact['EMAIL'][0], - 'displayName' => $contact['FN'], + 'eMailAddress' => $share->getUserEmail(), + 'displayName' => $share->getUserId(), 'language' => $defaultLang, 'link' => $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute( diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index c598073e2f..7208a1543b 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -56,7 +56,7 @@ class OptionService { private $acl; /** - * OptionController constructor. + * OptionService constructor. * @param OptionMapper $optionMapper * @param Option $option * @param PollMapper $pollMapper diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 83f6233f9d..af069d6ed5 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -101,7 +101,9 @@ public function list($pollId, $token) { * @return Share */ public function get($token) { - return $this->shareMapper->findByToken($token); + $this->share = $this->shareMapper->findByToken($token); + + return $this->share; } /** @@ -115,15 +117,12 @@ public function get($token) { * @throws NotAuthorizedException */ public function add($pollId, $type, $userId, $userEmail = '') { + \OC::$server->getLogger()->alert('==== Start '); if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } - if ($type === 'contact') { - $type = 'external'; - } - $this->share = new Share(); $this->share->setType($type); $this->share->setPollId($pollId); diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php new file mode 100644 index 0000000000..5932fae5c6 --- /dev/null +++ b/lib/Service/SystemService.php @@ -0,0 +1,414 @@ + + * + * @author René Gieling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Polls\Service; + +use Exception; +use OCA\Polls\Exceptions\NotAuthorizedException; +use OCA\Polls\Exceptions\TooShortException; +use OCA\Polls\Exceptions\UsernameInvalidException; + +use OCP\IGroupManager; +use OCP\IUser; +use OCP\IUserManager; +use OCP\IRequest; +use OCA\Polls\Db\Share; +use OCA\Polls\Db\ShareMapper; +use OCA\Polls\Db\Vote; +use OCA\Polls\Db\VoteMapper; + +class SystemService { + + /** @var IGroupManager */ + private $groupManager; + + /** @var IUserManager */ + private $userManager; + + /** @var VoteMapper */ + private $voteMapper; + + /** @var ShareMapper */ + private $shareMapper; + + /** + * SystemService constructor. + * @param IGroupManager $groupManager + * @param IUserManager $userManager + * @param VoteMapper $voteMapper + * @param ShareMapper $shareMapper + */ + public function __construct( + IGroupManager $groupManager, + IUserManager $userManager, + VoteMapper $voteMapper, + ShareMapper $shareMapper + ) { + $this->groupManager = $groupManager; + $this->userManager = $userManager; + $this->voteMapper = $voteMapper; + $this->shareMapper = $shareMapper; + } + + /** + * Validate string as email address + * @NoAdminRequired + * @param string $query + * @return bool + */ + private function isValidEmail($email) { + return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $email)) ? false : true; + } + + + /** + * Get a list of users + * @NoAdminRequired + * @param string $query + * @param array $skip - usernames to skip in return array + * @return Array + */ + public function getSiteUsers($query = '', $skip = array()) { + $users = array(); + foreach ($this->userManager->searchDisplayName($query) as $user) { + if (!in_array($user->getUID(), $skip) && $user->isEnabled()) { + $users[] = [ + 'id' => $user->getUID(), + 'user' => $user->getUID(), + 'displayName' => $user->getDisplayName(), + 'organisation' => '', + 'emailAddress' => $user->getEMailAddress(), + 'desc' => 'User', + 'type' => 'user', + 'icon' => 'icon-user', + 'avatarURL' => '', + 'avatar' => '', + 'lastLogin' => $user->getLastLogin(), + 'cloudId' => $user->getCloudId() + ]; + } + } + return $users; + } + + /** + * Get a list of user groups + * @NoAdminRequired + * @param string $query + * @param array $skip - group names to skip in return array + * @return Array + */ + public function getSiteGroups($query = '', $skip = array()) { + $groups = array(); + foreach ($this->groupManager->search($query) as $group) { + if (!in_array($group->getGID(), $skip)) { + $groups[] = [ + 'id' => $group->getGID(), + 'user' => $group->getGID(), + 'organisation' => '', + 'displayName' => $group->getGID(), + 'emailAddress' => '', + 'desc' => 'Group', + 'type' => 'group', + 'icon' => 'icon-group', + 'avatarURL' => '', + 'avatar' => '', + 'lastLogin' => '', + 'cloudId' => '' + + ]; + } + } + return $groups; + } + + /** + * Get a list of contacts + * @NoAdminRequired + * @param string $query + * @return Array + */ + public function getContacts($query = '') { + $contacts = array(); + foreach (\OC::$server->getContactsManager()->search($query, array('FN', 'EMAIL', 'ORG', 'CATEGORIES')) as $contact) { + if (!array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact)) { + + $emailAdresses = $contact['EMAIL']; + + if (!is_array($emailAdresses)) { + $emailAdresses = array($emailAdresses); + } else { + // take the first eMail address for now + $emailAdresses = array($emailAdresses[0]); + } + + foreach ($emailAdresses as $emailAddress) { + $contacts[] = [ + 'id' => $contact['UID'], + 'user' => $contact['FN'], + 'displayName' => $contact['FN'], + 'organisation' => isset($contact['ORG']) ? $contact['ORG'] : '', + 'emailAddress' => $emailAddress, + 'desc' => 'Contact', + 'type' => 'contact', + 'icon' => 'icon-mail', + 'avatarURL' => '', + 'avatar' => '', + 'lastLogin' => '', + 'cloudId' => '', + ]; + } + + } + } + return $contacts; + } + + /** + * Get a list of contacts + * @NoAdminRequired + * @param string $query + * @return Array + */ + public function getContactsGroupMembers($query = '') { + $contacts = array(); + \OC::$server->getLogger()->alert('Suche nach Gruppe: ' . $query); + foreach (\OC::$server->getContactsManager()->search($query, array('CATEGORIES')) as $contact) { + if ( + !array_key_exists('isLocalSystemBook', $contact) + && array_key_exists('EMAIL', $contact) + && in_array($query, explode(',', $contact['CATEGORIES'])) + ) { + $emailAdresses = $contact['EMAIL']; + + if (!is_array($emailAdresses)) { + $emailAdresses = array($emailAdresses); + } else { + // take the first eMail address for now + $emailAdresses = array($emailAdresses[0]); + } + + foreach ($emailAdresses as $emailAddress) { + $contacts[] = [ + 'id' => $contact['UID'], + 'user' => $contact['FN'], + 'displayName' => $contact['FN'], + 'organisation' => isset($contact['ORG']) ? $contact['ORG'] : '', + 'emailAddress' => $emailAddress, + 'desc' => 'Contact', + 'type' => 'contact', + 'icon' => 'icon-mail', + 'avatarURL' => '', + 'avatar' => '', + 'lastLogin' => '', + 'cloudId' => '', + ]; + } + } + } + return $contacts; + } + + /** + * Get a list of contact groups + * @NoAdminRequired + * @param string $query + * @return Array + */ + public function getContactsGroups($query = '') { + $contactGroups = array(); + $foundContacts = []; + + foreach (\OC::$server->getContactsManager()->search($query, array('CATEGORIES')) as $contact) { + + foreach (explode(',', $contact['CATEGORIES']) as $contactGroup) { + if (strpos($contactGroup, $query) === 0 && !in_array($contactGroup, $foundContacts)) { + $foundContacts[] = $contactGroup; + $contactGroups[] = [ + 'id' => 'contactgroup_' + $contactGroup, + 'user' => $contactGroup, + 'displayName' => $contactGroup, + 'organisation' => '', + 'emailAddress' => '', + 'desc' => 'Contact Group', + 'type' => 'contactGroup', + 'icon' => 'icon-group', + 'avatarURL' => '', + 'avatar' => '', + 'lastLogin' => '', + 'cloudId' => '', + ]; + }; + } + } + return $contactGroups; + } + + + /** + * Get a combined list of NC users, groups and contacts + * @NoAdminRequired + * @param string $query + * @param bool $getGroups - search in groups + * @param bool $getUsers - search in site users + * @param bool $getContacts - search in contacs + * @param bool $getContactGroups - search in contacs + * @param array $skipGroups - group names to skip in return array + * @param array $skipUsers - user names to skip in return array + * @return Array + */ + public function getSiteUsersAndGroups( + $query = '', + $getGroups = true, + $getUsers = true, + $getContacts = true, + $getContactGroups = true, + $getMail = false, + $skipGroups = array(), + $skipUsers = array() + ) { + $list = array(); + + if ($getMail && $this->isValidEmail($query)) { + $list[] = [ + 'id' => '', + 'user' => '', + 'organisation' => '', + 'displayName' => '', + 'emailAddress' => $query, + 'desc' => $query, + 'type' => 'email', + 'icon' => 'icon-mail', + 'avatarURL' => '', + 'avatar' => '', + 'lastLogin' => '', + 'cloudId' => '' + + ]; + } + if ($getGroups) { + $list = array_merge($list, $this->getSiteGroups($query, $skipGroups)); + } + + if ($getUsers) { + $list = array_merge($list, $this->getSiteUsers($query, $skipUsers)); + } + + if (\OC::$server->getContactsManager()->isEnabled()) { + if ($getContacts) { + $list = array_merge($list, $this->getContacts($query, $skipUsers)); + } + + if ($getContacts) { + $list = array_merge($list, $this->getContactsGroups($query, $skipGroups)); + } + } + + return $list; + } + + /** + * Validate it the user name is reservrd + * return false, if this username already exists as a user or as + * a participant of the poll + * @NoAdminRequired + * @return Boolean + * @throws NotAuthorizedException + * @throws TooShortException + * @throws UsernameInvalidException + */ + public function validatePublicUsername($pollId, $userName, $token) { + + // return forbidden, if $pollId does not match the share's pollId, force int compare + if (intval($this->shareMapper->findByToken($token)->getPollId()) !== intVal($pollId)) { + throw new NotAuthorizedException; + } + + // return forbidden, if the length of the userame is lower than 3 characters + if (strlen(trim($userName)) < 3) { + return new TooShortException('Username must have at least 3 characters'); + } + + $list = array(); + + // get all groups + $groups = $this->groupManager->search(''); + foreach ($groups as $group) { + $list[] = [ + 'id' => $group->getGID(), + 'user' => $group->getGID(), + 'type' => 'group', + 'displayName' => $group->getGID(), + ]; + } + + // get all users + $users = $this->userManager->searchDisplayName(''); + foreach ($users as $user) { + $list[] = [ + 'id' => $user->getUID(), + 'user' => $user->getUID(), + 'type' => 'user', + 'displayName' => $user->getDisplayName(), + ]; + } + + // get all participants + $votes = $this->voteMapper->findParticipantsByPoll($pollId); + foreach ($votes as $vote) { + if ($vote->getUserId() !== '' && $vote->getUserId() !== null) { + $list[] = [ + 'id' => $vote->getUserId(), + 'user' => $vote->getUserId(), + 'type' => 'participant', + 'displayName' => $vote->getUserId(), + ]; + } + } + + // get all shares for this poll + $shares = $this->shareMapper->findByPoll($pollId); + foreach ($shares as $share) { + if ($share->getUserId() !== '' && $share->getUserId() !== null) { + $list[] = [ + 'id' => $share->getUserId(), + 'user' => $share->getUserId(), + 'type' => 'share', + 'displayName' => $share->getUserId(), + ]; + } + } + + // check if the username is contained inside the generated list + // return forbidden, if list contains requested username + foreach ($list as $element) { + if (strtolower(trim($userName)) === strtolower(trim($element['id'])) || strtolower(trim($userName)) === strtolower(trim($element['displayName']))) { + throw new UsernameInvalidException; + } + } + + // return true, if username is allowed + return true; + } + +} diff --git a/src/js/components/Base/UserItem.vue b/src/js/components/Base/UserItem.vue index b0889c502d..d8e49cbc7c 100644 --- a/src/js/components/Base/UserItem.vue +++ b/src/js/components/Base/UserItem.vue @@ -109,6 +109,8 @@ export default { return 'icon-mail' } else if (this.type === 'external') { return 'icon-share' + } else if (this.type === 'contactGroup') { + return 'icon-group' } return 'icon-' + this.type } else { @@ -133,6 +135,8 @@ export default { } } else if (this.type === 'group') { displayName = this.userId + ' (' + t('polls', 'Group') + ')' + } else if (this.type === 'contactGroup') { + displayName = this.userId + ' (' + t('polls', 'Contact Group') + ')' } else if (this.type === 'public') { displayName = t('polls', 'Public share') } else { diff --git a/src/js/components/SideBar/SideBarTabShare.vue b/src/js/components/SideBar/SideBarTabShare.vue index ecf8af56b9..fb4a4d2ad1 100644 --- a/src/js/components/SideBar/SideBarTabShare.vue +++ b/src/js/components/SideBar/SideBarTabShare.vue @@ -111,6 +111,17 @@ @click="sendInvitation(share)"> {{ t('polls', 'Send invitation mail') }} + + {{ t('polls', 'Resolve contact group into individual invitations') }} + + + + + {{ t('polls', 'Remove invitation') }} + @@ -167,6 +178,13 @@ export default { }, methods: { + resolveContactGroup(share) { + this.$store.dispatch('poll/shares/resolveContactGroup', { share: share }) + .then((response) => { + this.$store.dispatch('poll/shares/delete', { share: share }) + }) + }, + sendInvitation(share) { this.$store.dispatch('poll/shares/sendInvitation', { share: share }) .then((response) => { diff --git a/src/js/store/modules/subModules/shares.js b/src/js/store/modules/subModules/shares.js index c684e29762..940aeeb5cd 100644 --- a/src/js/store/modules/subModules/shares.js +++ b/src/js/store/modules/subModules/shares.js @@ -62,15 +62,18 @@ const mutations = { const getters = { invitation: state => { - const invitationTypes = ['user', 'group', 'email', 'external', 'contact'] + // share types, which will be active, after the user gets his invitation + const invitationTypes = ['email', 'external', 'contact'] + // sharetype which are active without sending an invitation + const directShareTypes = ['user', 'group'] return state.list.filter(share => { - return invitationTypes.includes(share.type) && share.invitationSent + return (invitationTypes.includes(share.type) && share.invitationSent) || directShareTypes.includes(share.type) }) }, unsentInvitations: state => { return state.list.filter(share => { - return (share.userEmail || share.type === 'group') && !share.invitationSent + return (share.userEmail || share.type === 'group' || share.type === 'contactGroup') && !share.invitationSent }) }, @@ -140,6 +143,21 @@ const actions = { throw error }) }, + + resolveContactGroup(context, payload) { + const endPoint = 'apps/polls/share/resolveContactGroup' + return axios.post(generateUrl(endPoint.concat('/', payload.share.token))) + .then((response) => { + response.data.shares.forEach((item) => { + context.commit('add', item) + }) + return response + }) + .catch((error) => { + console.error('Error exploding group', { error: error.response }, { payload: payload }) + throw error + }) + }, } export default { namespaced, state, mutations, actions, getters } diff --git a/src/js/views/Vote.vue b/src/js/views/Vote.vue index 0f110a42e1..f5c5afea53 100644 --- a/src/js/views/Vote.vue +++ b/src/js/views/Vote.vue @@ -83,11 +83,9 @@
    - -
    - -
    + + @@ -169,6 +167,13 @@ export default { return t('polls', 'Ranked order') } }, + showRegisterModal() { + return (this.$route.name === 'publicVote' + && !this.share.userId + && !this.isExpired + && this.poll.id + ) + }, sortIcon() { if (this.ranked) { if (this.poll.type === 'datePoll') { From 2e1eccb0d11a324723e677c098a683ca2febfcd1 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 12 Aug 2020 22:10:26 +0200 Subject: [PATCH 032/117] add getDisplayName to groups --- lib/Service/SystemService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php index 5932fae5c6..5cabdadf5d 100644 --- a/lib/Service/SystemService.php +++ b/lib/Service/SystemService.php @@ -126,7 +126,7 @@ public function getSiteGroups($query = '', $skip = array()) { 'id' => $group->getGID(), 'user' => $group->getGID(), 'organisation' => '', - 'displayName' => $group->getGID(), + 'displayName' => $group->getDisplayName(), 'emailAddress' => '', 'desc' => 'Group', 'type' => 'group', From a36377b64103b264ac333172a8c6306edaee071d Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 12 Aug 2020 23:03:43 +0200 Subject: [PATCH 033/117] remove vote column width limitation --- src/js/components/VoteTable/VoteTable.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/components/VoteTable/VoteTable.vue b/src/js/components/VoteTable/VoteTable.vue index 9f85a58854..fe566556b7 100644 --- a/src/js/components/VoteTable/VoteTable.vue +++ b/src/js/components/VoteTable/VoteTable.vue @@ -327,7 +327,7 @@ export default { .vote-table__vote-row, .vote-table__footer { > div { - max-width: 230px; + // max-width: 230px; &.confirmed { margin-left: 8px; From c30ac7f507542048780d73fa8029557aeb361403 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 12 Aug 2020 23:58:29 +0200 Subject: [PATCH 034/117] update dependencies --- package-lock.json | 114 +++++++++++++++++++++++----------------------- package.json | 12 ++--- 2 files changed, 64 insertions(+), 62 deletions(-) diff --git a/package-lock.json b/package-lock.json index 565dd72712..aff8cace97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,15 +40,15 @@ } }, "@babel/core": { - "version": "7.11.0", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.11.0.tgz", - "integrity": "sha512-mkLq8nwaXmDtFmRkQ8ED/eA2CnVw4zr7dCztKalZXBvdK5EeNUAesrrwUqjQEzFgomJssayzB0aqlOsP1vGLqg==", + "version": "7.11.1", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.11.1.tgz", + "integrity": "sha512-XqF7F6FWQdKGGWAzGELL+aCO1p+lRY5Tj5/tbT3St1G8NaH70jhhDIKknIZaDans0OQBG5wRAldROLHSt44BgQ==", "requires": { "@babel/code-frame": "^7.10.4", "@babel/generator": "^7.11.0", "@babel/helper-module-transforms": "^7.11.0", "@babel/helpers": "^7.10.4", - "@babel/parser": "^7.11.0", + "@babel/parser": "^7.11.1", "@babel/template": "^7.10.4", "@babel/traverse": "^7.11.0", "@babel/types": "^7.11.0", @@ -122,9 +122,9 @@ } }, "@babel/parser": { - "version": "7.11.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.0.tgz", - "integrity": "sha512-qvRvi4oI8xii8NllyEc4MDJjuZiNaRzyb7Y7lup1NqJV8TZHF4O27CcP+72WPn/k1zkgJ6WJfnIbk4jTsVAZHw==" + "version": "7.11.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.3.tgz", + "integrity": "sha512-REo8xv7+sDxkKvoxEywIdsNFiZLybwdI7hcT5uEPyQrSMB4YQ973BfC9OOrD/81MaIjh6UxdulIQXkjmiH3PcA==" }, "@babel/template": { "version": "7.10.4", @@ -1311,9 +1311,9 @@ } }, "@babel/parser": { - "version": "7.11.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.0.tgz", - "integrity": "sha512-qvRvi4oI8xii8NllyEc4MDJjuZiNaRzyb7Y7lup1NqJV8TZHF4O27CcP+72WPn/k1zkgJ6WJfnIbk4jTsVAZHw==" + "version": "7.11.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.3.tgz", + "integrity": "sha512-REo8xv7+sDxkKvoxEywIdsNFiZLybwdI7hcT5uEPyQrSMB4YQ973BfC9OOrD/81MaIjh6UxdulIQXkjmiH3PcA==" }, "@babel/template": { "version": "7.10.4", @@ -2104,27 +2104,6 @@ } } }, - "@babel/polyfill": { - "version": "7.2.5", - "resolved": "https://registry.npmjs.org/@babel/polyfill/-/polyfill-7.2.5.tgz", - "integrity": "sha512-8Y/t3MWThtMLYr0YNC/Q76tqN1w30+b0uQMeFUYauG2UGTR19zyUtFrAzT23zNtBxPp+LbE5E/nwV/q/r3y6ug==", - "requires": { - "core-js": "^2.5.7", - "regenerator-runtime": "^0.12.0" - }, - "dependencies": { - "core-js": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", - "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" - }, - "regenerator-runtime": { - "version": "0.12.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", - "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" - } - } - }, "@babel/preset-env": { "version": "7.11.0", "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.11.0.tgz", @@ -4629,9 +4608,9 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.5.0.tgz", - "integrity": "sha512-vlUP10xse9sWt9SGRtcr1LAC67BENcQMFeV+w5EvLEoFe3xJ8cF1Skd0msziRx/VMC+72B4DxreCE+OR12OA6Q==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.6.0.tgz", + "integrity": "sha512-QlAManNtqr7sozWm5TF4wIH9gmUm2hE3vNRUvyoYAa4y1l5/jxD/PQStEjBMQtCqZmSep8UxrcecI60hOpe61w==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -4673,9 +4652,9 @@ }, "dependencies": { "acorn": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.3.1.tgz", - "integrity": "sha512-tLc0wSnatxAQHVHUapaHdz72pi9KUyHjq5KyHjGg9Y8Ifdc79pTh2XvI6I1/chZbnM7QtNKzh66ooDogPZSleA==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz", + "integrity": "sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w==", "dev": true }, "ansi-styles": { @@ -6991,9 +6970,9 @@ "integrity": "sha1-elSbvZ/+FYWwzQoZHiAwVb7ldLQ=" }, "jest-worker": { - "version": "26.2.1", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.2.1.tgz", - "integrity": "sha512-+XcGMMJDTeEGncRb5M5Zq9P7K4sQ1sirhjdOxsN1462h6lFo9w59bl2LVQmdGEEeU3m+maZCkS2Tcc9SfCHO4A==", + "version": "26.3.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.3.0.tgz", + "integrity": "sha512-Vmpn2F6IASefL+DVBhPzI2J9/GJUsqzomdeN+P+dK8/jKxbh8R3BtFnx3FIta7wYlPU62cpJMJQo4kuOowcMnw==", "dev": true, "requires": { "@types/node": "*", @@ -9239,14 +9218,14 @@ } }, "sass-loader": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-9.0.2.tgz", - "integrity": "sha512-nphcum3jNI442njnrZ5wJgSNX5lfEOHOKHCLf+PrTIaleploKqAMUuT9CVKjf+lyi6c2MCGPHh1vb9nGsjnZJA==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-9.0.3.tgz", + "integrity": "sha512-fOwsP98ac1VMme+V3+o0HaaMHp8Q/C9P+MUazLFVi3Jl7ORGHQXL1XeRZt3zLSGZQQPC8xE42Y2WptItvGjDQg==", "dev": true, "requires": { - "klona": "^1.1.1", + "klona": "^1.1.2", "loader-utils": "^2.0.0", - "neo-async": "^2.6.1", + "neo-async": "^2.6.2", "schema-utils": "^2.7.0", "semver": "^7.3.2" }, @@ -9274,6 +9253,12 @@ "json5": "^2.1.2" } }, + "neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", + "dev": true + }, "schema-utils": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.7.0.tgz", @@ -10474,19 +10459,19 @@ } }, "terser-webpack-plugin": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-3.0.8.tgz", - "integrity": "sha512-ygwK8TYMRTYtSyLB2Mhnt90guQh989CIq/mL/2apwi6rA15Xys4ydNUiH4ah6EZCfQxSk26ZFQilZ4IQ6IZw6A==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-4.1.0.tgz", + "integrity": "sha512-0ZWDPIP8BtEDZdChbufcXUigOYk6dOX/P/X0hWxqDDcVAQLb8Yy/0FAaemSfax3PAA67+DJR778oz8qVbmy4hA==", "dev": true, "requires": { "cacache": "^15.0.5", "find-cache-dir": "^3.3.1", - "jest-worker": "^26.1.0", + "jest-worker": "^26.3.0", "p-limit": "^3.0.2", "schema-utils": "^2.6.6", "serialize-javascript": "^4.0.0", "source-map": "^0.6.1", - "terser": "^4.8.0", + "terser": "^5.0.0", "webpack-sources": "^1.4.3" }, "dependencies": { @@ -10502,6 +10487,12 @@ "uri-js": "^4.2.2" } }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "find-cache-dir": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", @@ -10613,6 +10604,17 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true + }, + "terser": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.0.0.tgz", + "integrity": "sha512-olH2DwGINoSuEpSGd+BsPuAQaA3OrHnHnFL/rDB2TVNc3srUbz/rq/j2BlF4zDXI+JqAvGr86bIm1R2cJgZ3FA==", + "dev": true, + "requires": { + "commander": "^2.20.0", + "source-map": "~0.6.1", + "source-map-support": "~0.5.12" + } } } }, @@ -11266,9 +11268,9 @@ "integrity": "sha512-bhP7MlgJQ8TIkZJXAfDf78uJO+mEI3CaLABLjv0WNzr4CcGRGPIAItyWYnP6LsPA4Oq0WE+suidNs6dgpO4RHg==" }, "vue-router": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.3.4.tgz", - "integrity": "sha512-SdKRBeoXUjaZ9R/8AyxsdTqkOfMcI5tWxPZOUX5Ie1BTL5rPSZ0O++pbiZCeYeythiZIdLEfkDiQPKIaWk5hDg==" + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.4.3.tgz", + "integrity": "sha512-BADg1mjGWX18Dpmy6bOGzGNnk7B/ZA0RxuA6qedY/YJwirMfKXIDzcccmHbQI0A6k5PzMdMloc0ElHfyOoX35A==" }, "vue-style-loader": { "version": "4.1.2", @@ -11708,9 +11710,9 @@ } }, "webpack-merge": { - "version": "5.0.9", - "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.0.9.tgz", - "integrity": "sha512-P4teh6O26xIDPugOGX61wPxaeP918QOMjmzhu54zTVcLtOS28ffPWtnv+ilt3wscwBUCL2WNMnh97XkrKqt9Fw==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.1.1.tgz", + "integrity": "sha512-UhIkHAVqeG9EqFfYo7dRELrVfH6HYaOTYM7ssKCwfIIHYnWepGVOFp1E166GwgPGFqV6M68UgRiKOERjVOKIXA==", "dev": true, "requires": { "clone-deep": "^4.0.1", diff --git a/package.json b/package.json index 81a640a7a5..a7a3cfca4e 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "vue": "^2.6.11", "vue-clipboard2": "^0.3.1", "vue-fragment": "^1.5.1", - "vue-router": "^3.3.4", + "vue-router": "^3.4.3", "vuedraggable": "^2.24.0", "vuex": "^3.5.1" }, @@ -62,14 +62,14 @@ "node": ">=10.0.0" }, "devDependencies": { - "@babel/core": "^7.11.0", + "@babel/core": "^7.11.1", "@babel/preset-env": "^7.11.0", "@nextcloud/eslint-plugin": "^1.4.0", "babel-eslint": "^10.0.3", "babel-loader": "^8.0.6", "cross-env": "^7.0.0", "css-loader": "^3.6.0", - "eslint": "^7.5.0", + "eslint": "^7.6.0", "eslint-config-standard": "^14.1.0", "eslint-loader": "^4.0.2", "eslint-plugin-import": "^2.22.0", @@ -79,16 +79,16 @@ "eslint-plugin-vue": "^6.2.2", "file-loader": "^6.0.0", "node-sass": "^4.14.1", - "sass-loader": "^9.0.2", + "sass-loader": "^9.0.3", "stylelint": "^13.6.1", "stylelint-config-recommended-scss": "^4.2.0", "stylelint-scss": "^3.18.0", - "terser-webpack-plugin": "^3.0.8", + "terser-webpack-plugin": "^4.1.0", "vue-loader": "^15.9.3", "vue-style-loader": "^4.1.2", "vue-template-compiler": "^2.6.11", "webpack": "^4.44.1", "webpack-cli": "^3.3.12", - "webpack-merge": "^5.0.9" + "webpack-merge": "^5.1.1" } } From 081a116dd0155356f5b5475d0386168f01146ef8 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 13 Aug 2020 16:46:04 +0200 Subject: [PATCH 035/117] catch error on getDisplayName for groups --- lib/Service/SystemService.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php index 5cabdadf5d..dbc37c3f58 100644 --- a/lib/Service/SystemService.php +++ b/lib/Service/SystemService.php @@ -122,11 +122,19 @@ public function getSiteGroups($query = '', $skip = array()) { $groups = array(); foreach ($this->groupManager->search($query) as $group) { if (!in_array($group->getGID(), $skip)) { + try { + // seems to work only from NC19 on + $displayName = $group->getDisplayName(); + } catch (\Exception $e) { + // fallback + $displayName = $group->getGID(); + } + $groups[] = [ 'id' => $group->getGID(), 'user' => $group->getGID(), 'organisation' => '', - 'displayName' => $group->getDisplayName(), + 'displayName' => $displayName, 'emailAddress' => '', 'desc' => 'Group', 'type' => 'group', From 56d48b45a12314db6dd424ad69a478e2e4c84cc9 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 15 Aug 2020 20:17:48 +0200 Subject: [PATCH 036/117] Adding time zone information --- src/js/components/Base/OptionItem.vue | 24 ++++++++++++++++++++-- src/js/components/Base/PollInformation.vue | 9 +++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/js/components/Base/OptionItem.vue b/src/js/components/Base/OptionItem.vue index da4639e7b4..f82b1845b4 100644 --- a/src/js/components/Base/OptionItem.vue +++ b/src/js/components/Base/OptionItem.vue @@ -28,11 +28,11 @@ {{ option.rank }} -
    +
    {{ optionText }}
    -
    +
    {{ dateBoxMonth }}
    @@ -83,24 +83,43 @@ export default { ...mapState({ poll: state => state.poll, }), + isDraggable() { return this.draggable }, + dateLocalFormat() { return moment.unix(this.option.timestamp).format('llll') }, + + dateLocalFormatUTC() { + return moment.unix(this.option.timestamp).utc().format('llll').concat(' UTC') + }, + dateBoxMonth() { return moment.unix(this.option.timestamp).format('MMM') + " '" + moment.unix(this.option.timestamp).format('YY') }, + dateBoxDay() { return moment.unix(this.option.timestamp).format('Do') }, + dateBoxDow() { return moment.unix(this.option.timestamp).format('ddd') }, + dateBoxTime() { return moment.unix(this.option.timestamp).format('LT') }, + + optionTooltip() { + if (this.poll.type === 'datePoll') { + return this.dateLocalFormatUTC + } else { + return this.option.pollOptionText + } + }, + optionText() { if (this.poll.type === 'datePoll') { return this.dateLocalFormat @@ -108,6 +127,7 @@ export default { return this.option.pollOptionText } }, + show() { if (this.poll.type === 'datePoll' && this.display === 'dateBox') { return 'dateBox' diff --git a/src/js/components/Base/PollInformation.vue b/src/js/components/Base/PollInformation.vue index d80d1eb738..7d6040f077 100644 --- a/src/js/components/Base/PollInformation.vue +++ b/src/js/components/Base/PollInformation.vue @@ -33,11 +33,13 @@ {{ t('polls', 'You can place your vote until {dateString}.', { dateString: dateExpiryString }) }} - {{ t('polls', 'The names of other participants are hidden, as this is an anonymous poll. ') }} + {{ t('polls', 'This is an anonymous poll. Except to the poll owner, participants names are hidden.') }} {{ t('polls', 'Results are hidden. ') }} {{ t('polls', 'They will be revealed after the poll is expired. ') }} + + {{ t('polls', 'The used time zone is {timeZone}. ', { timeZone: currentTimeZone }) }}
    @@ -72,6 +74,11 @@ export default { dateExpiryString() { return moment.unix(this.poll.expire).format('LLLL') }, + + currentTimeZone() { + return Intl.DateTimeFormat().resolvedOptions().timeZone + }, + }, } From c679210764583b8a25df9c5e3a231eb0a8cfb9e3 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Mon, 17 Aug 2020 10:35:43 +0200 Subject: [PATCH 037/117] find possible calender conflicts --- appinfo/routes.php | 1 + lib/Controller/OptionController.php | 55 ++++++- lib/Service/CalendarService.php | 102 ++++++++++++ lib/Service/OptionService.php | 16 ++ src/js/components/Base/CalendarInfo.vue | 103 ++++++++++++ src/js/components/VoteTable/VoteTable.vue | 67 +++++++- .../VoteTable/VoteTableCalendarPeek.vue | 152 ++++++++++++++++++ .../VoteTable/VoteTableVoteItem.vue | 5 + src/js/store/modules/subModules/options.js | 13 ++ 9 files changed, 508 insertions(+), 6 deletions(-) create mode 100644 lib/Service/CalendarService.php create mode 100644 src/js/components/Base/CalendarInfo.vue create mode 100644 src/js/components/VoteTable/VoteTableCalendarPeek.vue diff --git a/appinfo/routes.php b/appinfo/routes.php index 1a3ff5c3f4..92efe4892f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -47,6 +47,7 @@ ['name' => 'option#confirm', 'url' => '/option/{optionId}/confirm', 'verb' => 'PUT'], ['name' => 'option#reorder', 'url' => '/options/reorder', 'verb' => 'POST'], ['name' => 'option#list', 'url' => '/polls/{pollId}/options', 'verb' => 'GET'], + ['name' => 'option#findCalendarEvents', 'url' => '/option/{optionId}/events', 'verb' => 'GET'], // ['name' => 'option#listByToken', 'url' => '/options/get/s/{token}', 'verb' => 'GET'], ['name' => 'vote#set', 'url' => '/vote/set', 'verb' => 'POST'], diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php index 3b1e7f1ead..e8fd8cad1a 100644 --- a/lib/Controller/OptionController.php +++ b/lib/Controller/OptionController.php @@ -23,6 +23,8 @@ namespace OCA\Polls\Controller; +use DateTime; +use DateInterval; use Exception; use OCP\IRequest; @@ -31,12 +33,17 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCA\Polls\Service\OptionService; +use OCA\Polls\Service\CalendarService; + class OptionController extends Controller { /** @var OptionService */ private $optionService; + /** @var CalendarService */ + private $calendarService; + /** * OptionController constructor. * @param string $appName @@ -47,10 +54,12 @@ class OptionController extends Controller { public function __construct( string $appName, IRequest $request, - OptionService $optionService + OptionService $optionService, + CalendarService $calendarService ) { parent::__construct($appName, $request); $this->optionService = $optionService; + $this->calendarService = $calendarService; } /** @@ -113,4 +122,48 @@ public function confirm($optionId) { public function reorder($pollId, $options) { return new DataResponse(['options' => $this->optionService->reorder($pollId, $options)], Http::STATUS_OK); } + + /** + * findCalendarEvents + * @NoAdminRequired + * @param integer $from + * @param integer $to + * @return DataResponse + */ + public function findCalendarEvents($optionId) { + + $searchFrom = new DateTime(); + $searchFrom = $searchFrom->setTimestamp($this->optionService->get($optionId)->getTimestamp())->sub(new DateInterval('PT1H')); + $searchTo = clone $searchFrom; + $searchTo = $searchTo->add(new DateInterval('PT3H')); + + \OC::$server->getLogger()->alert('Search events between ' . $searchFrom->format('Y-m-d H:i:s') . ' and ' . $searchTo->format('Y-m-d H:i:s')); + + return new DataResponse(['events' => array_values($this->calendarService->getEvents($searchFrom, $searchTo))], Http::STATUS_OK); + + + if (is_int($from)) { + $searchFrom = new DateTime(); + $searchFrom = $searchFrom->setTimestamp($from); + } else { + $searchFrom = new DateTime($from); + } + + + if (!$to) { + $searchTo = clone $searchFrom; + $searchTo = $searchTo->add(new DateInterval('PT1H')); + + } else if (is_int($to)) { + $searchTo = new DateTime(); + $searchTo = $searchTo->setTimestamp($to); + } else { + $searchTo = new DateTime($to); + } + + $events = array_values($this->calendarService->getEvents($searchFrom, $searchTo)); + return $events; + + } + } diff --git a/lib/Service/CalendarService.php b/lib/Service/CalendarService.php new file mode 100644 index 0000000000..68f9c0f21b --- /dev/null +++ b/lib/Service/CalendarService.php @@ -0,0 +1,102 @@ + + * + * @author René Gieling +* + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Polls\Service; + +use DateTime; +use OCP\Calendar\IManager as CalendarManager; +use OCP\Calendar\ICalendar; + +class CalendarService { + + private $calendarManager; + private $calendars; + + public function __construct( + CalendarManager $calendarManager + ) { + $this->calendarManager = $calendarManager; + $this->calendars = $this->calendarManager->getCalendars(); + } + + /** + * getEvents - get events from the user's calendars inside given timespan + * @NoAdminRequired + * @param DateTime $from + * @param DateTime $to + * @return Array + */ + public function getEvents($from, $to) { + $events = []; + + foreach ($this->calendars as $calendar) { + $foundEvents = $calendar->search('' ,['SUMMARY'], ['timerange' => ['start' => $from, 'end' => $to]]); + foreach ($foundEvents as $event) { + array_push($events, [ + 'relatedFrom' => $from->getTimestamp(), + 'relatedTo' => $to->getTimestamp(), + 'name' => $calendar->getDisplayName(), + 'key' => $calendar->getKey(), + 'displayColor' => $calendar->getDisplayColor(), + 'permissions' => $calendar->getPermissions(), + 'eventId' => $event['id'], + 'UID' => $event['objects'][0]['UID'][0], + 'summary' => isset($event['objects'][0]['SUMMARY'][0])? $event['objects'][0]['SUMMARY'][0] : '', + 'description' => isset($event['objects'][0]['DESCRIPTION'][0])? $event['objects'][0]['DESCRIPTION'][0] : '', + 'location' => isset($event['objects'][0]['LOCATION'][0]) ? $event['objects'][0]['LOCATION'][0] : '', + 'eventFrom' => isset($event['objects'][0]['DTSTART'][0]) ? $event['objects'][0]['DTSTART'][0]->getTimestamp() : 0, + 'eventTo' => isset($event['objects'][0]['DTEND'][0] ) ? $event['objects'][0]['DTEND'][0]->getTimestamp() : 0, + 'calDav' => $event + ]); + } + } + return $events; + } + + /** + * Get user's calendars + * @NoAdminRequired + * @return Array + */ + public function getCalendars() { + return $this->calendars; + } + + + /** + * Get events from the user's calendar which are 2 hours before and 3 hours after the timestamp + * @NoAdminRequired + * @param DateTime $from + * @return Array + */ + public function getEventsAround($from) { + $from = new DateTime($from); + $to = new DateTime($from); + return $this->getEvents( + $from->sub(new DateInterval('P2H')), + $to->add(new DateInterval('P3H')) + ); + } + +} diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 7208a1543b..0e2dbb8816 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -103,6 +103,22 @@ public function list($pollId = 0, $token = '') { } } + /** + * Get option + * @NoAdminRequired + * @param int $optionId + * @return Option + * @throws NotAuthorizedException + */ + public function get($optionId) { + + if (!$this->acl->set($this->optionMapper->find($optionId)->getPollId())->getAllowView()) { + throw new NotAuthorizedException; + } + + return $this->optionMapper->find($optionId); + } + /** * Add a new option diff --git a/src/js/components/Base/CalendarInfo.vue b/src/js/components/Base/CalendarInfo.vue new file mode 100644 index 0000000000..750dabd2e2 --- /dev/null +++ b/src/js/components/Base/CalendarInfo.vue @@ -0,0 +1,103 @@ + + + + + + + diff --git a/src/js/components/VoteTable/VoteTable.vue b/src/js/components/VoteTable/VoteTable.vue index f606397693..2e458f032d 100644 --- a/src/js/components/VoteTable/VoteTable.vue +++ b/src/js/components/VoteTable/VoteTable.vue @@ -43,6 +43,14 @@ :table-mode="tableMode" />
    +
    + +
    +