summaryrefslogtreecommitdiffstats
path: root/users/models
diff options
context:
space:
mode:
authorMichael Manfre2022-11-25 21:33:46 -0500
committerGitHub2022-11-25 19:33:46 -0700
commitd60ba9a0515aed0b8235a7738a5fecd8fd78f859 (patch)
treed571851b37d2b5c4a1f122e6fbf3890947ee7af2 /users/models
parentab7a8cb120fe905562281b331a08e87abeff0fbe (diff)
downloadtakahe-d60ba9a0515aed0b8235a7738a5fecd8fd78f859.tar.gz
takahe-d60ba9a0515aed0b8235a7738a5fecd8fd78f859.tar.bz2
takahe-d60ba9a0515aed0b8235a7738a5fecd8fd78f859.zip
Added default post visibility
Diffstat (limited to 'users/models')
-rw-r--r--users/models/identity.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/users/models/identity.py b/users/models/identity.py
index 5d7fd0b..8583487 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -1,4 +1,4 @@
-from functools import partial
+from functools import cached_property, partial
from typing import Dict, Literal, Optional, Tuple
from urllib.parse import urlparse
@@ -9,10 +9,12 @@ from django.db import IntegrityError, models
from django.template.defaultfilters import linebreaks_filter
from django.templatetags.static import static
from django.utils import timezone
+from django.utils.functional import lazy
from core.exceptions import ActorMismatchError
from core.html import sanitize_post
from core.ld import canonicalise, media_type_from_filename
+from core.models import Config
from core.signatures import HttpSignature, RsaKeys
from core.uploads import upload_namer
from stator.models import State, StateField, StateGraph, StatorModel
@@ -433,3 +435,17 @@ class Identity(StatorModel):
self.private_key, self.public_key = RsaKeys.generate_keypair()
self.public_key_id = self.actor_uri + "#main-key"
self.save()
+
+ ### Config ###
+
+ @cached_property
+ def config_identity(self) -> Config.IdentityOptions:
+ return Config.load_identity(self)
+
+ def lazy_config_value(self, key: str):
+ """
+ Lazily load a config value for this Identity
+ """
+ if key not in Config.IdentityOptions.__fields__:
+ raise KeyError(f"Undefined IdentityOption for {key}")
+ return lazy(lambda: getattr(self.config_identity, key))