add "approved by" to ping groups

master
Aevann 2024-10-16 08:08:17 +03:00
parent b3d5d49c1f
commit d2e22c8a35
5 changed files with 27 additions and 1 deletions

View File

@ -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()
}

View File

@ -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())

View File

@ -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}")

View File

@ -1,6 +1,14 @@
{% extends "default.html" %}
{% block pagetitle %}!{{group}}{% endblock %}
{% block content %}
{% if v.mods_group(group) %}
<div id="myself-in-table" class="d-none">
{% with user=v %}
{% include "user_in_table.html" %}
{% endwith %}
</div>
{% endif %}
<div class="mx-2">
{% if v.id != group.owner_id %}
<button id="leave-{{group}}" type="button" class="mt-4 btn btn-danger btn-block {% if v.id not in group.membership_user_ids %}d-none{% endif %}" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/!{{group}}/leave','leave-{{group}}','apply-{{group}}','d-none')">
@ -56,6 +64,7 @@
{% if name == 'members' %}
<th>Approved on</th>
<th>Approved by</th>
{% else %}
<th>Applied on</th>
{% endif %}
@ -105,6 +114,11 @@
{% if name == 'members' %}
<td id="time-{{membership.user_id}}" data-time="{{membership.approved_utc}}"></td>
<td>
{% with user=membership.approver %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
{% else %}
<td id="time-{{membership.user_id}}" data-time="{{membership.created_utc}}"></td>
{% endif %}

View File

@ -0,0 +1,4 @@
alter table group_memberships add column approver_id int;
ALTER TABLE ONLY public.group_memberships
ADD CONSTRAINT group_memberships_approver_fkey FOREIGN KEY (approver_id) REFERENCES public.users(id);