From d2e22c8a350cce6ffad3d9b04e5a7ad2dde38b3e Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 16 Oct 2024 08:08:17 +0300 Subject: [PATCH] add "approved by" to ping groups --- files/assets/js/group_members_owner.js | 5 +++++ files/classes/group_membership.py | 4 +++- files/routes/groups.py | 1 + files/templates/group_memberships.html | 14 ++++++++++++++ migrations/20241016-add-group-approved-by.sql | 4 ++++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 migrations/20241016-add-group-approved-by.sql diff --git a/files/assets/js/group_members_owner.js b/files/assets/js/group_members_owner.js index 4e8ccdc39..6c8035150 100644 --- a/files/assets/js/group_members_owner.js +++ b/files/assets/js/group_members_owner.js @@ -1,4 +1,5 @@ const members_tbody = document.getElementById('members_tbody') +const myself_in_table = document.getElementById('myself-in-table') function approve_membership(t, group, uid) { url = `/!${group}/${uid}/approve` @@ -12,6 +13,10 @@ function approve_membership(t, group, uid) { document.getElementById(`time-${uid}`).innerHTML = formatTime(new Date()); document.getElementById(`counter-${uid}`).innerHTML = parseInt(members_tbody.lastElementChild.firstElementChild.innerHTML) + 1 + const myself_in_table_cloned = document.createElement('td') + myself_in_table_cloned.innerHTML = myself_in_table.innerHTML + document.getElementById(uid).append(myself_in_table_cloned) + members_tbody.append(document.getElementById(uid)); t.parentElement.remove() } diff --git a/files/classes/group_membership.py b/files/classes/group_membership.py index e0adf493d..964505ba1 100644 --- a/files/classes/group_membership.py +++ b/files/classes/group_membership.py @@ -13,8 +13,10 @@ class GroupMembership(Base): created_utc = Column(Integer) approved_utc = Column(Integer) is_mod = Column(Boolean, default=False) + approver_id = Column(Integer, ForeignKey("users.id")) - user = relationship("User", uselist=False) + user = relationship("User", primaryjoin="User.id==GroupMembership.user_id", uselist=False) + approver = relationship("User", primaryjoin="User.id==GroupMembership.approver_id", uselist=False) def __init__(self, *args, **kwargs): if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) diff --git a/files/routes/groups.py b/files/routes/groups.py index 35260ff18..a0ba3411a 100644 --- a/files/routes/groups.py +++ b/files/routes/groups.py @@ -189,6 +189,7 @@ def group_approve(v, group_name, user_id): if not application.approved_utc: application.approved_utc = time.time() + application.approver_id = v.id g.db.add(application) if v.id != application.user_id: send_repeatable_notification(application.user_id, f"@{v.username} has approved your application to !{group}") diff --git a/files/templates/group_memberships.html b/files/templates/group_memberships.html index b6e628685..519c9b877 100644 --- a/files/templates/group_memberships.html +++ b/files/templates/group_memberships.html @@ -1,6 +1,14 @@ {% extends "default.html" %} {% block pagetitle %}!{{group}}{% endblock %} {% block content %} + {% if v.mods_group(group) %} +
+ {% with user=v %} + {% include "user_in_table.html" %} + {% endwith %} +
+ {% endif %} +
{% if v.id != group.owner_id %}