|
@@ -0,0 +1,66 @@
|
|
1
|
+# coding=utf-8
|
|
2
|
+import typing
|
|
3
|
+from datetime import datetime
|
|
4
|
+
|
|
5
|
+from sqlalchemy.orm import Session
|
|
6
|
+from tracim import CFG
|
|
7
|
+from tracim.models import User
|
|
8
|
+from tracim.models.auth import Profile
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+class UserInContext(object):
|
|
12
|
+ """
|
|
13
|
+ Interface to get User data and User data related to context.
|
|
14
|
+ """
|
|
15
|
+
|
|
16
|
+ def __init__(self, user: User, dbsession: Session, config: CFG):
|
|
17
|
+ self.user = user
|
|
18
|
+ self.dbsession = dbsession
|
|
19
|
+ self.config = config
|
|
20
|
+
|
|
21
|
+ # Default
|
|
22
|
+
|
|
23
|
+ @property
|
|
24
|
+ def email(self) -> str:
|
|
25
|
+ return self.user.email
|
|
26
|
+
|
|
27
|
+ @property
|
|
28
|
+ def user_id(self) -> int:
|
|
29
|
+ return self.user.user_id
|
|
30
|
+
|
|
31
|
+ @property
|
|
32
|
+ def display_name(self) -> str:
|
|
33
|
+ return self.user.display_name
|
|
34
|
+
|
|
35
|
+ @property
|
|
36
|
+ def created(self) -> datetime:
|
|
37
|
+ return self.user.created
|
|
38
|
+
|
|
39
|
+ @property
|
|
40
|
+ def is_active(self) -> bool:
|
|
41
|
+ return self.user.is_active
|
|
42
|
+
|
|
43
|
+ @property
|
|
44
|
+ def timezone(self) -> str:
|
|
45
|
+ return self.user.timezone
|
|
46
|
+
|
|
47
|
+ @property
|
|
48
|
+ def profile(self) -> Profile:
|
|
49
|
+ return self.user.profile
|
|
50
|
+
|
|
51
|
+ # Context related
|
|
52
|
+
|
|
53
|
+ @property
|
|
54
|
+ def calendar_url(self) -> typing.Optional[str]:
|
|
55
|
+ # TODO - G-M - 20-04-2018 - [Calendar] Replace calendar code to get
|
|
56
|
+ # url calendar url.
|
|
57
|
+ #
|
|
58
|
+ # from tracim.lib.calendar import CalendarManager
|
|
59
|
+ # calendar_manager = CalendarManager(None)
|
|
60
|
+ # return calendar_manager.get_workspace_calendar_url(self.workspace_id)
|
|
61
|
+ return None
|
|
62
|
+
|
|
63
|
+ @property
|
|
64
|
+ def avatar_url(self) -> typing.Optional[str]:
|
|
65
|
+ # TODO - G-M - 20-04-2018 - [Avatar] Add user avatar feature
|
|
66
|
+ return None
|