Merge pull request #549 from justcool393/fix-leaking-deleted-content
fix leak of deleted content
This commit is contained in:
commit
86fe498138
4 changed files with 35 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
from os import environ
|
||||
import re
|
||||
import time
|
||||
from typing import Optional
|
||||
from urllib.parse import urlencode, urlparse, parse_qs
|
||||
from flask import *
|
||||
from sqlalchemy import *
|
||||
|
@ -8,6 +9,7 @@ from sqlalchemy.orm import relationship
|
|||
from files.__main__ import Base, app
|
||||
from files.classes.votes import CommentVote
|
||||
from files.helpers.const import *
|
||||
from files.helpers.content import moderated_body
|
||||
from files.helpers.lazy import lazy
|
||||
from .flags import CommentFlag
|
||||
from random import randint
|
||||
|
@ -331,6 +333,8 @@ class Comment(Base):
|
|||
return data
|
||||
|
||||
def realbody(self, v):
|
||||
moderated:Optional[str] = moderated_body(self, v)
|
||||
if moderated: return moderated
|
||||
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
|
||||
|
||||
body = self.body_html or ""
|
||||
|
@ -371,6 +375,8 @@ class Comment(Base):
|
|||
return body
|
||||
|
||||
def plainbody(self, v):
|
||||
moderated:Optional[str] = moderated_body(self, v)
|
||||
if moderated: return moderated
|
||||
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
|
||||
body = self.body
|
||||
if not body: return ""
|
||||
|
|
|
@ -2,12 +2,14 @@ from os import environ
|
|||
import random
|
||||
import re
|
||||
import time
|
||||
from typing import Optional
|
||||
from urllib.parse import urlparse
|
||||
from flask import render_template
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import relationship, deferred
|
||||
from files.__main__ import Base, app
|
||||
from files.helpers.const import *
|
||||
from files.helpers.content import moderated_body
|
||||
from files.helpers.lazy import lazy
|
||||
from files.helpers.assetcache import assetcache_path
|
||||
from .flags import Flag
|
||||
|
@ -357,6 +359,9 @@ class Submission(Base):
|
|||
else: return ""
|
||||
|
||||
def realbody(self, v):
|
||||
moderated:Optional[str] = moderated_body(self, v)
|
||||
if moderated: return moderated
|
||||
|
||||
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
|
||||
|
||||
body = self.body_html or ""
|
||||
|
@ -381,6 +386,9 @@ class Submission(Base):
|
|||
return body
|
||||
|
||||
def plainbody(self, v):
|
||||
moderated:Optional[str] = moderated_body(self, v)
|
||||
if moderated: return moderated
|
||||
|
||||
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
|
||||
body = self.body
|
||||
if not body: return ""
|
||||
|
|
|
@ -108,6 +108,7 @@ FEATURES = {
|
|||
|
||||
PERMS = {
|
||||
"DEBUG_LOGIN_TO_OTHERS": 3,
|
||||
"POST_COMMENT_MODERATION": 2,
|
||||
"USER_SHADOWBAN": 2,
|
||||
}
|
||||
|
||||
|
|
20
files/helpers/content.py
Normal file
20
files/helpers/content.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from typing import Any, TYPE_CHECKING, Optional, Union
|
||||
|
||||
from files.helpers.const import PERMS
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from files.classes import Submission, Comment, User
|
||||
else:
|
||||
Submission = Any
|
||||
Comment = Any
|
||||
User = Any
|
||||
|
||||
def moderated_body(target:Union[Submission, Comment],
|
||||
v:Optional[User]) -> Optional[str]:
|
||||
if v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] \
|
||||
or v.id == target.author_id):
|
||||
return None
|
||||
if target.deleted_utc: return 'Deleted by author'
|
||||
if target.is_banned or target.filter_state == 'removed': return 'Removed'
|
||||
if target.filter_state == 'filtered': return 'Filtered'
|
||||
return None
|
Loading…
Add table
Add a link
Reference in a new issue