From 57813b4bc2dac150f4a5aa8a70cf4ae48bf9e932 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 22 Mar 2023 12:06:33 +0100 Subject: [PATCH] Fix link issues --- app/admin/routes.py | 2 +- app/models.py | 40 ++++++--- app/templates/_sidenav.html.j2 | 87 ++++++++++++------- app/templates/admin/user.html.j2 | 2 +- app/templates/corpora/public_corpus.html.j2 | 6 +- app/templates/settings/settings.html.j2 | 2 +- .../users/{profile.html.j2 => user.html.j2} | 57 +++++++----- app/users/routes.py | 20 +---- 8 files changed, 127 insertions(+), 89 deletions(-) rename app/templates/users/{profile.html.j2 => user.html.j2} (71%) diff --git a/app/admin/routes.py b/app/admin/routes.py index b2d0643b..c1014250 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -14,7 +14,7 @@ from app.users.utils import ( @bp.route('') @register_breadcrumb(bp, '.', 'admin_panel_settingsAdministration') -def index(): +def admin(): return render_template( 'admin/admin.html.j2', title='Administration' diff --git a/app/models.py b/app/models.py index 1ed18ada..a527c1b2 100644 --- a/app/models.py +++ b/app/models.py @@ -100,6 +100,15 @@ class ProfilePrivacySettings(IntEnum): SHOW_LAST_SEEN = 2 SHOW_MEMBER_SINCE = 4 + @staticmethod + def get(profile_privacy_setting: Union['ProfilePrivacySettings', int, str]) -> 'ProfilePrivacySettings': + if isinstance(profile_privacy_setting, ProfilePrivacySettings): + return profile_privacy_setting + if isinstance(profile_privacy_setting, int): + return ProfilePrivacySettings(profile_privacy_setting) + if isinstance(profile_privacy_setting, str): + return ProfilePrivacySettings[profile_privacy_setting] + raise TypeError('profile_privacy_setting must be ProfilePrivacySettings, int, or str') class CorpusFollowerPermission(IntEnum): VIEW = 1 @@ -227,18 +236,18 @@ class Role(HashidMixin, db.Model): return f'' def has_permission(self, permission: Union[Permission, int, str]): - perm = Permission.get(permission) - return self.permissions & perm.value == perm.value + p = Permission.get(permission) + return self.permissions & p.value == p.value def add_permission(self, permission: Union[Permission, int, str]): - perm = Permission.get(permission) - if not self.has_permission(perm): - self.permissions += perm.value + p = Permission.get(permission) + if not self.has_permission(p): + self.permissions += p.value def remove_permission(self, permission: Union[Permission, int, str]): - perm = Permission.get(permission) - if self.has_permission(perm): - self.permissions -= perm.value + p = Permission.get(permission) + if self.has_permission(p): + self.permissions -= p.value def reset_permissions(self): self.permissions = 0 @@ -763,15 +772,18 @@ class User(HashidMixin, UserMixin, db.Model): #region Profile Privacy settings def has_profile_privacy_setting(self, setting): - return self.profile_privacy_settings & setting == setting + s = ProfilePrivacySettings.get(setting) + return self.profile_privacy_settings & s.value == s.value def add_profile_privacy_setting(self, setting): - if not self.has_profile_privacy_setting(setting): - self.profile_privacy_settings += setting + s = ProfilePrivacySettings.get(setting) + if not self.has_profile_privacy_setting(s): + self.profile_privacy_settings += s.value def remove_profile_privacy_setting(self, setting): - if self.has_profile_privacy_setting(setting): - self.profile_privacy_settings -= setting + s = ProfilePrivacySettings.get(setting) + if self.has_profile_privacy_setting(s): + self.profile_privacy_settings -= s.value def reset_profile_privacy_settings(self): self.profile_privacy_settings = 0 @@ -838,7 +850,7 @@ class User(HashidMixin, UserMixin, db.Model): json_serializeable = { 'id': self.hashid, 'confirmed': self.confirmed, - 'avatar': url_for('users.profile_avatar', user_id=self.id), + 'avatar': url_for('users.user_avatar', user_id=self.id), 'email': self.email, 'last_seen': ( None if self.last_seen is None diff --git a/app/templates/_sidenav.html.j2 b/app/templates/_sidenav.html.j2 index 5f6f6482..3a01ec4a 100644 --- a/app/templates/_sidenav.html.j2 +++ b/app/templates/_sidenav.html.j2 @@ -4,13 +4,9 @@
{{ current_user.username }} @@ -25,39 +21,72 @@
#} {#
  • nopaque
  • #} -
  • emailNews
  • +
  • + emailNews +
  • {#
  • helpManual
  • #} -
  • Dashboard
  • -
  • IMy Corpora
  • -
  • JMy Jobs
  • -
  • new_labelMy Contributions
  • +
  • + dashboardDashboard + +
  • Processes & Services
  • -
  • File setup
  • -
  • OCR
  • +
  • + File setup +
  • +
  • + OCR +
  • {% if config.NOPAQUE_TRANSKRIBUS_ENABLED %} -
  • HTR
  • +
  • + HTR +
  • {% endif %} -
  • NLP
  • -
  • Corpus Analysis
  • +
  • + NLP +
  • +
  • + Corpus Analysis +
  • -
  • Social Area
  • -
  • personPublic Users
  • -
  • IPublic Corpora
  • +
  • + rocket_launchSocial Area + +
  • Account
  • -
  • settingsSettings
  • -
  • Log out
  • +
  • + settingsSettings +
  • +
  • + Log out +
  • {% if current_user.can('ADMINISTRATE') %}
  • -
  • Administration
  • -
  • ICorpora
  • -
  • JJobs
  • -
  • groupUsers
  • +
  • + admin_panel_settingsAdministration +
  • {% endif %} {% if current_user.can('USE_API') %} -
  • -
  • API
  • -
  • apiAPI
  • +
  • + apiAPI +
  • {% endif %} diff --git a/app/templates/admin/user.html.j2 b/app/templates/admin/user.html.j2 index 30f7c084..f8943430 100644 --- a/app/templates/admin/user.html.j2 +++ b/app/templates/admin/user.html.j2 @@ -5,7 +5,7 @@

     

    - user-image + user-image

    {{ title }}

    diff --git a/app/templates/corpora/public_corpus.html.j2 b/app/templates/corpora/public_corpus.html.j2 index ff445e38..77e3ea4b 100644 --- a/app/templates/corpora/public_corpus.html.j2 +++ b/app/templates/corpora/public_corpus.html.j2 @@ -48,11 +48,7 @@ {% endif %} - {% if user.show_email %} + {% if user.has_profile_privacy_setting('SHOW_EMAIL') %} @@ -78,18 +80,17 @@ {% endif %}
    - {% if corpus.user.avatar %} - user-image - {% else %} - user-image - {% endif %} + user-image diff --git a/app/templates/settings/settings.html.j2 b/app/templates/settings/settings.html.j2 index fe60f0d2..282d4185 100644 --- a/app/templates/settings/settings.html.j2 +++ b/app/templates/settings/settings.html.j2 @@ -114,7 +114,7 @@

    - user-image + user-image
    {{ wtf.render_field(edit_public_profile_information_form.avatar, accept='image/jpeg, image/png, image/gif', placeholder='Choose an image file', id='avatar-upload') }} diff --git a/app/templates/users/profile.html.j2 b/app/templates/users/user.html.j2 similarity index 71% rename from app/templates/users/profile.html.j2 rename to app/templates/users/user.html.j2 index 6e02a42c..cc138794 100644 --- a/app/templates/users/profile.html.j2 +++ b/app/templates/users/user.html.j2 @@ -1,6 +1,7 @@ {% extends "base.html.j2" %} {% import "materialize/wtf.html.j2" as wtf %} + {% block page_content %}
    @@ -10,9 +11,8 @@
    -
    -
    - user-image +

     

    + user-image
    @@ -27,16 +27,18 @@ {% else %} Private Profile {% endif %} + {% if user.has_profile_privacy_setting('SHOW_MEMBER_SINCE') %} + Member since: {{ user.member_since.strftime('%Y-%m-%d') }} + {% endif %} + {% if user.has_profile_privacy_setting('SHOW_LAST_SEEN') %} + Last seen: {{ user.last_seen.strftime('%Y-%m-%d') }} + {% endif %}
    - {% if user.show_last_seen %} -
    Last seen: {{ last_seen }}
    - {% endif %} {% if user.location %} -

    location_on{{ user.location }}

    +

     

    +

    location_on{{ user.location }}

    {% endif %} -

    -
    {% if user.about_me %}
    About me
    @@ -59,7 +61,7 @@
    {{ user.full_name }}
    email {{ user.email }}
    -
    - {% if user.show_member_since %} -

    Member since: {{ member_since }}

    - {% endif %} -

    -
    - {% if current_user.hashid == user.id %} - Edit profile - {% endif %} +

     

    + {% if current_user == user %} +
    +

    + Edit profile +

    +
    + {% endif %} @@ -119,8 +120,22 @@ {{ super() }} {% endblock scripts %} diff --git a/app/users/routes.py b/app/users/routes.py index 5d51e81f..2c2334f3 100644 --- a/app/users/routes.py +++ b/app/users/routes.py @@ -25,32 +25,18 @@ def users(): @login_required def user(user_id): user = User.query.get_or_404(user_id) - last_seen = user.last_seen.strftime('%Y-%m-%d %H:%M') - member_since = user.member_since.strftime('%Y-%m-%d') - followed_corpora = [ - c.to_json_serializeable() for c in user.followed_corpora - ] - own_public_corpora = [ - c.to_json_serializeable() for c - in Corpus.query.filter_by(is_public = True, user = user).all() - ] - if not user.is_public and user != current_user: + if not (user.is_public or user == current_user or current_user.is_administrator()): abort(403) return render_template( - 'users/profile.html.j2', - followed_corpora=followed_corpora, - last_seen=last_seen, - member_since=member_since, - own_public_corpora=own_public_corpora, + 'users/user.html.j2', user=user, - user_id=user_id, title=user.username ) @bp.route('//avatar') @login_required -def profile_avatar(user_id): +def user_avatar(user_id): user = User.query.get_or_404(user_id) if not (user.is_public or user == current_user or current_user.is_administrator()): abort(403)