add /blockers and /blocking to profile pages

pull/157/head
Aevann 2023-06-24 20:39:50 +03:00
parent c097a7c244
commit 8bd657b726
6 changed files with 82 additions and 26 deletions

View File

@ -762,6 +762,25 @@ def blockers(v:User, username:str):
return render_template("userpage/blockers.html", v=v, u=u, users=users, page=page, total=total)
@app.get("/@<username>/blocking")
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@auth_required
def blocking(v:User, username:str):
u = get_user(username, v=v)
page = get_page()
users = g.db.query(UserBlock, User).join(UserBlock, UserBlock.user_id == u.id) \
.filter(UserBlock.target_id == User.id)
total = users.count()
users = users.order_by(UserBlock.created_utc.desc()) \
.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE ).all()
return render_template("userpage/blocking.html", v=v, u=u, users=users, page=page, total=total)
@app.get("/@<username>/followers")
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@ -842,7 +861,7 @@ def u_username_wall(v:Optional[User], username:str):
if v and hasattr(u, 'is_blocking') and u.is_blocking:
if g.is_api_or_xhr:
abort(403, f"You are blocking @{u.username}.")
return render_template("userpage/blocking.html", u=u, v=v), 403
return render_template("userpage/blocked.html", u=u, v=v), 403
is_following = v and u.has_follower(v)
@ -892,7 +911,7 @@ def u_username_wall_comment(v:User, username:str, cid):
if v and hasattr(u, 'is_blocking') and u.is_blocking:
if g.is_api_or_xhr:
abort(403, f"You are blocking @{u.username}.")
return render_template("userpage/blocking.html", u=u, v=v), 403
return render_template("userpage/blocked.html", u=u, v=v), 403
is_following = v and u.has_follower(v)
@ -939,7 +958,7 @@ def u_username(v:Optional[User], username:str):
if v and hasattr(u, 'is_blocking') and u.is_blocking:
if g.is_api_or_xhr:
abort(403, f"You are blocking @{u.username}.")
return render_template("userpage/blocking.html", u=u, v=v), 403
return render_template("userpage/blocked.html", u=u, v=v), 403
is_following = v and u.has_follower(v)
@ -1010,7 +1029,7 @@ def u_username_comments(username, v=None):
if v and hasattr(u, 'is_blocking') and u.is_blocking:
if g.is_api_or_xhr:
abort(403, f"You are blocking @{u.username}.")
return render_template("userpage/blocking.html", u=u, v=v), 403
return render_template("userpage/blocked.html", u=u, v=v), 403
is_following = v and u.has_follower(v)

View File

@ -1,7 +1,6 @@
{% extends "settings.html" %}
{% block pagetitle %}Blocks{% endblock %}
{% block content %}
<script defer src="{{'js/settings_blocks.js' | asset}}"></script>
<div class="row settings-page" id="settings-page-blocks">
<div class="col col-lg-8">
<div class="settings">
@ -79,4 +78,6 @@
<i class="fas fa-exclamation-circle text-danger mr-2"></i><span id="toast-error-message">Error. Please try again.</span>
</div>
</div>
<script defer src="{{'js/settings_blocks.js' | asset}}"></script>
{% endblock %}

View File

