Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dav): store scopes for properties and filter locally scoped properties for federated address book sync #38048

Merged
merged 1 commit into from
May 10, 2023

Conversation

miaulalala
Copy link
Contributor

@miaulalala miaulalala commented May 3, 2023

Summary

Adds a users property scopes to the system address book. Private properties are not written at all.
When syncing with a federated share, the locally scoped properties should not be shared with the remote host.

Todo

  • Store scopes for properties
  • Write local properties to system address book too
  • Filter locally scoped properties for federated address book sync
  • Repair step to add scopes to existing card data
  • CardDav sync token adjustment for cards inaccessible to federated instances

How to test

Needs a federated instance setup

  1. Change a property on a local user to be scope local only
  2. trigger address book sync from remote host
  3. check the db for the changed contact by looking into the second system address book.
    Before
BEGIN:VCARD
VERSION:3.0
PRODID:-//Sabre//Sabre VObject 4.4.2//EN
UID:admin
FN;X-NC-SCOPE=v2-federated:admin
N;X-NC-SCOPE=v2-federated:admin;;;;
ADR;TYPE=OTHER;X-NC-SCOPE=v2-local:Testing test test test;;;;;;
EMAIL;TYPE=OTHER;X-NC-SCOPE=v2-federated:[email protected]
TEL;TYPE=OTHER;X-NC-SCOPE=v2-local:+435454454544
CLOUD:admin@http://localhost
END:VCARD

After

BEGIN:VCARD
VERSION:3.0
PRODID:-//Sabre//Sabre VObject 4.4.2//EN
UID:admin
FN;X-NC-SCOPE=v2-federated:admin
N;X-NC-SCOPE=v2-federated:admin;;;;
EMAIL;TYPE=OTHER;X-NC-SCOPE=v2-federated:[email protected]
CLOUD:admin@http://localhost
END:VCARD

Checklist

@miaulalala miaulalala self-assigned this May 3, 2023
@miaulalala miaulalala added 2. developing Work in progress feature: federation feature: carddav Related to CardDAV internals labels May 3, 2023
@miaulalala miaulalala changed the title Filter locally scoped properties for federated address book sync Store sopes for properties and filter locally scoped properties for federated address book sync May 3, 2023
@miaulalala miaulalala changed the title Store sopes for properties and filter locally scoped properties for federated address book sync Store scopes for properties and filter locally scoped properties for federated address book sync May 3, 2023
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.

👍 code looks very good

@ChristophWurst
Copy link
Member

Only one remark. Existing users with local properties don't get a trigger to update their vcards, right? Only when a user property changes we regenerate the system card

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.

Tested with my database user. Set all props to local and now I suddenly have an entry in the system addres book. All props are scoped to v2-local 👍

Didn't test federation

@miaulalala
Copy link
Contributor Author

Only one remark. Existing users with local properties don't get a trigger to update their vcards, right? Only when a user property changes we regenerate the system card

Yes that is indeed an issue, everything that already exists and doesn't update is gonna stay the same. Maybe a repair step could help?

@ChristophWurst
Copy link
Member

\OCA\DAV\CardDAV\SyncService::syncInstance can do the full instance update. Repair step would run for every future migration. This is a one-time thing. A migration without db schema feels wrong too. So yeah, repair step, but you have to add a flag to oc_preferences whether users were updated or not.

@miaulalala miaulalala force-pushed the enh/add-x-nc-scope-property branch from 98e22d2 to 5b85828 Compare May 3, 2023 18:43
@miaulalala miaulalala changed the title Store scopes for properties and filter locally scoped properties for federated address book sync feat(dav): store scopes for properties and filter locally scoped properties for federated address book sync May 4, 2023
@ChristophWurst
Copy link
Member

Is this generally ready to review?

@ChristophWurst ChristophWurst marked this pull request as ready for review May 4, 2023 15:16
@ChristophWurst ChristophWurst added 3. to review Waiting for reviews and removed 2. developing Work in progress labels May 4, 2023
@tcitworld
Copy link
Member

At this point there's hopefully a way to factorize things in SystemAddressbook.php.

