Skip to content

Conversation

SebastianKrupinski
Copy link
Contributor

@SebastianKrupinski SebastianKrupinski commented Feb 1, 2025

Summary

Automatically disables system address book when a configured limit is reached.

Checklist

@SebastianKrupinski SebastianKrupinski added the 3. to review Waiting for reviews label Feb 1, 2025
@SebastianKrupinski SebastianKrupinski self-assigned this Feb 1, 2025
@AndyScherzinger AndyScherzinger added this to the Nextcloud 32 milestone Feb 11, 2025
@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from 4950879 to f81af1e Compare February 12, 2025 05:34
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from f81af1e to a288ada Compare February 17, 2025 14:06
Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and tests are included.

@SebastianKrupinski
Copy link
Contributor Author

@st3iny thank you

@SebastianKrupinski
Copy link
Contributor Author

Temporarily converted to draft to adjust logic.

@SebastianKrupinski SebastianKrupinski marked this pull request as draft February 17, 2025 19:28
@st3iny
Copy link
Member

st3iny commented Feb 17, 2025

Temporarily converted to draft to adjust logic.

What is the problem? The sync being run despite the exposed config being set to no?

@kesselb
Copy link
Collaborator

kesselb commented Feb 17, 2025

What is the problem?

The code is only executed when running the sync command via occ or when installing nextcloud (but then you don't have a 5k user directory connected). It should be a migration / repair step to automatically disable sab. Not as side effection when calling the sync command.

@SebastianKrupinski
Copy link
Contributor Author

SebastianKrupinski commented Feb 17, 2025

What is the problem? The sync being run despite the exposed config being set to no?

No... at the moment the logic disables the system address book automatically even if the admin forces the "system_addressbook_exposed" to yes, if the limit is reached. And during our 1 on 1 today, we thought that is might cause confusion. So the solution is to only automatically disable the address book if the "system_addressbook_exposed" has not been set yet, I just have not made the adjustment yet.

@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from a288ada to 0ee3572 Compare February 17, 2025 23:46
st3iny
st3iny previously requested changes Feb 18, 2025
Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daniel is right though. The syncInstance() method is only called from the occ command (or during an old migration).

image

@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from 0ee3572 to 5d5e11b Compare March 4, 2025 00:21
@ChristophWurst
Copy link
Member

@SebastianKrupinski have the change requests been addressed in the last push?

@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch 4 times, most recently from f4e0035 to 5077b81 Compare June 2, 2025 21:52
@SebastianKrupinski SebastianKrupinski requested a review from st3iny June 2, 2025 22:00
@SebastianKrupinski
Copy link
Contributor Author

@SebastianKrupinski have the change requests been addressed in the last push?

yes, new code is up

@SebastianKrupinski SebastianKrupinski marked this pull request as ready for review June 2, 2025 22:04
* @inheritDoc
*/
public function getName(): string {
return $this->name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return $this->name;
return $this->l10nFactory->get(Application::APP_ID)->t('Contacts');

Copied from Calendar. I'm not sure if a changing name is a good idea. Especially given that the cached name will depend on the last notification to be prepared which is a bit arbitrary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 21 to 22
private string $name = 'CardDAV';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private string $name = 'CardDAV';

Not required anymore. See my other comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

$limit = $this->appConfig->getValueInt(Application::APP_ID, 'system_addressbook_limit', 5000);

if ($count > $limit) {
return SetupResult::warning($this->l10n->t('The system address book is enabled, but has more than the configured limit of %s users', (string)$limit));
Copy link
Member

@st3iny st3iny Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you derive something from the problem description at #49431?

Contacts rendering and mobile client syncing are the big issues I can think of

Does not seem to be addressed, as far as I can see.

(I don't care too much about the message. Just noticed this when I checked open conversations.)

Proposed additional text: This can cause performance issues in the Contacts app and when syncing with external CardDAV clients.

->setUser($user->getUID())
->setDateTime(new \DateTime())
->setSubject('SystemSystemAddressBookDisabled', []);
$this->notificationManager->notify($notification);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really dangerous as it will call the newly created INotifier implementation.

I'd recommend to move this logic in a repair step. Let me know in case you need to know more.

Copy link
Member

@st3iny st3iny Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is the only point of feedback I would like to see addressed hence the changes requested state.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed it to a repair step that only runs on 32

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@st3iny what is the dangerous aspect? That the notifier executes during schema migration?

This has to be a one-time thing. A regular repair step will execute again and again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was referenced Aug 22, 2025
@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from 1ab1b60 to b39ccb4 Compare August 26, 2025 15:22
@nextcloud-bot nextcloud-bot mentioned this pull request Aug 28, 2025
@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from a38c00e to 5e40b3b Compare August 28, 2025 19:29
Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good otherwise.

*/
public function run(IOutput $output) {
$output->info('Running repair step to disable system address book');
if ($this->serverVersion->getMajorVersion() !== 32) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this won't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the version check. Repair steps should be idempotent, i.e., be run over and over again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment on lines 41 to 65
public function run(IOutput $output) {
$output->info('Running repair step to disable system address book');
if ($this->serverVersion->getMajorVersion() !== 32) {
$output->info('Skipping repair step system address book this only applies to Nextcloud 32');
return;
}
// If the system address book is not exposed there is nothing to do
if ($this->appConfig->getAppValueBool('system_addressbook_exposed', true) === false) {
$output->info('Skipping repair step system address book is already disabled');
return;
}
// We use count seen because getting a user count from the backend can be very slow
$limit = $this->appConfig->getAppValueInt('system_addressbook_limit', 5000);
if ($this->userManager->countSeenUsers() <= $limit) {
$output->info("Skipping repair step system address book has less then the threshold $limit of contacts no need to disable");
return;
}
$this->appConfig->setAppValueBool('system_addressbook_exposed', false);
$output->warning("System address book disabled because it has more then the threshold of $limit contacts this can be re-enabled later");
// Notify all admin users about the system address book being disabled
foreach ($this->groupManager->get('admin')->getUsers() as $user) {
$notification = $this->notificationManager->createNotification();
$notification->setApp(Application::APP_ID)
->setUser($user->getUID())
->setDateTime(new \DateTime())
->setSubject('SystemSystemAddressBookDisabled', []);
$this->notificationManager->notify($notification);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole step is not really idempotent. If an admin re-enables the system address book (system_addressbook_exposed => true), it will be disabled again and again.

I think you need to check if the config has been set manually by admins and then skip this repair step. Just checking for false is not sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will only run if the setting has not been set before now

This was referenced Sep 2, 2025
@ChristophWurst
Copy link
Member

We will leave this as repair step and only take action when they config key is not set. So this is only executed once.

@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from 5e40b3b to 3712caa Compare September 15, 2025 14:36
@SebastianKrupinski
Copy link
Contributor Author

We will leave this as repair step and only take action when they config key is not set. So this is only executed once.

Done.

@SebastianKrupinski
Copy link
Contributor Author

I think reuse is drunk today lol

* Bad licenses: AGPL-3.0-later
* Missing licenses: AGPL-3.0-later


/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-later
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* SPDX-License-Identifier: AGPL-3.0-later
* SPDX-License-Identifier: AGPL-3.0-or-later

the SPDX check is right. This license identifier is invalid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. If that was the issue the error message was very misleading

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 # BAD LICENSES

'AGPL-3.0-later' found in:
* apps/dav/lib/Migration/DisableSystemAddressBook.php


# MISSING LICENSES

'AGPL-3.0-later' found in:
* apps/dav/lib/Migration/DisableSystemAddressBook.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly misleading

Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repair step makes sense now. Please address Christoph's feedback.

Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
@SebastianKrupinski SebastianKrupinski force-pushed the fix/49431-automatically-disable-sab branch from e636b0e to cab9a5d Compare September 18, 2025 15:01
@ChristophWurst ChristophWurst merged commit 09eb205 into master Sep 18, 2025
199 checks passed
@ChristophWurst ChristophWurst deleted the fix/49431-automatically-disable-sab branch September 18, 2025 15:39
@skjnldsv skjnldsv modified the milestones: Nextcloud 32, Nextcloud 33 Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically disable the system address book for large instances

7 participants