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

Css: Delete confirmation with css-only modal #2946

Merged
6 commits merged into from
Feb 2, 2018

Conversation

SaptakS
Copy link
Contributor

@SaptakS SaptakS commented Jan 27, 2018

Status

Work in progress

Description of Changes

Fixes #295.

Changes proposed in this pull request:
According to the discussions in #295 and #2506, I have implemented a CSS-only modal for confirmation of deletion of collections or documents. In this PR, I have replaced the js confirmation by the CSS confirmation modal for

  • multiple collection deletions
  • single collection deletion
  • multiple documents of a single collection deletion

Testing

How should the reviewer test this PR?
Send a message as a whistleblower, log as a journalist mark the message and press Delete. A confirmation modal will appear with options to Cancel or Delete. You can click on Cancel, close icon or anywhere outside the modal to close the modal. On clicking Delete, the selection collection(s)/document(s) will get deleted.

Checklist

If you made changes to the app code:

  • Unit and functional tests pass on the development VM

@SaptakS SaptakS requested a review from a user January 27, 2018 21:26
@SaptakS
Copy link
Contributor Author

SaptakS commented Jan 27, 2018

Following is the screenshot of how it looks:

screen shot 2018-01-28 at 2 08 35 am

@ghost ghost added feature CSS (Formerly also included SASS) labels Jan 27, 2018
@ghost
Copy link

ghost commented Jan 27, 2018

It looks awesome 💯 !

@ghost
Copy link

ghost commented Jan 27, 2018

And it works like a charm: manually tested all I could and did not find a problem. Very goooooood :-)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

This all looks both nice and straightforward. Nicely done !

Please let me know if you need guidance to modify the tests. The failure you see

self = 

    def test_journalist_interface_ui_with_javascript(self):
        self._source_visits_source_homepage()
        self._source_chooses_to_submit_documents()
        self._source_continues_to_submit_page()
        self._source_submits_a_file()
        self._source_logs_out()
        self._journalist_logs_in()
        self._journalist_uses_js_filter_by_sources()
        self._journalist_selects_all_sources_then_selects_none()
        self._journalist_selects_the_first_source()
        self._journalist_uses_js_buttons_to_download_unread()
>       self._journalist_delete_all_javascript()

tests/functional/test_journalist.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/functional/journalist_navigation_steps.py:688: in _journalist_delete_all_javascript
    self._alert_wait()
tests/functional/functional_test.py:211: in _alert_wait
    'Timed out waiting for confirmation popup.')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = 
method = 
message = 'Timed out waiting for confirmation popup.'

    def until(self, method, message=''):
        """Calls the method provided with the driver as an argument until the \
            return value is not False."""
        screen = None
        stacktrace = None
    
        end_time = time.time() + self._timeout
        while True:
            try:
                value = method(self._driver)
                if value:
                    return value
            except self._ignored_exceptions as exc:
                screen = getattr(exc, 'screen', None)
                stacktrace = getattr(exc, 'stacktrace', None)
            time.sleep(self._poll)
            if time.time() > end_time:
                break
>       raise TimeoutException(message, screen, stacktrace)
E       TimeoutException: Message: Timed out waiting for confirmation popup.

Leads you directly to the files where you can find examples to copy/paste. If this is all too unfamiliar for you I'd be happy to help and provide you with a draft implementation of the tests to get you started.

background: rgba(0, 0, 0, 0.8)
z-index: 99999
opacity: 0
-webkit-transition: opacity 100ms ease-in
Copy link

Choose a reason for hiding this comment

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

I think we can loose this because we don't support webkit ?

});
if (checked.length > 0) {
return confirm(get_string("collection-multi-delete-confirm-string").supplant({ size: checked.length }));
var checkboxes = document.querySelectorAll(".submission > [type='checkbox']");
Copy link

Choose a reason for hiding this comment

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

Nit: there is no need to change spacing here and that clarifies this part of the code is left untouched by this PR. Not a blocker for merge at all :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

@SaptakS SaptakS force-pushed the css/delete-confirm branch from 2e85020 to 436c3bb Compare January 31, 2018 10:18
Update functional tests for journalist to expect a modal with the cancel
and delete button and actions based on it rather than the previous
confirmation alert.
@SaptakS SaptakS force-pushed the css/delete-confirm branch from 436c3bb to 1ed2ec3 Compare January 31, 2018 10:23
Page layout tests now take screenshot of the modal instead of the confirmation
message text being saved.
@SaptakS SaptakS force-pushed the css/delete-confirm branch from fcecb9d to 5f0b1e0 Compare January 31, 2018 19:34
@codecov-io
Copy link

codecov-io commented Jan 31, 2018

Codecov Report

Merging #2946 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2946   +/-   ##
========================================
  Coverage    89.28%   89.28%           
========================================
  Files           31       31           
  Lines         1810     1810           
  Branches       209      209           
========================================
  Hits          1616     1616           
  Misses         144      144           
  Partials        50       50

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 18aa6ca...6ed9a86. Read the comment docs.

Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

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

Great job on this @SaptakS! We just need to wrap the strings used on the buttons in gettext() (see notes inline)

<h2>{{ gettext('Delete Confirmation') }}</h2>
<p>{{ gettext('Are you sure you want to delete the selected documents?') }}</p>
<a href="#close" id="cancel-selected-deletions" title="Cancel" class="btn sd-button">Cancel</a>
<button type="submit" name="action" value="confirm_delete" id="delete-selected" class="sd-button danger">Delete</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure each string is wrapped in gettext for translators, so instead of 'Delete', we should use {{ gettext('Delete') }}. This is also true for Cancel.

<a href="#close" title="Close" class="close">X</a>
<h2>{{ gettext('Delete Confirmation') }}</h2>
<p>{{ gettext('Are you sure you want to delete this collection?') }}</p>
<a href="#close" id="cancel-collection-deletions" title="Cancel" class="btn sd-button">Cancel</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

gettext here too

<a href="#close" title="Close" class="close">X</a>
<h2>{{ gettext('Delete Confirmation') }}</h2>
<p>{{ gettext('Are you sure you want to delete the selected collections?') }}</p>
<a href="#close" id="cancel-collections-deletions" title="Cancel" class="btn sd-button">Cancel</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

Last place for gettext

@SaptakS SaptakS force-pushed the css/delete-confirm branch from 5f0b1e0 to d98b7ee Compare February 1, 2018 05:18
@SaptakS SaptakS force-pushed the css/delete-confirm branch from d98b7ee to 51e8472 Compare February 1, 2018 05:22
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Impressive job on the tests: their logic is not for the faint of heart 💯

A few comments were added but they are minor: once addressed I'm confident we're good to merge :-)

