mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-09 01:57:58 +00:00
create admin whitelist page
This commit is contained in:
parent
a163f2baab
commit
5dcf375247
|
@ -25,7 +25,7 @@
|
|||
%tr
|
||||
%td.instance << Instance
|
||||
%td.software << Software
|
||||
%td << Joined
|
||||
%td.date << Joined
|
||||
%td.remove
|
||||
|
||||
%tbody
|
||||
|
|
|
@ -1,5 +1,31 @@
|
|||
-extends "base.haml"
|
||||
-set page="Whitelist"
|
||||
-block content
|
||||
.section
|
||||
UvU
|
||||
%details.section
|
||||
%summary << Add Domain
|
||||
%form(target="/admin/whitelist", method="POST")
|
||||
#add-domain
|
||||
%label(for="domain") << Domain
|
||||
%input(type="domain", id="domain" name="domain", placeholder="Domain")
|
||||
|
||||
%input(type="submit" value="Add Domain")
|
||||
|
||||
#whitelist.section
|
||||
%table
|
||||
%thead
|
||||
%tr
|
||||
%td.domain << Domain
|
||||
%td.date << Added
|
||||
%td.remove
|
||||
|
||||
%tbody
|
||||
-for item in whitelist
|
||||
%tr
|
||||
%td.domain
|
||||
=item.domain
|
||||
|
||||
%td.date
|
||||
=item.created.strftime("%Y-%m-%d")
|
||||
|
||||
%td.remove
|
||||
%a(href="/admin/whitelist/delete/{{item.domain}}" title="Remove whitlisted domain") << ✖
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
form input[type="submit"] {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
#whitelist .domain{
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#whitelist .date {
|
||||
width: max-content;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#add-domain {
|
||||
display: grid;
|
||||
grid-template-columns: max-content auto;
|
||||
grid-gap: var(--spacing);
|
||||
margin-top: var(--spacing);
|
||||
margin-bottom: var(--spacing);
|
||||
}
|
|
@ -193,7 +193,7 @@ class AdminWhitelist(View):
|
|||
|
||||
with self.database.session() as conn:
|
||||
context = {
|
||||
'domains': tuple(conn.execute('SELECT * FROM whitelist').all())
|
||||
'whitelist': tuple(conn.execute('SELECT * FROM whitelist').all())
|
||||
}
|
||||
|
||||
if error:
|
||||
|
@ -206,6 +206,34 @@ class AdminWhitelist(View):
|
|||
return Response.new(data, ctype = 'html')
|
||||
|
||||
|
||||
async def post(self, request: Request) -> Response:
|
||||
data = await request.post()
|
||||
|
||||
if not data['domain']:
|
||||
return await self.get(request, error = 'Missing domain')
|
||||
|
||||
with self.database.session(True) as conn:
|
||||
if (ban := conn.get_domain_whitelist(data['domain'])):
|
||||
return await self.get(request, message = "Domain already in whitelist")
|
||||
|
||||
conn.put_domain_whitelist(data['domain'])
|
||||
|
||||
return await self.get(request, message = "Added/updated domain ban")
|
||||
|
||||
|
||||
@register_route('/admin/whitelist/delete/{domain}')
|
||||
class AdminWhitlistDelete(View):
|
||||
async def get(self, request: Request, domain: str) -> Response:
|
||||
with self.database.session() as conn:
|
||||
if not (conn.get_domain_whitelist(domain)):
|
||||
msg = 'Whitelisted domain not found'
|
||||
return await AdminWhitelist.run("GET", request, message = msg)
|
||||
|
||||
conn.del_domain_whitelist(domain)
|
||||
|
||||
return await AdminWhitelist.run("GET", request, message = 'Removed domain from whitelist')
|
||||
|
||||
|
||||
@register_route('/admin/domain_bans')
|
||||
class AdminDomainBans(View):
|
||||
async def get(self,
|
||||
|
|
Loading…
Reference in a new issue