diff options
author | Andrew Godwin | 2022-11-16 21:42:25 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-16 21:42:25 -0700 |
commit | 5b34ea46c3f458a174c5443714ade43c21defdac (patch) | |
tree | e41dda2218cee559268f99a802210f7507f47b02 /users | |
parent | 9d97fc92d82289301896c88f8c828321aa99701d (diff) | |
download | takahe-5b34ea46c3f458a174c5443714ade43c21defdac.tar.gz takahe-5b34ea46c3f458a174c5443714ade43c21defdac.tar.bz2 takahe-5b34ea46c3f458a174c5443714ade43c21defdac.zip |
Call it admin rather than system settings
Diffstat (limited to 'users')
-rw-r--r-- | users/admin.py | 3 | ||||
-rw-r--r-- | users/middleware.py | 5 | ||||
-rw-r--r-- | users/migrations/0003_user_last_seen_alter_identity_domain.py | 34 | ||||
-rw-r--r-- | users/models/domain.py | 8 | ||||
-rw-r--r-- | users/models/user.py | 1 | ||||
-rw-r--r-- | users/views/admin.py (renamed from users/views/settings_system.py) | 46 | ||||
-rw-r--r-- | users/views/settings.py (renamed from users/views/settings_identity.py) | 12 |
7 files changed, 84 insertions, 25 deletions
diff --git a/users/admin.py b/users/admin.py index 5364880..7c3750d 100644 --- a/users/admin.py +++ b/users/admin.py @@ -10,7 +10,7 @@ class DomainAdmin(admin.ModelAdmin): @admin.register(User) class UserAdmin(admin.ModelAdmin): - pass + list_display = ["email", "created", "last_seen", "admin", "moderator", "banned"] @admin.register(UserEvent) @@ -21,6 +21,7 @@ class UserEventAdmin(admin.ModelAdmin): @admin.register(Identity) class IdentityAdmin(admin.ModelAdmin): list_display = ["id", "handle", "actor_uri", "state", "local"] + list_filter = ["local"] raw_id_fields = ["users"] actions = ["force_update"] readonly_fields = ["actor_json"] diff --git a/users/middleware.py b/users/middleware.py index aa22178..e6d4036 100644 --- a/users/middleware.py +++ b/users/middleware.py @@ -1,4 +1,6 @@ -from users.models import Identity +from django.utils import timezone + +from users.models import Identity, User class IdentityMiddleware: @@ -17,6 +19,7 @@ class IdentityMiddleware: else: try: request.identity = Identity.objects.get(id=identity_id) + User.objects.filter(pk=request.user.pk).update(last_seen=timezone.now()) except Identity.DoesNotExist: request.identity = None diff --git a/users/migrations/0003_user_last_seen_alter_identity_domain.py b/users/migrations/0003_user_last_seen_alter_identity_domain.py new file mode 100644 index 0000000..b6c49d1 --- /dev/null +++ b/users/migrations/0003_user_last_seen_alter_identity_domain.py @@ -0,0 +1,34 @@ +# Generated by Django 4.1.3 on 2022-11-17 04:18 + +import django.db.models.deletion +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("users", "0002_identity_public_key_id"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="last_seen", + field=models.DateTimeField( + auto_now_add=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AlterField( + model_name="identity", + name="domain", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="identities", + to="users.domain", + ), + ), + ] diff --git a/users/models/domain.py b/users/models/domain.py index af0bbab..4743503 100644 --- a/users/models/domain.py +++ b/users/models/domain.py @@ -49,10 +49,10 @@ class Domain(models.Model): updated = models.DateTimeField(auto_now=True) class urls(urlman.Urls): - root = "/settings/system/domains/" - create = "/settings/system/domains/create/" - edit = "/settings/system/domains/{self.domain}/" - delete = "/settings/system/domains/{self.domain}/delete/" + root = "/admin/domains/" + create = "/admin/domains/create/" + edit = "/admin/domains/{self.domain}/" + delete = "/admin/domains/{self.domain}/delete/" @classmethod def get_remote_domain(cls, domain: str) -> "Domain": diff --git a/users/models/user.py b/users/models/user.py index 6435bf5..08a703e 100644 --- a/users/models/user.py +++ b/users/models/user.py @@ -38,6 +38,7 @@ class User(AbstractBaseUser): created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) + last_seen = models.DateTimeField(auto_now_add=True) USERNAME_FIELD = "email" EMAIL_FIELD = "email" diff --git a/users/views/settings_system.py b/users/views/admin.py index e5e9e85..c1210f1 100644 --- a/users/views/settings_system.py +++ b/users/views/admin.py @@ -10,28 +10,26 @@ from django.views.generic import FormView, RedirectView, TemplateView from core.models import Config from users.decorators import admin_required -from users.models import Domain +from users.models import Domain, Identity, User @method_decorator(admin_required, name="dispatch") -class SystemSettingsRoot(RedirectView): - url = "/settings/system/basic/" +class AdminRoot(RedirectView): + pattern_name = "admin_basic" @method_decorator(admin_required, name="dispatch") -class SystemSettingsPage(FormView): +class AdminSettingsPage(FormView): """ Shows a settings page dynamically created from our settings layout at the bottom of the page. Don't add this to a URL directly - subclass! """ - template_name = "settings/settings_system.html" + template_name = "admin/settings.html" options_class = Config.SystemOptions section: ClassVar[str] options: Dict[str, Dict[str, str]] - extra_context = {"top_section": "settings_system"} - def get_form_class(self): # Create the fields dict from the config object fields = {} @@ -84,7 +82,7 @@ class SystemSettingsPage(FormView): return redirect(".") -class BasicPage(SystemSettingsPage): +class BasicPage(AdminSettingsPage): section = "basic" @@ -103,7 +101,7 @@ class BasicPage(SystemSettingsPage): @method_decorator(admin_required, name="dispatch") class DomainsPage(TemplateView): - template_name = "settings/settings_system_domains.html" + template_name = "admin/domains.html" def get_context_data(self): return { @@ -115,7 +113,7 @@ class DomainsPage(TemplateView): @method_decorator(admin_required, name="dispatch") class DomainCreatePage(FormView): - template_name = "settings/settings_system_domain_create.html" + template_name = "admin/domain_create.html" extra_context = {"section": "domains"} class form_class(forms.Form): @@ -175,7 +173,7 @@ class DomainCreatePage(FormView): @method_decorator(admin_required, name="dispatch") class DomainEditPage(FormView): - template_name = "settings/settings_system_domain_edit.html" + template_name = "admin/domain_edit.html" extra_context = {"section": "domains"} class form_class(forms.Form): @@ -221,7 +219,7 @@ class DomainEditPage(FormView): @method_decorator(admin_required, name="dispatch") class DomainDeletePage(TemplateView): - template_name = "settings/settings_system_domain_delete.html" + template_name = "admin/domain_delete.html" def dispatch(self, request, domain): self.domain = get_object_or_404( @@ -241,3 +239,27 @@ class DomainDeletePage(TemplateView): raise ValueError("Tried to delete domain with identities!") self.domain.delete() return redirect("/settings/system/domains/") + + +@method_decorator(admin_required, name="dispatch") +class UsersPage(TemplateView): + + template_name = "admin/users.html" + + def get_context_data(self): + return { + "users": User.objects.order_by("email"), + "section": "users", + } + + +@method_decorator(admin_required, name="dispatch") +class IdentitiesPage(TemplateView): + + template_name = "admin/identities.html" + + def get_context_data(self): + return { + "identities": Identity.objects.order_by("username"), + "section": "identities", + } diff --git a/users/views/settings_identity.py b/users/views/settings.py index f35928a..877ad01 100644 --- a/users/views/settings_identity.py +++ b/users/views/settings.py @@ -3,24 +3,22 @@ from django.views.generic import RedirectView from core.models import Config from users.decorators import identity_required -from users.views.settings_system import SystemSettingsPage +from users.views.admin import AdminSettingsPage @method_decorator(identity_required, name="dispatch") -class IdentitySettingsRoot(RedirectView): +class SettingsRoot(RedirectView): url = "/settings/interface/" -class IdentitySettingsPage(SystemSettingsPage): +class SettingsPage(AdminSettingsPage): """ Shows a settings page dynamically created from our settings layout at the bottom of the page. Don't add this to a URL directly - subclass! """ - extra_context = {"top_section": "settings"} - options_class = Config.IdentityOptions - template_name = "settings/settings_identity.html" + template_name = "settings/settings.html" def load_config(self): return Config.load_identity(self.request.identity) @@ -29,7 +27,7 @@ class IdentitySettingsPage(SystemSettingsPage): Config.set_identity(self.request.identity, key, value) -class InterfacePage(IdentitySettingsPage): +class InterfacePage(SettingsPage): section = "interface" |