From feffe83e060491818d134bb0f01f6c403efa3d93 Mon Sep 17 00:00:00 2001 From: Tobin Date: Wed, 1 Apr 2015 15:07:57 -0500 Subject: [PATCH] Disallow posting to /r/all, /r/front. Use subreddit instead of name --- rtv/docs.py | 2 +- rtv/subreddit.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rtv/docs.py b/rtv/docs.py index 13ab5a4..fe691e3 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -60,5 +60,5 @@ SUBMISSION_FILE = """ # The first line will be interpreted as the title # Following lines will be interpreted as the content # -# Posting to /r/{name} +# Posting to {name} """ diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 4559476..7f0a745 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -95,20 +95,20 @@ class SubredditPage(BasePage): def post_submission(self): # Abort if user isn't logged in if not self.reddit.is_logged_in(): - show_notification(self.stdscr, ["Login to reply"]) + show_notification(self.stdscr, ['Login to reply']) return - name = self.content.name - if '+' in name: - show_notification(self.stdscr, ['Can\'t post to a multireddit']) - return + subreddit = self.reddit.get_subreddit(self.content.name) - name = name.strip(' /') # Strip leading and trailing backslashes - if name.startswith('r/'): - name = name[2:] + # Make sure it is a valid subreddit for submission + sub = str(subreddit) + if '+' in sub or sub == '/r/all' or sub == '/r/front': + message = 'Can\'t post to {0}'.format(sub) + show_notification(self.stdscr, [message]) + return # Open the submission window - submission_info = SUBMISSION_FILE.format(name=name) + submission_info = SUBMISSION_FILE.format(name=sub) curses.endwin() submission_text = open_editor(submission_info) curses.doupdate() @@ -119,7 +119,7 @@ class SubredditPage(BasePage): return try: title, content = submission_text.split('\n', 1) - self.reddit.submit(name, title, text=content) + self.reddit.submit(subreddit, title, text=content) except praw.errors.APIException as e: show_notification(self.stdscr, [e.message]) else: