minor /set_new rework
parent
da4f3937f5
commit
3e3d39e432
|
@ -313,6 +313,16 @@ ACTIONTYPES = {
|
|||
"icon": 'fa-award',
|
||||
"color": 'bg-primary'
|
||||
},
|
||||
'set_new': {
|
||||
"str": 'changed the default sorting of comments on {self.target_link} to `new`',
|
||||
"icon": 'fa-sparkles',
|
||||
"color": 'bg-primary'
|
||||
},
|
||||
'set_hot': {
|
||||
"str": 'changed the default sorting of comments on {self.target_link} to `hot`',
|
||||
"icon": 'fa-fire',
|
||||
"color": 'bg-primary'
|
||||
},
|
||||
'set_nsfw': {
|
||||
"str": 'set {self.target_link} as +18',
|
||||
"icon": 'fa-eye-evil',
|
||||
|
|
|
@ -988,15 +988,46 @@ def pin_post(post_id, v):
|
|||
else: return {"message": "Post unpinned!"}
|
||||
return abort(404, "Post not found!")
|
||||
|
||||
@app.route("/post/<post_id>/new", methods=["PUT", "DELETE"])
|
||||
@app.put("/post/<post_id>/new")
|
||||
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)
|
||||
@auth_required
|
||||
def toggle_new_sort(post_id:int, v:User):
|
||||
def set_new_sort(post_id:int, v:User):
|
||||
post = get_post(post_id)
|
||||
if not v.can_edit(post): abort(403, "Only the post author can do that!")
|
||||
post.new = request.method == "PUT"
|
||||
post.new = True
|
||||
g.db.add(post)
|
||||
return {"message": f"Turned {'on' if post.new else 'off'} sort by new"}
|
||||
|
||||
if v.id != post.author_id:
|
||||
ma = ModAction(
|
||||
kind = "set_new",
|
||||
user_id = v.id,
|
||||
target_submission_id = post.id,
|
||||
)
|
||||
g.db.add(ma)
|
||||
send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has changed the the default sorting of comments on [{post.title}](/post/{post.id}) to `new`")
|
||||
|
||||
return {"message": f"Changed the the default sorting of comments on this post to 'new'"}
|
||||
|
||||
|
||||
@app.delete("/post/<post_id>/new")
|
||||
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)
|
||||
@auth_required
|
||||
def unset_new_sort(post_id:int, v:User):
|
||||
post = get_post(post_id)
|
||||
if not v.can_edit(post): abort(403, "Only the post author can do that!")
|
||||
post.new = None
|
||||
g.db.add(post)
|
||||
|
||||
if v.id != post.author_id:
|
||||
ma = ModAction(
|
||||
kind = "set_hot",
|
||||
user_id = v.id,
|
||||
target_submission_id = post.id,
|
||||
)
|
||||
g.db.add(ma)
|
||||
send_repeatable_notification(post.author_id, f"@{v.username} (Admin) has changed the the default sorting of comments on [{post.title}](/post/{post.id}) to `hot`")
|
||||
|
||||
return {"message": f"Changed the the default sorting of comments on this post to 'hot'"}
|
||||
|
||||
|
||||
extensions = IMAGE_FORMATS + VIDEO_FORMATS + AUDIO_FORMATS
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
{% endif %}
|
||||
{% if v.can_edit(p) %}
|
||||
<button type="button" class="dropdown-item {% if p.new %} d-none{% endif %} list-inline-item text-info" id="{{p.id}}-sort-new" onclick="postToastSwitch(this, '/post/{{p.id}}/new', this.id, '{{p.id}}-unsort-new', 'd-none', null, 'PUT')"><i class="fas fa-sparkles text-center text-primary mr-2"></i>Set Default Sort New</button>
|
||||
<button type="button" class="dropdown-item {% if not p.new %} d-none{% endif %} list-inline-item text-info" id="{{p.id}}-unsort-new" onclick="postToastSwitch(this, '/post/{{p.id}}/new', this.id, '{{p.id}}-sort-new', 'd-none', null, 'DELETE')"><i class="fas fa-sparkles text-center text-primary mr-2"></i>Unset Default Sort New</button>
|
||||
<button type="button" class="dropdown-item {% if not p.new %} d-none{% endif %} list-inline-item text-info" id="{{p.id}}-unsort-new" onclick="postToastSwitch(this, '/post/{{p.id}}/new', this.id, '{{p.id}}-sort-new', 'd-none', null, 'DELETE')"><i class="fas fa-fire text-center text-primary mr-2"></i>Set Default Sort Hot</button>
|
||||
{% endif %}
|
||||
{% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %}
|
||||
<button type="button" id="distinguish-{{p.id}}" class="dropdown-item {% if p.distinguish_level %}d-none{% endif %} list-inline-item text-info" onclick="postToastSwitch(this,'/distinguish/{{p.id}}','distinguish-{{p.id}}','undistinguish-{{p.id}}','d-none')"><i class="fas fa-crown"></i>Distinguish</button>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
{% if v.can_edit(p) %}
|
||||
<button id="{{p.id}}-sort-new-mobile" type="button" class="{% if p.new %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" onclick="postToastSwitch(this, '/post/{{p.id}}/new', this.id, '{{p.id}}-unsort-new-mobile', 'd-none', null, 'PUT')" data-bs-dismiss="modal"><i class="fas fa-sparkles text-center text-primary mr-2"></i>Set Default Sort New</button>
|
||||
<button id="{{p.id}}-unsort-new-mobile" type="button" class="{% if not p.new %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" id="{{p.id}}-unsort-new-mobile" onclick="postToastSwitch(this, '/post/{{p.id}}/new', this.id, '{{p.id}}-sort-new-mobile', 'd-none', null, 'DELETE')" data-bs-dismiss="modal"><i class="fas fa-sparkles text-center text-primary mr-2"></i>Unset Default Sort New</button>
|
||||
<button id="{{p.id}}-unsort-new-mobile" type="button" class="{% if not p.new %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" id="{{p.id}}-unsort-new-mobile" onclick="postToastSwitch(this, '/post/{{p.id}}/new', this.id, '{{p.id}}-sort-new-mobile', 'd-none', null, 'DELETE')" data-bs-dismiss="modal"><i class="fas fa-fire text-center text-primary mr-2"></i>Set Default Sort Hot</button>
|
||||
{% endif %}
|
||||
{% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] and (v.id == p.author.id or v.admin_level >= PERMS['POST_COMMENT_MODERATION']) %}
|
||||
<button type="button" id="distinguish2-{{p.id}}" class="{% if p.distinguish_level %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" onclick="postToastSwitch(this,'/distinguish/{{p.id}}','distinguish2-{{p.id}}','undistinguish2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-crown text-center text-primary mr-2"></i>Distinguish</button>
|
||||
|
|
Loading…
Reference in New Issue