forked from mirrors/bookwyrm
Create new email domain block entries
This commit is contained in:
parent
c705178c3b
commit
8717d8a675
5 changed files with 59 additions and 24 deletions
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.2.4 on 2021-09-08 21:37
|
# Generated by Django 3.2.4 on 2021-09-08 22:21
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
@ -6,24 +6,19 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
("bookwyrm", "0089_user_show_suggested_users"),
|
('bookwyrm', '0089_user_show_suggested_users'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name="EmailBlocklist",
|
name='EmailBlocklist',
|
||||||
fields=[
|
fields=[
|
||||||
(
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
"id",
|
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||||
models.AutoField(
|
('domain', models.CharField(max_length=255, unique=True)),
|
||||||
auto_created=True,
|
|
||||||
primary_key=True,
|
|
||||||
serialize=False,
|
|
||||||
verbose_name="ID",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
("created_date", models.DateTimeField(auto_now_add=True)),
|
|
||||||
("domain", models.CharField(max_length=255)),
|
|
||||||
],
|
],
|
||||||
|
options={
|
||||||
|
'ordering': ('-created_date',),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -127,12 +127,17 @@ class EmailBlocklist(models.Model):
|
||||||
"""blocked email addresses"""
|
"""blocked email addresses"""
|
||||||
|
|
||||||
created_date = models.DateTimeField(auto_now_add=True)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
domain = models.CharField(max_length=255)
|
domain = models.CharField(max_length=255, unique=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""default sorting"""
|
||||||
|
|
||||||
|
ordering = ("-created_date",)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def users(self):
|
def users(self):
|
||||||
"""find the users associated with this address"""
|
"""find the users associated with this address"""
|
||||||
User.objects.filter(email__endswith=f"@{self.domain}")
|
return User.objects.filter(email__endswith=f"@{self.domain}")
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
|
|
@ -8,13 +8,18 @@
|
||||||
{% block form %}
|
{% block form %}
|
||||||
<form name="add-domain" method="post" action="{% url 'settings-email-blocks' %}">
|
<form name="add-domain" method="post" action="{% url 'settings-email-blocks' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="field">
|
|
||||||
<label class="label" for="id_event_date">{% trans "Domain:" %}</label>
|
<label class="label" for="id_event_date">{% trans "Domain:" %}</label>
|
||||||
|
<div class="field has-addons">
|
||||||
|
<div class="control">
|
||||||
|
<div class="button is-disabled">@</div>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
{{ form.domain }}
|
{{ form.domain }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% for error in form.domain.errors %}
|
{% for error in form.domain.errors %}
|
||||||
<p class="help is-danger">{{ error | escape }}</p>
|
<p class="help is-danger">{{ error | escape }}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{% extends 'settings/layout.html' %}
|
{% extends 'settings/layout.html' %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load humanize %}
|
||||||
|
|
||||||
{% block title %}{% trans "Email Blocklist" %}{% endblock %}
|
{% block title %}{% trans "Email Blocklist" %}{% endblock %}
|
||||||
|
|
||||||
{% block header %}{% trans "Email Blocklist" %}{% endblock %}
|
{% block header %}{% trans "Email Blocklist" %}{% endblock %}
|
||||||
|
@ -17,13 +19,14 @@
|
||||||
{% trans "When someone tries to register with an email from this domain, no account will be created. The registration process will appear to have worked." %}
|
{% trans "When someone tries to register with an email from this domain, no account will be created. The registration process will appear to have worked." %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table class="table is-striped">
|
<table class="table is-striped is-fullwidth">
|
||||||
<tr>
|
<tr>
|
||||||
{% url 'settings-federation' as url %}
|
{% url 'settings-federation' as url %}
|
||||||
<th>
|
<th>
|
||||||
{% trans "Domain" as text %}
|
{% trans "Domain" as text %}
|
||||||
{% include 'snippets/table-sort-header.html' with field="server_name" sort=sort text=text %}
|
{% include 'snippets/table-sort-header.html' with field="server_name" sort=sort text=text %}
|
||||||
</th>
|
</th>
|
||||||
|
<th></th>
|
||||||
<th>
|
<th>
|
||||||
{% trans "Options" %}
|
{% trans "Options" %}
|
||||||
</th>
|
</th>
|
||||||
|
@ -31,17 +34,30 @@
|
||||||
{% for domain in domains %}
|
{% for domain in domains %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ domain.domain }}</td>
|
<td>{{ domain.domain }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'settings-users' %}?email=@{{ domain.domain }}">
|
||||||
|
{% with user_count=domain.users.count %}
|
||||||
|
{% blocktrans trimmed count conter=user_count with display_count=user_count|intcomma %}
|
||||||
|
{{ display_count }} user
|
||||||
|
{% plural %}
|
||||||
|
{{ display_count }} users
|
||||||
|
{% endblocktrans %}
|
||||||
|
{% endwith %}
|
||||||
|
</a>
|
||||||
<td>
|
<td>
|
||||||
{% trans "Delete" as button_text %}
|
{% trans "Delete" as button_text %}
|
||||||
<button class="button">
|
<button class="button">
|
||||||
<span class="icon icon-x" title="{{ button_text }}" aria-hidden="true"></span>
|
<span class="icon icon-x" title="{{ button_text }}" aria-hidden="true"></span>
|
||||||
<span class="is-hidden-mobile">{{ button_text }}</span>
|
<span class="is-hidden-mobile">{{ button_text }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
{% trans "Block users" as button_text %}
|
||||||
|
<button class="button is-danger">
|
||||||
|
{{ button_text }}
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% include 'snippets/pagination.html' with page=servers path=request.path %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -22,3 +22,17 @@ class EmailBlocklist(View):
|
||||||
"form": forms.EmailBlocklistForm(),
|
"form": forms.EmailBlocklistForm(),
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "settings/email_blocklist.html", data)
|
return TemplateResponse(request, "settings/email_blocklist.html", data)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
"""create a new domain block"""
|
||||||
|
form = forms.EmailBlocklistForm(request.POST)
|
||||||
|
data = {
|
||||||
|
"domains": models.EmailBlocklist.objects.order_by("-created_date").all(),
|
||||||
|
"form": form,
|
||||||
|
}
|
||||||
|
if not form.is_valid():
|
||||||
|
return TemplateResponse(request, "settings/email_blocklist.html", data)
|
||||||
|
form.save()
|
||||||
|
|
||||||
|
data["form"] = forms.EmailBlocklistForm()
|
||||||
|
return TemplateResponse(request, "settings/email_blocklist.html", data)
|
||||||
|
|
Loading…
Reference in a new issue