From b01a1ee32302072e5f87d6cfdd1a194760d83966 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 24 Jun 2023 17:43:54 +0000 Subject: [PATCH] people: Move profile page into main website Signed-off-by: Michael Tremer --- Makefile.am | 7 +- src/backend/accounts.py | 3 + src/templates/people/user.html | 221 --------------------------- src/templates/users/show.html | 271 +++++++++++++++++++++++++++++++++ src/web/__init__.py | 5 +- src/web/people.py | 10 -- src/web/users.py | 15 ++ 7 files changed, 299 insertions(+), 233 deletions(-) delete mode 100644 src/templates/people/user.html create mode 100644 src/templates/users/show.html create mode 100644 src/web/users.py diff --git a/Makefile.am b/Makefile.am index c545593a..e08d4b5d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,6 +93,7 @@ web_PYTHON = \ src/web/nopaste.py \ src/web/people.py \ src/web/ui_modules.py \ + src/web/users.py \ src/web/wiki.py webdir = $(backenddir)/web @@ -272,7 +273,6 @@ templates_people_DATA = \ src/templates/people/subscribed.html \ src/templates/people/unsubscribe.html \ src/templates/people/unsubscribed.html \ - src/templates/people/user.html \ src/templates/people/user-edit.html \ src/templates/people/users.html @@ -303,6 +303,11 @@ templates_static_DATA = \ templates_staticdir = $(templatesdir)/static +templates_users_DATA = \ + src/templates/users/show.html + +templates_usersdir = $(templatesdir)/users + templates_wiki_DATA = \ src/templates/wiki/404.html \ src/templates/wiki/base.html \ diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 35079d9b..5dabbef0 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -786,6 +786,9 @@ class Account(LDAPObject): def has_sip(self): return "sipUser" in self.classes or "sipRoutingObject" in self.classes + def is_lwl(self): + return self.is_member_of_group("lwl-staff") + def can_be_managed_by(self, account): """ Returns True if account is allowed to manage this account diff --git a/src/templates/people/user.html b/src/templates/people/user.html deleted file mode 100644 index 1ed41715..00000000 --- a/src/templates/people/user.html +++ /dev/null @@ -1,221 +0,0 @@ -{% extends "../base.html" %} - -{% block title %}{{ account }}{% end block %} - -{% block container %} - {% import phonenumbers %} - -
-
-
-
- {{ account }} -
- -
-

{{ account }}

- - {% if account.description %} -
- {% module Markdown(account.description) %} -
- {% end %} - -
- - {{ _("Community Profile") }} - - - {% if account.has_shell() %} - - {{ _("Home Directory") }} - - {% end %} - - {% if account.can_be_managed_by(current_user) %} - {% if account.has_sip() %} - - {{ _("Calls") }} - - {% end %} - - - {{ _("Edit") }} - - - - {{ _("Change Password") }} - - {% end %} -
-
-
-
-
- - {% if current_user == account or current_user.is_staff() %} -
-
- {% if account == current_user %} - {# Suggest adding a description #} - {% if not current_user.description %} -
-
{{ _("Tell Us About Yourself" ) }}
- -

- {{ _("Add a couple of lines about yourself to your profile so that others get to know you better") }} - - {{ _("Edit Profile") }} -

-
- - {# Suggest uploading an avatar if this user does not have one #} - {% elif not current_user.has_avatar() %} -
-
{{ _("Upload An Avatar" ) }}
- -

- {{ _("A picture says more than a thousand words") }} - - {{ _("Upload Avatar") }} -

-
- {% end %} - {% end %} - -
-
- {% if current_user.is_staff() %} -
{{ _("Email") }}
- - - {% end %} - - {% if account.address %} -
{{ _("Address") }}
- -
- {{ account.name }}
- {% for line in account.address %} - {{ line }}
- {% end %} -
- {% end %} - - {% if account.phone_number or account.fax_number %} -
{{ _("Phone Numbers") }}
- - - {% end %} - - {% if account.phone_numbers %} -
{{ _("External Phone Numbers") }}
- -
    - {% for number in account.phone_numbers %} -
  • - {% if phonenumbers.number_type(number) == phonenumbers.PhoneNumberType.MOBILE %} - - {% else %} - - {% end %} - - {{ format_phone_number(number) }} -
  • - {% end %} -
- {% end %} -
- - {% if current_user.is_staff() %} -
- {% if account.groups %} -
{{ _("Groups") }}
- -
- {% for g in account.groups %} - - {{ g }} - - {% end %} -
- {% end %} - -
    -
  • - {{ _("Joined %s") % locale.format_date(account.created_at, shorter=True) }} -
  • - - {% if current_user.is_admin() %} -
  • - {{ _("Last Modified %s") % locale.format_date(account.modified_at) }} -
  • - - {% if account.last_successful_authentication %} -
  • - {{ _("Last successful authentication: %s") % locale.format_date(account.last_successful_authentication) }} -
  • - {% end %} - - {% if account.failed_login_count %} -
  • - {{ _("One unsuccessful authentication attempt.", "%(num)s unsuccessful authentication attempts.", account.failed_login_count) % { "num" : account.failed_login_count } }} - - {% if account.last_failed_authentication %} - {{ _("Last attempt: %s") % locale.format_date(account.last_failed_authentication) }} - {% end %} -
  • - {% end %} - {% end %} -
-
- {% end %} -
-
-
- {% end %} -{% end block %} diff --git a/src/templates/users/show.html b/src/templates/users/show.html new file mode 100644 index 00000000..29bc136b --- /dev/null +++ b/src/templates/users/show.html @@ -0,0 +1,271 @@ +{% extends "../base.html" %} + +{% block title %}{{ account }}{% end block %} + +{% block container %} + {% import phonenumbers %} + +
+
+
+
+
+ + +

{{ account }}

+
{{ account.uid }}
+ + {# Description #} + {% if account.description %} +
+
+ {% module Markdown(account.description) %} +
+
+ {% end %} +
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+ + + + + + {{ account.email }} + + + + + + + + + {{ _("Community Profile") }} + + + + {% if account.has_shell() %} + + + + + + {{ _("Home Directory") }} + + + {% end %} + + {% if account.can_be_managed_by(current_user) %} + {% if account.has_sip() %} + + + + + + {{ _("Calls") }} + + + {% end %} + + + {{ _("Edit") }} + + + + {{ _("Change Password") }} + + {% end %} +
+ + {% if account == current_user %} + {# Suggest adding a description #} + {% if not current_user.description %} +
+ {{ _("Tell Us About Yourself!") }} + + {{ _("Add a couple of lines about yourself to your profile so that others get to know you better") }} + + {{ _("Edit Profile") }} +
+ + {# Suggest uploading an avatar if this user does not have one #} + {% elif not current_user.has_avatar() %} +
+ {{ _("Upload An Avatar!") }} + + {{ _("A picture says more than a thousand words") }} + + {{ _("Upload Avatar") }} +
+ {% end %} + {% end %} +
+
+ + {% if current_user == account or current_user.is_staff() %} +
+
+
+ {# Address #} + {% if account.address %} +
+
{{ _("Address") }}
+ +
+ {{ account.name }}
+ {% for line in account.address %} + {{ line }}
+ {% end %} +
+
+ {% end %} + + {# Phone Numbers #} + {% if account.phone_number or account.fax_number %} +
+
{{ _("Phone Numbers") }}
+ + +
+ {% end %} + + {% if current_user.is_staff() %} + {% if account.groups %} +
+
{{ _("Groups") }}
+ + +
+ {% end %} + {% end %} +
+
+
+ +
+
+ +
+
+ {% end %} +{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index a75e48cf..f28ff8f6 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -25,6 +25,7 @@ from . import location from . import nopaste from . import people from . import ui_modules +from . import users from . import wiki class Application(tornado.web.Application): @@ -147,6 +148,9 @@ class Application(tornado.web.Application): (r"/donate/error", donate.ErrorHandler), (r"/donation", tornado.web.RedirectHandler, { "url" : "/donate" }), + # Users + (r"/users/([\w]+)", users.ShowHandler), + # RSS feed (r"/news.rss", tornado.web.RedirectHandler, { "url" : "https://blog.ipfire.org/feed.xml" }), @@ -298,7 +302,6 @@ class Application(tornado.web.Application): (r"/register", auth.RegisterHandler), (r"/search", people.SearchHandler), (r"/users", people.UsersHandler), - (r"/users/([a-z_][a-z0-9_-]{0,31})", people.UserHandler), (r"/users/([a-z_][a-z0-9_-]{0,31})\.jpg", people.AvatarHandler), (r"/users/([a-z_][a-z0-9_-]{0,31})/calls/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})", people.CallHandler), (r"/users/([a-z_][a-z0-9_-]{0,31})/calls(?:/(\d{4}-\d{2}-\d{2}))?", people.CallsHandler), diff --git a/src/web/people.py b/src/web/people.py index 5a3f3da6..68c29734 100644 --- a/src/web/people.py +++ b/src/web/people.py @@ -270,16 +270,6 @@ class UsersHandler(auth.CacheMixin, base.BaseHandler): self.render("people/users.html") -class UserHandler(auth.CacheMixin, 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 UserEditHandler(auth.CacheMixin, base.BaseHandler): @tornado.web.authenticated def get(self, uid): diff --git a/src/web/users.py b/src/web/users.py new file mode 100644 index 00000000..d3544863 --- /dev/null +++ b/src/web/users.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +import tornado.web + +from . import auth +from . import base + +class ShowHandler(auth.CacheMixin, 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("users/show.html", account=account) -- 2.47.3