]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/web/people.py
Move talk.ipfire.org -> people.ipfire.org
[ipfire.org.git] / src / web / people.py
index de2ac8bd97cddd983f45d520c08c9689bb4f5958..face462cf202ba0a533512488cd2f13bf55557e0 100644 (file)
@@ -4,6 +4,13 @@ import logging
 import tornado.web
 
 from . import handlers_base as base
+from . import ui_modules
+
+class IndexHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self):
+               self.render("people/index.html")
+
 
 class AvatarHandler(base.BaseHandler):
        def get(self, uid):
@@ -40,3 +47,82 @@ class AvatarHandler(base.BaseHandler):
 
                # Deliver payload
                self.finish(avatar)
+
+
+class RegistrationsHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       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("people/registrations.html", account=account)
+
+
+class SearchHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self):
+               q = self.get_argument("q")
+
+               # Perform the search
+               accounts = self.backend.talk.search(q)
+
+               # Redirect when only one result was found
+               if len(accounts) == 1:
+                       self.redirect("/users/%s" % accounts[0].uid)
+                       return
+
+               self.render("people/search.html", q=q, accounts=accounts)
+
+
+class UsersHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self):
+               self.render("people/users.html")
+
+
+class UserHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, uid):
+               account = self.backend.accounts.get_by_uid(uid)
+               if not account:
+                       raise tornado.web.HTTPError(404, "Could not find account %s" % uid)
+
+               self.render("people/user.html", account=account)
+
+
+class AccountsListModule(ui_modules.UIModule):
+       def render(self, accounts=None):
+               if accounts is None:
+                       accounts = self.backend.talk.accounts
+
+               return self.render_string("people/modules/accounts-list.html", accounts=accounts)
+
+
+class CDRModule(ui_modules.UIModule):
+       def render(self, account, limit=None):
+               cdr = account.get_cdr(limit=limit)
+
+               return self.render_string("people/modules/cdr.html", account=account, cdr=cdr)
+
+
+class ChannelsModule(ui_modules.UIModule):
+       def render(self, account):
+               channels = self.backend.talk.freeswitch.get_sip_channels(account)
+
+               return self.render_string("people/modules/channels.html", account=account, channels=channels)
+
+
+class RegistrationsModule(ui_modules.UIModule):
+       def render(self, account):
+               return self.render_string("people/modules/registrations.html", account=account)