forked from MarseyWorld/MarseyWorld
separate code and make it make sense
parent
fac9d67284
commit
bd079cdca0
|
@ -23,6 +23,17 @@ function approve_membership(t, group, uid) {
|
|||
);
|
||||
}
|
||||
|
||||
function leave_membership(t, group) {
|
||||
url = `/!${group}/leave`
|
||||
postToast(t, url,
|
||||
{
|
||||
},
|
||||
() => {
|
||||
t.parentElement.parentElement.parentElement.remove();
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
function reject_membership(t, group, uid) {
|
||||
url = `/!${group}/${uid}/reject`
|
||||
postToast(t, url,
|
||||
|
|
|
@ -131,7 +131,21 @@ def leave_group(v, group_name):
|
|||
text = f"@{v.username} has cancelled their application to !{group}"
|
||||
msg = f"You have cancelled your application to !{group} successfully!"
|
||||
|
||||
send_notification(group.owner_id, text)
|
||||
if v.id == group.owner_id:
|
||||
new_owner_id = g.db.query(GroupMembership.user_id).filter(
|
||||
GroupMembership.user_id != group.owner_id,
|
||||
GroupMembership.group_name == group.name,
|
||||
GroupMembership.approved_utc != None,
|
||||
).order_by(GroupMembership.is_mod.desc(), GroupMembership.approved_utc).first()
|
||||
|
||||
if new_owner_id:
|
||||
new_owner_id = new_owner_id[0]
|
||||
send_repeatable_notification(new_owner_id, f"@{group.owner.username} (!{group}'s owner) has left the group, You're now the new owner!")
|
||||
group.owner_id = new_owner_id
|
||||
g.db.add(group)
|
||||
else:
|
||||
send_notification(group.owner_id, text)
|
||||
|
||||
g.db.delete(existing)
|
||||
|
||||
return {"message": msg}
|
||||
|
@ -215,25 +229,19 @@ def group_reject(v, group_name, user_id):
|
|||
if not membership:
|
||||
stop(404, "There is no membership to reject!")
|
||||
|
||||
if v.id != membership.user_id: #implies kicking and not leaving
|
||||
if membership.user_id == group.owner_id and v.admin_level < PERMS["MODS_EVERY_GROUP"]:
|
||||
stop(403, "You can't kick the group owner!")
|
||||
if membership.user_id == group.owner_id and v.admin_level < PERMS["MODS_EVERY_GROUP"]:
|
||||
stop(403, "You can't kick the group owner!")
|
||||
|
||||
if v.id != group.owner_id and membership.is_mod and v.admin_level < PERMS["MODS_EVERY_GROUP"]:
|
||||
stop(403, "Only the group owner can kick mods!")
|
||||
if v.id != group.owner_id and membership.is_mod and v.admin_level < PERMS["MODS_EVERY_GROUP"]:
|
||||
stop(403, "Only the group owner can kick mods!")
|
||||
|
||||
if v.id == membership.user_id:
|
||||
verb = "left the group"
|
||||
msg = f"You have left !{group} successfully!"
|
||||
if membership.approved_utc:
|
||||
text = f"@{v.username} has kicked you from !{group}"
|
||||
msg = f"You have kicked @{membership.user.username} successfully!"
|
||||
else:
|
||||
verb = "been kicked from the group by site admins"
|
||||
if membership.approved_utc:
|
||||
text = f"@{v.username} has kicked you from !{group}"
|
||||
msg = f"You have kicked @{membership.user.username} successfully!"
|
||||
else:
|
||||
text = f"@{v.username} has rejected your application to !{group}"
|
||||
msg = f"You have rejected @{membership.user.username} successfully!"
|
||||
send_repeatable_notification(membership.user_id, text)
|
||||
text = f"@{v.username} has rejected your application to !{group}"
|
||||
msg = f"You have rejected @{membership.user.username} successfully!"
|
||||
send_repeatable_notification(membership.user_id, text)
|
||||
|
||||
if membership.user_id == group.owner_id:
|
||||
new_owner_id = g.db.query(GroupMembership.user_id).filter(
|
||||
|
@ -244,7 +252,7 @@ def group_reject(v, group_name, user_id):
|
|||
|
||||
if new_owner_id:
|
||||
new_owner_id = new_owner_id[0]
|
||||
send_repeatable_notification(new_owner_id, f"@{group.owner.username} (!{group}'s owner) has {verb}, You're now the new owner!")
|
||||
send_repeatable_notification(new_owner_id, f"@{group.owner.username} (!{group}'s owner) has been kicked from the group by site admins, You're now the new owner!")
|
||||
group.owner_id = new_owner_id
|
||||
g.db.add(group)
|
||||
|
||||
|
|
|
@ -97,7 +97,11 @@
|
|||
|
||||
{% if v.id == membership.user_id or v.id == group.owner_id or not membership.user.mods_group(group) %}
|
||||
<div id="kick-{{membership.user_id}}" {% if name == 'applications' %}class="d-none"{% endif %}>
|
||||
<button type="button" class="btn btn-danger btn-block" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="reject_membership(this,'{{group}}','{{membership.user_id}}')">{% if v.id == membership.user_id %}Leave{% else %}Kick{% endif %}</button>
|
||||
{% if v.id == membership.user_id %}
|
||||
<button type="button" class="btn btn-danger btn-block" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="leave_membership(this,'{{group}}')">Leave</button>
|
||||
{% else %}
|
||||
<button type="button" class="btn btn-danger btn-block" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="reject_membership(this,'{{group}}','{{membership.user_id}}')">Kick</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue