Skip to content

Commit

Permalink
Merge pull request #3748 from nextcloud/fix/fixes/next
Browse files Browse the repository at this point in the history
more fixes and optimizations after tests
  • Loading branch information
dartcafe authored Oct 10, 2024
2 parents 8586c77 + 869f48d commit c5db5c6
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 45 deletions.
11 changes: 11 additions & 0 deletions lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ 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
*/
#[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
2 changes: 0 additions & 2 deletions lib/Model/Settings/AppSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -239,7 +238,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
20 changes: 2 additions & 18 deletions src/components/Shares/SharePublicAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -23,25 +23,9 @@
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.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'
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 c5db5c6

Please sign in to comment.