mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-09 18:08:00 +00:00
create admin config page
This commit is contained in:
parent
e6831f04eb
commit
e5d8c9dcb0
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
import bsql
|
import bsql
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .config import get_default_value
|
from .config import CONFIG_DEFAULTS, THEMES, get_default_value
|
||||||
from .connection import RELAY_SOFTWARE, Connection
|
from .connection import RELAY_SOFTWARE, Connection
|
||||||
from .schema import TABLES, VERSIONS, migrate_0
|
from .schema import TABLES, VERSIONS, migrate_0
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,10 @@ THEMES = {
|
||||||
|
|
||||||
CONFIG_DEFAULTS: dict[str, tuple[str, Any]] = {
|
CONFIG_DEFAULTS: dict[str, tuple[str, Any]] = {
|
||||||
'schema-version': ('int', 20240206),
|
'schema-version': ('int', 20240206),
|
||||||
|
'private-key': ('str', None),
|
||||||
'log-level': ('loglevel', logging.LogLevel.INFO),
|
'log-level': ('loglevel', logging.LogLevel.INFO),
|
||||||
'name': ('str', 'ActivityRelay'),
|
'name': ('str', 'ActivityRelay'),
|
||||||
'note': ('str', 'Make a note about your instance here.'),
|
'note': ('str', 'Make a note about your instance here.'),
|
||||||
'private-key': ('str', None),
|
|
||||||
'theme': ('str', 'default'),
|
'theme': ('str', 'default'),
|
||||||
'whitelist-enabled': ('bool', False)
|
'whitelist-enabled': ('bool', False)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,37 @@
|
||||||
-extends "base.haml"
|
-extends "base.haml"
|
||||||
-set page="Config"
|
-set page="Config"
|
||||||
-block content
|
-block content
|
||||||
.section
|
%form.section(action="/admin/config" method="POST")
|
||||||
UvU
|
#config-options
|
||||||
|
%label(for="name") << Name
|
||||||
|
%input(id = "name" name="name" placeholder="Relay Name" value="{{config.name or ''}}")
|
||||||
|
|
||||||
|
%label(for="description") << Description
|
||||||
|
%textarea(id="description" name="note" value="{{config.note}}") << {{config.note}}
|
||||||
|
|
||||||
|
%label(for="theme") << Color Theme
|
||||||
|
%select(id="theme" name="theme")
|
||||||
|
-for theme in themes
|
||||||
|
-if theme == config.theme
|
||||||
|
%option(value="{{theme}}" selected) -> =theme.title()
|
||||||
|
|
||||||
|
-else
|
||||||
|
%option(value="{{theme}}") -> =theme.title()
|
||||||
|
|
||||||
|
%label(for="log-level") << Log Level
|
||||||
|
%select(id="log-level" name="log-level")
|
||||||
|
-for level in LogLevel
|
||||||
|
-if level == config["log-level"]
|
||||||
|
%option(value="{{level.name}}" selected) -> =level.name.title()
|
||||||
|
|
||||||
|
-else
|
||||||
|
%option(value="{{level.name}}") -> =level.name.title()
|
||||||
|
|
||||||
|
%label(for="whitelist-enabled") << Whitelist
|
||||||
|
-if config["whitelist-enabled"]
|
||||||
|
%input(id="whitelist-enabled" name="whitelist-enabled" type="checkbox" checked)
|
||||||
|
|
||||||
|
-else
|
||||||
|
%input(id="whitelist-enabled" name="whitelist-enabled" type="checkbox")
|
||||||
|
|
||||||
|
%input(type="submit" value="Save")
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
%form(target="/admin/instances", method="POST")
|
%form(target="/admin/instances", method="POST")
|
||||||
#add-instance
|
#add-instance
|
||||||
%label(for="domain") << Domain
|
%label(for="domain") << Domain
|
||||||
%input(type="domain", name="domain", placeholder="Domain")
|
%input(type="domain", id="domain" name="domain", placeholder="Domain")
|
||||||
%label(for="actor") << Actor URL
|
%label(for="actor") << Actor URL
|
||||||
%input(type="url", name="actor", placeholder="Actor URL")
|
%input(type="url", id="actor" name="actor", placeholder="Actor URL")
|
||||||
%label(for="inbox") << Inbox URL
|
%label(for="inbox") << Inbox URL
|
||||||
%input(type="url", name="inbox", placeholder="Inbox URL")
|
%input(type="url", id="inbox" name="inbox", placeholder="Inbox URL")
|
||||||
%label(for="software") << Software
|
%label(for="software") << Software
|
||||||
%input(name="software", placeholder="software")
|
%input(name="software", id="software" placeholder="software")
|
||||||
|
|
||||||
%input(type="submit" value="Add Instance")
|
%input(type="submit" value="Add Instance")
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
-set page = "Home"
|
-set page = "Home"
|
||||||
-block content
|
-block content
|
||||||
.section
|
.section
|
||||||
=config.note
|
-for line in config.note.splitlines()
|
||||||
|
-if line
|
||||||
|
%p -> =line
|
||||||
|
|
||||||
.section
|
.section
|
||||||
%p
|
%p
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#config-options {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: max-content auto;
|
||||||
|
grid-gap: var(--spacing);
|
||||||
|
margin-bottom: var(--spacing);
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
form input[type="submit"] {
|
||||||
|
display: block;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
form input[type="checkbox"] {
|
||||||
|
justify-self: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
height: 4em;
|
||||||
|
}
|
|
@ -7,6 +7,8 @@ from argon2.exceptions import VerifyMismatchError
|
||||||
|
|
||||||
from .base import View, register_route
|
from .base import View, register_route
|
||||||
|
|
||||||
|
from ..database import CONFIG_DEFAULTS, THEMES
|
||||||
|
from ..logger import LogLevel
|
||||||
from ..misc import ACTOR_FORMATS, Message, Response
|
from ..misc import ACTOR_FORMATS, Message, Response
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
|
@ -18,6 +20,11 @@ UNAUTH_ROUTES = {
|
||||||
'/login'
|
'/login'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CONFIG_IGNORE = (
|
||||||
|
'schema-version',
|
||||||
|
'private-key'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@web.middleware
|
@web.middleware
|
||||||
async def handle_frontend_path(request: web.Request, handler: Coroutine) -> Response:
|
async def handle_frontend_path(request: web.Request, handler: Coroutine) -> Response:
|
||||||
|
@ -200,11 +207,37 @@ class AdminSoftwareBans(View):
|
||||||
|
|
||||||
@register_route('/admin/config')
|
@register_route('/admin/config')
|
||||||
class AdminConfig(View):
|
class AdminConfig(View):
|
||||||
async def get(self, request: Request) -> Response:
|
async def get(self, request: Request, message: str | None = None) -> Response:
|
||||||
data = self.template.render('page/admin-config.haml', self)
|
context = {
|
||||||
|
'themes': tuple(THEMES.keys()),
|
||||||
|
'LogLevel': LogLevel,
|
||||||
|
'message': message
|
||||||
|
}
|
||||||
|
data = self.template.render('page/admin-config.haml', self, **context)
|
||||||
return Response.new(data, ctype = 'html')
|
return Response.new(data, ctype = 'html')
|
||||||
|
|
||||||
|
|
||||||
|
async def post(self, request: Request) -> Response:
|
||||||
|
form = dict(await request.post())
|
||||||
|
|
||||||
|
with self.database.session(True) as conn:
|
||||||
|
for key in CONFIG_DEFAULTS:
|
||||||
|
value = form.get(key)
|
||||||
|
|
||||||
|
if key == 'whitelist-enabled':
|
||||||
|
value = bool(value)
|
||||||
|
|
||||||
|
elif key.lower() in CONFIG_IGNORE:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
conn.put_config(key, value)
|
||||||
|
|
||||||
|
return await self.get(request, message = 'Updated config')
|
||||||
|
|
||||||
|
|
||||||
@register_route('/style.css')
|
@register_route('/style.css')
|
||||||
class StyleCss(View):
|
class StyleCss(View):
|
||||||
async def get(self, request: Request) -> Response:
|
async def get(self, request: Request) -> Response:
|
||||||
|
|
Loading…
Reference in a new issue