rDrama/files/helpers/can_see.py

45 lines
1.8 KiB
Python
Raw Normal View History

2023-10-05 10:14:59 +00:00
from .config.const import *
2023-10-05 10:09:58 +00:00
from files.classes.post import Post
from files.classes.comment import Comment
2023-10-07 17:55:50 +00:00
from files.classes.hole import Hole
2023-10-05 10:09:58 +00:00
from flask import request
2024-03-05 00:55:20 +00:00
def can_see(user, obj):
if isinstance(obj, (Post, Comment)):
2024-04-26 21:45:19 +00:00
if not user and SITE == 'watchpeopledie.tv' and isinstance(obj, Post) and obj.hole in {'sandshit','isis'}:
return False
2024-03-05 00:55:20 +00:00
if not can_see(user, obj.author): return False
if user and user.id == obj.author_id: return True
if isinstance(obj, Post):
if obj.hole and not can_see(user, obj.hole_obj):
2023-10-05 10:09:58 +00:00
return False
if request.headers.get("Cf-Ipcountry") == 'NZ':
2024-03-05 00:55:20 +00:00
if 'christchurch' in obj.title.lower():
2023-10-05 10:09:58 +00:00
return False
2024-03-05 00:55:20 +00:00
if SITE == 'watchpeopledie.tv' and obj.id in {5, 17212, 22653, 23814}:
2023-10-05 10:09:58 +00:00
return False
else:
2024-03-05 01:16:47 +00:00
if obj.pinned == "Admin Note":
2024-04-05 07:45:25 +00:00
return user and user.admin_level >= PERMS['ADMIN_NOTES']
2024-03-05 00:55:20 +00:00
if hasattr(obj, 'is_blocking') and obj.is_blocking and not request.path.endswith(f'/{obj.id}'):
2023-10-05 10:09:58 +00:00
return False
2024-03-05 00:55:20 +00:00
if obj.parent_post:
return can_see(user, obj.post)
2023-10-05 10:09:58 +00:00
else:
2024-03-05 00:55:20 +00:00
if not user and not obj.wall_user_id: return False
2023-10-05 10:09:58 +00:00
2024-03-05 00:55:20 +00:00
if obj.sentto:
if obj.sentto == MODMAIL_ID:
if obj.top_comment.author_id == user.id: return True
2023-10-05 10:09:58 +00:00
return user.admin_level >= PERMS['VIEW_MODMAIL']
2024-03-08 08:10:23 +00:00
if obj.sentto != user.id:
2023-10-05 10:09:58 +00:00
return user.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS']
2024-03-05 00:55:20 +00:00
elif isinstance(obj, Hole):
if obj.name == 'chudrama': return bool(user) and user.can_see_chudrama
if obj.name == 'countryclub': return bool(user) and user.can_see_countryclub
if obj.name == 'highrollerclub': return bool(user) and user.can_see_highrollerclub
elif obj.__class__.__name__ == 'User':
return not obj.shadowbanned or (user and user.id == obj.id) or (user and user.admin_level >= PERMS['USER_SHADOWBAN'])
2023-10-05 10:09:58 +00:00
return True