Skip to content

Commit

Permalink
fixing some aftermath
Browse files Browse the repository at this point in the history
Signed-off-by: dartcafe <[email protected]>
  • Loading branch information
dartcafe committed Oct 8, 2024
1 parent eaeccc6 commit 34817c3
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 65 deletions.
29 changes: 14 additions & 15 deletions lib/Model/UserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,6 @@ public function getSubName(): string {
return $this->getDescription();
}

/**
* @deprecated Not used anymore?
*/
private function getIcon(): string {
return $this->icon;
}

public function getEmailAddress(): string {
return $this->emailAddress;
}
Expand Down Expand Up @@ -321,12 +314,10 @@ public function getRichUserArray(): array {
'desc' => $this->getDescription(),
'type' => $this->getType(),
'id' => $this->getId(),
'user' => $this->getId(),
'organisation' => $this->getOrganisation(),
'languageCode' => $this->getLanguageCode(),
'localeCode' => $this->getLocaleCode(),
'timeZone' => $this->getTimeZoneName(),
'icon' => $this->getIcon(),
'categories' => $this->getCategories(),
];
}
Expand All @@ -337,18 +328,26 @@ public function getRichUserArray(): array {

/**
* Simply user array returning safe attributes
* @return (bool|string)[]
*
* @psalm-return array{id: string, userId: string, displayName: string, emailAddress: string, isNoUser: bool, type: string}
* @return (bool|null|string)[]
*
* @psalm-return array{id: string, displayName: string, emailAddress: string, isNoUser: bool, type: string, subName: null, subtitle: null, desc: null, user: null, organisation: null, languageCode: null, localeCode: null, timeZone: null, icon: null, categories: null}

Check failure on line 334 in lib/Model/UserBase.php

View workflow job for this annotation

GitHub Actions / Psalm (master, 8.1)

MoreSpecificReturnType

lib/Model/UserBase.php:334:19: MoreSpecificReturnType: The declared return type 'array{categories: null, desc: null, displayName: string, emailAddress: string, icon: null, id: string, isNoUser: bool, languageCode: null, localeCode: null, organisation: null, subName: null, subtitle: null, timeZone: null, type: string, user: null}' for OCA\Polls\Model\UserBase::getSimpleUserArray is more specific than the inferred return type 'array{categories: null, desc: null, displayName: string, emailAddress: null|string, id: string, isNoUser: bool, languageCode: null, localeCode: null, organisation: null, subName: null, subtitle: null, timeZone: null, type: string}' (see https://psalm.dev/070)
*/
protected function getSimpleUserArray(): array {
return [

Check failure on line 337 in lib/Model/UserBase.php

View workflow job for this annotation

GitHub Actions / Psalm (master, 8.1)

LessSpecificReturnStatement

lib/Model/UserBase.php:337:10: LessSpecificReturnStatement: The type 'array{categories: null, desc: null, displayName: string, emailAddress: null|string, id: string, isNoUser: bool, languageCode: null, localeCode: null, organisation: null, subName: null, subtitle: null, timeZone: null, type: string}' is more general than the declared return type 'array{categories: null, desc: null, displayName: string, emailAddress: string, icon: null, id: string, isNoUser: bool, languageCode: null, localeCode: null, organisation: null, subName: null, subtitle: null, timeZone: null, type: string, user: null}' for OCA\Polls\Model\UserBase::getSimpleUserArray (see https://psalm.dev/129)
'id' => $this->getSafeId(),
'userId' => $this->getSafeId(),
'displayName' => $this->getSafeDisplayName(),
'emailAddress' => $this->getSafeEmailAddress(),
'isNoUser' => $this->getIsNoUser(),
'type' => $this->getSafeType(),
'subName' => null,
'subtitle' => null,
'desc' => null,
'organisation' => null,
'languageCode' => null,
'localeCode' => null,
'timeZone' => null,
'categories' => null,
];
}

Expand Down Expand Up @@ -392,7 +391,7 @@ public function getSafeDisplayName(): string {
}

// Function for obfuscating mail adresses; Default return the email address
public function getSafeEmailAddress(): string {
public function getSafeEmailAddress(): string | null {
// return real email address for cron jobs
if ($this->userSession->getUser()->getIsSystemUser()) {
return $this->getEmailAddress();
Expand All @@ -404,14 +403,14 @@ public function getSafeEmailAddress(): string {
}

if ($this->anonymizeLevel === EntityWithUser::ANON_FULL) {
return '';
return null;
}

if ($this->appSettings->getAllowSeeMailAddresses()) {
return $this->getEmailAddress();
}

return '';
return null;
}

public function getOrganisation(): string {
Expand Down
22 changes: 10 additions & 12 deletions src/Types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,22 @@ export type AppPermissions = {
}

export type User = {
id: string
displayName: string
emailAddress: string
subName: string
subtitle: string
emailAddress: string | null
isNoUser: boolean
desc: string
type: UserType
id: string
organisation: string
languageCode: string
localeCode: string
timeZone: string
categories: string[]
subName: string | null
subtitle: string | null
desc: string | null
organisation: string | null
languageCode: string | null
localeCode: string | null
timeZone: string | null
categories: string[] | null
}

export type Participant = {
userId: string
displayName: string
pollId: number
user: User
}
Expand Down
23 changes: 15 additions & 8 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 { VirtualUserItemType } from '../../Types/index.ts'
import { User, UserType, VirtualUserItemType } from '../../Types/index.ts'
import { useSharesStore } from '../../stores/shares.ts'
const sharesStore = useSharesStore()
Expand All @@ -23,13 +23,20 @@
type: VirtualUserItemType.AddPublicLink,
}
const user = {
user: {
type: 'public',
userId: '',
displayName: '',
emailAddress: '',
},
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() {
Expand Down
10 changes: 9 additions & 1 deletion src/components/User/UserItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@
displayName: '',
emailAddress: '',
isNoUser: true,
type: null,
type: UserType.None,
subName: null,
subtitle: null,
desc: null,
organisation: null,
languageCode: null,
localeCode: null,
timeZone: null,
categories: null,
}
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/VoteTable/VoteTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
</div>

<div v-for="(participant) in pollStore.safeParticipants"
:key="participant.user.id"
:class="['participant', {'current-user': (participant.user.id === sessionStore.currentUser.id) }]">
:key="participant.id"
:class="['participant', {'current-user': (participant.id === sessionStore.currentUser.id) }]">
<UserItem :user="participant" condensed />

<ActionDelete v-if="pollStore.permissions.edit"
class="user-actions"
:name="t('polls', 'Delete votes')"
@delete="removeUser(participant.user.id)" />
@delete="removeUser(participant.id)" />
</div>

<div v-if="optionsStore.proposalsExist" class="owner" />
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/modules/arrayHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const uniqueOptions = (options: Option[]) =>

const uniqueParticipants = (votes: Vote[]): Participant[] => {
const participants: Participant[] = votes.map((vote) => ({
userId: vote.user.id,
displayName: vote.user.displayName,
isNoUser: vote.user.isNoUser,
user: vote.user,
pollId: vote.pollId,
}))
Expand Down
32 changes: 12 additions & 20 deletions src/stores/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,19 @@ export const usePollStore = defineStore('poll', {
maxVotesPerUser: 0,
},
owner: {
id: '',
displayName: '',
emailAddress: '',
subName: '',
subtitle: '',
isNoUser: false,
desc: '',
type: UserType.User,
id: '',
organisation: '',
languageCode: '',
localeCode: '',
timeZone: '',
categories: [],
type: UserType.None,
subName: null,
subtitle: null,
desc: null,
organisation: null,
languageCode: null,
localeCode: null,
timeZone: null,
categories: null,
},
status: {
lastInteraction: 0,
Expand Down Expand Up @@ -241,11 +241,7 @@ export const usePollStore = defineStore('poll', {

// add current user, if not among participants and voting is allowed
if (!participants.find((participant: User) => participant.id === sessionStore.currentUser.id) && sessionStore.currentUser.id && state.permissions.vote) {
participants.push({
id: sessionStore.currentUser.id,
displayName: sessionStore.currentUser.displayName,
isNoUser: sessionStore.currentUser.isNoUser,
})
participants.push(sessionStore.currentUser)
}

return participants
Expand All @@ -254,11 +250,7 @@ export const usePollStore = defineStore('poll', {
safeParticipants() {
const sessionStore = useSessionStore()
if (this.getSafeTable) {
return [{
id: sessionStore.currentUser.id,
displayName: sessionStore.currentUser.displayName,
isNoUser: sessionStore.currentUser.isNoUser,
}]
return [sessionStore.currentUser]
}
return this.participants
},
Expand Down
6 changes: 3 additions & 3 deletions src/stores/shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ export const useSharesStore = defineStore('shares', {
}
},

async add(payload: { user: { type: string, userId: string, displayName: string, emailAddress: string }} ): Promise<void> {
async add(user: User ): Promise<void> {
const sessionStore = useSessionStore()
try {
await SharesAPI.addShare(sessionStore.route.params.id, payload.user)
await SharesAPI.addShare(sessionStore.route.params.id, user)
} catch (error) {
if (error?.code === 'ERR_CANCELED') return
Logger.error('Error writing share', { error, payload })
Logger.error('Error writing share', { error, payload: user })
throw error
} finally {
this.load()
Expand Down

0 comments on commit 34817c3

Please sign in to comment.