fix leak of deleted content
This commit is contained in:
parent
fb65cf0416
commit
24af1b4433
4 changed files with 32 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
from os import environ
|
from os import environ
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
from typing import Optional
|
||||||
from urllib.parse import urlencode, urlparse, parse_qs
|
from urllib.parse import urlencode, urlparse, parse_qs
|
||||||
from flask import *
|
from flask import *
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
|
@ -8,6 +9,7 @@ from sqlalchemy.orm import relationship
|
||||||
from files.__main__ import Base, app
|
from files.__main__ import Base, app
|
||||||
from files.classes.votes import CommentVote
|
from files.classes.votes import CommentVote
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
|
from files.helpers.content import moderated_body
|
||||||
from files.helpers.lazy import lazy
|
from files.helpers.lazy import lazy
|
||||||
from .flags import CommentFlag
|
from .flags import CommentFlag
|
||||||
from random import randint
|
from random import randint
|
||||||
|
@ -331,6 +333,8 @@ class Comment(Base):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def realbody(self, v):
|
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>"
|
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 ""
|
body = self.body_html or ""
|
||||||
|
@ -371,6 +375,8 @@ class Comment(Base):
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def plainbody(self, v):
|
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>"
|
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
|
body = self.body
|
||||||
if not body: return ""
|
if not body: return ""
|
||||||
|
|
|
@ -2,12 +2,14 @@ from os import environ
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
from typing import Optional
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship, deferred
|
from sqlalchemy.orm import relationship, deferred
|
||||||
from files.__main__ import Base, app
|
from files.__main__ import Base, app
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
|
from files.helpers.content import moderated_body
|
||||||
from files.helpers.lazy import lazy
|
from files.helpers.lazy import lazy
|
||||||
from files.helpers.assetcache import assetcache_path
|
from files.helpers.assetcache import assetcache_path
|
||||||
from .flags import Flag
|
from .flags import Flag
|
||||||
|
@ -357,6 +359,9 @@ class Submission(Base):
|
||||||
else: return ""
|
else: return ""
|
||||||
|
|
||||||
def realbody(self, v):
|
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>"
|
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 ""
|
body = self.body_html or ""
|
||||||
|
@ -381,6 +386,9 @@ class Submission(Base):
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def plainbody(self, v):
|
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>"
|
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
|
body = self.body
|
||||||
if not body: return ""
|
if not body: return ""
|
||||||
|
|
|
@ -108,6 +108,7 @@ FEATURES = {
|
||||||
|
|
||||||
PERMS = {
|
PERMS = {
|
||||||
"DEBUG_LOGIN_TO_OTHERS": 3,
|
"DEBUG_LOGIN_TO_OTHERS": 3,
|
||||||
|
"POST_COMMENT_MODERATION": 2,
|
||||||
"USER_SHADOWBAN": 2,
|
"USER_SHADOWBAN": 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
files/helpers/content.py
Normal file
17
files/helpers/content.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
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:User) -> Optional[str]:
|
||||||
|
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: 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