diff --git a/drama/classes/user.py b/drama/classes/user.py index 3d668d68c..1588c113a 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -277,6 +277,28 @@ class User(Base, Stndrd, Age_times): def __repr__(self): return f"" + @property + def unban_string(self): + if self.unban_utc == 0: + return "permanently banned" + + wait = self.unban_utc - int(time.time()) + + if wait < 60: + text = f"{wait}s" + else: + days = wait//(24*60*60) + wait -= days*24*60*60 + + hours = wait//(60*60) + wait -= hours*60*60 + + mins = wait//60 + + text = f"{days}d {hours:02d}h {mins:02d}m" + + return f"Unban in {text}" + @property @lazy def post_notifications_count(self): diff --git a/drama/routes/admin.py b/drama/routes/admin.py index a1f5eb432..1b58c8664 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -633,7 +633,7 @@ def ban_user(user_id, v): user = g.db.query(User).filter_by(id=user_id).first() - if user.admin_level != 0: abort(403) + if user.admin_level >= v.admin_level: abort(403) # check for number of days for suspension days = int(request.form.get("days")) if request.form.get('days') else 0 @@ -642,7 +642,7 @@ def ban_user(user_id, v): if not user: abort(400) - if user.admin_level > 0: abort(403) + #if user.admin_level > 0: abort(403) if days > 0: if message: diff --git a/drama/routes/comments.py b/drama/routes/comments.py index 553ed829d..cb7f93f6d 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -433,7 +433,7 @@ def api_comment(v): included. \n\n*This is an automated message; if you need help, you can message us [here](/contact).*""" - body = body.replace("\n", "\n\n") + #body = body.replace("\n", "\n\n") with CustomRenderer(post_id=parent_id) as renderer: body_md = renderer.render(mistletoe.Document(body)) @@ -920,7 +920,7 @@ def toggle_comment_pin(cid, v): comment = get_comment(cid, v=v) - if v.admin_level != 6 and v.id != comment.post.author_id: + if v.admin_level < 1 and v.id != comment.post.author_id: abort(403) comment.is_pinned = not comment.is_pinned diff --git a/drama/routes/login.py b/drama/routes/login.py index 5fff1b2bf..cffd90be5 100644 --- a/drama/routes/login.py +++ b/drama/routes/login.py @@ -338,7 +338,8 @@ def sign_up_post(v): email=email, created_utc=int(time.time()), referred_by=ref_id or None, - ban_evade = int(any([x.is_banned for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])) + ban_evade = int(any([x.is_banned for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])), + agendaposter = any([x.agendaposter for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]) ) except Exception as e: diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 94c9ea49e..3818a72d5 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -465,6 +465,9 @@ def settings_block_user(v): if not existing: send_block_notif(v.id, user.id, f"@{v.username} has blocked you!") if request.args.get("notoast"): return "", 204 + + if v.admin_level == 1: return jsonify({"message": f"@{user.username} banned!"}) + return jsonify({"message": f"@{user.username} blocked."}) @@ -487,6 +490,9 @@ def settings_unblock_user(v): if not existing: send_unblock_notif(v.id, user.id, f"@{v.username} has unblocked you!") if request.args.get("notoast"): return "", 204 + + if v.admin_level == 1: return jsonify({"message": f"@{user.username} unbanned!"}) + return jsonify({"message": f"@{user.username} unblocked."}) diff --git a/drama/routes/users.py b/drama/routes/users.py index eaade85f3..839021d19 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -304,9 +304,9 @@ def u_username(username, v=None): listing = get_posts(ids, v=v) if u.unban_utc: - unban = datetime.fromtimestamp(u.unban_utc).strftime('%c') + #unban = datetime.fromtimestamp(u.unban_utc).strftime('%c') return {'html': lambda: render_template("userpage.html", - unban=unban, + unban=u.unban_string, u=u, v=v, listing=listing, diff --git a/drama/templates/comments.html b/drama/templates/comments.html index 4f8a13ca6..b51c87fe0 100644 --- a/drama/templates/comments.html +++ b/drama/templates/comments.html @@ -121,7 +121,7 @@ {% if c.distinguish_level %} {% endif %} {% if c.is_op %} {% endif %} {% if c.is_bot %} {% endif %} - {% if c.is_blocking %} {% endif %} + {% if c.is_blocking %} {% endif %} {% if c.is_blocked %} {% endif %} {{c.author.username}}{% if c.author.customtitle %}  {{c.author.customtitle | safe}}{% endif %} @@ -318,6 +318,11 @@ >Block user {% endif %} + {% if not v.id==c.author_id and v.admin_level == 1 %} + Ban user + {% endif %} + {% if v.admin_level>=3 %} {% if not c.is_banned %} Remove @@ -331,7 +336,7 @@ {% endif %} {% endif %} - {% if v and c.post and (v.admin_level == 6 or v.id == c.post.author_id) %} + {% if v and c.post and (v.admin_level >= 1 or v.id == c.post.author_id) %} {% if c.level == 1 %} {{"Unpin" if c.is_pinned else "Pin"}} @@ -518,7 +523,7 @@ {% endif %} {% endif %} - {% if v and c.post and (v.admin_level == 6 or v.id == c.post.author_id) %} + {% if v and c.post and (v.admin_level >= 1 or v.id == c.post.author_id) %} {% if c.level == 1 %}
  • {{'Unpin' if c.is_pinned else 'Pin'}}
  • diff --git a/drama/templates/submission.html b/drama/templates/submission.html index e8921b16b..66eeb5d5a 100644 --- a/drama/templates/submission.html +++ b/drama/templates/submission.html @@ -227,7 +227,7 @@ {% if p.private %}unlisted{% endif %} {% if p.repost_id %}repost{% endif %} {% if p.flags %}{{p.active_flags}} Reports{% endif %} -    {{p.author.username}}{% if p.author.customtitle %}  {{p.author.customtitle | safe}}{% endif %} +    {{p.author.username}}{% if p.author.customtitle %}  {{p.author.customtitle | safe}}{% endif %}  {{p.age_string}} ({% if p.realurl(v) %}{{p.domain}}{% else %}text post{% endif %}) @@ -389,6 +389,13 @@ >Unblock user {% endif %} + {% if not v.id==p.author_id and v.admin_level == 1 %} +
  • Ban user
  • +
  • Unban user
  • + {% endif %} + {% if v.admin_level >=3 and v.id!=p.author_id %} {% if p.author.is_banned %}
  • unlisted{% endif %} {% if p.repost_id %} repost{% endif %} {% if p.flags %}{{p.active_flags}} Reports{% endif %} -  {{p.author.username}}{% if p.author.customtitle %}  {{p.author.customtitle | safe}}{% endif %} +  {{p.author.username}}{% if p.author.customtitle %}  {{p.author.customtitle | safe}}{% endif %}  {{p.age_string}}   ({% if p.realurl(v) %}{{p.domain}}{% else %}text post{% endif %}) diff --git a/drama/templates/userpage.html b/drama/templates/userpage.html index 4eea1f9ad..f4bc2c597 100644 --- a/drama/templates/userpage.html +++ b/drama/templates/userpage.html @@ -65,9 +65,9 @@
    - {% if u.is_banned %} + {% if u.is_suspended %}
    BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
    - {% if unban %}
    until {{unban}}
    {% endif %} + {% if unban %}
    {{unban}}
    {% endif %} {% endif %}
    @@ -77,13 +77,13 @@ {% endif %} - {% if u.admin_level > 1 %} + {% if u.admin_level > 1 or (u.admin_level == 1 and (not v or v.admin_level < 2)) %} {% elif u.admin_level == 1 %} - + {% endif %} {% if v and v.has_follower(u) %} @@ -157,7 +157,7 @@ Edit profile Profile views {% endif %} - {% if v and v.id != u.id and v.admin_level > 0 and u.admin_level == 0 %} + {% if v and v.id != u.id and v.admin_level > 1 and u.admin_level <= 1 %}

    @@ -280,9 +280,9 @@
    - {% if u.is_banned %} + {% if u.is_suspended %}
    BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
    - {% if unban %}
    until {{unban}}
    {% endif %} + {% if unban %}
    {{unban}}
    {% endif %} {% endif %}

    {{u.username}}

    @@ -337,7 +337,7 @@ - {% if v.admin_level > 0 and u.admin_level == 0 %} + {% if v.admin_level > 1 and u.admin_level <= 1 %}

    diff --git a/drama/templates/userpage_blocking.html b/drama/templates/userpage_blocking.html index b51c0fa10..53515e938 100644 --- a/drama/templates/userpage_blocking.html +++ b/drama/templates/userpage_blocking.html @@ -38,10 +38,15 @@
    - + {% if v.admin_level == 1 %}{% else %}{% endif %} + {% if v.admin_level == 1 %} +

    @{{u.username}} is banned

    +

    This account has been suspended.

    + {% else %}

    You are blocking @{{u.username}}.

    So we aren't going to show you their profile.

    + {% endif %}