@ChristophWurst
Copy link
Member

To be sure the filtered sync changes work as expected I'd like to throw DAVxc5 and Thunderbird against the federated address book using system:sharedsecret. That should work, right?

@miaulalala
Copy link
Contributor Author

To be sure the filtered sync changes work as expected I'd like to throw DAVxc5 and Thunderbird against the federated address book using system:sharedsecret. That should work, right?

If you know the shared secret that should work, yes.

@ChristophWurst
Copy link
Member

ChristophWurst commented May 5, 2023

I'm struggling to connect to the collection with the system user. I have a debugger attached at \OCA\Federation\DAV\FedAuth::validateUserPass but it doesn't go there apparently. It does but I can't list the system user address book home nor the SAB

Could not access /remote.php/dav/addressbooks/users/system/system/ (not WebDAV-enabled?):
404 Not Found

Edit: had the wrong URL

Authentication required for Nextcloud on server `localhost':
Username: system
Password: 
dav:/remote.php/dav/addressbooks/system/system/system/> ls
Listing collection `/remote.php/dav/addressbooks/system/system/system/': collection is empty.

@miaulalala
Copy link
Contributor Author

drone fails because of merge conflict

apps/dav/lib/CardDAV/Converter.php Fixed Show fixed Hide fixed
apps/dav/lib/CardDAV/SystemAddressbook.php Fixed Show fixed Hide fixed
}

if (!$this->carddavBackend instanceof SyncSupport) {
return null;

Check failure

Code scanning / Psalm

NullableReturnStatement

The declared return type 'array<array-key, mixed>' for OCA\DAV\CardDAV\SystemAddressbook::getChanges is not nullable, but the function returns 'null'
throw new UnsupportedLimitOnInitialSyncException();
}

if (!$this->carddavBackend instanceof SyncSupport) {

Check notice

Code scanning / Psalm

DocblockTypeContradiction

Docblock-defined type OCA\DAV\CardDAV\CardDavBackend for OCA\DAV\CardDAV\CardDavBackend is always Sabre\CardDAV\Backend\SyncSupport
@ChristophWurst
Copy link
Member

Listing collection `/remote.php/dav/addressbooks/system/system/system/': collection is empty.

Unintentionally tested the sharing enumeration restriction. Works 👍

Without it, I finally get my system contacts:

dav:/remote.php/dav/addressbooks/system/system/system/> ls
Listing collection `/remote.php/dav/addressbooks/system/system/system/': succeeded.
        Database:admin.vcf                   515  May  4 20:01
        Database:asdfasdfdasfsdfdsfasd.vcf        248  May  4 19:46
        Database:asdfasfasfasdf.vcf          259  May  4 20:26

My user's location is only shown in the downloaded .vcf if set to federated or published. If set to local it's not readable for the remote instance 👍

@ChristophWurst

This comment was marked as outdated.

@miaulalala

This comment was marked as resolved.

@ChristophWurst

This comment was marked as resolved.

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.

I let davx5 play federated instance and sync the addressbook. Works on master, then switched to this branch, rebuilt the SAB and synced again. No local props show up on the phone 👍

@ChristophWurst
Copy link
Member

Fixed the static analysis issue with nullable changes. Even tried to fix upstream but the usual suspect was faster: sabre-io/dav@9b10ec6

/**
* @throws UnsupportedLimitOnInitialSyncException
*/
public function getChanges($syncToken, $syncLevel, $limit = null) {

Check failure

Code scanning / Psalm

InvalidNullableReturnType

The declared return type 'array<array-key, mixed>' for OCA\DAV\CardDAV\SystemAddressbook::getChanges is not nullable, but 'array<array-key, mixed>|null' contains null
…erties for federated address book sync

Signed-off-by: Anna Larch <[email protected]>
@ChristophWurst ChristophWurst added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels May 9, 2023
@ChristophWurst
Copy link
Member

contacts menu integration test fails reliably -> merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish feature: carddav Related to CardDAV internals feature: federation
Projects
Development

Successfully merging this pull request may close these issues.

Store local properties in system addressbook too
4 participants