1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-18 08:23:51 +03:00

python: models: add get_primary_group method to User model

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
Rob van der Linde
2024-04-30 23:43:30 +12:00
committed by Andrew Bartlett
parent 1f47c0f609
commit 8fe7f0a6d5

View File

@@ -27,6 +27,7 @@ from samba.dsdb import DS_GUID_USERS_CONTAINER
from .exceptions import NotFound
from .fields import DnField, EnumField, IntegerField, NtTimeField, StringField
from .group import Group
from .org import OrganizationalPerson
from .types import AccountType, UserAccountControl
@@ -52,6 +53,11 @@ class User(OrganizationalPerson):
"""Return sAMAccountName rather than cn for User model."""
return self.account_name
def get_primary_group(self, samdb) -> Group:
"""Returns the primary Group object for this User."""
group_sid = f"{samdb.domain_sid}-{self.primary_group_id}"
return Group.get(samdb, object_sid=group_sid)
@staticmethod
def get_base_dn(samdb):
"""Return the base DN for the User model.