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
1 change: 1 addition & 0 deletions apps/settings/lib/Settings/Admin/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function getForm() {
'restrictUserEnumerationFullMatchDisplayname' => $this->shareManager->matchDisplayName(),
'restrictUserEnumerationFullMatchEmail' => $this->shareManager->matchEmail(),
'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->shareManager->ignoreSecondDisplayName(),
'showAccountEmail' => $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_SHOW_ACCOUNT_EMAIL),
'enforceLinksPassword' => $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_ENFORCED),
'enforceLinksPasswordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [],
'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ describe('AdminSettingsSharingForm', () => {
expect(mocks.setCoreConfigValue).toHaveBeenCalledWith('shareapi_allow_links', 'no')
})

it('stores whether email addresses of other accounts are shown', async () => {
mocks.settings.showAccountEmail = true
const { getByRole } = render(AdminSettingsSharingForm)

await fireEvent.click(getByRole('switch', { name: 'Show email addresses of other accounts in the contacts menu and in account name autocompletion' }))

expect(mocks.setCoreConfigValue).toHaveBeenCalledOnce()
expect(mocks.setCoreConfigValue).toHaveBeenCalledWith('shareapi_show_account_email', 'no')
})

it('stores the group sharing limitation', async () => {
const { getByRole } = render(AdminSettingsSharingForm)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ async function saveDisclaimer(text: string) {
</NcCheckboxRadioSwitch>
</fieldset>

<NcCheckboxRadioSwitch v-model="settings.showAccountEmail" type="switch">
{{ t('settings', 'Show email addresses of other accounts in the contacts menu and in account name autocompletion') }}
</NcCheckboxRadioSwitch>

<NcCheckboxRadioSwitch v-model="isDisclaimerEnabled" type="switch">
{{ t('settings', 'Show disclaimer text on the public link upload page (only shown when the file list is hidden)') }}
</NcCheckboxRadioSwitch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('useSharingSettings', () => {
['allowLinks', false, 'shareapi_allow_links', 'no'],
['enabled', true, 'shareapi_enabled', 'yes'],
['restrictUserEnumerationFullMatchIgnoreSecondDN', true, 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'yes'],
['showAccountEmail', false, 'shareapi_show_account_email', 'no'],
['excludeGroupsList', ['admin', 'group 1'], 'shareapi_exclude_groups_list', '["admin","group 1"]'],
['expireAfterNDays', '14', 'shareapi_expire_after_n_days', '14'],
['internalExpireAfterNDays', '3', 'shareapi_internal_expire_after_n_days', '3'],
Expand Down
1 change: 1 addition & 0 deletions apps/settings/src/sections/sharing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ISharingSettings {
restrictUserEnumerationFullMatchDisplayname: boolean
restrictUserEnumerationFullMatchEmail: boolean
restrictUserEnumerationFullMatchIgnoreSecondDN: boolean
showAccountEmail: boolean
enforceLinksPassword: boolean
enforceLinksPasswordExcludedGroups: string[]
enforceLinksPasswordExcludedGroupsEnabled: boolean
Expand Down
4 changes: 4 additions & 0 deletions apps/settings/tests/Settings/Admin/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function testGetFormWithoutExcludedGroups(): void {
['core', 'shareapi_enforce_links_password', false],
['core', 'shareapi_default_expire_date', false],
['core', 'shareapi_enforce_expire_date', false],
['core', 'shareapi_show_account_email', true],
]);

$this->config
Expand Down Expand Up @@ -128,6 +129,7 @@ public function testGetFormWithoutExcludedGroups(): void {
'restrictUserEnumerationFullMatchDisplayname' => true,
'restrictUserEnumerationFullMatchEmail' => true,
'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
'showAccountEmail' => true,
'enforceLinksPassword' => false,
'onlyShareWithGroupMembers' => false,
'enabled' => true,
Expand Down Expand Up @@ -172,6 +174,7 @@ public function testGetFormWithExcludedGroups(): void {
['core', 'shareapi_enforce_links_password', false],
['core', 'shareapi_default_expire_date', false],
['core', 'shareapi_enforce_expire_date', false],
['core', 'shareapi_show_account_email', true],
]);

$this->config
Expand Down Expand Up @@ -237,6 +240,7 @@ public function testGetFormWithExcludedGroups(): void {
'restrictUserEnumerationFullMatchDisplayname' => true,
'restrictUserEnumerationFullMatchEmail' => true,
'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
'showAccountEmail' => true,
'enforceLinksPassword' => false,
'onlyShareWithGroupMembers' => false,
'enabled' => true,
Expand Down
7 changes: 7 additions & 0 deletions core/AppInfo/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ConfigLexicon implements ILexicon {
public const SHARE_LINK_PASSWORD_ENFORCED = 'shareapi_enforce_links_password';
public const SHARE_LINK_EXPIRE_DATE_DEFAULT = 'shareapi_default_expire_date';
public const SHARE_LINK_EXPIRE_DATE_ENFORCED = 'shareapi_enforce_expire_date';
public const SHARE_SHOW_ACCOUNT_EMAIL = 'shareapi_show_account_email';
public const USER_LANGUAGE = 'lang';
public const OCM_DISCOVERY_ENABLED = 'ocm_discovery_enabled';
public const DAV_REPAIR_REMOVED_BROKEN_PROPERTIES = 'dav_repair_removed_broken_properties';
Expand Down Expand Up @@ -98,6 +99,12 @@ public function getAppConfigs(): array {
},
definition: 'Enforce expiration date for shares via link or mail'
),
new Entry(
key: self::SHARE_SHOW_ACCOUNT_EMAIL,
type: ValueType::BOOL,
defaultRaw: true,
definition: 'Show the email address of accounts to other accounts in the contacts menu and in sharee search results',
),
new Entry(self::LASTCRON_TIMESTAMP, ValueType::INT, 0, 'timestamp of last cron execution'),
new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM'),
new Entry(self::UNIFIED_SEARCH_MIN_SEARCH_LENGTH, ValueType::INT, 1, 'Minimum search length to trigger the request', rename: 'unified-search.min-search-length'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OC\KnownUser\KnownUserService;
use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
Expand All @@ -33,6 +34,7 @@ public function __construct(
IUserSession $userSession,
IEmailValidator $emailValidator,
IUserManager $userManager,
IAppConfig $appConfig,
mixed $shareWithGroupOnlyExcludeGroupsList = [],
) {
parent::__construct(
Expand All @@ -44,6 +46,7 @@ public function __construct(
$userSession,
$emailValidator,
$userManager,
$appConfig,
$shareWithGroupOnlyExcludeGroupsList,
IShare::TYPE_EMAIL,
);
Expand Down
48 changes: 28 additions & 20 deletions lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

namespace OC\Collaboration\Collaborators;

use OC\Core\AppInfo\ConfigLexicon;
use OC\KnownUser\KnownUserService;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\Contacts\IManager;
use OCP\Federation\ICloudId;
use OCP\Federation\ICloudIdManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
Expand All @@ -36,6 +38,8 @@ class MailPlugin implements ISearchPlugin {

protected bool $shareeEnumerationFullMatchEmail;

protected bool $showAccountEMail;

public function __construct(
private IManager $contactsManager,
private ICloudIdManager $cloudIdManager,
Expand All @@ -45,6 +49,7 @@ public function __construct(
private IUserSession $userSession,
private IEmailValidator $emailValidator,
private IUserManager $userManager,
private IAppConfig $appConfig,
private mixed $shareWithGroupOnlyExcludeGroupsList,
private int $shareType,
) {
Expand All @@ -54,6 +59,7 @@ public function __construct(
$this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
$this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes';
$this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes';
$this->showAccountEMail = $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_SHOW_ACCOUNT_EMAIL);

if ($this->shareWithGroupOnly) {
$this->shareWithGroupOnlyExcludeGroupsList = json_decode($this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''), true) ?? [];
Expand Down Expand Up @@ -145,16 +151,7 @@ public function search(string $search, int $limit, int $offset, ISearchResult $s
}

if ($this->shareType === IShare::TYPE_USER && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($type, $cloud->getUser())) {
$singleResult = [[
'label' => $displayName,
'uuid' => $contact['UID'] ?? $emailAddress,
'name' => $contact['FN'] ?? $displayName,
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => $cloud->getUser(),
],
'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
]];
$singleResult = [$this->formatAccount($contact, $emailAddress, $displayName, $cloud->getUser())];
$searchResult->addResultSet($type, [], $singleResult);
$searchResult->markExactIdMatch($type);
}
Expand Down Expand Up @@ -185,16 +182,7 @@ public function search(string $search, int $limit, int $offset, ISearchResult $s
if ($count++ >= $limit) {
$hasMore = true;
} else {
$results['wide'][] = [
'label' => $displayName,
'uuid' => $contact['UID'] ?? $emailAddress,
'name' => $contact['FN'] ?? $displayName,
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => $cloud->getUser(),
],
'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
];
$results['wide'][] = $this->formatAccount($contact, $emailAddress, $displayName, $cloud->getUser());
}
}
}
Expand Down Expand Up @@ -259,6 +247,26 @@ public function search(string $search, int $limit, int $offset, ISearchResult $s
return $hasMore;
}

/**
* Format an account found in the system address book as search result,
* without its email address if those are hidden from other accounts.
*/
private function formatAccount(array $contact, string $emailAddress, string $displayName, string $userId): array {
if (!$this->showAccountEMail) {
$displayName = $contact['FN'] ?? $userId;
}
return [
'label' => $displayName,
'uuid' => $contact['UID'] ?? $emailAddress,
'name' => $contact['FN'] ?? $displayName,
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => $userId,
],
'shareWithDisplayNameUnique' => $this->showAccountEMail && !empty($emailAddress) ? $emailAddress : $userId,
];
}

public function isCurrentUser(ICloudId $cloud): bool {
$currentUser = $this->userSession->getUser();
return $currentUser instanceof IUser && $currentUser->getUID() === $cloud->getUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OC\KnownUser\KnownUserService;
use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
Expand All @@ -33,6 +34,7 @@ public function __construct(
IUserSession $userSession,
IEmailValidator $emailValidator,
IUserManager $userManager,
IAppConfig $appConfig,
mixed $shareWithGroupOnlyExcludeGroupsList = [],
) {
parent::__construct(
Expand All @@ -44,6 +46,7 @@ public function __construct(
$userSession,
$emailValidator,
$userManager,
$appConfig,
$shareWithGroupOnlyExcludeGroupsList,
IShare::TYPE_USER,
);
Expand Down
8 changes: 7 additions & 1 deletion lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OC\Collaboration\Collaborators;

use OC\Core\AppInfo\ConfigLexicon;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
Expand Down Expand Up @@ -173,10 +174,15 @@ public function search(string $search, int $limit, int $offset, ISearchResult $s
$this->userStatusManager->getUserStatuses(array_keys($users)),
);

$showAccountEMail = $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_SHOW_ACCOUNT_EMAIL);

$result = ['wide' => [], 'exact' => []];
foreach ($users as $match) {
$match[2] ??= null;
[$type, $user, $uniqueDisplayName] = $match;
if (!$showAccountEMail) {
$uniqueDisplayName = null;
}

$displayName = $user->getDisplayName();
if ($uniqueDisplayName !== null) {
Expand All @@ -193,7 +199,7 @@ public function search(string $search, int $limit, int $offset, ISearchResult $s
'shareType' => IShare::TYPE_USER,
'shareWith' => $user->getUID(),
],
'shareWithDisplayNameUnique' => $uniqueDisplayName ?? $user->getSystemEMailAddress() ?: $user->getUID(),
'shareWithDisplayNameUnique' => $uniqueDisplayName ?? ($showAccountEMail ? $user->getSystemEMailAddress() : null) ?: $user->getUID(),
'status' => $status,
];
}
Expand Down
9 changes: 7 additions & 2 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OC\Contacts\ContactsMenu;

use OC\Core\AppInfo\ConfigLexicon;
use OC\KnownUser\KnownUserService;
use OC\Profile\ProfileManager;
use OC\Share20\ShareDisableChecker;
Expand All @@ -15,6 +16,7 @@
use OCP\Contacts\ContactsMenu\IContactsStore;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\IManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
Expand All @@ -40,6 +42,7 @@ public function __construct(
private KnownUserService $knownUserService,
private IL10NFactory $l10nFactory,
private ShareDisableChecker $shareDisableChecker,
private IAppConfig $appConfig,
) {
}

Expand Down Expand Up @@ -204,7 +207,7 @@ private function filterContacts(

$filterOutUser = true;

$mailAddresses = $entry->getEMailAddresses();
$mailAddresses = $entry->getProperty('EMAIL') ?? [];
foreach ($mailAddresses as $mailAddress) {
if ($mailAddress === $filter) {
$filterOutUser = false;
Expand Down Expand Up @@ -335,7 +338,9 @@ private function contactArrayToEntry(array $contact): Entry {
$entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
}

if (!empty($contact['EMAIL'])) {
$hideEMailAddresses = ($contact['isLocalSystemBook'] ?? false) === true
&& !$this->appConfig->getValueBool('core', ConfigLexicon::SHARE_SHOW_ACCOUNT_EMAIL);
if (!empty($contact['EMAIL']) && !$hideEMailAddresses) {
foreach ($contact['EMAIL'] as $email) {
$entry->addEMailAddress($email);
}
Expand Down
Loading
Loading