]>
Commit | Line | Data |
---|---|---|
2cd9af74 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import logging | |
4 | import tornado.web | |
5 | ||
f6ed3d4d | 6 | from . import handlers_base as base |
786e9ca8 MT |
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 | ||
2cd9af74 | 14 | |
c4f1a618 | 15 | class AvatarHandler(base.BaseHandler): |
0cddf220 | 16 | def get(self, uid): |
2cd9af74 MT |
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 | ||
0cddf220 | 25 | logging.debug("Querying for avatar of %s" % uid) |
2cd9af74 | 26 | |
f6ed3d4d | 27 | # Fetch user account |
0cddf220 | 28 | account = self.backend.accounts.get_by_uid(uid) |
f6ed3d4d | 29 | if not account: |
0cddf220 | 30 | raise tornado.web.HTTPError(404, "Could not find account %s" % uid) |
2cd9af74 | 31 | |
f6ed3d4d MT |
32 | # Allow downstream to cache this for 60 minutes |
33 | self.set_expires(3600) | |
2cd9af74 | 34 | |
f6ed3d4d MT |
35 | # Resize avatar |
36 | avatar = account.get_avatar(size) | |
2cd9af74 | 37 | |
f6ed3d4d MT |
38 | # If there is no avatar, we serve a default image |
39 | if not avatar: | |
0cddf220 MT |
40 | logging.debug("No avatar uploaded for %s" % account) |
41 | ||
c740fe40 | 42 | return self.redirect("https://static.ipfire.org%s" % self.static_url("img/default-avatar.jpg")) |
2cd9af74 | 43 | |
f6ed3d4d | 44 | # Set headers about content |
0cddf220 | 45 | self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account.uid) |
2cd9af74 MT |
46 | self.set_header("Content-Type", "image/jpeg") |
47 | ||
f6ed3d4d | 48 | # Deliver payload |
2cd9af74 | 49 | self.finish(avatar) |
786e9ca8 MT |
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.talk.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.talk.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) |