Skip to content

Commit

Permalink
more fixes and optimizations after tests
Browse files Browse the repository at this point in the history
Signed-off-by: dartcafe <github@dartcafe.de>
  • Loading branch information
dartcafe committed Oct 10, 2024
1 parent 8586c77 commit c08482d
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 27 deletions.
15 changes: 15 additions & 0 deletions lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 60 in lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / Psalm (stable29, 8.1)

UnusedDocblockParam

lib/Controller/ShareController.php:60:19: UnusedDocblockParam: Docblock parameter $type in docblock for OCA\Polls\Controller\ShareController::addPublicShare does not have a counterpart in signature parameter list (see https://psalm.dev/319)
* @param string $userId User id

Check failure on line 61 in lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / Psalm (stable29, 8.1)

UnusedDocblockParam

lib/Controller/ShareController.php:61:19: UnusedDocblockParam: Docblock parameter $userId in docblock for OCA\Polls\Controller\ShareController::addPublicShare does not have a counterpart in signature parameter list (see https://psalm.dev/319)
* @param string $displayName Displayname of user

Check failure on line 62 in lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / Psalm (stable29, 8.1)

UnusedDocblockParam

lib/Controller/ShareController.php:62:19: UnusedDocblockParam: Docblock parameter $displayName in docblock for OCA\Polls\Controller\ShareController::addPublicShare does not have a counterpart in signature parameter list (see https://psalm.dev/319)
* @param string $emailAddress Email address of user

Check failure on line 63 in lib/Controller/ShareController.php

View workflow job for this annotation

GitHub Actions / Psalm (stable29, 8.1)

UnusedDocblockParam

lib/Controller/ShareController.php:63:19: UnusedDocblockParam: Docblock parameter $emailAddress in docblock for OCA\Polls\Controller\ShareController::addPublicShare does not have a counterpart in signature parameter list (see https://psalm.dev/319)
*/
#[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
Expand Down
1 change: 0 additions & 1 deletion lib/Model/Settings/AppSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
14 changes: 11 additions & 3 deletions src/Api/modules/shares.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
},

Expand Down
7 changes: 3 additions & 4 deletions src/components/Base/modules/InputDiv.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

if (model.value !== nextValue) {
model.value = nextValue
emit('submit')
emit('change')
}
}

Expand All @@ -163,7 +163,7 @@

if (model.value !== nextValue) {
model.value = nextValue
emit('submit')
emit('change')
}
}

Expand All @@ -173,7 +173,6 @@

</script>


<template>
<div :class="['input-div', { numeric: useNumModifiers }]">
<label v-if="label">
Expand All @@ -195,7 +194,7 @@
<Spinner v-if="checking" class="signaling-icon spinner" />
<AlertIcon v-else-if="error" class="signaling-icon error" />
<CheckIcon v-else-if="success" class="signaling-icon success" />
<ArrowRightIcon v-else-if="showSubmit" class="signaling-icon submit" @click="emit('change')" />
<ArrowRightIcon v-else-if="showSubmit" class="signaling-icon submit" @click="emit('submit')" />
<MinusIcon v-if="useNumModifiers" class="modifier subtract" @click="subtract()" />
<PlusIcon v-if="useNumModifiers" class="modifier add" @click="add()" />
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/components/Comments/CommentAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
class="comment-add__input"
:placeholder="t('polls', 'New comment …')"
submit
@submit="writeComment()"
@change="writeComment()" />
@submit="writeComment()" />
</div>
</template>

Expand Down
1 change: 0 additions & 1 deletion src/components/Configuration/ConfigOptionLimit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
inputmode="numeric"
:num-min="1"
use-num-modifiers
@submit="pollStore.write()"
@change="pollStore.write()" />

<NcCheckboxRadioSwitch v-if="pollStore.configuration.maxVotesPerOption"
Expand Down
1 change: 0 additions & 1 deletion src/components/Configuration/ConfigVoteLimit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
:num-min="1"
:num-max="optionsStore.list.length"
num-wrap
@submit="pollStore.write()"
@change="pollStore.write()"/>
</div>
</template>
2 changes: 1 addition & 1 deletion src/components/Settings/AdminSettings/AdminCombo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
:multiple="true"
:loading="isLoading"
:placeholder="t('polls', 'Leave empty to disable globally')"
@update:model-value="appSettingsStore.write()"
@search="appSettingsStore.loadGroups" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
:multiple="true"
:loading="isLoading"
:placeholder="t('polls', 'Leave empty to disable globally')"
@update:model-value="appSettingsStore.write()"
@search="appSettingsStore.loadGroups" />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Shares/SharePublicAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

async function addPublicShare() {
try {
await sharesStore.add(user)
await sharesStore.addPublicShare()
} catch {
showError(t('polls', 'Error adding public link'))
}
Expand Down
11 changes: 4 additions & 7 deletions src/components/User/UserSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check failure on line 17 in src/components/User/UserSearch.vue

View workflow job for this annotation

GitHub Actions / ESLint

Expected indentation of 1 tab but found 0 tabs

const sharesStore = useSharesStore()
const users = ref([])
Expand All @@ -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'))
}
Expand Down
16 changes: 15 additions & 1 deletion src/stores/shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export const useSharesStore = defineStore('shares', {

async add(user: User ): Promise<void> {
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 })
Expand All @@ -101,6 +102,19 @@ export const useSharesStore = defineStore('shares', {
}
},

async addPublicShare(): Promise<void> {
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)
Expand Down

0 comments on commit c08482d

Please sign in to comment.