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

Add support for sending the password for a share by Nextcloud Talk #10238

Conversation

danxuliu
Copy link
Member

@danxuliu danxuliu commented Jul 13, 2018

Server part of nextcloud/spreed#1049

When a file is shared by email the file can be accessed by anyone as long as the token of the share is known, so to limit that access the share can be protected with a password. When a password was set it was also sent by email to the sharee. This pull request (and its Talk counterpart) adds another option: sending the password with Nextcloud Talk.

Now when the sharer protects the share with a password no email is sent. Instead, when the receiver tries to open the share the public share authentication page is shown, which now contains a Request password button. When that button is clicked an embedded Nextcloud UI is shown and a conversation is started between the sharer and the user trying to open the file, which allows the sharer to verify the identity of the user before telling her the password and thus granting her access to the file.

Note that it is the sharer who decides whether the receiver of an email share can call her or not; you will not be bothered with password requests if you do not choose to ;-)

This pull request updates the server parts needed to provide that feature, which are basically those related to shares; the handling of rooms and the Talk UI is isolated from the server and done in the Talk app. The "bridge" between the public share authentication page and the Talk UI is the share controller, that simply appends a Talk template when sending the password by Talk is enabled for the share. That template just loads some JavaScript code that, when run on the browser, adjusts the page generated by the server to inject the Talk UI as needed.

password-protect-by-talk

Regardind the share menu, a new item was added to the menu, Password protect by Talk, that behaves like the previous Password protect; sending the password by mail and sending it by Talk are mutually exclusive actions, so when one of the checkboxes is enabled the other one is automatically disabled (radio buttons may have been better, but it would be strange to have radio buttons mixed with the rest of checkboxes in the menu).

When switching from sending by Talk to sending by email the previous password is reused; however, when switching from sending by email to sending by Talk a new password must be provided, and the share will not be updated until that is done.

For reviewers, note that in ShareAPIController the ServerContainer is injected and then the AppManager is got from the container, instead of directly injecting the AppManager; this is on purpose, as the ServerContainer will be necessary for another pull request in the works ;-)

Also note that when a password is set in the list of shares the loading icon is misplaced; that happens too in current master and is not related to this pull request.

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

Hmm

@@ -25,3 +25,7 @@ class="svg icon-confirm input-button-inline" value="" disabled="disabled" />
</p>
</fieldset>
</form>

<?php if ($_['sendPasswordByTalk']): ?>
<?php echo (new \OCP\Template('spreed', 'publicshareauth'))->fetchPage($_['sendPasswordByTalk']); ?>
Copy link
Member

Choose a reason for hiding this comment

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

Cross app reference

Copy link
Member

Choose a reason for hiding this comment

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

Should also be possible to add an event in the relevant controller.
Talk could then load a JS script which creates the UI instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not know if the template system provides any event to add more content to a page. Even if all the markup was generated using JavaScript in the browser at the very least the page would need to be extended with the links in the header to load the scripts.

Copy link
Member

Choose a reason for hiding this comment

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

Well basically it should work like OCA\Files::loadAdditionalScripts and the first run wizard

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmm, I think that would not work here. The reason is that, besides the scripts themselves, the handler of the event has to add some HTML elements too (in order to provide the share token in a data property). As far as I know currently it is not possible to add arbitrary elements to be rendered.

I think that the template system would have to be extended to add another template class that allows rendering subtemplates (like the PublicTemplateResponse and the IMenuAction, but generic). Or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

As far as I know currently it is not possible to add arbitrary elements to be rendered

you can do this quite easily?
$('form.searchbox').after($('<div>').attr('id', 'notifications'));

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, adding an element from the Talk script is no problem (that is what it is done already for the sidebar). The problem is injecting the share token, which should be done when the template is rendered, not when the JavaScript is executed.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, that's it, I'm officially dumb xD I have just realized that I can simply add a hidden input field in the publicshareauth template with the share token, just like it is done in the public share template; there is no real need to inject it only when Talk is used.

@MorrisJobke
Copy link
Member

For reviewers, note that in ShareAPIController the ServerContainer is injected and then the AppManager is got from the container, instead of directly injecting the AppManager; this is on purpose, as the ServerContainer will be necessary for another pull request in the works ;-)

Not really nice IMO 🙈

