manage: add unban command

This commit is contained in:
Izalia Mae 2021-09-22 19:14:04 -04:00
parent 369ffe9e2a
commit bb37740096
2 changed files with 55 additions and 35 deletions

View file

@ -1,6 +1,17 @@
from izzylib import logging
def cmd_ban(self, handle=None, domain=None):
row = self.get.ban(handle, domain)
if row:
self.remove(row=row)
self.cache.ban.remove(f'{handle}@{domain}')
return True
return False
def cmd_instance(self, data):
instance = self.get.instance(data)

View file

@ -62,6 +62,9 @@ python3 -m remove <actor, inbox, or domain>:
python3 -m uncia.manage ban <handle@domain or domain> [*reason]:
Ban a user or domain. A reason may optionally be specified.
python3 -m uncia.manage unban <handle@domain or domain>: **
Unban a user or domain
python3 -m uncia.manage bans ["users" or "domains"]:
List the currently banned domains and users. A ban type ("users"/"domains")
may be specified to only list that type.
@ -69,18 +72,18 @@ python3 -m uncia.manage bans ["users" or "domains"]:
python3 -m uncia.manage rules [list]:
List the current rules.
python3 -m uncia.manage rules add <rule>:
python3 -m uncia.manage rules add <rule>: **
Add a rule to the list.
python3 -m uncia.manage rules remove <rule number>:
python3 -m uncia.manage rules remove <rule number>: **
Remove a rule from the list.
python3 -m uncia.manage config [key] [value]:
python3 -m uncia.manage config [key] [value]: **
Gets or sets the config. Specify a key and value to set a config option.
Only specify a key to get the value of a specific option. Leave out the
key and value to get all the options and their values.
python3 -m uncia.manage set <key> [value]:
python3 -m uncia.manage set <key> [value]: **
Set a config option to a value. If no value is specified, the default is used.
python3 -m uncia.manage request:
@ -97,6 +100,7 @@ python3 -m uncia.manage convert [pleroma or uncia]:
Pleroma Relay by default.
* = The relay needs to be running for the command to work
** = Caching prevents this from taking effect until restart.
'''
@ -256,39 +260,12 @@ python3 -m uncia.manage convert [pleroma or uncia]:
return f'Removed rule: {rule_text}'
def cmd_ban(self, string, *args):
handle = None
domain = None
def cmd_ban(self, string, *reason):
return self.manage_ban('ban', string, *reason)
data = string.split('@')
if len(data) == 1:
domain = data[0]
elif len(data) == 2:
handle = data[0]
domain = data[1]
elif len(data) == 3:
handle = data[1]
domain = data[2]
reason = None if not args else ' '.join(args)
with db.session as s:
row = s.put.ban(handle, domain, reason)
if row:
if handle:
return f'Banned {user}@{domain}'
return f'Banned {domain}'
else:
if handle:
return f'Already banned {user}@{domain}'
return f'Already banned {domain}'
def cmd_unban(self, string):
return self.manage_ban('unban', string)
def cmd_bans(self, type=None):
@ -503,6 +480,38 @@ python3 -m uncia.manage convert [pleroma or uncia]:
pl_cfg.db.delete()
def manage_ban(self, action, string, *args):
handle = None
domain = None
data = string.split('@')
if len(data) == 1:
domain = data[0]
elif len(data) == 2:
handle = data[0]
domain = data[1]
elif len(data) == 3:
handle = data[1]
domain = data[2]
reason = None if not args else ' '.join(args)
data = f'{user}@{domain}' if handle else domain
with db.session as s:
if action == 'ban':
row = s.put.ban(handle, domain, reason)
return f'Banned {data}' if row else f'Already banned {data}'
elif action == 'unban':
row = s.delete.ban(handle, domain)
return f'Unbanned {data}' if row else f'{data} not banned'
return f'Invalid action: {action}'
def load_old_uncia_config():
try:
load_envbash(path.config.join('production.env'))