If you feel inspired (but that's not a blocker for merge), it would be nice to factor the modal HTML blocks into a single file that is included and modified by variables to keep it DRY.

self._journalist_clicks_delete_selected_javascript()
self._alert_dismiss()
self._journalist_clicks_delete_selected_link()
self._journalist_clicks_delete_selected_cancel_on_modal()
Copy link

Choose a reason for hiding this comment

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

These should be after assert select_count > 0 because this assert verifies there are selected docs to work with. And after self._journalist_clicks_delete_selected_cancel_on_modal() there should be an assert like

assert selected_count == len(self.driver.find_elements_by_name('doc_names_selected'))

to verify no deletion took place.

return $(this).prop('checked');
});
if (checked.length > 0) {
return confirm(get_string("collection-multi-delete-confirm-string").supplant({ size: checked.length }));
Copy link

Choose a reason for hiding this comment

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

All get_string must also be revomved from the securedrop/journalist_templates/js-strings.html file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved this.

@@ -55,6 +55,58 @@ p.breadcrumbs
&:dir(rtl)
text-align: right

.modal-dialog
Copy link

Choose a reason for hiding this comment

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

What about moving this to modules/_modal.sass or a similar name which would then be included in _base.sass ? Do you envision problems if doing that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will check on this.

redshiftzero
redshiftzero previously approved these changes Feb 1, 2018
Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

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

my comments were addressed, 👍 from me

@SaptakS
Copy link
Contributor Author

SaptakS commented Feb 1, 2018

@dachary I have separated out the confirmation modal and tried to write it in a generic way so that even for confirmations other than deletion can use that modal in future. Also separated out the sass code into a module and imported only in journalist.sass because it is being used, for now, only there. Should I move that to _base.sass instead?

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Manually verified to work with the tor browser. 👍 🎉

@ghost ghost merged commit 4b20ad0 into freedomofpress:develop Feb 2, 2018
@toast
Copy link
Contributor

toast commented Feb 2, 2018

Love this. And I like this anchor-based approach @SaptakS

A small thing but perhaps worth mentioning / testing: I noticed in the codepen (from #2506 ) that when I open the modal and and then cancel it; that when I press the back button, the modal pops up again.

@ghost
Copy link

ghost commented Feb 2, 2018

@toast @SaptakS note that @redshiftzero created a UX category in the forum in case you would like to discuss ambitious plans to improve the SecureDrop UX :-)

@SaptakS
Copy link
Contributor Author

SaptakS commented Feb 3, 2018

@toast agreed. It also pops up on refresh since I am using anchor Ids and they work that way. Any suggestions from your side what is the best way to deal with it?

It can be dealt with javascript but the whole point is not to use javascript, so.

@redshiftzero redshiftzero added this to the 0.6 milestone Feb 27, 2018
@redshiftzero redshiftzero mentioned this pull request Feb 28, 2018
22 tasks
legoktm added a commit that referenced this pull request Feb 9, 2022
This page was originally used as a confirmation interstitial when deleting
files or messages, but in 1e64f36 (#2946) it was replaced with a CSS-only
deletion confirmation on the same page, so users would never hit the
separate confirmation page.

Remove the tests that were still calling this endpoint, the HTML template
and code that was checking for the "confirm_delete" action.
legoktm added a commit that referenced this pull request Feb 9, 2022
This page was originally used as a confirmation interstitial when deleting
files or messages, but in 1e64f36 (#2946) it was replaced with a CSS-only
deletion confirmation on the same page, so users would never hit the
separate confirmation page.

Remove the tests that were still calling this endpoint, the HTML template
and code that was checking for the "confirm_delete" action.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS (Formerly also included SASS) feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If journalists enable NoScript, they don't get warning when deleting source codename
4 participants