add rule editing
This commit is contained in:
parent
7bf5faebe6
commit
ee900b5282
40
README.md
40
README.md
|
@ -30,44 +30,6 @@ You can run either `make run` or `~/.local/share/venv/uncia/bin/python -m uncia`
|
|||
|
||||
## Manage Commands
|
||||
|
||||
There are a number of commands that can be ran to manage various parts of the relay. Some require the relay to be running in order to work.
|
||||
There are a number of commands that can be ran to manage various parts of the relay. Some require the relay to be running in order to work. Run the `help` command to list all of the available commands.
|
||||
|
||||
~/.local/share/venv/uncia/bin/python -m uncia.manage <command> [*args]
|
||||
|
||||
### Command List
|
||||
|
||||
list all commands and how to use them
|
||||
|
||||
help
|
||||
|
||||
get current settings
|
||||
|
||||
config
|
||||
|
||||
change a setting
|
||||
|
||||
set <key> [value]
|
||||
|
||||
list current requests
|
||||
|
||||
request
|
||||
|
||||
accept a request (relay has to be running)
|
||||
|
||||
accept <actor, inbox, or domain>
|
||||
|
||||
reject a request (relay has to be running)
|
||||
|
||||
reject <actor, inbox, or domain>
|
||||
|
||||
list all subscribed instances
|
||||
|
||||
list
|
||||
|
||||
add an instance to the database (relay has to be running)
|
||||
|
||||
add <actor or domain>
|
||||
|
||||
remove an instance from the database
|
||||
|
||||
remove <actor, inbox, or domain>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
from izzylib import DotDict, boolean, logging
|
||||
|
@ -77,7 +79,7 @@ class Session(SqlSession):
|
|||
privkey = (None, str),
|
||||
name = ('Uncia Relay', str),
|
||||
description = ('Small and fast ActivityPub relay', str),
|
||||
rules = ([], DotDict),
|
||||
rules = (["No homophobia, transphobia, or racism"], json.loads),
|
||||
require_approval = (True, boolean),
|
||||
email = (None, str),
|
||||
show_domain_bans = (False, boolean),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
|
||||
from datetime import datetime
|
||||
from izzylib import logging
|
||||
from izzylib import DotDict, logging
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
|
@ -32,6 +34,12 @@ def cmd_config(self, key, value=None):
|
|||
if not value:
|
||||
value = self.config_defaults[key][0]
|
||||
|
||||
if type(value) == DotDict:
|
||||
value = value.to_json()
|
||||
|
||||
elif type(value) in [dict, list, set, tuple]:
|
||||
value = json.dumps(value)
|
||||
|
||||
if row:
|
||||
self.update(row=row, value=value)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.item -> %a(href='/') << Home
|
||||
.item -> %a(href='/rules') << Rules
|
||||
.item -> %a(href='/about') << About
|
||||
|
||||
;-if not request.user
|
||||
; .item -> %a(href='/login') << Login
|
||||
|
|
|
@ -16,4 +16,4 @@
|
|||
-for instance in instances:
|
||||
%tr
|
||||
%td.domain -> %a(href='https://{{instance.domain}}/about', target='_new') -> =instance.domain
|
||||
%td.timestamp -> =instance.date
|
||||
%td.timestamp -> =instance.timestamp.strftime('%Y-%m-%d')
|
||||
|
|
|
@ -10,7 +10,7 @@ from .messages import Message
|
|||
|
||||
|
||||
exe = f'{sys.executable} -m uncia.manage'
|
||||
forbidden_keys = ['pubkey', 'privkey', 'version']
|
||||
forbidden_keys = ['pubkey', 'privkey', 'version', 'rules']
|
||||
|
||||
|
||||
## todo: use argparse to simplify argument parsing
|
||||
|
@ -70,6 +70,15 @@ python3 -m uncia.manage accept <actor, inbox, or domain>: *
|
|||
python3 -m uncia.manage deny <actor, inbox, or domain>: *
|
||||
Reject a request.
|
||||
|
||||
python3 -m uncia.manage rules [list]:
|
||||
List the current rules
|
||||
|
||||
python3 -m uncia.manage rules add <rule>:
|
||||
Add a rule to the list
|
||||
|
||||
python3 -m uncia.manage rules remove <rule number>:
|
||||
Remove a rule from the list
|
||||
|
||||
* = The relay needs to be running for the command to work
|
||||
'''
|
||||
|
||||
|
@ -190,6 +199,46 @@ python3 -m uncia.manage deny <actor, inbox, or domain>: *
|
|||
return f'Instance does not exist: {data}'
|
||||
|
||||
|
||||
def cmd_rules(self, *args):
|
||||
try:
|
||||
action = args[0]
|
||||
except IndexError:
|
||||
action = 'list'
|
||||
|
||||
try:
|
||||
rule = ' '.join(args[1:])
|
||||
except IndexError:
|
||||
rule = None
|
||||
|
||||
if action in ['add', 'remove'] and rule == None:
|
||||
return 'You forgot to specify a rule'
|
||||
|
||||
with db.session as s:
|
||||
rules = s.get.config('rules')
|
||||
|
||||
if action == 'list':
|
||||
if not rules:
|
||||
return 'No rules specified'
|
||||
|
||||
text = 'Relay Rules:\n'
|
||||
text += '\n'.join([f'{idx} {rule}' for idx, rule in enumerate(rules)])
|
||||
|
||||
return text
|
||||
|
||||
elif action == 'add':
|
||||
rules.append(rule)
|
||||
s.put.config('rules', rules)
|
||||
return f'Added rule: {rule}'
|
||||
|
||||
elif action == 'remove':
|
||||
rule = int(rule)
|
||||
rule_text = rules[rule]
|
||||
|
||||
rules.remove(rule_text)
|
||||
s.put.config('rules', rules)
|
||||
return f'Removed rule: {rule_text}'
|
||||
|
||||
|
||||
class InvalidCommandError(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
@ -13,24 +13,17 @@ class UnciaHome(View):
|
|||
paths = ['/']
|
||||
|
||||
async def get(self, request, response):
|
||||
instances = []
|
||||
|
||||
with db.session as s:
|
||||
for row in s.get.instance_list():
|
||||
if not row.followid:
|
||||
instances.append({
|
||||
'domain': row.domain,
|
||||
'date': row.timestamp.strftime('%Y-%m-%d')
|
||||
})
|
||||
instances = s.get.instance_list()
|
||||
|
||||
return response.template('page/home.haml', {'instances': instances})
|
||||
|
||||
|
||||
class UnciaRules(View):
|
||||
paths = ['/rules']
|
||||
class UnciaAbout(View):
|
||||
paths = ['/about']
|
||||
|
||||
async def get(self, request, response):
|
||||
return response.template('page/rules.haml')
|
||||
return response.template('page/about.haml')
|
||||
|
||||
|
||||
class UnciaRegister(View):
|
||||
|
@ -118,7 +111,7 @@ class UnciaActor(View):
|
|||
'preferredUsername': 'relay',
|
||||
'type': 'Application',
|
||||
'inbox': f'https://{config.host}/inbox',
|
||||
'url': f'https://{config.host}/actor',
|
||||
'url': f'https://{config.host}/',
|
||||
'manuallyApprovesFollowers': cfg.require_approval,
|
||||
'endpoints': {
|
||||
'sharedInbox': f"https://{config.host}/inbox"
|
||||
|
|
Loading…
Reference in a new issue