add ping group description

master
Aevann 2024-02-13 15:00:58 +02:00
parent f7b4771cff
commit 1c88ea8851
5 changed files with 60 additions and 0 deletions

View File

@ -15,6 +15,7 @@ class Group(Base):
name = Column(String, primary_key=True) name = Column(String, primary_key=True)
created_utc = Column(Integer) created_utc = Column(Integer)
owner_id = Column(Integer, ForeignKey("users.id")) owner_id = Column(Integer, ForeignKey("users.id"))
description = Column(String)
memberships = relationship("GroupMembership", primaryjoin="GroupMembership.group_name==Group.name", order_by="GroupMembership.approved_utc") memberships = relationship("GroupMembership", primaryjoin="GroupMembership.group_name==Group.name", order_by="GroupMembership.approved_utc")
owner = relationship("User", primaryjoin="Group.owner_id==User.id") owner = relationship("User", primaryjoin="Group.owner_id==User.id")

View File

@ -333,3 +333,30 @@ def group_usurp(v, group_name):
g.db.add(group) g.db.add(group)
return {"message": f'You have usurped control of !{group.name} successfully!'} return {"message": f'You have usurped control of !{group.name} successfully!'}
@app.post("/!<group_name>/description")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def group_change_description(v, group_name):
group_name = group_name.strip().lower()
group = g.db.get(Group, group_name)
if not group: abort(404)
if v.id != group.owner_id:
abort(403, f"Only the group owner (@{group.owner.username}) can change the description!")
description = request.values.get('description')
if description:
description = description.strip()
else:
description = None
group.description = description
g.db.add(group)
return {"message": 'Description changed successfully!'}

View File

@ -13,6 +13,31 @@
<button id="apply-{{group}}" type="button" class="mt-4 {% if v.id in group.membership_user_ids %}d-none{% endif %} btn btn-success btn-block" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/!{{group}}/apply','leave-{{group}}','apply-{{group}}','d-none')">{% if group.name != 'verifiedrich' %}Apply to {% endif %}Join</button> <button id="apply-{{group}}" type="button" class="mt-4 {% if v.id in group.membership_user_ids %}d-none{% endif %} btn btn-success btn-block" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/!{{group}}/apply','leave-{{group}}','apply-{{group}}','d-none')">{% if group.name != 'verifiedrich' %}Apply to {% endif %}Join</button>
{% endif %} {% endif %}
{% if v.id == group.owner_id %}
<h5 class="mt-5">!{{group}} Description</h3>
<form class="mt-3" action="/!{{group.name}}/description" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHR(this)">
<div class="container pb-0" style="background-color: transparent !important">
<div class="row">
<div class="col col-md-6 px-0 py-3 py-md-0">
<div class="body">
<input hidden name="formkey" value="{{v|formkey}}">
<input maxlength="100" class="form-control" type="text" name="description" {% if group.description %}value="{{group.description}}"{% endif %}>
<small>Limit of 100 characters</small>
<div class="footer">
<div class="d-flex">
<button type="submit" class="btn btn-primary ml-auto">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
{% elif group.description %}
<h5 class="mt-5">!{{group}} Description</h3>
<p class="mb-2">{{group.description}}</p>
{% endif %}
<br> <br>
{% macro process_memberships(memberships, name) %} {% macro process_memberships(memberships, name) %}
<h5 class="my-3">!{{group}} {{name}}</h5> <h5 class="my-3">!{{group}} {{name}}</h5>

View File

@ -33,6 +33,7 @@
<th>#</th> <th>#</th>
<th>Name</th> <th>Name</th>
<th class="members">Members</th> <th class="members">Members</th>
<th>Description</th>
<th>Created on</th> <th>Created on</th>
</tr> </tr>
</thead> </thead>
@ -56,6 +57,11 @@
<button id="apply-{{group}}" type="button" class="ml-3 ml-md-5 {% if v.id in group.membership_user_ids %}d-none{% endif %} btn btn-primary" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/!{{group}}/apply','leave-{{group}}','apply-{{group}}','d-none')">{% if group.name != 'verifiedrich' %}Apply to {% endif %}Join</button> <button id="apply-{{group}}" type="button" class="ml-3 ml-md-5 {% if v.id in group.membership_user_ids %}d-none{% endif %} btn btn-primary" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/!{{group}}/apply','leave-{{group}}','apply-{{group}}','d-none')">{% if group.name != 'verifiedrich' %}Apply to {% endif %}Join</button>
{% endif %} {% endif %}
</td> </td>
<td>
{% if group.description %}
{{group.description}}
{% endif %}
</td>
<td data-time="{{group.created_utc}}"></td> <td data-time="{{group.created_utc}}"></td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -0,0 +1 @@
alter table groups add column description varchar(100) default '' not null;