Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Util;

#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
Expand All @@ -40,6 +41,7 @@ public function __construct(
private IL10N $l10n,
private ?string $userId,
private DashboardService $service,
private IUserManager $userManager,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -71,6 +73,8 @@ public function index(): TemplateResponse {
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
$this->initialState->provideInitialState('firstRun', $this->userConfig->getValueBool($this->userId, 'dashboard', 'firstRun', true));
$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
$user = $this->userManager->get($this->userId);
$this->initialState->provideInitialState('displayLabel', $user?->getDisplayLabel() ?? '');
$this->userConfig->setValueBool($this->userId, 'dashboard', 'firstRun', false);

$response = new TemplateResponse('dashboard', 'index', [
Expand Down
16 changes: 7 additions & 9 deletions apps/dashboard/src/DashboardApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@
enabledStatuses: loadState('dashboard', 'statuses'),
panels,
firstRun,
displayName: getCurrentUser()?.displayName,
uid: getCurrentUser()?.uid,
displayLabel: loadState('dashboard', 'displayLabel', ''),
modal: false,
appStoreUrl: generateUrl('/settings/apps/dashboard'),
appStoreEnabled: loadState('dashboard', 'appStoreEnabled', true),
Expand Down Expand Up @@ -267,33 +266,32 @@
const good = {
morning: {
generic: t('dashboard', 'Good morning'),
withName: t('dashboard', 'Good morning, {name}', { name: this.displayName }, { escape: false }),
withName: t('dashboard', 'Good morning, {name}', { name: this.displayLabel }, { escape: false }),
},

afternoon: {
generic: t('dashboard', 'Good afternoon'),
withName: t('dashboard', 'Good afternoon, {name}', { name: this.displayName }, { escape: false }),
withName: t('dashboard', 'Good afternoon, {name}', { name: this.displayLabel }, { escape: false }),
},

evening: {
generic: t('dashboard', 'Good evening'),
withName: t('dashboard', 'Good evening, {name}', { name: this.displayName }, { escape: false }),
withName: t('dashboard', 'Good evening, {name}', { name: this.displayLabel }, { escape: false }),
},

night: {
// Don't use "Good night" as it's not a greeting
generic: t('dashboard', 'Hello') /* TRANSLATORS: Greeting to be used at night (in English there is no specific greeting, think of it like "good morning") */,
withName: t('dashboard', 'Hello, {name}', { name: this.displayName }, { escape: false }) /* TRANSLATORS: Greeting to be used at night (in English there is no specific greeting, think of it like "Good morning, J. Doe" but at night) */,
withName: t('dashboard', 'Hello, {name}', { name: this.displayLabel }, { escape: false }) /* TRANSLATORS: Greeting to be used at night (in English there is no specific greeting, think of it like "Good morning, J. Doe" but at night) */,
},

birthday: {
generic: t('dashboard', 'Happy birthday 🥳🤩🎂🎉'),
withName: t('dashboard', 'Happy birthday, {name} 🥳🤩🎂🎉', { name: this.displayName }, { escape: false }),
withName: t('dashboard', 'Happy birthday, {name} 🥳🤩🎂🎉', { name: this.displayLabel }, { escape: false }),
},
}

// Figure out which greeting to show
const shouldShowName = this.displayName && this.uid !== this.displayName
const shouldShowName = this.displayLabel !== ''
return { text: shouldShowName ? good[partOfDay].withName : good[partOfDay].generic }
},

Expand Down Expand Up @@ -372,7 +370,7 @@
* Method to register panels that will be called by the integrating apps
*
* @param {string} app The unique app id for the widget
* @param {Function} callback The callback function to register a panel which gets the DOM element passed as parameter

Check warning on line 373 in apps/dashboard/src/DashboardApp.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Prefer a more specific type to `Function`
*/
register(app, callback) {
this.callbacks[app] = callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ protected function getUserData(string $userId, bool $includeScopes = false): ?ar
$data[self::USER_FIELD_NOTIFICATION_EMAIL] = $targetUserObject->getPrimaryEMailAddress();

$backend = $targetUserObject->getBackend();
$data['displayLabel'] = $targetUserObject->getDisplayLabel();
$data['backendCapabilities'] = [
'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME),
'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD),
Expand Down
4 changes: 1 addition & 3 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,7 @@ public function editUserMultiField(

// Apply remaining changes — all fully validated, setters won't throw
if ($displayName !== null) {
// OC\User\User::setDisplayName() rejects empty strings (!empty check),
// so "clear display name" means "reset to userId" — the default.
$targetUser->setDisplayName($displayName !== '' ? $displayName : $userId);
$targetUser->setDisplayName($displayName);
}

if ($email !== null) {
Expand Down
1 change: 1 addition & 0 deletions apps/provisioning_api/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* biographyScope?: Provisioning_APIUserDetailsScope,
* display-name: string,
* displayname: string,
* displayLabel: string,
* displaynameScope?: Provisioning_APIUserDetailsScope,
* email: ?string,
* emailScope?: Provisioning_APIUserDetailsScope,
Expand Down
4 changes: 4 additions & 0 deletions apps/provisioning_api/openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"biography",
"display-name",
"displayname",
"displayLabel",
"email",
"fediverse",
"groups",
Expand Down Expand Up @@ -162,6 +163,9 @@
"displayname": {
"type": "string"
},
"displayLabel": {
"type": "string"
},
"displaynameScope": {
"$ref": "#/components/schemas/UserDetailsScope"
},
Expand Down
4 changes: 4 additions & 0 deletions apps/provisioning_api/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"biography",
"display-name",
"displayname",
"displayLabel",
"email",
"fediverse",
"groups",
Expand Down Expand Up @@ -209,6 +210,9 @@
"displayname": {
"type": "string"
},
"displayLabel": {
"type": "string"
},
"displaynameScope": {
"$ref": "#/components/schemas/UserDetailsScope"
},
Expand Down
4 changes: 4 additions & 0 deletions apps/provisioning_api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"biography",
"display-name",
"displayname",
"displayLabel",
"email",
"fediverse",
"groups",
Expand Down Expand Up @@ -209,6 +210,9 @@
"displayname": {
"type": "string"
},
"displayLabel": {
"type": "string"
},
"displaynameScope": {
"$ref": "#/components/schemas/UserDetailsScope"
},
Expand Down
20 changes: 17 additions & 3 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,10 @@ public function testGetUserDataAsAdmin(): void {
->expects($this->once())
->method('getDisplayName')
->willReturn('Demo User');
$targetUser
->expects($this->once())
->method('getDisplayLabel')
->willReturn('Demo User');
$targetUser
->expects($this->once())
->method('getHome')
Expand Down Expand Up @@ -1696,6 +1700,7 @@ public function testGetUserDataAsAdmin(): void {
'email' => 'demo@nextcloud.com',
'displayname' => 'Demo User',
'display-name' => 'Demo User',
'displayLabel' => 'Demo User',
'phone' => 'phone',
'address' => 'address',
'website' => 'website',
Expand Down Expand Up @@ -1788,6 +1793,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible(): void {
->expects($this->once())
->method('getDisplayName')
->willReturn('Demo User');
$targetUser
->expects($this->once())
->method('getDisplayLabel')
->willReturn('Demo User');
$targetUser
->expects($this->never())
->method('getHome');
Expand Down Expand Up @@ -1844,6 +1853,7 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible(): void {
'email' => 'demo@nextcloud.com',
'displayname' => 'Demo User',
'display-name' => 'Demo User',
'displayLabel' => 'Demo User',
'phone' => 'phone',
'address' => 'address',
'website' => 'website',
Expand Down Expand Up @@ -1970,6 +1980,10 @@ public function testGetUserDataAsSubAdminSelfLookup(): void {
->expects($this->once())
->method('getDisplayName')
->willReturn('Subadmin User');
$targetUser
->expects($this->once())
->method('getDisplayLabel')
->willReturn('Subadmin User');
$targetUser
->expects($this->once())
->method('getSystemEMailAddress')
Expand Down Expand Up @@ -2028,6 +2042,7 @@ public function testGetUserDataAsSubAdminSelfLookup(): void {
'email' => 'subadmin@nextcloud.com',
'displayname' => 'Subadmin User',
'display-name' => 'Subadmin User',
'displayLabel' => 'Subadmin User',
'phone' => 'phone',
'address' => 'address',
'website' => 'website',
Expand Down Expand Up @@ -3554,7 +3569,7 @@ public function testUpdateUserForceLanguageBlocksNonAdmin(): void {
$this->assertArrayHasKey('language', $result->getData()['errors']);
}

public function testEditUserMultiFieldClearDisplayNameResetsToUserId(): void {
public function testEditUserMultiFieldClearDisplayName(): void {
$currentUser = $this->createMock(IUser::class);
$currentUser->method('getUID')->willReturn('admin');
$this->userSession->method('getUser')->willReturn($currentUser);
Expand All @@ -3572,8 +3587,7 @@ public function testEditUserMultiFieldClearDisplayNameResetsToUserId(): void {
$subAdmin = $this->createMock(ISubAdmin::class);
$this->groupManager->method('getSubAdmin')->willReturn($subAdmin);

// Clearing display name (empty string) should reset to userId
$targetUser->expects($this->once())->method('setDisplayName')->with('targetuser')->willReturn(true);
$targetUser->expects($this->once())->method('setDisplayName')->with('')->willReturn(true);

$result = $this->api->editUserMultiField('targetuser', displayName: '');
$this->assertSame(Http::STATUS_OK, $result->getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function getForm(): TemplateResponse {
'usage' => Util::humanFileSize($storageInfo['used']),
'usageRelative' => round($storageInfo['relative']),
'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME),
'displayLabel' => $user->getDisplayLabel(),
'statusMessage' => $statusMessage,
'emailMap' => $this->getEmailMap($account),
'phone' => $this->getProperty($account, IAccountManager::PROPERTY_PHONE),
Expand Down
1 change: 1 addition & 0 deletions apps/settings/src/components/Users/userFormUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('userToFormData', () => {
const user = {
id: 'bob',
displayname: 'Bob Smith',
displayLabel: 'Bob Smith',
email: 'bob@example.com',
groups: ['admin', 'devs'],
subadmin: ['devs'],
Expand Down
4 changes: 2 additions & 2 deletions apps/settings/src/components/Users/userFormUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function resolveLanguage(user, serverLanguages): LanguageOption {

/**
* Maps a user store object to the flat, API-aligned shape used by the form.
* Keeps a clean separation between the store model (e.g. `user.displayname`,
* Keeps a clean separation between the store model (e.g. `user.displayLabel`,
* `user.quota.quota`) and the form model (e.g. `displayName`, `quota`).
*
* @param user The user store object
Expand Down Expand Up @@ -99,7 +99,7 @@ export function userToFormData(user, allGroups, quotaOptions, serverLanguages) {

return {
username: user.id,
displayName: user.displayname ?? '',
displayName: user.displayLabel ?? '',
password: '',
email: user.email ?? '',
groups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import { ref } from 'vue'
import AccountPropertySection from './shared/AccountPropertySection.vue'
import { NAME_READABLE_ENUM } from '../../../constants/AccountPropertyConstants.ts'

const { displayName } = loadState<{ displayName: IAccountProperty }>('settings', 'personalInfoParameters')
const { displayName, displayLabel } = loadState<{
displayName: IAccountProperty
displayLabel: string
}>('settings', 'personalInfoParameters')
const { displayNameChangeSupported } = loadState<{ displayNameChangeSupported: boolean }>('settings', 'accountParameters')
const property = ref({ ...displayName, readable: NAME_READABLE_ENUM[displayName.name] })

/**
* @param value The entered display name
*/
function onValidate(value: string): boolean {
return value !== ''
}
const property = ref({ ...displayName, value: displayLabel, readable: NAME_READABLE_ENUM[displayName.name] })

/**
* @param value The saved display name
Expand All @@ -44,6 +40,5 @@ function onSave(value: string) {
:placeholder="t('settings', 'Your full name')"
autocomplete="username"
:disabled="!displayNameChangeSupported"
:onValidate="onValidate"
:onSave="onSave" />
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const loading = ref(false)
* @param newDisplayName The saved display name
*/
function handleDisplayNameUpdate(newDisplayName: string) {
displayName.value = newDisplayName
displayName.value = newDisplayName || userId
}

onMounted(() => subscribe('settings:display-name:updated', handleDisplayNameUpdate))
Expand Down
1 change: 1 addition & 0 deletions apps/settings/src/views/user-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export interface IUser {
id: string
displayname: string
displayLabel?: string
email: string | null
groups: string[]
subadmin: string[]
Expand Down
13 changes: 13 additions & 0 deletions lib/private/User/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ public function getDisplayName($uid): string {
return empty($this->cache[$uid]['displayname']) ? $uid : $this->cache[$uid]['displayname'];
}

/**
* Display name stored in the users table, or an empty string when none is set.
*/
public function getDisplayLabel(string $uid): string {
$this->loadUser($uid);
$cached = $this->cache[$uid] ?? false;
if (!is_array($cached)) {
return '';
}

return (string)($cached['displayname'] ?? '');
}

/**
* Get a list of all display names and user ids.
*
Expand Down
5 changes: 5 additions & 0 deletions lib/private/User/LazyUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public function getDisplayName(): string {
return $this->userManager->getDisplayName($this->uid) ?? $this->uid;
}

#[\Override]
public function getDisplayLabel(): string {
return $this->getUser()->getDisplayLabel();
}

#[\Override]
public function setDisplayName($displayName): bool {
return $this->getUser()->setDisplayName($displayName);
Expand Down
Loading
Loading