From c08482dbe771e4a3aa2f2254ee435768a0aedf59 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 10 Oct 2024 18:29:41 +0200 Subject: [PATCH 1/3] more fixes and optimizations after tests Signed-off-by: dartcafe --- lib/Controller/ShareController.php | 15 +++++++++++++++ lib/Model/Settings/AppSettings.php | 1 - lib/Service/MailService.php | 2 +- lib/Service/SettingsService.php | 2 +- src/Api/modules/shares.js | 14 +++++++++++--- src/components/Base/modules/InputDiv.vue | 7 +++---- src/components/Comments/CommentAdd.vue | 3 +-- .../Configuration/ConfigOptionLimit.vue | 1 - src/components/Configuration/ConfigVoteLimit.vue | 1 - .../Settings/AdminSettings/AdminCombo.vue | 2 +- .../Settings/AdminSettings/AdminPollCreation.vue | 2 +- .../Settings/AdminSettings/AdminPollDownload.vue | 2 +- .../AdminSettings/AdminShareOpenPoll.vue | 1 + .../AdminSettings/AdminSharePublicCreate.vue | 1 + .../AdminSettings/AdminShowMailAddresses.vue | 2 +- src/components/Shares/SharePublicAdd.vue | 2 +- src/components/User/UserSearch.vue | 11 ++++------- src/stores/shares.ts | 16 +++++++++++++++- 18 files changed, 58 insertions(+), 27 deletions(-) diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index d784a8a67..249da48cd 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -54,6 +54,21 @@ public function add(int $pollId, string $type, string $userId = '', string $disp return $this->responseCreate(fn () => ['share' => $this->shareService->add($pollId, $type, $userId, $displayName, $emailAddress)]); } + /** + * Add share + * @param int $pollId poll id + * @param string $type Share type + * @param string $userId User id + * @param string $displayName Displayname of user + * @param string $emailAddress Email address of user + */ + #[NoAdminRequired] + #[OpenAPI(OpenAPI::SCOPE_IGNORE)] + #[FrontpageRoute(verb: 'POST', url: '/poll/{pollId}/publicshare')] + public function addPublicShare(int $pollId): JSONResponse { + return $this->responseCreate(fn () => ['share' => $this->shareService->add($pollId, Share::TYPE_PUBLIC)]); + } + /** * Change the contraints for email addresses in public polls * @param string $token Share token diff --git a/lib/Model/Settings/AppSettings.php b/lib/Model/Settings/AppSettings.php index 90af209c5..610ab767d 100644 --- a/lib/Model/Settings/AppSettings.php +++ b/lib/Model/Settings/AppSettings.php @@ -239,7 +239,6 @@ public function jsonSerialize(): array { self::SETTING_IMPRINT_URL => $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_IMPRINT_URL), self::SETTING_PRIVACY_URL => $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_PRIVACY_URL), self::SETTING_UPDATE_TYPE => $this->getUpdateType(), - 'storedKeys' => $this->appConfig->getKeys(AppConstants::APP_ID), 'usePrivacyUrl' => $this->getUsePrivacyUrl(), 'useImprintUrl' => $this->getUseImprintUrl(), 'defaultPrivacyUrl' => $this->appConfig->getValueString('theming', 'privacyUrl'), diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index ee929ec91..4b89319b6 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -102,7 +102,7 @@ public static function extractEmailAddressAndName($eMailString): array { preg_match(self::REGEX_PARSE_MAIL_AND_NAME, $eMailString, $matches); // Check if the found element is a valid email address - $emailAddress = boolval($matches[1]) ? trim($matches[1]) : null; + $emailAddress = !empty($matches[1]) ? trim($matches[1]) : null; if ($emailAddress !== null && filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { // Extract the name based on the input string diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index e86741ace..7fdbcac74 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -53,7 +53,7 @@ public function writeAppSettings(array $settingsArray): void { $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_POLL_CREATION_GROUPS, array_column($settingsArray[AppSettings::SETTING_POLL_CREATION_GROUPS], 'id')); $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_POLL_DOWNLOAD_GROUPS, array_column($settingsArray[AppSettings::SETTING_POLL_DOWNLOAD_GROUPS], 'id')); - $this->appConfig->setValueInt(AppConstants::APP_ID, AppSettings::SETTING_AUTO_ARCHIVE_OFFSET, $settingsArray[AppSettings::SETTING_AUTO_ARCHIVE_OFFSET]); + $this->appConfig->setValueInt(AppConstants::APP_ID, AppSettings::SETTING_AUTO_ARCHIVE_OFFSET, intval($settingsArray[AppSettings::SETTING_AUTO_ARCHIVE_OFFSET])); $this->appConfig->setValueString(AppConstants::APP_ID, AppSettings::SETTING_UPDATE_TYPE, $settingsArray[AppSettings::SETTING_UPDATE_TYPE]); $this->appConfig->setValueString(AppConstants::APP_ID, AppSettings::SETTING_PRIVACY_URL, $settingsArray[AppSettings::SETTING_PRIVACY_URL]); diff --git a/src/Api/modules/shares.js b/src/Api/modules/shares.js index b74d3c0c4..0c0c70fb8 100644 --- a/src/Api/modules/shares.js +++ b/src/Api/modules/shares.js @@ -14,12 +14,20 @@ const shares = { }) }, - addShare(pollId, user) { + addUserShare(pollId, user) { return httpInstance.request({ method: 'POST', url: `poll/${pollId}/share`, - data: { ...user }, - cancelToken: cancelTokenHandlerObject[this.addShare.name].handleRequestCancellation().token, + data: user, + cancelToken: cancelTokenHandlerObject[this.addUserShare.name].handleRequestCancellation().token, + }) + }, + + addPublicShare(pollId) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/publicshare`, + cancelToken: cancelTokenHandlerObject[this.addPublicShare.name].handleRequestCancellation().token, }) }, diff --git a/src/components/Base/modules/InputDiv.vue b/src/components/Base/modules/InputDiv.vue index 842360498..f9d25a7ec 100644 --- a/src/components/Base/modules/InputDiv.vue +++ b/src/components/Base/modules/InputDiv.vue @@ -150,7 +150,7 @@ if (model.value !== nextValue) { model.value = nextValue - emit('submit') + emit('change') } } @@ -163,7 +163,7 @@ if (model.value !== nextValue) { model.value = nextValue - emit('submit') + emit('change') } } @@ -173,7 +173,6 @@ - diff --git a/src/components/Configuration/ConfigOptionLimit.vue b/src/components/Configuration/ConfigOptionLimit.vue index 5be104f5c..07aea7947 100644 --- a/src/components/Configuration/ConfigOptionLimit.vue +++ b/src/components/Configuration/ConfigOptionLimit.vue @@ -47,7 +47,6 @@ inputmode="numeric" :num-min="1" use-num-modifiers - @submit="pollStore.write()" @change="pollStore.write()" /> diff --git a/src/components/Settings/AdminSettings/AdminCombo.vue b/src/components/Settings/AdminSettings/AdminCombo.vue index c9b9b76a4..adc58b3ef 100644 --- a/src/components/Settings/AdminSettings/AdminCombo.vue +++ b/src/components/Settings/AdminSettings/AdminCombo.vue @@ -31,7 +31,7 @@ :multiple="true" :loading="appSettingsStore.status.loadingGroups" :placeholder="t('polls', 'Leave empty to disable globally')" - @option:selected="appSettingsStore.write()" + @update:model-value="appSettingsStore.write()" @search="appSettingsStore.loadGroups" /> diff --git a/src/components/Settings/AdminSettings/AdminPollCreation.vue b/src/components/Settings/AdminSettings/AdminPollCreation.vue index 3d81cfdcf..efc6d77fd 100644 --- a/src/components/Settings/AdminSettings/AdminPollCreation.vue +++ b/src/components/Settings/AdminSettings/AdminPollCreation.vue @@ -30,7 +30,7 @@ :multiple="true" :loading="isLoading" :placeholder="t('polls', 'Leave empty to disable globally')" - @option:selected="appSettingsStore.write()" + @update:model-value="appSettingsStore.write()" @search="appSettingsStore.loadGroups" /> diff --git a/src/components/Settings/AdminSettings/AdminPollDownload.vue b/src/components/Settings/AdminSettings/AdminPollDownload.vue index 76a14011f..f5a39e87e 100644 --- a/src/components/Settings/AdminSettings/AdminPollDownload.vue +++ b/src/components/Settings/AdminSettings/AdminPollDownload.vue @@ -31,7 +31,7 @@ :multiple="true" :loading="isLoading" :placeholder="t('polls', 'Leave empty to disable globally')" - @option:selected="appSettingsStore.write()" + @update:model-value="appSettingsStore.write()" @search="appSettingsStore.loadGroups" /> diff --git a/src/components/Settings/AdminSettings/AdminShareOpenPoll.vue b/src/components/Settings/AdminSettings/AdminShareOpenPoll.vue index ce5d8853c..60d9b5aaf 100644 --- a/src/components/Settings/AdminSettings/AdminShareOpenPoll.vue +++ b/src/components/Settings/AdminSettings/AdminShareOpenPoll.vue @@ -32,6 +32,7 @@ :multiple="true" :loading="isLoading" :placeholder="t('polls', 'Leave empty to disable globally')" + @update:model-value="appSettingsStore.write()" @search="appSettingsStore.loadGroups" /> diff --git a/src/components/Settings/AdminSettings/AdminSharePublicCreate.vue b/src/components/Settings/AdminSettings/AdminSharePublicCreate.vue index ab8985f7d..818b4e625 100644 --- a/src/components/Settings/AdminSettings/AdminSharePublicCreate.vue +++ b/src/components/Settings/AdminSettings/AdminSharePublicCreate.vue @@ -31,6 +31,7 @@ :multiple="true" :loading="isLoading" :placeholder="t('polls', 'Leave empty to disable globally')" + @update:model-value="appSettingsStore.write()" @search="appSettingsStore.loadGroups" /> diff --git a/src/components/Settings/AdminSettings/AdminShowMailAddresses.vue b/src/components/Settings/AdminSettings/AdminShowMailAddresses.vue index 482668dd7..64d9c78a3 100644 --- a/src/components/Settings/AdminSettings/AdminShowMailAddresses.vue +++ b/src/components/Settings/AdminSettings/AdminShowMailAddresses.vue @@ -31,7 +31,7 @@ :multiple="true" :loading="isLoading" :placeholder="t('polls', 'Leave empty to disable globally.')" - @option:selected="appSettingsStore.write()" + @update:model-value="appSettingsStore.write()" @search="appSettingsStore.loadGroups" /> diff --git a/src/components/Shares/SharePublicAdd.vue b/src/components/Shares/SharePublicAdd.vue index 322abaf38..652853c20 100644 --- a/src/components/Shares/SharePublicAdd.vue +++ b/src/components/Shares/SharePublicAdd.vue @@ -41,7 +41,7 @@ async function addPublicShare() { try { - await sharesStore.add(user) + await sharesStore.addPublicShare() } catch { showError(t('polls', 'Error adding public link')) } diff --git a/src/components/User/UserSearch.vue b/src/components/User/UserSearch.vue index 7c8d7e23a..e2885afc9 100644 --- a/src/components/User/UserSearch.vue +++ b/src/components/User/UserSearch.vue @@ -14,6 +14,7 @@ import { AppSettingsAPI } from '../../Api/index.js' import { Logger } from '../../helpers/index.ts' import { useSharesStore } from '../../stores/shares.ts' +import { User } from '../../Types/index.ts' const sharesStore = useSharesStore() const users = ref([]) @@ -39,14 +40,10 @@ } }, 250) - async function clickAdd(payload) { + async function clickAdd(user: User) { + Logger.debug('Adding share clicAdd', user) try { - await sharesStore.add({ - user: { - ...payload, - }, - }, - ) + await sharesStore.add(user) } catch { showError(t('polls', 'Error while adding share')) } diff --git a/src/stores/shares.ts b/src/stores/shares.ts index fb3b2ed3d..c004a5e67 100644 --- a/src/stores/shares.ts +++ b/src/stores/shares.ts @@ -90,8 +90,9 @@ export const useSharesStore = defineStore('shares', { async add(user: User ): Promise { const sessionStore = useSessionStore() + try { - await SharesAPI.addShare(sessionStore.route.params.id, user) + await SharesAPI.addUserShare(sessionStore.route.params.id, user) } catch (error) { if (error?.code === 'ERR_CANCELED') return Logger.error('Error writing share', { error, payload: user }) @@ -101,6 +102,19 @@ export const useSharesStore = defineStore('shares', { } }, + async addPublicShare(): Promise { + const sessionStore = useSessionStore() + try { + await SharesAPI.addPublicShare(sessionStore.route.params.id) + } catch (error) { + if (error?.code === 'ERR_CANCELED') return + Logger.error('Error writing share', { error}) + throw error + } finally { + this.load() + } + }, + update(payload: { share: Share }): void { const foundIndex = this.list.findIndex((share: Share) => share.id === payload.share.id) Object.assign(this.list[foundIndex], payload.share) From 384e223e5f15600bd092dad6d27670854003e0c3 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Thu, 10 Oct 2024 18:33:38 +0200 Subject: [PATCH 2/3] fix doc block Signed-off-by: dartcafe --- lib/Controller/ShareController.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index 249da48cd..cd8639a96 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -57,10 +57,6 @@ public function add(int $pollId, string $type, string $userId = '', string $disp /** * Add share * @param int $pollId poll id - * @param string $type Share type - * @param string $userId User id - * @param string $displayName Displayname of user - * @param string $emailAddress Email address of user */ #[NoAdminRequired] #[OpenAPI(OpenAPI::SCOPE_IGNORE)] From 869f48deb19c7187c920550631f7f323668d043a Mon Sep 17 00:00:00 2001 From: dartcafe Date: Fri, 11 Oct 2024 00:54:45 +0200 Subject: [PATCH 3/3] fix and lint Signed-off-by: dartcafe --- lib/Model/Settings/AppSettings.php | 1 - src/components/Shares/SharePublicAdd.vue | 18 +----------------- src/components/User/UserSearch.vue | 2 +- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/lib/Model/Settings/AppSettings.php b/lib/Model/Settings/AppSettings.php index 610ab767d..3f145dca8 100644 --- a/lib/Model/Settings/AppSettings.php +++ b/lib/Model/Settings/AppSettings.php @@ -12,7 +12,6 @@ use OCA\Polls\AppConstants; use OCA\Polls\Model\Group\Group; use OCA\Polls\UserSession; -// use OCP\AppFramework\Services\IAppConfig; use OCP\IAppConfig; class AppSettings implements JsonSerializable { diff --git a/src/components/Shares/SharePublicAdd.vue b/src/components/Shares/SharePublicAdd.vue index 652853c20..67ada84a5 100644 --- a/src/components/Shares/SharePublicAdd.vue +++ b/src/components/Shares/SharePublicAdd.vue @@ -13,7 +13,7 @@ import PlusIcon from 'vue-material-design-icons/Plus.vue' import UserItem from '../User/UserItem.vue' - import { User, UserType, VirtualUserItemType } from '../../Types/index.ts' + import { VirtualUserItemType } from '../../Types/index.ts' import { useSharesStore } from '../../stores/shares.ts' const sharesStore = useSharesStore() @@ -23,22 +23,6 @@ type: VirtualUserItemType.AddPublicLink, } - const user: User = { - id: '', - displayName: '', - emailAddress: '', - isNoUser: false, - type: UserType.None, - subName: null, - subtitle: null, - desc: null, - organisation: null, - languageCode: null, - localeCode: null, - timeZone: null, - categories: null, - } - async function addPublicShare() { try { await sharesStore.addPublicShare() diff --git a/src/components/User/UserSearch.vue b/src/components/User/UserSearch.vue index e2885afc9..b8a5f9af6 100644 --- a/src/components/User/UserSearch.vue +++ b/src/components/User/UserSearch.vue @@ -14,7 +14,7 @@ import { AppSettingsAPI } from '../../Api/index.js' import { Logger } from '../../helpers/index.ts' import { useSharesStore } from '../../stores/shares.ts' -import { User } from '../../Types/index.ts' + import { User } from '../../Types/index.ts' const sharesStore = useSharesStore() const users = ref([])