Skip to content

Conversation

@karakayasemi
Copy link
Contributor

@karakayasemi karakayasemi commented Aug 19, 2019

Description

This PR adds an OCS API for public link e-mail notifications. old ajax endpoints removed and oc10 adjusted to use the new API.

I aimed to keep the same functionality as oc10. In addition, the current code is simplified by removing redundant post parameters:

  • The old endpoint is taking many pieces of information related to the share of link as POST parameter like expiration date, filename, itemType, etc. It is also trying to validate them on the backend. However, we can already extract these parameters by reaching related share object on the backend. So, I considered them redundant and, removed.
  • I could not find any usage of cc and bcc fields in the codebase. So, I removed these options regards to YAGNI principle.
  • When toSelf parameter is posted, the backend side is only adding user's e-mail to the recipient list. I moved this logic to the client-side and removed toSelf from POST parameters.

UPDATE

  • Internal email notification mechanism also moved to the new controller.

Usage

  • URL
    /ocs/v1.php/apps/files_sharing/api/v1/notification/notifypubliclinkwithemail

  • Method:
    POST

  • POST Params
    Required:
    recipients=[string[]]
    link=[string]
    personalNote=[string]

* **Success Response:**
{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK","totalitems":"","itemsperpage":""},"data":[]}}
 
* **Fail Response:**
{"ocs":{"meta":{"status":"error","statuscode":400,"message":"Couldn't send mail to following recipient(s): test@email.com","totalitems":"","itemsperpage":""},"data":[]}}

Related Issue

Motivation and Context

In Phoenix, shared links shall be sent via email. We need an API for that.

How Has This Been Tested?

  • Unit tests are added.
  • Manually by sending public link e-mails from the web interface.
  • Manually with API call.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

public function notifyPublicLinkRecipientsWithEmail($link, $recipients, $personalNote) {
$message = null;
$code = 100;
$mailNotification = new MailNotifications(
Copy link
Member

Choose a reason for hiding this comment

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

maybe simplify this be injecting class MailNotifications?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we refactor this class, it will be unit testable. Since Internal email notification part of the code is also using this class. I can move internal email notification to the new controller after refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MailNotifications class is now injectable. Internal sharing email notification mechanism also moved to the new controller. PR description updated to according to this.

/**
* @NoAdminRequired
*
* @param string $link
Copy link
Member

Choose a reason for hiding this comment

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

This way this API could be used for sending any data to anybody. We might want to change the api to reference a share id and also check if the current use is allowed to access the share.

@DeepDiver1975
Copy link
Member

DeepDiver1975 commented Aug 19, 2019

  • The email subject did change. Before this change: 'Admin shared foo.txt with you' After the change: 'Admin shares public link with you' - link name va file name
  • ^ same with the email body
  • unrelated to this change but found while testing: the subject is html escaped - which is bad
    Screenshot from 2019-08-19 16-50-31

@codecov
Copy link

codecov bot commented Aug 19, 2019

Codecov Report

Merging #36063 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #36063   +/-   ##
=======================================
  Coverage   53.85%   53.85%           
=======================================
  Files          63       63           
  Lines        7377     7377           
  Branches     1301     1302    +1     
=======================================
  Hits         3973     3973           
  Misses       3019     3019           
  Partials      385      385
Flag Coverage Δ
#javascript 53.85% <100%> (ø) ⬆️
Impacted Files Coverage Δ
core/js/sharedialogmailview.js 62.37% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c15243...ab4138f. Read the comment docs.

@DeepDiver1975
Copy link
Member

@karakayasemi
Copy link
Contributor Author

karakayasemi commented Aug 20, 2019

@DeepDiver1975 Reason behind the e-mail subject and, body change is related to my mistake. I mistakenly used $share->getName() as file name. Now, I corrected it.Html escape issue is also related to this mistake. Since it's no longer needed, I've reverted your last commit changes.

Acceptance test fail is also related to this mistake. I hope this time, it will pass. Please, review the PR one more time. Thanks.

@karakayasemi karakayasemi marked this pull request as ready for review August 20, 2019 18:33
@DeepDiver1975
Copy link
Member

Html escape issue is also related to this mistake. Since it's no longer needed, I've reverted your last commit changes.

If the file name holds e.g. äöü - the subject is not escaped? This issue also existed before this PR - please double check. THX

@karakayasemi
Copy link
Contributor Author

@DeepDiver1975 You were right, I re-added your commit changes. Thank you for guidance.

There was conflicts due to the recent merges, now they are resolved. I believe this is ready to review again.

@PVince81 PVince81 requested a review from jvillafanez August 23, 2019 09:49

$userFolder = $this->rootFolder->getUserFolder($sender->getUID());
$nodes = $userFolder->getById($itemSource, true);
$node = $nodes[0] ?? null;
Copy link
Member

Choose a reason for hiding this comment

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

$node = $nodes[0] ? I don't think we need more than that...
In addition, what happens with the rest of the nodes? Consider to add a comment explainig.

Copy link
Contributor Author

@karakayasemi karakayasemi Aug 23, 2019

Choose a reason for hiding this comment

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

@jvillafanez in the beginning, this pr aimed only to add ocs api for public link email notification. However, I had to refactor MailNotifications class to make it injectable and testable.

The only other consumer of this class was this method. Since Share20OcsController already pretty big, I did not want to inject new dependency to it. To keep the change minimum, I just moved this method from Share20OcsController to the new NotificationController and, adapted the code to use injected MailNotifications class.

So, I did not interest with the logic behind this method. I guess this node will be used for checking both sender and recipient have it 😕.

Copy link
Member

Choose a reason for hiding this comment

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

we'll have to check it at some point. It's ok for now.

@settermjd
Copy link
Contributor

@karakayasemi, I've not been able to use the API successfully, as yet. The only response I get is the following:

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>failure</status>
  <statuscode>403</statuscode>
  <message>Public link mail notification is not allowed</message>
  <totalitems></totalitems>
  <itemsperpage></itemsperpage>
 </meta>
 <data/>
</ocs>

That said, the following two configuration options are in effect:

'shareapi_allow_public_notification' => 'yes',
'dav.enable.tech_preview' => true,

Any suggestions?

@karakayasemi
Copy link
Contributor Author

image

Please enable the option that I highlighted in the image from admin sharing settings.

@settermjd
Copy link
Contributor

Thanks for the clarification. I had thought that setting the config value would be sufficient.

@settermjd
Copy link
Contributor

It seems I don't have the same version as you do.

Screenshot_2019-10-04 Settings - ownCloud

@settermjd
Copy link
Contributor

I'm running 10.3.0 alpha2 (cloned from master).

@karakayasemi
Copy link
Contributor Author

There is another option appearing after allowing users to share via link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants