rename fullnames

Handle a couple places with `t3_` that persisted from code movement.
on master after time of branch.

Then, fix commenting, which used inaccurate fullname parsing logic.
This commit is contained in:
justcool393 2023-07-13 12:37:28 -07:00 committed by GitHub
parent db1f578f26
commit 8191d5a4cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 27 additions and 28 deletions

View file

@ -139,7 +139,7 @@ class Comment(CreatedBase):
@property
@lazy
def fullname(self):
return f"t3_{self.id}"
return f"comment_{self.id}"
@property
@lazy
@ -151,8 +151,8 @@ class Comment(CreatedBase):
@property
@lazy
def parent_fullname(self):
if self.parent_comment_id: return f"t3_{self.parent_comment_id}"
elif self.parent_submission: return f"t2_{self.parent_submission}"
if self.parent_comment_id: return f"comment_{self.parent_comment_id}"
elif self.parent_submission: return f"post_{self.parent_submission}"
def replies(self, user):
if self.replies2 != None: return [x for x in self.replies2 if not x.author.shadowbanned]

View file

@ -164,7 +164,7 @@ class Submission(CreatedBase):
@property
@lazy
def fullname(self):
return f"t2_{self.id}"
return f"post_{self.id}"
@property
@lazy

View file

@ -243,7 +243,7 @@ class User(CreatedBase):
@property
@lazy
def fullname(self):
return f"t1_{self.id}"
return f"user_{self.id}"
@property
@lazy

View file

@ -111,16 +111,15 @@ def api_comment(v):
parent_fullname = request.values.get("parent_fullname", "").strip()
if len(parent_fullname) < 4: abort(400)
id = parent_fullname[3:]
parent = None
parent_post = None
parent_comment_id = None
if parent_fullname.startswith("t2_"):
parent = get_post(id, v=v)
if parent_fullname.startswith("post_"):
parent = get_post(parent_fullname.split("post_")[1], v=v)
parent_post = parent
elif parent_fullname.startswith("t3_"):
parent = get_comment(id, v=v)
elif parent_fullname.startswith("comment_"):
parent = get_comment(parent_fullname.split("comment_")[1], v=v)
parent_post = get_post(parent.parent_submission, v=v) if parent.parent_submission else None
parent_comment_id = parent.id
else: abort(400)

View file

@ -17,8 +17,8 @@ def admin_vote_info_get(v):
if not link: return render_template("votes.html", v=v)
try:
if "t2_" in link: thing = get_post(link.split("t2_")[1], v=v)
elif "t3_" in link: thing = get_comment(link.split("t3_")[1], v=v)
if "post_" in link: thing = get_post(link.split("post_")[1], v=v)
elif "comment_" in link: thing = get_comment(link.split("comment_")[1], v=v)
else: abort(400)
except: abort(400)

View file

@ -1,10 +1,10 @@
<div id="reply-to-{{c.id}}" class="d-none">
<div id="comment-form-space-{{c.fullname}}" class="comment-write collapsed child">
<form id="reply-to-t3_{{c.id}}" action="/comment" method="post" enctype="multipart/form-data">
<form id="reply-to-{{c.fullname}}" action="/comment" method="post" enctype="multipart/form-data">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="parent_fullname" value="{{c.fullname}}">
<input autocomplete="off" id="reply-form-submission-{{c.fullname}}" type="hidden" name="submission" value="{{c.post.id}}">
<textarea required autocomplete="off" minlength="1" maxlength="{{COMMENT_BODY_LENGTH_MAXIMUM}}" oninput="markdown('reply-form-body-{{c.fullname}}', 'reply-edit-{{c.id}}');charLimit('reply-form-body-{{c.fullname}}','charcount-{{c.id}}')" id="reply-form-body-{{c.fullname}}" data-fullname="{{c.fullname}}" name="body" form="reply-to-t3_{{c.id}}" class="comment-box form-control rounded" aria-label="With textarea" placeholder="Add your comment..." rows="3"></textarea>
<textarea required autocomplete="off" minlength="1" maxlength="{{COMMENT_BODY_LENGTH_MAXIMUM}}" oninput="markdown('reply-form-body-{{c.fullname}}', 'reply-edit-{{c.id}}');charLimit('reply-form-body-{{c.fullname}}','charcount-{{c.id}}')" id="reply-form-body-{{c.fullname}}" data-fullname="{{c.fullname}}" name="body" form="reply-to-{{c.fullname}}" class="comment-box form-control rounded" aria-label="With textarea" placeholder="Add your comment..." rows="3"></textarea>
<div class="text-small font-weight-bold mt-1" id="charcount-{{c.id}}" style="right: 1rem; bottom: 0.5rem; z-index: 3;"></div>

View file

@ -3,7 +3,7 @@
<div id="comment-form-space-{{c.id}}" class="comment-write collapsed child">
<form id="reply-to-message-{{c.id}}" action="/reply" method="post" class="input-group" enctype="multipart/form-data">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<textarea required autocomplete="off" minlength="1" maxlength="{{MESSAGE_BODY_LENGTH_MAXIMUM}}" name="body" form="reply-to-t3_{{c.id}}" data-id="{{c.id}}" class="comment-box form-control rounded" id="reply-form-body-{{c.id}}" aria-label="With textarea" rows="3" oninput="markdown('reply-form-body-{{c.id}}', 'message-reply-{{c.id}}')"></textarea>
<textarea required autocomplete="off" minlength="1" maxlength="{{MESSAGE_BODY_LENGTH_MAXIMUM}}" name="body" form="reply-to-message-{{c.id}}" data-id="{{c.id}}" class="comment-box form-control rounded" id="reply-form-body-{{c.id}}" aria-label="With textarea" rows="3" oninput="markdown('reply-form-body-{{c.id}}', 'message-reply-{{c.id}}')"></textarea>
<div class="comment-format" id="comment-format-bar-{{c.id}}">
{% if c.sentto == MODMAIL_ID %}
<label class="btn btn-secondary m-0 mt-3" for="file-upload">

View file

@ -421,7 +421,7 @@
<div id="comment-form-space-{{p.fullname}}" class="comment-write mb-3">
<form id="reply-to-{{p.fullname}}" action="/comment" method="post">
{{forms.formkey(v)}}
<input type="hidden" name="parent_fullname" value="t2_{{p.id}}">
<input type="hidden" name="parent_fullname" value="{{p.fullname}}">
<input autocomplete="off" id="reply-form-submission-{{p.fullname}}" type="hidden" name="submission" value="{{p.id}}">
<textarea required autocomplete="off" minlength="1" maxlength="{{COMMENT_BODY_LENGTH_MAXIMUM}}" oninput="markdown('reply-form-body-{{p.fullname}}', 'form-preview-{{p.id}}');charLimit('reply-form-body-{{p.fullname}}','charcount-reply')" id="reply-form-body-{{p.fullname}}" data-fullname="{{p.fullname}}" class="comment-box form-control rounded" id="comment-form" name="body" form="reply-to-{{p.fullname}}" aria-label="With textarea" placeholder="Add your comment..." rows="3"></textarea>

View file

@ -15,7 +15,7 @@ class CommentsFixture:
assert submit_get_response.status_code == 200
comment_body = data.get('body', util.generate_text())
submit_comment_response = client.post("/comment", data={
"parent_fullname": f't2_{post_id}',
"parent_fullname": f'post_{post_id}',
'parent_level': 1,
'submission': post_id,
"body": comment_body,

View file

@ -24,9 +24,9 @@ class SubmissionsFixture:
assert post_body in submit_post_response.text
post_info = util.ItemData.from_html(submit_post_response.text)
post_id_full = post_info.id_full
assert post_id_full.startswith('t2_')
assert post_id_full.startswith('post_')
post_id = int(post_id_full[3:])
post_id = int(post_id_full.split('_')[1])
db = db_session()
submission = db.query(Submission).filter_by(id=post_id).first()

View file

@ -115,19 +115,19 @@ def test_comment_descendant_count(accounts, submissions, comments):
reply1 = comments.comment_for_client(alice_client, post.id, {
'body': 'You\'re wrong, this isn\'t contentious',
'parent_fullname': f't3_{root.id}',
'parent_fullname': f'comment_{root.id}',
'parent_level': root.level,
})
rereply1 = comments.comment_for_client(alice_client, post.id, {
'body': 'no u',
'parent_fullname': f't3_{reply1.id}',
'parent_fullname': f'comment_{reply1.id}',
'parent_level': reply1.level,
})
reply2 = comments.comment_for_client(alice_client, post.id, {
'body': 'Good poast',
'parent_fullname': f't3_{root.id}',
'parent_fullname': f'comment_{root.id}',
'parent_level': root.level,
})
@ -153,7 +153,7 @@ def test_more_button_label_in_deep_threads(accounts, submissions, comments):
for i in range(1, 25 + 1):
c = comments.comment_for_client(alice_client, post.id, {
'body': str(i),
'parent_fullname': f't3_{c.id}',
'parent_fullname': f'comment_{c.id}',
'parent_level': c.level,
})
if i % 5 == 0:

View file

@ -37,9 +37,9 @@ def no_rate_limit(test_function):
# this is meant to be a utility class that stores post and comment references so you can use them in other calls
# it's pretty barebones and will probably be fleshed out
class ItemData:
id = None
id_full = None
url = None
id: str | None = None
id_full: str | None = None
url: str | None = None
@staticmethod
def from_html(text):
@ -52,7 +52,7 @@ class ItemData:
result = ItemData()
result.id = match.group(1) # this really should get yanked out of the JS, not the URL
result.id_full = f"t2_{result.id}"
result.id_full = f"post_{result.id}"
result.url = url
return result
@ -69,6 +69,6 @@ class ItemData:
result = ItemData()
result.id = match.group(1) # this really should get yanked out of the JS, not the HTML
result.id_full = f"t3_{result.id}"
result.id_full = f"comment_{result.id}"
result.url = f"/comment/{result.id}"
return result