Skip to content

Commit

Permalink
Fix activity file deletion (#1114)
Browse files Browse the repository at this point in the history
Restore ability to delete files retained after activity deauthorization. Fixes #1113
  • Loading branch information
madprime authored Jul 1, 2020
1 parent 268d4d9 commit 3124af9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="row">
<div class="col-xs-12">
<p>Are you sure you want to remove all of the data files from
<strong>{{ source|source_to_name }}</strong>?</p>
<strong>{{ project.name }}</strong>?</p>
</div>
</div>

Expand Down
6 changes: 6 additions & 0 deletions open_humans/templates/partials/activity-panel-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
{% load utilities %}
{# the "data" panel on an activity page #}
<h2>Your Data</h2>
<p class="text-muted"><small>
This activity is no longer authorized to add data to your account,
but your account retains these files.
<a href="{% url 'delete-source-data-files' slug=project.slug %}">
Click here to permanently remove these files</a>.
</small></p>
<table class="table table-hover">
<thead>
<tr>
Expand Down
4 changes: 1 addition & 3 deletions open_humans/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ class SmokeTests(SmokeTestCase):
"/member/me/edit/",
"/member/me/joined/",
"/member/me/data/",
"/member/me/research-data/delete/pgp/",
"/member/me/research-data/delete/american_gut/",
"/member/me/research-data/delete/runkeeper/",
"/activity/groovy-music/delete-files/",
"/member/me/send-confirmation-email/",
"/public-data/activate-1-overview/",
"/public-data/activate-2-information/",
Expand Down
10 changes: 5 additions & 5 deletions open_humans/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@
path(
"member/me/data/", member_views.MemberDataView.as_view(), name="my-member-data"
),
re_path(
r"^member/me/research-data/delete/(?P<source>[a-z0-9-_]+)/$",
views.SourceDataFilesDeleteView.as_view(),
name="delete-source-data-files",
),
path(
"member/me/account-settings/",
member_views.MemberSettingsEditView.as_view(),
Expand Down Expand Up @@ -240,6 +235,11 @@
views.ActivityMessageFormView.as_view(),
name="activity-messaging",
),
re_path(
r"^activity/(?P<slug>[A-Za-z0-9_-]+)/delete-files/$",
views.SourceDataFilesDeleteView.as_view(),
name="delete-source-data-files",
),
path(
"201805-notice-of-terms-update/",
TemplateView.as_view(template_name="pages/201805-notice-of-terms-update.html"),
Expand Down
13 changes: 7 additions & 6 deletions open_humans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,28 @@ class SourceDataFilesDeleteView(PrivateMixin, DeleteView):
success_url = reverse_lazy("my-member-data")

def get_object(self, queryset=None):
source = self.kwargs["source"]
self.source = source
project_slug = self.kwargs["slug"]
self.project = DataRequestProject.objects.get(slug=project_slug)

return ProjectDataFile.objects.filter(user=self.request.user, source=source)
return ProjectDataFile.objects.filter(
user=self.request.user, direct_sharing_project=self.project
)

def get_context_data(self, **kwargs):
"""
Add the source to the request context.
"""
context = super(SourceDataFilesDeleteView, self).get_context_data(**kwargs)

context.update({"source": self.kwargs["source"]})
context.update({"project": self.project})

return context

def get_success_url(self):
"""
Direct to relevant activity page.
"""
url_slug = source_to_url_slug(self.source)
return reverse("activity", kwargs={"slug": url_slug})
return reverse("activity", kwargs={"slug": self.project.slug})


class ExceptionView(View):
Expand Down

0 comments on commit 3124af9

Please sign in to comment.