From: Michael Tremer Date: Wed, 10 Oct 2018 13:42:41 +0000 (+0100) Subject: talk: Allow admins to see registrations of all users X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b78ec69bf4b584d8c9317237c0d46e54c1fdf235;p=ipfire.org.git talk: Allow admins to see registrations of all users Signed-off-by: Michael Tremer --- diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 3a80b7b3..7e6e4431 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -229,7 +229,7 @@ class Account(Object): for dn, attrs in res: cns = attrs.get("cn") if cns: - self._groups.append(cns[0]) + self._groups.append(cns[0].decode()) return self._groups diff --git a/src/backend/talk.py b/src/backend/talk.py index d9e47520..9b7d2f62 100644 --- a/src/backend/talk.py +++ b/src/backend/talk.py @@ -63,7 +63,7 @@ class SIPRegistration(object): @lazy_property def latency(self): - if self.is_reachable(): + if self.is_reachable() and self.data.ping_time: return self.data.ping_time / 1000.0 diff --git a/src/templates/talk/modules/registrations.html b/src/templates/talk/modules/registrations.html index 85e349f5..0143b389 100644 --- a/src/templates/talk/modules/registrations.html +++ b/src/templates/talk/modules/registrations.html @@ -5,7 +5,7 @@ {{ reg.user_agent }} {{ reg.protocol }}/{{ reg.network_ip }}:{{ reg.network_port }} - {% if reg.is_reachable() %} + {% if reg.is_reachable() and reg.latency %} {{ "%.2f ms" % reg.latency }} {% else %} {{ _("N/A") }} diff --git a/src/templates/talk/registrations.html b/src/templates/talk/registrations.html index a0b8939b..98538d94 100644 --- a/src/templates/talk/registrations.html +++ b/src/templates/talk/registrations.html @@ -6,10 +6,10 @@
- {{ _("Active Registrations for %s") % current_user }} + {{ _("Active Registrations for %s") % account }}
- {% module TalkRegistrations(current_user) %} + {% module TalkRegistrations(account) %}
{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 2fb74651..3bf077be 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -239,7 +239,7 @@ class Application(tornado.web.Application): # talk.ipfire.org self.add_handlers(r"talk(\.dev)?\.ipfire\.org", [ (r"/", talk.IndexHandler), - (r"/registrations", talk.RegistrationsHandler), + (r"/user/(\w+)/registrations", talk.RegistrationsHandler), (r"/conferences", TalkConferencesHandler), (r"/diagnosis", TalkDiagnosisHandler), (r"/hangup/(.*)", TalkHangupChannelHandler), diff --git a/src/web/talk.py b/src/web/talk.py index b6a6da87..c3158eec 100644 --- a/src/web/talk.py +++ b/src/web/talk.py @@ -13,8 +13,22 @@ class IndexHandler(base.BaseHandler): class RegistrationsHandler(base.BaseHandler): @tornado.web.authenticated - def get(self): - self.render("talk/registrations.html") + def get(self, uid): + # Get own account + if self.current_user.uid == uid: + account = self.current_user + + # Admins can access all other users, too + elif self.current_user.is_admin(): + account = self.backend.accounts.get_by_uid(uid) + if not account: + raise tornado.web.HTTPError(404, "Could not find account %s" % uid) + + # Otherwise, no access is permitted + else: + raise tornado.web.HTTPError(403) + + self.render("talk/registrations.html", account=account) class RegistrationsModule(ui_modules.UIModule):