Skip to content

Commit

Permalink
Merge pull request #3744 from nextcloud/fix/user/next
Browse files Browse the repository at this point in the history
fixing some aftermath
  • Loading branch information
dartcafe authored Oct 8, 2024
2 parents eaeccc6 + 0d017cd commit 3855acc
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 88 deletions.
2 changes: 0 additions & 2 deletions lib/Model/Group/Circle.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
*/
class Circle extends UserBase {
public const TYPE = 'circle';
public const ICON = 'icon-circles';

private CirclesCircle $circle;

public function __construct(
string $id,
) {
parent::__construct($id, self::TYPE);
$this->icon = self::ICON;
$this->description = $this->l10n->t('Circle');
$this->richObjectType = 'circle';

Expand Down
2 changes: 0 additions & 2 deletions lib/Model/Group/ContactGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

class ContactGroup extends UserBase {
public const TYPE = 'contactGroup';
public const ICON = 'icon-group';

public function __construct(
string $id,
) {
parent::__construct($id, self::TYPE);
$this->icon = self::ICON;
$this->description = $this->l10n->t('Contact group');
$this->richObjectType = 'addressbook-contact';

Expand Down
2 changes: 0 additions & 2 deletions lib/Model/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

class Group extends UserBase {
public const TYPE = 'group';
public const ICON = 'icon-group';

private IGroup $group;

public function __construct(
string $id,
) {
parent::__construct($id, self::TYPE);
$this->icon = self::ICON;
$this->description = $this->l10n->t('Group');
$this->richObjectType = 'user-group';

Expand Down
1 change: 0 additions & 1 deletion lib/Model/User/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class Admin extends User {
public const TYPE = 'admin';
public const ICON = 'icon-settings';

public function __construct(string $id) {
parent::__construct($id, self::TYPE);
Expand Down
2 changes: 0 additions & 2 deletions lib/Model/User/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

class Contact extends UserBase {
public const TYPE = 'contact';
public const ICON = 'icon-mail';

protected LoggerInterface $logger;
private array $contact = [];

public function __construct(string $id) {
parent::__construct($id, self::TYPE);
$this->icon = self::ICON;
$this->description = $this->l10n->t('Contact');
$this->richObjectType = 'addressbook-contact';
$this->logger = Container::queryClass(LoggerInterface::class);
Expand Down
2 changes: 0 additions & 2 deletions lib/Model/User/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class Email extends UserBase {
public const TYPE = 'email';
public const ICON = 'icon-mail';

public function __construct(
string $id,
Expand All @@ -22,7 +21,6 @@ public function __construct(
string $languageCode = '',
) {
parent::__construct($id, self::TYPE, languageCode: $languageCode);
$this->icon = self::ICON;
$this->richObjectType = 'email';
$this->description = $emailAddress !== '' ? $emailAddress : $this->l10n->t('External Email');
$this->emailAddress = $emailAddress !== '' ? $emailAddress : $id;
Expand Down
4 changes: 0 additions & 4 deletions lib/Model/User/GenericUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

class GenericUser extends UserBase {
public const TYPE = 'external';
public const ICON_DEFAULT = 'icon-share';
public const ICON_PUBLIC = 'icon-public';

public function __construct(
string $id,
Expand All @@ -27,12 +25,10 @@ public function __construct(
) {
parent::__construct($id, $type, $displayName, $emailAddress, $languageCode, $localeCode, $timeZoneName);

$this->icon = self::ICON_DEFAULT;
$this->description = $this->l10n->t('External participant');
$this->richObjectType = 'guest';

if ($type === UserBase::TYPE_PUBLIC) {
$this->icon = self::ICON_PUBLIC;
// $this->description = $this->l10n->t('Public link');
$this->description = '';
}
Expand Down
1 change: 0 additions & 1 deletion lib/Model/User/Ghost.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class Ghost extends UserBase {
public const TYPE = 'deleted';
public const ICON = 'icon-ghost';

public function __construct(string $id) {
parent::__construct($id, self::TYPE);
Expand Down
3 changes: 0 additions & 3 deletions lib/Model/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class User extends UserBase {
/** @var string */
public const TYPE = 'user';
/** @var string */
public const ICON = 'icon-user';
/** @var string */
public const PRINCIPAL_PREFIX = 'principals/users/';

private IConfig $config;
Expand All @@ -30,7 +28,6 @@ public function __construct(
string $type = self::TYPE,
) {
parent::__construct($id, $type);
$this->icon = self::ICON;
$this->description = $this->l10n->t('User');

$this->setUp();
Expand Down
31 changes: 12 additions & 19 deletions lib/Model/UserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class UserBase implements JsonSerializable {
protected string $description = '';
protected string $richObjectType = 'user';
protected string $organisation = '';
protected string $icon = '';
protected IDateTimeZone $timeZone;
protected IGroupManager $groupManager;
protected IL10N $l10n;
Expand All @@ -71,7 +70,6 @@ public function __construct(
protected string $localeCode = '',
protected string $timeZoneName = '',
) {
$this->icon = 'icon-share';
$this->l10n = Container::getL10N();
$this->groupManager = Server::get(IGroupManager::class);
$this->timeZone = Server::get(IDateTimeZone::class);
Expand Down Expand Up @@ -185,13 +183,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 @@ -307,8 +298,6 @@ public function jsonSerialize(): array {
* without obfuscating/anonymizing
*
* @return (bool|string|string[])[]
*
* @psalm-return array{userId: string, displayName: string, emailAddress: string, subName: string, subtitle: string, isNoUser: bool, desc: string, type: string, id: string, user: string, organisation: string, languageCode: string, localeCode: string, timeZone: string, icon: string, categories: array<string>}
*/
public function getRichUserArray(): array {
return [
Expand All @@ -321,12 +310,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 +324,24 @@ 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)[]
*/
protected function getSimpleUserArray(): array {
return [
'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 +385,7 @@ public function getSafeDisplayName(): string {
}

// Function for obfuscating mail adresses; Default return the email address
public function getSafeEmailAddress(): string {
public function getSafeEmailAddress(): ?string {
// return real email address for cron jobs
if ($this->userSession->getUser()->getIsSystemUser()) {
return $this->getEmailAddress();
Expand All @@ -404,14 +397,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
Loading

0 comments on commit 3855acc

Please sign in to comment.