Skip to content

Commit

Permalink
refs #933. Supports deactivating credentials.
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Littman committed Jun 8, 2018
1 parent 65d18b2 commit 1f8fe6d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sfm/ui/templates/ui/collection_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ <h4 class="modal-title" id="addNoteTurnInactiveModalLabel">Add note & deactivate
<a data-toggle="collapse" href="#collapse">Details <span class="caret"></span></a>
</div>
<div id="collapse" class="collapse" style="margin-bottom: 10px;margin-left: 10px; margin-top: 10px">
<p><strong>Credential:</strong> {% if has_perm %}<a href={% url "credential_detail" collection.credential.pk %}>{% endif %}{{ collection.credential.name }}{% if has_perm %}</a>{% endif %}</p>
<p><strong>Credential:</strong> {% if has_perm %}<a href={% url "credential_detail" collection.credential.pk %}>{% endif %}{{ collection.credential.name }}{% if has_perm %}</a>{% endif %}{% if not credential.is_active %} <span class="text-warning">(Deleted)</span>{% endif %}</p>
{{ collection.harvest_options|json }}
{% if collection.schedule_minutes %}
<p><strong>Schedule:</strong> {{ collection.get_schedule_minutes_display }}</p>
Expand Down
22 changes: 20 additions & 2 deletions sfm/ui/templates/ui/credential_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,26 @@
<div class="row">
<div class="col-md-12">
<h1>{{ credential.name }}
<a class="btn btn-primary btn-aligned" href={% url "credential_update" credential.pk %} {% if not can_edit %}disabled="disabled"{% endif %} >
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></h1>
{% if not credential.is_active %}<span class="text-warning">(Deleted)</span>{% endif %}
</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="btn btn-primary" href="{% url "credential_update" credential.pk %}" {% if not can_edit %}disabled="disabled"{% endif %} >
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a>
<div class="btn-group">
<form method="post" id = "toggleForm" action={% url "credential_toggle_active" credential.pk %}>
{% csrf_token %}
{% if credential.is_active %}
<button {% if not can_edit %}disabled="disabled"{% endif %} type="submit" class="btn btn-danger">
Delete</span>
</button><br />
{% else %}
<button {% if not can_edit %}disabled="disabled"{% endif %} type="submit" class="btn btn-default">Undelete</button>
{% endif %}
</form>
</div>
</div>
</div>
{% endblock %}
Expand Down
4 changes: 2 additions & 2 deletions sfm/ui/templates/ui/credential_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<div class="row">
<div class="col-md-12">
<h1>Credentials</h1>
<h4>Credentials are used to authorize Social Feed Manager to collect data from Twitter, Tumblr, Weibo and Flickr.</h4>
<h4>Authorize Social Feed Manager by connecting your account or adding credentials manually.</h4>
<p>Credentials are used to authorize Social Feed Manager to collect data from Twitter, Tumblr, Weibo and Flickr.</p>
<p>Authorize Social Feed Manager by connecting your account or adding credentials manually.</p>
</div>
</div>
{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion sfm/ui/templates/ui/credential_list_snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</thead>
{% for credential in credential_list %}
<tr>
<td><a href={% url "credential_detail" credential.pk %}>{{ credential.name }}</a></td>
<td><a href={% url "credential_detail" credential.pk %}>{{ credential.name }}</a>{% if not credential.is_active %} <span class="text-warning">(Deleted)</span>{% endif %}</td>
<td>{{ credential.date_added }}</td>
<td>{{ credential.date_updated }}</td>
</tr>
Expand Down
4 changes: 4 additions & 0 deletions sfm/ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
views.CredentialUpdateView.as_view(),
name="credential_update"),

url(r'^credentials/(?P<pk>\d+)/toggle/$',
views.CredentialToggleActiveView.as_view(),
name="credential_toggle_active"),

url(r'^credentials/$',
views.CredentialListView.as_view(),
name="credential_list"),
Expand Down
19 changes: 18 additions & 1 deletion sfm/ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def _get_credential_list(collection_set_pk, harvest_type, extra_credential=None)
q = Q(platform=platform, user=User.objects.filter(groups=collection_set.group))
if extra_credential:
q = q | Q(pk=extra_credential.pk)
return Credential.objects.filter(q).order_by('name')
return Credential.objects.filter(q).filter(is_active=True).order_by('name')


def _get_credential_use_map(credentials, harvest_type):
Expand Down Expand Up @@ -807,6 +807,23 @@ def get_success_url(self):
return reverse("credential_detail", args=(self.object.pk,))


class CredentialToggleActiveView(LoginRequiredMixin, UserOrSuperuserPermissionMixin, RedirectView):
permanent = False
pattern_name = "credential_detail"
http_method_names = ['post', 'put']

def get_redirect_url(self, *args, **kwargs):
credential = get_object_or_404(Credential, pk=kwargs['pk'])
credential.is_active = not credential.is_active
credential.history_note = self.request.POST.get("history_note", "")
if credential.is_active:
messages.info(self.request, "Credential undeleted.")
else:
messages.info(self.request, "Credential deleted.")
credential.save()
return super(CredentialToggleActiveView, self).get_redirect_url(*args, **kwargs)


class ExportListView(LoginRequiredMixin, ListView):
model = Export
template_name = 'ui/export_list.html'
Expand Down

0 comments on commit 1f8fe6d

Please sign in to comment.