]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/people.py
23339daa4c480fb7a9a30b1476caff5b3db0da47
6 from . import handlers_base
as base
7 from . import ui_modules
9 class IndexHandler(base
.BaseHandler
):
10 @tornado.web
.authenticated
12 self
.render("people/index.html")
15 class AvatarHandler(base
.BaseHandler
):
17 # Get the desired size of the avatar file
18 size
= self
.get_argument("size", 0)
22 except (TypeError, ValueError):
25 logging
.debug("Querying for avatar of %s" % uid
)
28 account
= self
.backend
.accounts
.get_by_uid(uid
)
30 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
32 # Allow downstream to cache this for 60 minutes
33 self
.set_expires(3600)
36 avatar
= account
.get_avatar(size
)
38 # If there is no avatar, we serve a default image
40 logging
.debug("No avatar uploaded for %s" % account
)
42 return self
.redirect("https://static.ipfire.org%s" % self
.static_url("img/default-avatar.jpg"))
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")
52 class RegistrationsHandler(base
.BaseHandler
):
53 @tornado.web
.authenticated
56 if self
.current_user
.uid
== uid
:
57 account
= self
.current_user
59 # Admins can access all other users, too
60 elif self
.current_user
.is_admin():
61 account
= self
.backend
.accounts
.get_by_uid(uid
)
63 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
65 # Otherwise, no access is permitted
67 raise tornado
.web
.HTTPError(403)
69 self
.render("people/registrations.html", account
=account
)
72 class SearchHandler(base
.BaseHandler
):
73 @tornado.web
.authenticated
75 q
= self
.get_argument("q")
78 accounts
= self
.backend
.accounts
.search(q
)
80 # Redirect when only one result was found
81 if len(accounts
) == 1:
82 self
.redirect("/users/%s" % accounts
[0].uid
)
85 self
.render("people/search.html", q
=q
, accounts
=accounts
)
88 class UsersHandler(base
.BaseHandler
):
89 @tornado.web
.authenticated
91 self
.render("people/users.html")
94 class UserHandler(base
.BaseHandler
):
95 @tornado.web
.authenticated
97 account
= self
.backend
.accounts
.get_by_uid(uid
)
99 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
101 self
.render("people/user.html", account
=account
)
104 class AccountsListModule(ui_modules
.UIModule
):
105 def render(self
, accounts
=None):
107 accounts
= self
.backend
.accounts
109 return self
.render_string("people/modules/accounts-list.html", accounts
=accounts
)
112 class CDRModule(ui_modules
.UIModule
):
113 def render(self
, account
, limit
=None):
114 cdr
= account
.get_cdr(limit
=limit
)
116 return self
.render_string("people/modules/cdr.html", account
=account
, cdr
=cdr
)
119 class ChannelsModule(ui_modules
.UIModule
):
120 def render(self
, account
):
121 channels
= self
.backend
.talk
.freeswitch
.get_sip_channels(account
)
123 return self
.render_string("people/modules/channels.html", account
=account
, channels
=channels
)
126 class RegistrationsModule(ui_modules
.UIModule
):
127 def render(self
, account
):
128 return self
.render_string("people/modules/registrations.html", account
=account
)