fix(identity): isolate public web entries
This commit is contained in:
1 parent
240f1f9903
commit
2065fe2acd
5 files changed
+17
-34
No files matched your search
+1
-31
@@ -75,32 +75,6 @@ def sync_application_exports() -> int:
|
||||
return GoogleSheetsExportService(application_store()).sync_pending()
|
||||
|
||||
|
||||
_WEB_PROFILE_KEY = "web_user"
|
||||
|
||||
|
||||
def save_profile(payload):
|
||||
name = str(payload.get("name", "")).strip()
|
||||
raw_id = payload.get("character_id")
|
||||
try:
|
||||
character_id = int(raw_id) if raw_id not in (None, "") else None
|
||||
except (TypeError, ValueError):
|
||||
raise ApiError("ID персонажа должно быть числом")
|
||||
if not name or character_id is None:
|
||||
raise ApiError("Нужно указать и имя, и ID персонажа")
|
||||
identity = identity_dir().remember(name=name, character_id=character_id)
|
||||
actor_id = int(_WEB_PROFILE_KEY.encode().hex(), 16) if isinstance(_WEB_PROFILE_KEY, str) else 0
|
||||
identity_dir().remember_profile(actor_id=actor_id, name=name, character_id=character_id)
|
||||
return {"status": "saved", "name": identity.name, "character_id": identity.character_id}
|
||||
|
||||
|
||||
def get_profile():
|
||||
actor_id = int(_WEB_PROFILE_KEY.encode().hex(), 16) if isinstance(_WEB_PROFILE_KEY, str) else 0
|
||||
profile = identity_dir().profile(actor_id=actor_id)
|
||||
if profile:
|
||||
return {"status": "found", "name": profile.name, "character_id": profile.character_id}
|
||||
return {"status": "not_found"}
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
server_version = "BelkiCalculator/0.1"
|
||||
protocol_version = "HTTP/1.1"
|
||||
@@ -243,7 +217,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
def do_POST(self) -> None: # noqa: N802
|
||||
if self.path not in ("/api/admin/auth", "/api/admin/logout", "/api/web/upload", "/api/calculate", "/api/inspect-bulk", "/api/resolve-identity",
|
||||
"/api/save-profile", "/api/get-profile", "/api/applications"):
|
||||
"/api/applications"):
|
||||
self._json(404, {"error": "Не найдено"})
|
||||
return
|
||||
try:
|
||||
@@ -288,10 +262,6 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._json(200, inspect_bulk_payload(payload))
|
||||
elif self.path == "/api/resolve-identity":
|
||||
self._json(200, resolve_identity_payload(payload))
|
||||
elif self.path == "/api/save-profile":
|
||||
self._json(200, save_profile(payload))
|
||||
elif self.path == "/api/get-profile":
|
||||
self._json(200, get_profile())
|
||||
elif self.path == "/api/applications":
|
||||
application = validate_application(payload)
|
||||
application_id = application_store().create(application=application, actor_id=None, reply_peer_id=None, source="web")
|
||||
|
||||
Reference in new issue
Block a user