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

Changed Content-Disposition header to download Contact Photo with correct extension #21945

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

jacobneplokh
Copy link
Member

Now prompts to download as ContactPhoto.png cross-browser

Signed-off-by: Jacob Neplokh me@jacobneplokh.com

--
Fixes #20143
@jancborchardt @skjnldsv

The Content-Disposition header now also has the file name (set to ContactPhoto.png — if this needs to be changed, let me know) to make sure it is downloaded with the correct file extension, and across browsers.

@jacobneplokh jacobneplokh requested review from skjnldsv and rullzer July 23, 2020 20:54
@jacobneplokh
Copy link
Member Author

Hey @rullzer and @skjnldsv ,

I made some changes using the suggestions. As this is a "good first issue," I chose this to get some practice and learn some more :)

So let me know if there is something to change/more to do. Also, I noticed the PHP Code-Standards check failed, but am having a little trouble understanding where specifically the error is.

Thank you!

@skjnldsv
Copy link
Member

@jneplokh please also rebase and squash your commits into one :)

@jacobneplokh jacobneplokh force-pushed the fix-contact-download-picture branch 2 times, most recently from 84ea799 to aba247e Compare July 25, 2020 21:11
@skjnldsv
Copy link
Member

skjnldsv commented Jul 26, 2020

There is a failure on the carddav integration test build/integration/features/carddav.feature:53
Expected value 'attachment' for header 'Content-Disposition', got 'attachment; filename=bjoern.vcf.jpg' (Exception)

The two other failures are false positive :)

@jacobneplokh
Copy link
Member Author

jacobneplokh commented Jul 26, 2020

Ok, I fixed the error on the carddav integration test by changing the expected header. To clarify, those 3 other failures (nodb, postgres11-php7.2, and integration-auth) are false positives correct?

Also, looking at the drone page, jsunit seemed to have failed because of a failed connection to codecov.io?

@jacobneplokh jacobneplokh force-pushed the fix-contact-download-picture branch from 4dc69a2 to 23dc6f6 Compare July 26, 2020 15:51
@skjnldsv
Copy link
Member

  1. OCA\DAV\Tests\unit\CardDAV\ImageExportPluginTest::testCard with data set Name the repository "server" #1 (null, true)
    Undefined index: imgtype

/drone/src/apps/dav/lib/CardDAV/ImageExportPlugin.php:106
/drone/src/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php:198

  1. OCA\DAV\Tests\unit\CardDAV\ImageExportPluginTest::testCard with data set Use shields for IRC links #3 (32, true)
    Undefined index: imgtype

/drone/src/apps/dav/lib/CardDAV/ImageExportPlugin.php:106
/drone/src/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php:198

This seems related though

@jacobneplokh
Copy link
Member Author

Hmm, true. Maybe something with not getting the full mimetype but just the extension. I'll see what is going on there.

@jacobneplokh jacobneplokh reopened this Aug 29, 2020
@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Aug 31, 2020
@jacobneplokh
Copy link
Member Author

Hey,

Sorry for the late comment here, got busy with something for a few weeks. I went over the PHPUnit docs, but I am honestly lost on what to change in the test. I got some great help from the Contacts channel, but am still confused on how to make the test work with the changes.

What should the next course of action be? If it is closing the PR, I understand.

Thank you for all the help, though, during this PR!

@skjnldsv
Copy link
Member

skjnldsv commented Sep 3, 2020

What should the next course of action be? If it is closing the PR, I understand.

No no! :)
Next step is to fix the step and get this in 😉

Look at the line of the test

$this->response->expects($this->at(3))
->method('setHeader')
->with('Content-Type', 'imgtype');
$this->response->expects($this->at(4))
->method('setHeader')
->with('Content-Disposition', 'attachment');

Since you changed the headers, the unit tests needs to reflect those changes too :)
You can run your test locally by running phpunit --bootstrap apps/dav/tests/unit/bootstrap.php apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php

@jacobneplokh
Copy link
Member Author

No no! :)
Next step is to fix the step and get this in 😉

Awesome!

