Coverage for src/paperap/models/user/model.py: 93%

1"""

2----------------------------------------------------------------------------

3

4 METADATA:

5

6 File: user.py

7 Project: paperap

8 Created: 2025-03-04

9 Version: 0.0.5

10 Author: Jess Mann

11 Email: jess@jmann.me

12 Copyright (c) 2025 Jess Mann

13

14----------------------------------------------------------------------------

15

16 LAST MODIFIED:

17

18 2025-03-04 By Jess Mann

19

20"""

21

22 from __future__ import annotations

23

24 from typing import Any, Optional

25

26 from pydantic import Field

27

28 from paperap.models.abstract.model import StandardModel

29 from paperap.models.user.queryset import GroupQuerySet, UserQuerySet

30

31

32 class Group(StandardModel):

33 """

34 Represents a user group in Paperless-NgX.

35 """

36

37 name: str | None = None

38 permissions: list[str] = Field(default_factory=list)

39

40 class Meta(StandardModel.Meta):

41 queryset = GroupQuerySet

42

43 @property

44 def users(self) -> "UserQuerySet":

45 """

46 Get the users in this group.

47

48 Returns:

49 UserQuerySet: The users in this group

50

51 """

52 return self._client.users().all().in_group(self.id)

53

54

55 class User(StandardModel):

56 """

57 Represents a user in Paperless-NgX.

58 """

59

60 username: str | None = None

61 email: str | None = None

62 password: str | None = None

63 first_name: str | None = None

64 last_name: str | None = None

65 date_joined: str | None = None

66 is_staff: bool | None = None

67 is_active: bool | None = None

68 is_superuser: bool | None = None

69 groups: list[int] = Field(default_factory=list)

70 user_permissions: list[str] = Field(default_factory=list)

71 inherited_permissions: list[str] = Field(default_factory=list)

72

73 class Meta(StandardModel.Meta):

74 queryset = UserQuerySet

75

76 def get_groups(self) -> "GroupQuerySet":

77 """

78 Get the groups this user is a member of.

79

80 Returns:

81 GroupQuerySet: The groups this user is a member

82

83 """

84 return self._client.groups().all().id(self.groups)