diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 40ea6d2e4..faf04e015 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -262,48 +262,6 @@ ACTIONTYPES={ "color": "bg-muted", "title": 'un-pinned post {self.target_post.title}' }, - "invite_mod":{ - "str":'invited admin {self.target_link}', - "icon":"fa-user-crown", - "color": "bg-info", - "title": 'invited admin @{self.target_user.username}' - }, - "uninvite_mod":{ - "str":'rescinded admin invitation to {self.target_link}', - "icon":"fa-user-crown", - "color": "bg-muted", - "title": 'rescinded admin invitation to @{self.target_user.username}' - }, - "accept_mod_invite":{ - "str":'accepted admin invitation', - "icon":"fa-user-crown", - "color": "bg-warning", - "title": 'accepted admin invitation' - }, - "remove_mod":{ - "str":'removed admin {self.target_link}', - "icon":"fa-user-crown", - "color": "bg-danger", - "title": 'removed admin @{self.target_user.username}' - }, - "add_mod":{ - "str":'added admin {self.target_link}', - "icon":"fa-user-crown", - "color": "bg-success", - "title": 'added admin @{self.target_user.username}' - }, - "update_settings":{ - "str":'updated setting', - "icon":"fa-cog", - "color": "bg-info", - "title": 'updated settings' - }, - "update_appearance":{ - "str":'updated appearance', - "icon":"fa-palette", - "color": "bg-info", - "title": 'updated appearance' - }, "set_nsfw":{ "str":'set nsfw on post {self.target_link}', "icon":"fa-eye-evil", @@ -340,6 +298,18 @@ ACTIONTYPES={ "color": "bg-muted", "title": "reinstated post {self.target_post.title}" }, + "club":{ + "str": 'marked post {self.target_link} as viewable to users with +150 coins only', + "icon":"fa-eye-slash", + "color": "bg-danger", + "title": 'marked post {self.target_post} as viewable to users with +150 coins only' + }, + "unclub":{ + "str": 'unmarked post {self.target_link} as viewable to users with +150 coins only', + "icon":"fa-eye", + "color": "bg-muted", + "title": 'unmarked post {self.target_post} as viewable to users with +150 coins only' + }, "ban_comment":{ "str": 'removed {self.target_link}', "icon":"fa-comment", diff --git a/files/classes/submission.py b/files/classes/submission.py index e570a3e74..6018fa191 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -54,6 +54,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): stickied = Column(Boolean, default=False) is_pinned = Column(Boolean, default=False) private = Column(Boolean, default=False) + club = Column(Boolean, default=False) comment_count = Column(Integer, default=0) comments = relationship( "Comment", @@ -359,10 +360,11 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): g.db.add(self.submission_aux) def realtitle(self, v): - if self.title_html: title = self.title_html + if self.club and not (v and v.coins > 150): return 'COUNTRY CLUB MEMBERS ONLY' + elif self.title_html: title = self.title_html else: title = self.title - if not v or v.slurreplacer: + if not v or v.slurreplacer: for s,r in SLURS.items(): title = title.replace(s, r) return title diff --git a/files/classes/user.py b/files/classes/user.py index f0e52cd04..4a16ba17a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -541,20 +541,6 @@ class User(Base, Stndrd, Age_times): def is_blocked(self): return self.__dict__.get('_is_blocked', 0) - def refresh_referral_badges(self): - - # check self-setting badges - badge_types = g.db.query(BadgeDef).filter(BadgeDef.qualification_expr.isnot(None)).all() - for badge in badge_types: - if eval(badge.qualification_expr, {}, {'v': self}): - if not self.has_badge(badge.id): - new_badge = Badge(user_id=self.id, badge_id=badge.id) - g.db.add(new_badge) - else: - bad_badge = self.has_badge(badge.id) - if bad_badge: g.db.delete(bad_badge) - - g.db.add(self) @property def applications(self): diff --git a/files/routes/login.py b/files/routes/login.py index 1b92b07ce..c8776c68f 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -334,7 +334,17 @@ def sign_up_post(v): ref_user = g.db.query(User).options( lazyload('*')).filter_by(id=ref_id).first() if ref_user: - ref_user.refresh_referral_badges() + # check self-setting badges + badge_types = g.db.query(BadgeDef).filter(BadgeDef.qualification_expr.isnot(None)).all() + for badge in badge_types: + if eval(badge.qualification_expr, {}, {'v': self}): + if not ref_user.has_badge(badge.id): + new_badge = Badge(user_id=ref_user.id, badge_id=badge.id) + g.db.add(new_badge) + else: + bad_badge = ref_user.has_badge(badge.id) + if bad_badge: g.db.delete(bad_badge) + g.db.add(ref_user) id_1 = g.db.query(User).filter_by(id=6).count() diff --git a/files/routes/posts.py b/files/routes/posts.py index 04fe51a64..218dfe3ad 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -21,10 +21,35 @@ from files.__main__ import app, limiter, cache from PIL import Image as PILimage from .front import frontlist, changeloglist + site = environ.get("DOMAIN").strip() with open("snappy.txt", "r") as f: snappyquotes = f.read().split("{[para]}") + +@app.post("/toggle_club/") +@auth_required +def toggle_club(pid, v): + + post = get_post(pid) + + if not post.author_id == v.id and not v.admin_level >= 3: abort(403) + + post.club = not post.club + g.db.add(post) + + if post.author_id!=v.id: + ma=ModAction( + kind="club" if post.club else "unclub", + user_id=v.id, + target_submission_id=post.id, + ) + g.db.add(ma) + + if post.club: return {"message": "Post has been marked as +150-coins only!"} + else: return {"message": "Post has been unmarked as +150-coins only!"} + + @app.post("/publish/") @auth_required @validate_formkey @@ -83,6 +108,8 @@ def post_id(pid, anything=None, v=None): post = get_post(pid, v=v) + if post.club and not (v and v.coins > 150): abort(403) + if v: votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() @@ -830,6 +857,7 @@ def submit_post(v): new_post = Submission( private=bool(request.form.get("private","")), + club=bool(request.form.get("club","")), author_id=v.id, over_18=bool(request.form.get("over_18","")), app_id=v.client.application.id if v.client else None, diff --git a/files/routes/static.py b/files/routes/static.py index b5893b91f..94e8554d7 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -99,7 +99,7 @@ def log(v): page=int(request.args.get("page",1)) if v and v.admin_level == 6: actions = g.db.query(ModAction).order_by(ModAction.id.desc()).offset(25 * (page - 1)).limit(26).all() - else: actions=g.db.query(ModAction).filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban").order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all() + else: actions=g.db.query(ModAction).filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban", ModAction.kind!="club", ModAction.kind!="unclub").order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all() next_exists=len(actions)==26 actions=actions[:25] diff --git a/files/templates/submission.html b/files/templates/submission.html index c1016cbf1..ce32d7803 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -131,6 +131,12 @@ {% if v %} + + {% if v.admin_level >=3 or v.id == p.author.id and v.coins > 150 %} + + + {% endif %} + {% if v.admin_level >=3 %} @@ -247,6 +253,7 @@