@ -72,7 +72,7 @@
{% if v and (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']) -%}
<div class="font-weight-bolder mb-2" id="profile--simphate">
<a class="mr-1" href="/@{{u.username}}/views">Profile Views</a> | <a class="mx-1" href="/@{{u.username}}/upvoters">Simps</a> | <a class="mx-1" href="/@{{u.username}}/downvoters">Haters</a> | <a class="mx-1" href="/@{{u.username}}/upvoting">Simps For</a> | <a class="mx-1" href="/@{{u.username}}/downvoting">Hates</a> | <a class="ml-1" href="/@{{u.username}}/voted/posts">Voted</a>
<a class="mr-1" href="/@{{u.username}}/views">Profile Views</a> | <a class="mx-1" href="/@{{u.username}}/upvoters">Simps</a> | <a class="mx-1" href="/@{{u.username}}/downvoters">Haters</a> | <a class="mx-1" href="/@{{u.username}}/upvoting">Simps For</a> | <a class="mx-1" href="/@{{u.username}}/downvoting">Hates</a> | <a class="mx-1" href="/@{{u.username}}/voted/posts">Voted</a> | <a class="mx-1" href="/@{{u.username}}/blockers">Blockers</a> | <a class="mx-1" href="/@{{u.username}}/blocking">Blocking</a>
</div>
{%- endif %}
@ -354,7 +354,7 @@
{% if v and (v.id == u.id or v.admin_level >= PERMS['USER_VOTERS_VISIBLE']) -%}
<div class="font-weight-bolder mb-2" id="profile-mobile--simphate">
<a class="mr-1" href="/@{{u.username}}/views">Profile Views</a> | <a class="mx-1" href="/@{{u.username}}/upvoters">Simps</a> | <a class="mx-1" href="/@{{u.username}}/downvoters">Haters</a> | <a class="mx-1" href="/@{{u.username}}/upvoting">Simps For</a> | <a class="mx-1" href="/@{{u.username}}/downvoting">Hates</a> | <a class="ml-1" href="/@{{u.username}}/voted/posts">Voted</a>
<a class="mr-1" href="/@{{u.username}}/views">Profile Views</a> | <a class="mx-1" href="/@{{u.username}}/upvoters">Simps</a> | <a class="mx-1" href="/@{{u.username}}/downvoters">Haters</a> | <a class="mx-1" href="/@{{u.username}}/upvoting">Simps For</a> | <a class="mx-1" href="/@{{u.username}}/downvoting">Hates</a> | <a class="mx-1" href="/@{{u.username}}/voted/posts">Voted</a> | <a class="mx-1" href="/@{{u.username}}/blockers">Blockers</a> | <a class="mx-1" href="/@{{u.username}}/blocking">Blocking</a>
</div>
{%- endif %}

View File

@ -0,0 +1,20 @@
{% extends "default.html" %}
{% block pagetype %}userpage{% endblock %}
{% block pagetitle %}@{{u.username}}{% endblock %}
{% block content %}
<div class="row no-gutters">
<div class="col-12">
<div class="text-center py-6 py-md-8">
<span class="fa-stack fa-2x text-muted mb-2">
<i class="fas fa-square text-danger opacity-25 fa-stack-2x"></i>
<i class="fas text-danger fa-user-cog fa-stack-1x text-lg"></i>
</span>
<h5>You are blocking @{{u.username}}.</h5>
<p class="text-muted">So we aren't going to show you their profile.</p>
<button type="button" class="btn btn-success text-success mt-2" data-nonce="{{g.nonce}}" data-onclick="postToastReload(this,'/settings/unblock?username={{u.username}}')"><i class="fas fa-eye text-success mr-2"></i>Unblock @{{u.username}}</a>
</div>
</div>
</div>
{% endblock %}
{% block pagenav %}{% endblock %}

View File

@ -19,8 +19,6 @@
</tbody>
</table>
<script defer src="{{'js/blockers.js' | asset}}"></script>
{% endblock %}
{% block pagenav %}

View File

@ -1,20 +1,38 @@
{% extends "default.html" %}
{% block pagetype %}userpage{% endblock %}
{% block pagetitle %}@{{u.username}}{% endblock %}
{% block pagetitle %}Users blocked by @{{u.username}}{% endblock %}
{% block content %}
<div class="row no-gutters">
<div class="col-12">
<div class="text-center py-6 py-md-8">
<span class="fa-stack fa-2x text-muted mb-2">
<i class="fas fa-square text-danger opacity-25 fa-stack-2x"></i>
<i class="fas text-danger fa-user-cog fa-stack-1x text-lg"></i>
</span>
<h5>You are blocking @{{u.username}}.</h5>
<p class="text-muted">So we aren't going to show you their profile.</p>
<button type="button" class="btn btn-success text-success mt-2" data-nonce="{{g.nonce}}" data-onclick="postToastReload(this,'/settings/unblock?username={{u.username}}')"><i class="fas fa-eye text-success mr-2"></i>Unblock @{{u.username}}</a>
</div>
</div>
</div>
<h5 class="my-3">Users blocked by @{{u.username}}</h5>
<div class="overflow-x-auto mt-1"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>Name</th>
<th class="disable-sort-click">Blocking since</th>
{% if v.id == u.id %}
<th class="disable-sort-click"></th>
{% endif %}
</tr>
</thead>
<tbody id="blockers-table">
{% for block, user in users %}
<tr>
<td>{% include "user_in_table.html" %}</td>
<td {% if block.created_utc > 1599343262 %}data-time="{{block.created_utc}}"{% endif %}></td>
{% if v.id == u.id %}
<td>
<button type="button" class="btn btn-primary" data-nonce="{{g.nonce}}" data-onclick="unblock_user(this, '/settings/unblock?username={{user.username}}&formkey={{v|formkey}}')">Unblock</button>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% if v.id == u.id %}
<script defer src="{{'js/settings_blocks.js' | asset}}"></script>
{% endif %}
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{% endblock %}
{% block pagenav %}{% endblock %}