Exemplo n.º 1
0
    def GET_listing(self, where, vuser, sort, time, **env):
        self.where = where
        self.sort = sort
        self.time = time

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in  ('hot', 'new'):
            self.time = 'all'


        # hide spammers profile pages
        if (not c.user_is_loggedin or
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        if (where not in ('overview', 'submitted', 'comments')
            and not votes_visible(vuser)):
            return self.abort404()

        check_cheating('user')

        self.vuser = vuser
        self.render_params = {'user' : vuser}
        c.profilepage = True

        return ListingController.GET_listing(self, **env)
Exemplo n.º 2
0
    def GET_listing(self, where, vuser, **env):
        self.where = where
        self.vuser = vuser
        self.render_params = {'user' : vuser}
        c.profilepage = True

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        # pretend deleted users don't exist (although they are in the db still)
        if vuser._deleted:
            return self.abort404()

        # hide spammers profile pages
        if (not c.user_is_loggedin or
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        if (where not in ('profile', 'overview', 'submitted', 'comments')
            and not votes_visible(vuser)):
            return self.abort404()

        check_cheating('user')

        if where == 'profile':
            url = self.check_wiki_maybe_redirect_url()
            if url is not None:
                return self.redirect(url, 303)

        return ListingController.GET_listing(self, **env)
    def GET_listing(self, where, vuser, sort, time, **env):
        self.where = where
        self.sort = sort
        self.time = time

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in ('hot', 'new'):
            self.time = 'all'

        # hide spammers profile pages
        if (not c.user_is_loggedin or
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        if (where not in ('overview', 'submitted', 'comments')
                and not votes_visible(vuser)):
            return self.abort404()

        check_cheating('user')

        self.vuser = vuser
        self.render_params = {'user': vuser}
        c.profilepage = True

        return ListingController.GET_listing(self, **env)
Exemplo n.º 4
0
    def GET_listing(self, where, vuser, sort, time, **env):
        self.where = where
        self.sort = sort
        self.time = time

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in ("hot", "new"):
            self.time = "all"

        # hide spammers profile pages
        if (not c.user_is_loggedin or (c.user._id != vuser._id and not c.user_is_admin)) and vuser._spam:
            return self.abort404()

        if where not in ("overview", "submitted", "comments") and not votes_visible(vuser):
            return self.abort404()

        check_cheating("user")

        self.vuser = vuser
        self.render_params = {"user": vuser}
        c.profilepage = True

        if vuser.pref_hide_from_robots:
            self.robots = "noindex,nofollow"

        return ListingController.GET_listing(self, **env)
Exemplo n.º 5
0
    def GET_listing(self, where, vuser, **env):
        self.where = where

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        # pretend deleted users don't exist (although they are in the db still)
        if vuser._deleted:
            return self.abort404()

        # hide spammers profile pages
        if (not c.user_is_loggedin or
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        if (where not in ('overview', 'submitted', 'comments')
                and not votes_visible(vuser)):
            return self.abort404()

        check_cheating('user')

        self.vuser = vuser
        self.render_params = {'user': vuser}
        c.profilepage = True

        return ListingController.GET_listing(self, **env)
Exemplo n.º 6
0
    def GET_listing(self, where, vuser, sort, time, show, **env):
        self.where = where
        self.sort = sort
        self.time = time
        self.show = show

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in  ('hot', 'new'):
            self.time = 'all'


        # hide spammers profile pages
        if (not c.user_is_loggedin or
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        if where in ('liked', 'disliked') and not votes_visible(vuser):
            return self.abort403()

        if ((where in ('saved', 'hidden') or 
                (where == 'gilded' and show == 'given')) and
                not (c.user_is_loggedin and c.user._id == vuser._id) and
                not c.user_is_admin):
            return self.abort403()

        if where == 'saved':
            self.show_chooser = True
            category = VSavedCategory('category').run(env.get('category'))
            srname = request.GET.get('sr')
            if srname and c.user.gold:
                try:
                    sr = Subreddit._by_name(srname)
                except NotFound:
                    sr = None
            else:
                sr = None
            if category and not c.user.gold:
                category = None
            self.savedsr = sr
            self.savedcategory = category

        check_cheating('user')

        self.vuser = vuser
        self.render_params = {'user' : vuser}
        c.profilepage = True

        if vuser.pref_hide_from_robots:
            self.robots = 'noindex,nofollow'

        return ListingController.GET_listing(self, **env)
Exemplo n.º 7
0
    def GET_listing(self, where, vuser, sort, time, show, **env):
        self.where = where
        self.sort = sort
        self.time = time
        self.show = show

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in ("hot", "new"):
            self.time = "all"

        # hide spammers profile pages
        if (not c.user_is_loggedin or (c.user._id != vuser._id and not c.user_is_admin)) and vuser._spam:
            return self.abort404()

        if where in ("liked", "disliked") and not votes_visible(vuser):
            return self.abort403()

        if (
            (where in ("saved", "hidden") or (where == "gilded" and show == "given"))
            and not (c.user_is_loggedin and c.user._id == vuser._id)
            and not c.user_is_admin
        ):
            return self.abort403()

        if where == "saved":
            self.show_chooser = True
            category = VSavedCategory("category").run(env.get("category"))
            srname = request.GET.get("sr")
            if srname and c.user.gold:
                try:
                    sr = Subreddit._by_name(srname)
                except NotFound:
                    sr = None
            else:
                sr = None
            if category and not c.user.gold:
                category = None
            self.savedsr = sr
            self.savedcategory = category

        check_cheating("user")

        self.vuser = vuser
        self.render_params = {"user": vuser}
        c.profilepage = True

        if vuser.pref_hide_from_robots:
            self.robots = "noindex,nofollow"

        return ListingController.GET_listing(self, **env)
Exemplo n.º 8
0
Arquivo: front.py Projeto: cmak/reddit
    def GET_comments(self, article, comment, context, sort, num_comments):
        """Comment page for a given 'article'."""
        if not c.default_sr and c.site._id != article.sr_id: 
            return self.abort404()

        # if there is a focal comment, communicate down to comment_skeleton.html who
        # that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        # figure out number to show based on the menu
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == 'true' else user_num

        builder = CommentBuilder(article, CommentSortMenu.operator(sort), 
                                 comment, context)
        listing = NestedListing(builder, num = num,
                                parent_name = article._fullname)
        
        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.permalink))

        # insert reply box only for logged in user
        if c.user_is_loggedin and article.subreddit_slow.can_submit(c.user):
            displayPane.append(CommentReplyBox())
            #no comment box for permalinks
            if not comment:
                displayPane.append(CommentReplyBox(link_name = 
                                                   article._fullname))
        # finally add the comment listing
        displayPane.append(listing.listing())

        loc = None if c.focal_comment or context is not None else 'comments'
        
        res = LinkInfoPage(link = article, 
                           content = displayPane, 
                           nav_menus = [CommentSortMenu(default = sort), 
                                        NumCommentsMenu(article.num_comments,
                                                        default=num_comments)],
                           infotext = infotext).render()
        return res
Exemplo n.º 9
0
    def GET_listing(self, where, vuser, sort, time, show, **env):
        self.where = where
        self.sort = sort
        self.time = time
        self.show = show

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in  ('hot', 'new'):
            self.time = 'all'


        # hide spammers profile pages
        if (not c.user_is_loggedin or
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        if where in ('liked', 'disliked') and not votes_visible(vuser):
            return self.abort403()

        if ((where in ('saved', 'hidden') or 
                (where == 'gilded' and show == 'given')) and
                not (c.user_is_loggedin and c.user._id == vuser._id) and
                not c.user_is_admin):
            return self.abort403()

        if where == 'saved':
            self.show_chooser = True

        check_cheating('user')

        self.vuser = vuser
        self.render_params = {'user' : vuser}
        c.profilepage = True

        if vuser.pref_hide_from_robots:
            self.robots = 'noindex,nofollow'

        return ListingController.GET_listing(self, **env)
Exemplo n.º 10
0
    def GET_listing(self, where, vuser, sort, time, show, **env):
        self.where = where
        self.sort = sort
        self.time = time
        self.show = show

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in ('hot', 'new'):
            self.time = 'all'

        # hide spammers profile pages
        if (not c.user_is_loggedin or
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        if where in ('liked', 'disliked') and not votes_visible(vuser):
            return self.abort403()

        if ((where in ('saved', 'hidden') or
             (where == 'gilded' and show == 'given'))
                and not (c.user_is_loggedin and c.user._id == vuser._id)
                and not c.user_is_admin):
            return self.abort403()

        if where == 'saved':
            self.show_chooser = True

        check_cheating('user')

        self.vuser = vuser
        self.render_params = {'user': vuser}
        c.profilepage = True

        if vuser.pref_hide_from_robots:
            self.robots = 'noindex,nofollow'

        return ListingController.GET_listing(self, **env)
Exemplo n.º 11
0
    def GET_listing(self, where, vuser, **env):
        self.where = where

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        # hide spammers profile pages
        if (not c.user_is_loggedin or (c.user._id != vuser._id and not c.user_is_admin)) and vuser._spam:
            return self.abort404()

        if where not in ("overview", "submitted", "comments") and not votes_visible(vuser):
            return self.abort404()

        check_cheating("user")

        self.vuser = vuser
        self.render_params = {"user": vuser}
        c.profilepage = True

        return ListingController.GET_listing(self, **env)
Exemplo n.º 12
0
    def GET_listing(self, where, vuser, sort, time, show, **env):
        self.where = where
        self.sort = sort
        self.time = time
        self.show = show

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        if self.sort in ("hot", "new"):
            self.time = "all"

        # hide spammers profile pages
        if (not c.user_is_loggedin or (c.user._id != vuser._id and not c.user_is_admin)) and vuser._spam:
            return self.abort404()

        if where in ("liked", "disliked") and not votes_visible(vuser):
            return self.abort403()

        if (
            (where in ("saved", "hidden") or (where == "gilded" and show == "given"))
            and not (c.user_is_loggedin and c.user._id == vuser._id)
            and not c.user_is_admin
        ):
            return self.abort403()

        if where == "saved":
            self.show_chooser = True

        check_cheating("user")

        self.vuser = vuser
        self.render_params = {"user": vuser}
        c.profilepage = True

        if vuser.pref_hide_from_robots:
            self.robots = "noindex,nofollow"

        return ListingController.GET_listing(self, **env)
Exemplo n.º 13
0
    def GET_comments(self, article, comment, context, sort, num_comments):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        if not c.default_sr and c.site._id != article.sr_id:
            return self.redirect(article.make_permalink_slow(), 301)

        # moderator is either reddit's moderator or an admin
        is_moderator = c.user_is_loggedin and c.site.is_moderator(c.user) or c.user_is_admin
        if article._spam and not is_moderator:
            return self.abort404()

        if not article.subreddit_slow.can_view(c.user):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # if there is a focal comment, communicate down to comment_skeleton.html who
        # that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        # figure out number to show based on the menu
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == 'true' else user_num

        # Override sort if the link has a default set
        if hasattr(article, 'comment_sort_order'):
            sort = article.comment_sort_order

        builder = CommentBuilder(article, CommentSortMenu.operator(sort),
                                 comment, context)
        listing = NestedListing(builder, num = num,
                                parent_name = article._fullname)

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            permamessage = PermalinkMessage(
                comment.make_anchored_permalink(
                    context = context + 1 if context else 1,
                    anchor  = 'comments'
                ),
                has_more_comments = hasattr(comment, 'parent_id')
            )
            displayPane.append(permamessage)

        # insert reply box only for logged in user
        if c.user_is_loggedin and article.subreddit_slow.can_comment(c.user):
            displayPane.append(CommentReplyBox())
            #no comment box for permalinks
            if not comment:
                displayPane.append(CommentReplyBox(link_name =
                                                   article._fullname))
        # finally add the comment listing
        displayPane.append(listing.listing())

        loc = None if c.focal_comment or context is not None else 'comments'

        if article.comments_enabled:
            sort_menu = CommentSortMenu(default = sort, type='dropdown2')
            if hasattr(article, 'comment_sort_order'):
                sort_menu.enabled = False
            nav_menus = [sort_menu,
                         NumCommentsMenu(article.num_comments,
                                         default=num_comments)]

            content = CommentListing(
                content = displayPane,
                num_comments = article.num_comments,
                nav_menus = nav_menus,
            )
        else:
            content = PaneStack()

        is_canonical = article.canonical_url.endswith(_force_unicode(request.path)) and not request.GET

        res = LinkInfoPage(link = article, comment = comment,
                           content = content,
                           infotext = infotext,
                           is_canonical = is_canonical).render()

        if c.user_is_loggedin:
            article._click(c.user)

        return res
Exemplo n.º 14
0
 def GET_listing(self, **env):
     check_cheating('site')
     return self.build_listing(**env)
Exemplo n.º 15
0
Arquivo: front.py Projeto: NkL4/reddit
    def GET_comments(self, article, comment, context, sort, limit, depth):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        sr = Subreddit._byID(article.sr_id, True)

        if sr.name == g.takedown_sr:
            request.environ['REDDIT_TAKEDOWN'] = article._fullname
            return self.abort404()

        if not c.default_sr and c.site._id != sr._id:
            return self.abort404()

        if not can_view_link_comments(article):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # If there is a focal comment, communicate down to
        # comment_skeleton.html who that will be. Also, skip
        # comment_visits check
        previous_visits = None
        if comment:
            c.focal_comment = comment._id36
        elif (c.user_is_loggedin and c.user.gold and
              c.user.pref_highlight_new_comments):
            #TODO: remove this profiling if load seems okay
            from datetime import datetime
            before = datetime.now(g.tz)
            previous_visits = self._comment_visits(article, c.user, c.start_time)
            after = datetime.now(g.tz)
            delta = (after - before)
            msec = (delta.seconds * 1000 + delta.microseconds / 1000)
            if msec >= 100:
                g.log.warning("previous_visits code took %d msec" % msec)

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        if not c.user.pref_num_comments:
            num = g.num_comments
        elif c.user.gold:
            num = min(c.user.pref_num_comments, g.max_comments_gold)
        else:
            num = min(c.user.pref_num_comments, g.max_comments)

        kw = {}
        # allow depth to be reset (I suspect I'll turn the VInt into a
        # validator on my next pass of .compact)
        if depth is not None and 0 < depth < MAX_RECURSION:
            kw['max_depth'] = depth
        elif c.render_style == "compact":
            kw['max_depth'] = 5

        displayPane = PaneStack()

        # allow the user's total count preferences to be overwritten
        # (think of .embed as the use case together with depth=1)

        if limit and limit > 0:
            num = limit

        if c.user_is_loggedin and c.user.gold:
            if num > g.max_comments_gold:
                displayPane.append(InfoBar(message =
                                           strings.over_comment_limit_gold
                                           % max(0, g.max_comments_gold)))
                num = g.max_comments_gold
        elif num > g.max_comments:
            if limit:
                displayPane.append(InfoBar(message =
                                       strings.over_comment_limit
                                       % dict(max=max(0, g.max_comments),
                                              goldmax=max(0,
                                                   g.max_comments_gold))))
            num = g.max_comments

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        displayPane.append(LinkCommentSep())

        # insert reply box only for logged in user
        if c.user_is_loggedin and can_comment_link(article) and not is_api():
            #no comment box for permalinks
            display = False
            if not comment:
                age = c.start_time - article._date
                if age.days < g.REPLY_AGE_LIMIT:
                    display = True
            displayPane.append(UserText(item = article, creating = True,
                                        post_form = 'comment',
                                        display = display,
                                        cloneable = True))

        if previous_visits:
            displayPane.append(CommentVisitsBox(previous_visits))
            # Used in later "more comments" renderings
            pv_hex = md5(repr(previous_visits)).hexdigest()
            g.cache.set(pv_hex, previous_visits, time=g.comment_visits_period)
            c.previous_visits_hex = pv_hex

        # Used in template_helpers
        c.previous_visits = previous_visits

        # finally add the comment listing
        displayPane.append(CommentPane(article, CommentSortMenu.operator(sort),
                                       comment, context, num, **kw))

        subtitle_buttons = []

        if c.focal_comment or context is not None:
            subtitle = None
        elif article.num_comments == 0:
            subtitle = _("no comments (yet)")
        elif article.num_comments <= num:
            subtitle = _("all %d comments") % article.num_comments
        else:
            subtitle = _("top %d comments") % num

            if g.max_comments > num:
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments, gold=False)

            if (c.user_is_loggedin and c.user.gold
                and article.num_comments > g.max_comments):
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments_gold, gold=True)

        res = LinkInfoPage(link = article, comment = comment,
                           content = displayPane,
                           subtitle = subtitle,
                           subtitle_buttons = subtitle_buttons,
                           nav_menus = [CommentSortMenu(default = sort)],
                           infotext = infotext).render()
        return res
Exemplo n.º 16
0
    def GET_comments(self, article, comment, context, sort, limit, depth):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        sr = Subreddit._byID(article.sr_id, True)

        if sr.name == g.takedown_sr:
            request.environ['REDDIT_TAKEDOWN'] = article._fullname
            return self.abort404()

        if not c.default_sr and c.site._id != sr._id:
            return self.abort404()

        if not can_view_link_comments(article):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # If there is a focal comment, communicate down to
        # comment_skeleton.html who that will be. Also, skip
        # comment_visits check
        previous_visits = None
        if comment:
            c.focal_comment = comment._id36
        elif (c.user_is_loggedin and c.user.gold and
              c.user.pref_highlight_new_comments):
            #TODO: remove this profiling if load seems okay
            from datetime import datetime
            before = datetime.now(g.tz)
            previous_visits = self._comment_visits(article, c.user, c.start_time)
            after = datetime.now(g.tz)
            delta = (after - before)
            msec = (delta.seconds * 1000 + delta.microseconds / 1000)
            if msec >= 100:
                g.log.warning("previous_visits code took %d msec" % msec)

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        if not c.user.pref_num_comments:
            num = g.num_comments
        elif c.user.gold:
            num = min(c.user.pref_num_comments, g.max_comments_gold)
        else:
            num = min(c.user.pref_num_comments, g.max_comments)

        kw = {}
        # allow depth to be reset (I suspect I'll turn the VInt into a
        # validator on my next pass of .compact)
        if depth is not None and 0 < depth < MAX_RECURSION:
            kw['max_depth'] = depth
        elif c.render_style == "compact":
            kw['max_depth'] = 5

        displayPane = PaneStack()

        # allow the user's total count preferences to be overwritten
        # (think of .embed as the use case together with depth=1)

        if limit and limit > 0:
            num = limit

        if c.user_is_loggedin and c.user.gold:
            if num > g.max_comments_gold:
                displayPane.append(InfoBar(message =
                                           strings.over_comment_limit_gold
                                           % max(0, g.max_comments_gold)))
                num = g.max_comments_gold
        elif num > g.max_comments:
            if limit:
                displayPane.append(InfoBar(message =
                                       strings.over_comment_limit
                                       % dict(max=max(0, g.max_comments),
                                              goldmax=max(0,
                                                   g.max_comments_gold))))
            num = g.max_comments

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        displayPane.append(LinkCommentSep())

        # insert reply box only for logged in user
        if c.user_is_loggedin and can_comment_link(article) and not is_api():
            #no comment box for permalinks
            display = False
            if not comment:
                age = c.start_time - article._date
                if age.days < g.REPLY_AGE_LIMIT:
                    display = True
            displayPane.append(UserText(item = article, creating = True,
                                        post_form = 'comment',
                                        display = display,
                                        cloneable = True))

        if previous_visits:
            displayPane.append(CommentVisitsBox(previous_visits))
            # Used in later "more comments" renderings
            pv_hex = md5(repr(previous_visits)).hexdigest()
            g.cache.set(pv_hex, previous_visits, time=g.comment_visits_period)
            c.previous_visits_hex = pv_hex

        # Used in template_helpers
        c.previous_visits = previous_visits

        # finally add the comment listing
        displayPane.append(CommentPane(article, CommentSortMenu.operator(sort),
                                       comment, context, num, **kw))

        subtitle_buttons = []

        if c.focal_comment or context is not None:
            subtitle = None
        elif article.num_comments == 0:
            subtitle = _("no comments (yet)")
        elif article.num_comments <= num:
            subtitle = _("all %d comments") % article.num_comments
        else:
            subtitle = _("top %d comments") % num

            if g.max_comments > num:
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments, gold=False)

            if (c.user_is_loggedin and c.user.gold
                and article.num_comments > g.max_comments):
                self._add_show_comments_link(subtitle_buttons, article, num,
                                             g.max_comments_gold, gold=True)

        res = LinkInfoPage(link = article, comment = comment,
                           content = displayPane,
                           subtitle = subtitle,
                           subtitle_buttons = subtitle_buttons,
                           nav_menus = [CommentSortMenu(default = sort)],
                           infotext = infotext).render()
        return res
Exemplo n.º 17
0
    def GET_comments(self, article, comment, context, sort, num_comments):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        if not c.default_sr and c.site._id != article.sr_id:
            return self.abort404()

        if not article.subreddit_slow.can_view(c.user):
            abort(403, "forbidden")

        # check for 304
        self.check_modified(article, "comments")

        # if there is a focal comment, communicate down to
        # comment_skeleton.html who that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get("already_submitted"):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating("comments")

        # figure out number to show based on the menu (when num_comments
        # is 'true', the user wants to temporarily override their
        # comments limit pref
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == "true" else user_num

        builder = CommentBuilder(article, CommentSortMenu.operator(sort), comment, context)
        listing = NestedListing(builder, num=num, parent_name=article._fullname)

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        # insert reply box only for logged in user
        if c.user_is_loggedin and article.subreddit_slow.can_comment(c.user) and not is_api():
            # no comment box for permalinks
            displayPane.append(
                UserText(item=article, creating=True, post_form="comment", display=not bool(comment), cloneable=True)
            )

        # finally add the comment listing
        displayPane.append(listing.listing())

        loc = None if c.focal_comment or context is not None else "comments"

        res = LinkInfoPage(
            link=article,
            comment=comment,
            content=displayPane,
            subtitle=_("comments"),
            nav_menus=[CommentSortMenu(default=sort), NumCommentsMenu(article.num_comments, default=num_comments)],
            infotext=infotext,
        ).render()
        return res
Exemplo n.º 18
0
    def GET_listing(self, where, user=None, **kw):
        allow_on_fake_sr = ["blocked", "friends"]
        if isinstance(c.site, FakeSubreddit) and not where in allow_on_fake_sr:
            return self.abort404()

        self.where = where

        has_mod_access = ((c.user_is_loggedin and
                           c.site.is_moderator_with_perms(c.user, 'access'))
                          or c.user_is_admin)

        if not c.user_is_loggedin and where not in ['contributors', 'moderators']:
            abort(403)

        self.listing_cls = None
        self.editable = True
        self.paginated = True
        self.jump_to_val = request.GET.get('user')
        self.show_not_found = bool(self.jump_to_val)

        if where == 'contributors':
            # On public reddits, only moderators may see the whitelist.
            if c.site.type == 'public' and not has_mod_access:
                abort(403)
            # Used for subreddits like /r/lounge
            if c.site.hide_subscribers:
                abort(403)
            self.listing_cls = ContributorListing
            self.editable = has_mod_access

        elif where == 'banned':
            if not has_mod_access:
                abort(403)
            self.listing_cls = BannedListing

        elif where == 'wikibanned':
            if not c.site.is_moderator_with_perms(c.user, 'wiki'):
                abort(403)
            self.listing_cls = WikiBannedListing

        elif where == 'wikicontributors':
            if not c.site.is_moderator_with_perms(c.user, 'wiki'):
                abort(403)
            self.listing_cls = WikiMayContributeListing

        elif where == 'moderators':
            self.editable = ((c.user_is_loggedin and
                              c.site.is_unlimited_moderator(c.user)) or
                             c.user_is_admin)
            self.listing_cls = ModListing
            self.paginated = False

        elif where == 'friends':
            self.listing_cls = FriendListing
            self.paginated = False

        elif where == 'blocked':
            self.listing_cls = EnemyListing
            self.paginated = False
            self.show_not_found = True

        if not self.listing_cls:
            abort(404)

        self.user = user
        self.show_jump_to = self.paginated

        if not self.paginated:
            kw['num'] = 0

        check_cheating('site')
        return self.build_listing(**kw)
Exemplo n.º 19
0
    def GET_comments(self, article, comment, context, sort, num_comments,
                     limit, depth):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        sr = Subreddit._byID(article.sr_id, True)

        if sr.name == g.takedown_sr:
            request.environ['REDDIT_TAKEDOWN'] = article._fullname
            return self.abort404()

        if not c.default_sr and c.site._id != sr._id:
            return self.abort404()

        if not can_view_link_comments(article):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # if there is a focal comment, communicate down to
        # comment_skeleton.html who that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        # figure out number to show based on the menu (when num_comments
        # is 'true', the user wants to temporarily override their
        # comments limit pref
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == 'true' else user_num

        kw = {}
        # allow depth to be reset (I suspect I'll turn the VInt into a
        # validator on my next pass of .compact)
        if depth is not None and 0 < depth < MAX_RECURSION:
            kw['max_depth'] = depth
        # allow the user's total count preferences to be overwritten
        # (think of .embed as the use case together with depth=1)x
        if limit is not None and 0 < limit < g.max_comments:
            num = limit

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        # insert reply box only for logged in user
        if c.user_is_loggedin and can_comment_link(article) and not is_api():
            #no comment box for permalinks
            display = not bool(comment)
            displayPane.append(
                UserText(item=article,
                         creating=True,
                         post_form='comment',
                         display=display,
                         cloneable=True))

        # finally add the comment listing
        displayPane.append(
            CommentPane(article, CommentSortMenu.operator(sort), comment,
                        context, num, **kw))

        loc = None if c.focal_comment or context is not None else 'comments'

        res = LinkInfoPage(link=article,
                           comment=comment,
                           content=displayPane,
                           subtitle=_("comments"),
                           nav_menus=[
                               CommentSortMenu(default=sort),
                               NumCommentsMenu(article.num_comments,
                                               default=num_comments)
                           ],
                           infotext=infotext).render()
        return res
Exemplo n.º 20
0
    def GET_comments(self, article, comment, context, sort, num_comments):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        if not c.default_sr and c.site._id != article.sr_id:
            return self.abort404()

        if not article.subreddit_slow.can_view(c.user):
            abort(403, "forbidden")

        # check for 304
        self.check_modified(article, "comments")

        # if there is a focal comment, communicate down to comment_skeleton.html who
        # that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get("already_submitted"):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating("comments")

        # figure out number to show based on the menu
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == "true" else user_num

        builder = CommentBuilder(article, CommentSortMenu.operator(sort), comment, context)
        listing = NestedListing(builder, num=num, parent_name=article._fullname)

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            permamessage = PermalinkMessage(
                comment.make_anchored_permalink(context=context + 1 if context else 1, anchor="comments"),
                has_more_comments=hasattr(comment, "parent_id"),
            )
            displayPane.append(permamessage)

        # insert reply box only for logged in user
        if c.user_is_loggedin and article.subreddit_slow.can_comment(c.user):
            displayPane.append(CommentReplyBox())
            # no comment box for permalinks
            if not comment:
                displayPane.append(CommentReplyBox(link_name=article._fullname))
        # finally add the comment listing
        displayPane.append(listing.listing())

        loc = None if c.focal_comment or context is not None else "comments"

        if article.comments_enabled:
            content = CommentListing(
                content=displayPane,
                num_comments=article.num_comments,
                nav_menus=[CommentSortMenu(default=sort), NumCommentsMenu(article.num_comments, default=num_comments)],
            )
        else:
            content = PaneStack()

        res = LinkInfoPage(link=article, comment=comment, content=content, infotext=infotext).render()
        return res
Exemplo n.º 21
0
    def GET_comments(self, article, comment, context, sort, num_comments):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        if not c.default_sr and c.site._id != article.sr_id:
            return self.redirect(article.make_permalink_slow(), 301)

        # moderator is either reddit's moderator or an admin
        is_moderator = c.user_is_loggedin and c.site.is_moderator(
            c.user) or c.user_is_admin
        if article._spam and not is_moderator:
            return self.abort404()

        if not article.subreddit_slow.can_view(c.user):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # if there is a focal comment, communicate down to comment_skeleton.html who
        # that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        # figure out number to show based on the menu
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == 'true' else user_num

        # Override sort if the link has a default set
        if hasattr(article, 'comment_sort_order'):
            sort = article.comment_sort_order

        builder = CommentBuilder(article, CommentSortMenu.operator(sort),
                                 comment, context)
        listing = NestedListing(builder,
                                num=num,
                                parent_name=article._fullname)

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            permamessage = PermalinkMessage(comment.make_anchored_permalink(
                context=context + 1 if context else 1, anchor='comments'),
                                            has_more_comments=hasattr(
                                                comment, 'parent_id'))
            displayPane.append(permamessage)

        # insert reply box only for logged in user
        if c.user_is_loggedin and article.subreddit_slow.can_comment(c.user):
            displayPane.append(CommentReplyBox())
            #no comment box for permalinks
            if not comment:
                displayPane.append(
                    CommentReplyBox(link_name=article._fullname))
        # finally add the comment listing
        displayPane.append(listing.listing())

        loc = None if c.focal_comment or context is not None else 'comments'

        if article.comments_enabled:
            sort_menu = CommentSortMenu(default=sort, type='dropdown2')
            if hasattr(article, 'comment_sort_order'):
                sort_menu.enabled = False
            nav_menus = [
                sort_menu,
                NumCommentsMenu(article.num_comments, default=num_comments)
            ]

            content = CommentListing(
                content=displayPane,
                num_comments=article.num_comments,
                nav_menus=nav_menus,
            )
        else:
            content = PaneStack()

        is_canonical = article.canonical_url.endswith(
            _force_unicode(request.path)) and not request.GET

        res = LinkInfoPage(link=article,
                           comment=comment,
                           content=content,
                           infotext=infotext,
                           is_canonical=is_canonical).render()

        if c.user_is_loggedin:
            article._click(c.user)

        return res
Exemplo n.º 22
0
 def GET_listing(self, **env):
     check_cheating('site')
     return self.build_listing(**env)
Exemplo n.º 23
0
    def GET_listing(self, where, user=None, **kw):
        allow_on_fake_sr = ["blocked", "friends"]
        if isinstance(c.site, FakeSubreddit) and not where in allow_on_fake_sr:
            return self.abort404()

        self.where = where

        has_mod_access = ((c.user_is_loggedin and
                           c.site.is_moderator_with_perms(c.user, 'access'))
                          or c.user_is_admin)

        if not c.user_is_loggedin and where not in [
                'contributors', 'moderators'
        ]:
            abort(403)

        self.listing_cls = None
        self.editable = True
        self.paginated = True
        self.jump_to_val = request.GET.get('user')
        self.show_not_found = bool(self.jump_to_val)

        if where == 'contributors':
            # On public reddits, only moderators may see the whitelist.
            if c.site.type == 'public' and not has_mod_access:
                abort(403)
            # Used for subreddits like /r/lounge
            if c.site.hide_subscribers:
                abort(403)
            self.listing_cls = ContributorListing
            self.editable = has_mod_access

        elif where == 'banned':
            if not has_mod_access:
                abort(403)
            self.listing_cls = BannedListing

        elif where == 'wikibanned':
            if not c.site.is_moderator_with_perms(c.user, 'wiki'):
                abort(403)
            self.listing_cls = WikiBannedListing

        elif where == 'wikicontributors':
            if not c.site.is_moderator_with_perms(c.user, 'wiki'):
                abort(403)
            self.listing_cls = WikiMayContributeListing

        elif where == 'moderators':
            self.editable = ((c.user_is_loggedin
                              and c.site.is_unlimited_moderator(c.user))
                             or c.user_is_admin)
            self.listing_cls = ModListing
            self.paginated = False

        elif where == 'friends':
            self.listing_cls = FriendListing
            self.paginated = False

        elif where == 'blocked':
            self.listing_cls = EnemyListing
            self.paginated = False
            self.show_not_found = True

        if not self.listing_cls:
            abort(404)

        self.user = user
        self.show_jump_to = self.paginated

        if not self.paginated:
            kw['num'] = 0

        check_cheating('site')
        return self.build_listing(**kw)
Exemplo n.º 24
0
    def GET_comments(self, article, comment, context, sort, num_comments,
                     limit, depth):
        """Comment page for a given 'article'."""
        if comment and comment.link_id != article._id:
            return self.abort404()

        sr = Subreddit._byID(article.sr_id, True)

        if sr.name == g.takedown_sr:
            request.environ['REDDIT_TAKEDOWN'] = article._fullname
            return self.abort404()

        if not c.default_sr and c.site._id != sr._id:
            return self.abort404()

        if not can_view_link_comments(article):
            abort(403, 'forbidden')

        #check for 304
        self.check_modified(article, 'comments')

        # if there is a focal comment, communicate down to
        # comment_skeleton.html who that will be
        if comment:
            c.focal_comment = comment._id36

        # check if we just came from the submit page
        infotext = None
        if request.get.get('already_submitted'):
            infotext = strings.already_submitted % article.resubmit_link()

        check_cheating('comments')

        # figure out number to show based on the menu (when num_comments
        # is 'true', the user wants to temporarily override their
        # comments limit pref
        user_num = c.user.pref_num_comments or g.num_comments
        num = g.max_comments if num_comments == 'true' else user_num

        kw = {}
        # allow depth to be reset (I suspect I'll turn the VInt into a
        # validator on my next pass of .compact)
        if depth is not None and 0 < depth < MAX_RECURSION:
            kw['max_depth'] = depth
        elif c.render_style == "compact":
            kw['max_depth'] = 5
        # allow the user's total count preferences to be overwritten
        # (think of .embed as the use case together with depth=1)x
        if limit is not None and 0 < limit < g.max_comments:
            num = limit

        displayPane = PaneStack()

        # if permalink page, add that message first to the content
        if comment:
            displayPane.append(PermalinkMessage(article.make_permalink_slow()))

        # insert reply box only for logged in user
        if c.user_is_loggedin and can_comment_link(article) and not is_api():
            #no comment box for permalinks
            display = False
            if not comment:
                age = c.start_time - article._date
                if age.days < g.REPLY_AGE_LIMIT:
                    display = True
            displayPane.append(UserText(item = article, creating = True,
                                        post_form = 'comment',
                                        display = display,
                                        cloneable = True))

        # finally add the comment listing
        displayPane.append(CommentPane(article, CommentSortMenu.operator(sort),
                                       comment, context, num, **kw))

        loc = None if c.focal_comment or context is not None else 'comments'

        res = LinkInfoPage(link = article, comment = comment,
                           content = displayPane, 
                           subtitle = _("comments"),
                           nav_menus = [CommentSortMenu(default = sort), 
                                        NumCommentsMenu(article.num_comments,
                                                        default=num_comments)],
                           infotext = infotext).render()
        return res
Exemplo n.º 25
0
Arquivo: front.py Projeto: cmak/reddit
    def GET_user(self, num, vuser, sort, time, after, reverse, count, location, **env):
        """user profile pages"""

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        # hide spammers profile pages
        if (not c.user_is_loggedin or 
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        check_cheating('user')
        
        content_pane = PaneStack()

        # enable comments displaying with their titles when rendering
        c.profilepage = True
        listing = None

        db_sort = SortMenu.operator(sort)
        db_time = TimeMenu.operator(time)

        # function for extracting the proper thing if query is a relation (see liked)
        prewrap_fn = None

        # default (nonexistent) query to trip an error on if location is unhandles
        query      = None
        
        # build the sort menus for the space above the content
        sortbar = [SortMenu(default = sort), TimeMenu(default = time)]

        # overview page is a merge of comments and links
        if location == 'overview':
            links = Link._query(Link.c.author_id == vuser._id,
                                Link.c._spam == (True, False))
            comments = Comment._query(Comment.c.author_id == vuser._id,
                                      Comment.c._spam == (True, False))
            query = thing.Merge((links, comments), sort = db_sort, data = True)

        elif location == 'comments':
            query = Comment._query(Comment.c.author_id == vuser._id,
                                   Comment.c._spam == (True, False),
                                   sort = db_sort)

        elif location == 'submitted':
            query = Link._query(Link.c.author_id == vuser._id,
                                Link.c._spam == (True, False),
                                sort = db_sort)

        # (dis)liked page: pull votes and extract thing2
        elif ((location == 'liked' or location == 'disliked') and
              votes_visible(vuser)):
            rel = Vote.rel(vuser, Link)
            query = rel._query(rel.c._thing1_id == vuser._id,
                               rel.c._t2_deleted == False)
            query._eager(True, True)
            
            if location == 'liked':
                query._filter(rel.c._name == '1')
            else:
                query._filter(rel.c._name == '-1')
            sortbar = []
            query._sort = desc('_date')
            prewrap_fn = lambda x: x._thing2

        # TODO: this should be handled with '' above once merges work
        elif location == 'hidden' and votes_visible(vuser):
            db_time = None
            query = SaveHide._query(SaveHide.c._thing1_id == vuser._id,
                                    SaveHide.c._name == 'hide',
                                    eager_load = True,
                                    thing_data = True)
            sortbar = []
            query._sort = desc('_date')
            prewrap_fn = lambda x: x._thing2

        # any admin pages live here.
        elif c.user_is_admin:
            db_time = None
            query, prewrap_fn = admin_profile_query(vuser, location, db_sort)

        if query is None:
            return self.abort404()

        if db_time:
            query._filter(db_time)


        builder = QueryBuilder(query, num = num, prewrap_fn = prewrap_fn,
                               after = after, count = count, reverse = reverse,
                               wrap = ListingController.builder_wrapper)
        listing = LinkListing(builder)

        if listing:
            content_pane.append(listing.listing())

        titles = {'':          _("overview for %(user)s on %(site)s"),
                  'comments':  _("comments by %(user)s on %(site)s"),
                  'submitted': _("submitted by %(user)s on %(site)s"),
                  'liked':     _("liked by %(user)s on %(site)s"),
                  'disliked':  _("disliked by %(user)s on %(site)s"),
                  'hidden':    _("hidden by %(user)s on %(site)s")}
        title = titles.get(location, _('profile for %(user)s')) \
               % dict(user = vuser.name, site = c.site.name)

        return ProfilePage(vuser, title = title,
                           nav_menus = sortbar, 
                           content = content_pane).render()