From e25c9d1715d7075327be7df8e977a87aa8a9e856 Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Sat, 11 Oct 2025 13:30:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Define=20explicit=20user=5Fgroup?= =?UTF-8?q?s=20proxy-table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ohmyapi/builtin/auth/models.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ohmyapi/builtin/auth/models.py b/src/ohmyapi/builtin/auth/models.py index 831ebae..aeaa4ae 100644 --- a/src/ohmyapi/builtin/auth/models.py +++ b/src/ohmyapi/builtin/auth/models.py @@ -39,7 +39,7 @@ class User(Model): is_admin: bool = field.BooleanField(default=False) is_staff: bool = field.BooleanField(default=False) groups: field.ManyToManyRelation[Group] = field.ManyToManyField( - "ohmyapi_auth.Group", related_name="users", through="usergroups" + "ohmyapi_auth.Group", related_name="users", through="ohmyapi_auth_user_groups" ) class Schema: @@ -72,3 +72,20 @@ class User(Model): if user and user.verify_password(password): return user return None + + +class UserGroups(Model): + user: field.ForeignKeyRelation[User] = field.ForeignKeyField( + "ohmyapi_auth.User", + related_name="user_groups", + index=True, + ) + group: field.ForeignKeyRelation[Group] = field.ForeignKeyField( + "ohmyapi_auth.Group", + related_name="group_users", + index=True, + ) + + class Meta: + table = "ohmyapi_auth_user_groups" + constraints = [("UNIQUE", ("user_id", "group_id"))]