@danxuliu danxuliu force-pushed the add-support-for-sending-the-password-for-a-share-by-nextcloud-talk branch 2 times, most recently from 20d46ac to 02d6e55 Compare July 16, 2018 07:00
apps/files_sharing/lib/Controller/ShareAPIController.php Outdated Show resolved Hide resolved
apps/files_sharing/lib/Controller/ShareAPIController.php Outdated Show resolved Hide resolved
apps/files_sharing/lib/Controller/ShareController.php Outdated Show resolved Hide resolved
core/Migrations/Version14000Date20180710092004.php Outdated Show resolved Hide resolved
core/js/sharedialogshareelistview.js Outdated Show resolved Hide resolved
@@ -25,3 +25,7 @@ class="svg icon-confirm input-button-inline" value="" disabled="disabled" />
</p>
</fieldset>
</form>

<?php if ($_['sendPasswordByTalk']): ?>
<?php echo (new \OCP\Template('spreed', 'publicshareauth'))->fetchPage($_['sendPasswordByTalk']); ?>
Copy link
Member

Choose a reason for hiding this comment

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

Should also be possible to add an event in the relevant controller.
Talk could then load a JS script which creates the UI instead?

@danxuliu danxuliu force-pushed the add-support-for-sending-the-password-for-a-share-by-nextcloud-talk branch from 02d6e55 to 7a29e67 Compare July 17, 2018 17:30
Copy link
Member

@rullzer rullzer 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. 🐘
I'd say lets merge it and iron out tiny bugs later.

@danxuliu danxuliu force-pushed the add-support-for-sending-the-password-for-a-share-by-nextcloud-talk branch 2 times, most recently from 381f5db to 8a6514c Compare July 18, 2018 16:18
Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

Fine by me too :electron:
No direct code call anymore

@nickvergessen nickvergessen dismissed their stale review July 19, 2018 08:55

No direct code call anymore

@MorrisJobke MorrisJobke mentioned this pull request Jul 24, 2018
21 tasks
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
When a password was set for a mail share an e-mail was sent to the
recipient with the password. Now the e-mail is no longer sent if the
password is meant to be sent by Talk.

However, before the e-mail was not sent when the share was updated but
the password was not changed. Now an e-mail is sent in that case too if
switching from a password sent by Talk to a password sent by mail.

On the other hand, when switching from a password sent by mail to a
password sent by Talk it is mandatory to change the password; otherwise
the recipient would already have access to the share without having to
call the sharer to verify her identity.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
Before the public share authentication page is rendered now an event to
load additional scripts is dispatched. Thanks to this any app can load
its own scripts that, when run on the browser, adjust as needed the page
generated by the server.

Note, however, that during the handling of the event apps are only able
to add scripts or styles to be loaded; they can not render arbitrary
content on the page, or change how the content is rendered by the
original template; all those changes have to be done by the scripts at
run-time.

This implies that the scripts of the apps can use only those parameters,
like the token of the share, added to the page when it is generated by
the "publicshareauth" template. Due to this, and given that the event is
being introduced to be used by Talk to inject the UI needed to request
the password for a share, the token of the share is now provided in the
generated page, just like done in the public share page.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
@danxuliu danxuliu force-pushed the add-support-for-sending-the-password-for-a-share-by-nextcloud-talk branch from 8a6514c to cd6d99c Compare July 24, 2018 12:06
@danxuliu
Copy link
Member Author

I have rebased onto master to fix the merge conflicts. Note that now this pull request adds a migration with a previous date than another one already in master, but given that the version is bumped too according to @nickvergessen it should not be a problem.

Until now the password to be sent by mail was set by enabling a checkbox
in the share menu and then entering the password in an input field shown
below. Now, when Talk is enabled, another item is added to the share
menu to do the same for a password to be sent by Talk.

Sending the password by mail and sending it by Talk are mutually
exclusive actions, so when one of the checkboxes is enabled the other
one is automatically disabled.

Note that the icon set for the field, "icon-passwordtalk", does not
currently exist; it simply mimics the "icon-passwordmail" (which does
not exist either) used for the field of the password protect by mail to
get the right padding in the menu.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
@danxuliu danxuliu force-pushed the add-support-for-sending-the-password-for-a-share-by-nextcloud-talk branch from cd6d99c to 9110935 Compare July 24, 2018 12:50
@MorrisJobke
Copy link
Member

For me there is now no such sharing option anymore :/

@MorrisJobke
Copy link
Member

Server side looks good, but the talk app seems to be a bit broken:

bildschirmfoto 2018-07-24 um 16 55 37
bildschirmfoto 2018-07-24 um 16 55 18

@danxuliu
Copy link
Member Author

the talk app seems to be a bit broken

Known issue unrelated to this pull request; it was broken by #9982

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.

4 participants