Since you changed the headers, the unit tests needs to reflect those changes too

Ok yeah, I thought this was happening but was not exactly sure where to change it. Thanks for the testing command too.

I'll keep working on it :)

@jacobneplokh
Copy link
Member Author

jacobneplokh commented Sep 5, 2020

Since you changed the headers, the unit tests needs to reflect those changes too

Ok, I just pushed changes which update the headers with a .jpg extension. Do I need to create test cases for all the file extensions?

Also, are those two failures false positives?

- Make ALLOWED_CONTENT_TYPES public in order to use
- Add $fileName variable which uses "$node->getName()" to get the proper file name and "$file->getMimeType()" along with the ALLOWED_CONTENT_TYPES array in PhotoCache.php to get the proper file extension
- Make "$fileName" the name of the file in the Content-Disposition header when downloading a Contact's photo
- Add filename to the CardDAV integration image export test header
- Change headers in ImageExportPluginTest to reflect changes

Signed-off-by: Jacob Neplokh <me@jacobneplokh.com>
@jacobneplokh jacobneplokh force-pushed the fix-contact-download-picture branch from 23dc6f6 to e8a4feb Compare September 5, 2020 18:46
@faily-bot
Copy link

faily-bot bot commented Sep 5, 2020

🤖 beep boop beep 🤖

Here are the logs for the failed build:

Status of 32690: failure

mariadb10.4-php7.3

Show full log
There were 2 warnings:

1) Test\Files\ViewTest::testRenameFailDeleteTargetKeepSource
Trying to configure method "writeStream" which cannot be configured because it does not exist, has not been specified, is final, or is static

2) Test\Files\ViewTest::testCopyFailDeleteTargetKeepSource
Trying to configure method "writeStream" which cannot be configured because it does not exist, has not been specified, is final, or is static

--

There was 1 failure:

1) OCA\Files_Sharing\Tests\SharedMountTest::testPermissionMovedGroupShare with data set #30 ('folder', 3, 17)
Failed asserting that false is true.

/drone/src/apps/files_sharing/tests/SharedMountTest.php:367

mysql5.6-php7.2

Show full log
There was 1 error:

1) Test\Comments\ManagerTest::testGetTreeNoReplies
InvalidArgumentException: IDs must be translatable to a number in this implementation.

/drone/src/lib/private/Comments/Manager.php:248
/drone/src/lib/private/Comments/Manager.php:305
/drone/src/tests/lib/Comments/ManagerTest.php:174

--

There were 2 warnings:

1) Test\Files\ViewTest::testRenameFailDeleteTargetKeepSource
Trying to configure method "writeStream" which cannot be configured because it does not exist, has not been specified, is final, or is static

2) Test\Files\ViewTest::testCopyFailDeleteTargetKeepSource
Trying to configure method "writeStream" which cannot be configured because it does not exist, has not been specified, is final, or is static

@skjnldsv
Copy link
Member

skjnldsv commented Sep 5, 2020

Also, are those two failures false positives?

Looks like it :)

@jacobneplokh
Copy link
Member Author

Looks like it :)

Awesome! So is it effectively ready to be merged?

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 2. developing Work in progress labels Sep 7, 2020
@skjnldsv skjnldsv modified the milestones: Nextcloud 21, Nextcloud 20 Sep 7, 2020
@skjnldsv skjnldsv merged commit 54438c9 into master Sep 7, 2020
@skjnldsv skjnldsv deleted the fix-contact-download-picture branch September 7, 2020 06:40
@welcome
Copy link

welcome bot commented Sep 7, 2020

Thanks for your first pull request and welcome to the community! Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/server/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22

@skjnldsv
Copy link
Member

skjnldsv commented Sep 7, 2020

Thank you @jneplokh !!

@jacobneplokh
Copy link
Member Author

No problem! Definitely learned, too.

And thanks for the help during it! :)

@rullzer rullzer mentioned this pull request Sep 8, 2020
13 tasks
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 bug feature: dav
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Download picture" downloaded file has a wrong .vcf extension (Firefox only)
4 participants