Skip to content

feat: add example contact on first login #50156

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

Merged
merged 1 commit into from
Mar 26, 2025
Merged

Conversation

hamza221
Copy link
Contributor

@hamza221 hamza221 commented Jan 13, 2025

Checklist

@hamza221 hamza221 marked this pull request as ready for review January 21, 2025 12:30
@hamza221 hamza221 self-assigned this Jan 21, 2025
@hamza221 hamza221 added enhancement 3. to review Waiting for reviews feature: carddav Related to CardDAV internals labels Jan 21, 2025
@hamza221 hamza221 force-pushed the feat/cardav-example-contact branch from b237d7a to 3af4fc4 Compare January 22, 2025 12:47
@hamza221 hamza221 marked this pull request as draft January 23, 2025 09:45
@hamza221 hamza221 added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jan 23, 2025
@hamza221 hamza221 marked this pull request as ready for review January 23, 2025 14:33
@hamza221 hamza221 requested a review from st3iny January 23, 2025 14:33
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.

Tested and works.

@st3iny st3iny added this to the Nextcloud 32 milestone Jan 27, 2025
@st3iny st3iny added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jan 27, 2025
@hamza221 hamza221 force-pushed the feat/cardav-example-contact branch 2 times, most recently from 3c3150b to 85f8d9f Compare January 28, 2025 11:27
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.

There are new classes but no new tests. Could you please add some unit tests at least?

}

if (is_null($cardData)) {
$cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf');
Copy link
Member

Choose a reason for hiding this comment

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

Error handling missing

Copy link
Member

Choose a reason for hiding this comment

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

file_get_contents returns false on error. This is not handled.

@hamza221 hamza221 force-pushed the feat/cardav-example-contact branch from 85f8d9f to 4c0fd9e Compare February 7, 2025 13:39
@hamza221
Copy link
Contributor Author

hamza221 commented Feb 7, 2025

commited 3rdParty by mistake 😢

@hamza221 hamza221 force-pushed the feat/cardav-example-contact branch from 4c0fd9e to a0b6856 Compare February 7, 2025 13:47
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.

Psalm is not happy about the int vs string addressbookId

Looks good

}

if (is_null($cardData)) {
$cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf');
Copy link
Member

Choose a reason for hiding this comment

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

file_get_contents returns false on error. This is not handled.

@hamza221 hamza221 force-pushed the feat/cardav-example-contact branch from a0b6856 to 74eb1da Compare March 25, 2025 13:47
@hamza221 hamza221 requested review from a team as code owners March 25, 2025 13:47
@hamza221 hamza221 requested review from susnux, artonge, nfebe and come-nc and removed request for a team March 25, 2025 13:47
@hamza221 hamza221 force-pushed the feat/cardav-example-contact branch 3 times, most recently from 9bad0ac to 916abc8 Compare March 26, 2025 09:31
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
@hamza221 hamza221 force-pushed the feat/cardav-example-contact branch from 916abc8 to 099d9fb Compare March 26, 2025 09:58
@hamza221 hamza221 merged commit 28a2965 into master Mar 26, 2025
190 of 193 checks passed
@hamza221 hamza221 deleted the feat/cardav-example-contact branch March 26, 2025 12:47
public function createDefaultContact(int $addressBookId): void {
$appData = $this->appDataFactory->get('dav');
try {
$folder = $appData->getFolder('defaultContact');
Copy link
Member

Choose a reason for hiding this comment

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

This creates some log spam on richdocuments integration tests.

Should it rather also create that folder if it does not exist yet here?

https://github.com/nextcloud/richdocuments/actions/runs/14662537867/job/41149995116?pr=4698

{
  "Exception": "OCP\\Files\\NotFoundException",
  "Message": "/appdata_oceljvc7njtr/dav/defaultContact",
  "Code": 0,
  "Trace": [
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/Files/Node/LazyFolder.php",
      "line": 138,
      "function": "get",
      "class": "OC\\Files\\Node\\Root",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/Files/AppData/AppData.php",
      "line": 114,
      "function": "get",
      "class": "OC\\Files\\Node\\LazyFolder",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/apps/dav/lib/Service/DefaultContactService.php",
      "line": 30,
      "function": "getFolder",
      "class": "OC\\Files\\AppData\\AppData",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/apps/dav/lib/Listener/UserEventsListener.php",
      "line": 155,
      "function": "createDefaultContact",
      "class": "OCA\\DAV\\Service\\DefaultContactService",
      "type": "->",
      "args": [
        "*** sensitive parameters replaced ***"
      ]
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/apps/dav/lib/Listener/UserEventsListener.php",
      "line": 71,
      "function": "firstLogin",
      "class": "OCA\\DAV\\Listener\\UserEventsListener",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/EventDispatcher/ServiceEventListener.php",
      "line": 68,
      "function": "handle",
      "class": "OCA\\DAV\\Listener\\UserEventsListener",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
      "line": 220,
      "function": "__invoke",
      "class": "OC\\EventDispatcher\\ServiceEventListener",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
      "line": 56,
      "function": "callListeners",
      "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/EventDispatcher/EventDispatcher.php",
      "line": 67,
      "function": "dispatch",
      "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/EventDispatcher/EventDispatcher.php",
      "line": 79,
      "function": "dispatch",
      "class": "OC\\EventDispatcher\\EventDispatcher",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/User/Session.php",
      "line": 528,
      "function": "dispatchTyped",
      "class": "OC\\EventDispatcher\\EventDispatcher",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/User/Session.php",
      "line": 357,
      "function": "prepareUserLogin",
      "class": "OC\\User\\Session",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/User/Session.php",
      "line": 585,
      "function": "completeLogin",
      "class": "OC\\User\\Session",
      "type": "->",
      "args": [
        "*** sensitive parameters replaced ***"
      ]
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/User/Session.php",
      "line": 307,
      "function": "loginWithPassword",
      "class": "OC\\User\\Session",
      "type": "->",
      "args": [
        "*** sensitive parameters replaced ***"
      ]
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/User/Session.php",
      "line": 405,
      "function": "login",
      "class": "OC\\User\\Session",
      "type": "->",
      "args": [
        "*** sensitive parameters replaced ***"
      ]
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/User/Session.php",
      "line": 544,
      "function": "logClientIn",
      "class": "OC\\User\\Session",
      "type": "->",
      "args": [
        "*** sensitive parameters replaced ***"
      ]
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/base.php",
      "line": 1143,
      "function": "tryBasicAuthLogin",
      "class": "OC\\User\\Session",
      "type": "->"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/ocs/v1.php",
      "line": 46,
      "function": "handleLogin",
      "class": "OC",
      "type": "::"
    },
    {
      "file": "/home/runner/actions-runner/_work/richdocuments/richdocuments/ocs/v2.php",
      "line": 7,
      "args": [
        "/home/runner/actions-runner/_work/richdocuments/richdocuments/ocs/v1.php"
      ],
      "function": "require_once"
    }
  ],
  "File": "/home/runner/actions-runner/_work/richdocuments/richdocuments/lib/private/Files/Node/Root.php",
  "Line": 182,
  "message": "Couldn't get default contact file",
  "exception": {},
  "CustomMessage": "Couldn't get default contact file"
}

Copy link
Member

@st3iny st3iny Apr 28, 2025

Choose a reason for hiding this comment

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

I'd prefer catching NotFoundException in a separate block and not logging it. If there is no default contact template, we don't need to create it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll push a fix soon

Copy link
Member

Choose a reason for hiding this comment

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

Done: #52493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement feature: carddav Related to CardDAV internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create an example contact
4 participants