]> git.ipfire.org Git - ipfire.org.git/blob - src/web/people.py
23339daa4c480fb7a9a30b1476caff5b3db0da47
[ipfire.org.git] / src / web / people.py
1 #!/usr/bin/python
2
3 import logging
4 import tornado.web
5
6 from . import handlers_base as base
7 from . import ui_modules
8
9 class IndexHandler(base.BaseHandler):
10 @tornado.web.authenticated
11 def get(self):
12 self.render("people/index.html")
13
14
15 class AvatarHandler(base.BaseHandler):
16 def get(self, uid):
17 # Get the desired size of the avatar file
18 size = self.get_argument("size", 0)
19
20 try:
21 size = int(size)
22 except (TypeError, ValueError):
23 size = None
24
25 logging.debug("Querying for avatar of %s" % uid)
26
27 # Fetch user account
28 account = self.backend.accounts.get_by_uid(uid)
29 if not account:
30 raise tornado.web.HTTPError(404, "Could not find account %s" % uid)
31
32 # Allow downstream to cache this for 60 minutes
33 self.set_expires(3600)
34
35 # Resize avatar
36 avatar = account.get_avatar(size)
37
38 # If there is no avatar, we serve a default image
39 if not avatar:
40 logging.debug("No avatar uploaded for %s" % account)
41
42 return self.redirect("https://static.ipfire.org%s" % self.static_url("img/default-avatar.jpg"))
43
44 # Set headers about content
45 self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account.uid)
46 self.set_header("Content-Type", "image/jpeg")
47
48 # Deliver payload
49 self.finish(avatar)
50
51
52 class RegistrationsHandler(base.BaseHandler):
53 @tornado.web.authenticated
54 def get(self, uid):
55 # Get own account
56 if self.current_user.uid == uid:
57 account = self.current_user
58
59 # Admins can access all other users, too
60 elif self.current_user.is_admin():
61 account = self.backend.accounts.get_by_uid(uid)
62 if not account:
63 raise tornado.web.HTTPError(404, "Could not find account %s" % uid)
64
65 # Otherwise, no access is permitted
66 else:
67 raise tornado.web.HTTPError(403)
68
69 self.render("people/registrations.html", account=account)
70
71
72 class SearchHandler(base.BaseHandler):
73 @tornado.web.authenticated
74 def get(self):
75 q = self.get_argument("q")
76
77 # Perform the search
78 accounts = self.backend.accounts.search(q)
79
80 # Redirect when only one result was found
81 if len(accounts) == 1:
82 self.redirect("/users/%s" % accounts[0].uid)
83 return
84
85 self.render("people/search.html", q=q, accounts=accounts)
86
87
88 class UsersHandler(base.BaseHandler):
89 @tornado.web.authenticated
90 def get(self):
91 self.render("people/users.html")
92
93
94 class UserHandler(base.BaseHandler):
95 @tornado.web.authenticated
96 def get(self, uid):
97 account = self.backend.accounts.get_by_uid(uid)
98 if not account:
99 raise tornado.web.HTTPError(404, "Could not find account %s" % uid)
100
101 self.render("people/user.html", account=account)
102
103
104 class AccountsListModule(ui_modules.UIModule):
105 def render(self, accounts=None):
106 if accounts is None:
107 accounts = self.backend.accounts
108
109 return self.render_string("people/modules/accounts-list.html", accounts=accounts)
110
111
112 class CDRModule(ui_modules.UIModule):
113 def render(self, account, limit=None):
114 cdr = account.get_cdr(limit=limit)
115
116 return self.render_string("people/modules/cdr.html", account=account, cdr=cdr)
117
118
119 class ChannelsModule(ui_modules.UIModule):
120 def render(self, account):
121 channels = self.backend.talk.freeswitch.get_sip_channels(account)
122
123 return self.render_string("people/modules/channels.html", account=account, channels=channels)
124
125
126 class RegistrationsModule(ui_modules.UIModule):
127 def render(self, account):
128 return self.render_string("people/modules/registrations.html", account=account)