]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/people.py
8 from . import handlers_base
as base
9 from . import ui_modules
11 class IndexHandler(base
.BaseHandler
):
12 @tornado.web
.authenticated
14 self
.render("people/index.html")
17 class AvatarHandler(base
.BaseHandler
):
21 # Get the desired size of the avatar file
22 size
= self
.get_argument("size", 0)
26 except (TypeError, ValueError):
29 logging
.debug("Querying for avatar of %s" % uid
)
32 account
= self
.backend
.accounts
.get_by_uid(uid
)
34 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
36 # Allow downstream to cache this for 60 minutes
37 self
.set_expires(3600)
40 avatar
= account
.get_avatar(size
)
42 # If there is no avatar, we serve a default image
44 logging
.debug("No avatar uploaded for %s" % account
)
46 return self
.redirect(self
.static_url("img/default-avatar.jpg"))
48 # Set headers about content
49 self
.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account
.uid
)
50 self
.set_header("Content-Type", "image/jpeg")
56 class CallsHandler(base
.BaseHandler
):
57 @tornado.web
.authenticated
58 def get(self
, uid
, date
=None):
59 account
= self
.backend
.accounts
.get_by_uid(uid
)
61 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
65 date
= datetime
.datetime
.strptime(date
, "%Y-%m-%d").date()
67 raise tornado
.web
.HTTPError(400, "Invalid date: %s" % date
)
69 date
= datetime
.date
.today()
71 self
.render("people/calls.html", account
=account
, date
=date
)
74 class CallHandler(base
.BaseHandler
):
75 @tornado.web
.authenticated
76 def get(self
, uid
, uuid
):
77 call
= self
.backend
.talk
.freeswitch
.get_call_by_uuid(uuid
)
79 raise tornado
.web
.HTTPError(404, "Could not find call %s" % uuid
)
83 self
.render("people/call.html", call
=call
)
86 class SearchHandler(base
.BaseHandler
):
87 @tornado.web
.authenticated
89 q
= self
.get_argument("q")
92 accounts
= self
.backend
.accounts
.search(q
)
94 # Redirect when only one result was found
95 if len(accounts
) == 1:
96 self
.redirect("/users/%s" % accounts
[0].uid
)
99 self
.render("people/search.html", q
=q
, accounts
=accounts
)
102 class SIPHandler(base
.BaseHandler
):
103 @tornado.web
.authenticated
105 account
= self
.backend
.accounts
.get_by_uid(uid
)
107 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
109 # Check for permissions
110 if not account
.can_be_managed_by(self
.current_user
):
111 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
113 self
.render("people/sip.html", account
=account
)
116 class UsersHandler(base
.BaseHandler
):
117 @tornado.web
.authenticated
119 self
.render("people/users.html")
122 class UserHandler(base
.BaseHandler
):
123 @tornado.web
.authenticated
125 account
= self
.backend
.accounts
.get_by_uid(uid
)
127 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
129 self
.render("people/user.html", account
=account
)
132 class UserEditHandler(base
.BaseHandler
):
133 @tornado.web
.authenticated
135 account
= self
.backend
.accounts
.get_by_uid(uid
)
137 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
139 # Check for permissions
140 if not account
.can_be_managed_by(self
.current_user
):
141 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
143 self
.render("people/user-edit.html", account
=account
)
145 @tornado.web
.authenticated
147 account
= self
.backend
.accounts
.get_by_uid(uid
)
149 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
151 # Check for permissions
152 if not account
.can_be_managed_by(self
.current_user
):
153 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
155 # Unfortunately this cannot be wrapped into a transaction
157 account
.first_name
= self
.get_argument("first_name")
158 account
.last_name
= self
.get_argument("last_name")
159 account
.address
= self
.get_argument("address")
163 filename
, data
, mimetype
= self
.get_file("avatar")
165 if not mimetype
.startswith("image/"):
166 raise tornado
.web
.HTTPError(400, "Avatar is not an image file: %s" % mimetype
)
168 account
.upload_avatar(data
)
173 account
.mail_routing_address
= self
.get_argument("mail_routing_address", None)
176 account
.phone_numbers
= self
.get_argument("phone_numbers", "").splitlines()
177 account
.sip_routing_address
= self
.get_argument("sip_routing_address", None)
178 except ldap
.STRONG_AUTH_REQUIRED
as e
:
179 raise tornado
.web
.HTTPError(403, "%s" % e
) from e
181 # Redirect back to user page
182 self
.redirect("/users/%s" % account
.uid
)
185 class UserPasswdHandler(base
.BaseHandler
):
186 @tornado.web
.authenticated
188 account
= self
.backend
.accounts
.get_by_uid(uid
)
190 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
192 # Check for permissions
193 if not account
.can_be_managed_by(self
.current_user
):
194 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
196 self
.render("people/passwd.html", account
=account
)
198 @tornado.web
.authenticated
200 account
= self
.backend
.accounts
.get_by_uid(uid
)
202 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
204 # Check for permissions
205 if not account
.can_be_managed_by(self
.current_user
):
206 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
208 # Get current password
209 password
= self
.get_argument("password")
212 password1
= self
.get_argument("password1")
213 password2
= self
.get_argument("password2")
215 # Passwords must match
216 if not password1
== password2
:
217 raise tornado
.web
.HTTPError(400, "Passwords do not match")
219 # XXX Check password complexity
221 # Check if old password matches
222 if not account
.check_password(password
):
223 raise tornado
.web
.HTTPError(403, "Incorrect password for %s" % account
)
226 account
.passwd(password1
)
228 # Redirect back to user's page
229 self
.redirect("/users/%s" % account
.uid
)
232 class AccountsListModule(ui_modules
.UIModule
):
233 def render(self
, accounts
=None):
235 accounts
= self
.backend
.accounts
237 return self
.render_string("people/modules/accounts-list.html", accounts
=accounts
)
240 class CDRModule(ui_modules
.UIModule
):
241 def render(self
, account
, date
=None, limit
=None):
242 cdr
= account
.get_cdr(date
=date
, limit
=limit
)
244 return self
.render_string("people/modules/cdr.html", account
=account
, cdr
=cdr
)
247 class ChannelsModule(ui_modules
.UIModule
):
248 def render(self
, account
):
249 return self
.render_string("people/modules/channels.html",
250 account
=account
, channels
=account
.sip_channels
)
253 class MOSModule(ui_modules
.UIModule
):
254 def render(self
, call
):
255 return self
.render_string("people/modules/mos.html", call
=call
)
258 class RegistrationsModule(ui_modules
.UIModule
):
259 def render(self
, account
):
260 return self
.render_string("people/modules/registrations.html", account
=account
)
263 class SIPStatusModule(ui_modules
.UIModule
):
264 def render(self
, account
):
265 return self
.render_string("people/modules/sip-status.html", account
=account
)