-
Notifications
You must be signed in to change notification settings - Fork 555
Add bulk banning functionality to the admin #24939
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
Changes from 5 commits
5c7a43f
5388c2e
541b6d0
7ef1d85
250b24e
566ccb8
c724247
aac0dcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,3 +61,16 @@ def clean(self): | |
| data['network'] = f'{ip_address}/32' | ||
|
|
||
| return data | ||
|
|
||
|
|
||
| class BulkBanForm(forms.Form): | ||
| user_ids = forms.CharField( | ||
| label='', required=True, widget=forms.Textarea(attrs={'rows': 30, 'cols': 80}) | ||
| ) | ||
|
|
||
| def clean_user_ids(self): | ||
| data = self.cleaned_data.get('user_ids', '') | ||
| user_ids = {id_ for id_ in data.splitlines() if id_.isdigit()} | ||
| if not user_ids: | ||
| raise forms.ValidationError('This field must contain a least one user id') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do wonder if the form shouldn't raise on bad input rather than just silently ignore. I don't see a use case of Operations pasting in content with a mix of valid user ids and other random text they want to be ignored - accidentaly adding an extra character on the same line as a user id seems a more common case, that they would want to know about and correct.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My reasoning was, it could be coming from a csv with headers and we should ignore those, but for the rest, the confirmation that shows how many users we found should be enough (Operations folks can ensure what they paste has unique ids to compare the number shown in the confirmation page with the number of lines from their input) |
||
| return user_ids | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| {% extends "admin/base_site.html" %} | ||
| {% load i18n admin_urls static %} | ||
|
|
||
| {% block extrahead %} | ||
| {{ block.super }} | ||
| {{ media }} | ||
| <script src="{% static 'admin/js/cancel.js' %}" async></script> | ||
| {% endblock %} | ||
|
|
||
| {% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} bulk-ban-confirmation{% endblock %} | ||
|
|
||
| {% block breadcrumbs %} | ||
| <div class="breadcrumbs"> | ||
| <a href="{% url 'admin:index' %}">Home</a> | ||
| › <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a> | ||
| › <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a> | ||
| › Bulk ban | ||
| </div> | ||
| {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <form method="post"> | ||
| {% csrf_token %} | ||
| {% if user_ids_to_ban %} | ||
| <p>You're about to bulk-ban {{ user_ids_to_ban|length }} user(s). Are you sure ?</p> | ||
| {{ form.as_p }} | ||
| <input type="hidden" name="post" value="yes"> | ||
| <input type="submit" value="Yes, I'm sure"> | ||
| <a href="#" class="button cancel-link">No, take me back</a> | ||
| {% else %} | ||
| <p>Paste user ids to ban below, separated by newlines (only lines containing digits will be considered). A confirmation will be displayed on the next page.</p> | ||
| {{ form.as_p }} | ||
| <input type="submit" value="Submit"> | ||
| {% endif %} | ||
| </form> | ||
| {% endblock content %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| {% extends "admin/change_list_object_tools.html" %} | ||
| {% load i18n admin_urls %} | ||
|
|
||
| {% block object-tools-items %} | ||
| {{ block.super }} | ||
| {% if has_users_ban_permission %} | ||
| <li> | ||
| {% url 'admin:users_userprofile_bulk_ban' as ban_url %} | ||
| <a href="{{ ban_url }}">Bulk ban</a> | ||
| </li> | ||
| {% endif %} | ||
| {% endblock %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @import url('./admin/amoadmin.css'); | ||
| @import url('./admin/l10n.css'); | ||
| @import url('./admin/pagination.css'); | ||
| @import url('./admin/users.css'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .bulk-ban-confirmation .cancel-link { | ||
| display: inline-block; | ||
| vertical-align: middle; | ||
| height: 0.9375rem; | ||
| line-height: 0.9375rem; | ||
| border-radius: 4px; | ||
| padding: 10px 15px; | ||
| color: var(--button-fg); | ||
| background: var(--close-button-bg); | ||
| margin: 0 0 0 10px; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to trim here too - a trailing space makes the number no longer
isdigit() is True.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c724247 and aac0dcc