Commit graph

3790 commits

Author SHA1 Message Date
justcool393
3f2e8629df ratelimiting: check after required request g attributes are set 2022-12-17 09:21:40 -08:00
justcool393
a213396854
Solve blocking weaponization.
* allow anyone to reply to their blockers

* revert userblocks thing

* get rid of unnecessary template

* make blocking page accurate

* comment author things

* fix prev commit

* fix block page

* comma splice

Co-authored-by: Snakes <104547575+TLSM@users.noreply.github.com>
2022-12-17 11:11:51 -06:00
justcool393
0c632d73b7
Rework error system a bit to remove a bunch of duplicated code (#434) 2022-12-01 20:58:27 -06:00
Ben Rog-Wilhelm
08602b4279 Volunteer Janitor: Minor cleanups. 2022-12-01 18:53:24 -08:00
Ben Rog-Wilhelm
5fef5ca908 Volunteer Janitor: Add global enable/disable. 2022-12-01 18:53:24 -08:00
Ben Rog-Wilhelm
0f91324603 Volunteer Janitor: Response recording. 2022-12-01 18:53:24 -08:00
Ben Rog-Wilhelm
0a8bbae290 Volunteer Janitor: Record accepted tasks. 2022-12-01 18:53:24 -08:00
Ben Rog-Wilhelm
03b323c7a1 Volunteer Janitor: Initial duty acquisition. 2022-12-01 18:53:24 -08:00
Ben Rog-Wilhelm
e43db0535d Volunteer Janitor: Initial hooks. 2022-12-01 18:53:24 -08:00
TLSM
afe209d5d8
Eager load comments for post rendering.
GET /post/1/clever-unique-post-title-number-0
|----------|--------|--------|--------|--------|--------|------------|
| Database | SELECT | INSERT | UPDATE | DELETE | Totals | Duplicates |
|----------|--------|--------|--------|--------|--------|------------|
| default  |  942   |   0    |   1    |   0    |  943   |    921     |
|----------|--------|--------|--------|--------|--------|------------|
Total queries: 943 in 0.377s # request time in browser 17249ms

GET /post/1/clever-unique-post-title-number-0
|----------|--------|--------|--------|--------|--------|------------|
| Database | SELECT | INSERT | UPDATE | DELETE | Totals | Duplicates |
|----------|--------|--------|--------|--------|--------|------------|
| default  |   58   |   0    |   1    |   0    |   59   |     35     |
|----------|--------|--------|--------|--------|--------|------------|
Total queries: 59 in 0.0423s # request time in browser 544ms

Also, fixes seed_db not populating top_comment_id on generated
comments. If you want to test locally with seed_db test data, you need
to reseed.
2022-11-28 17:47:54 -05:00
TLSM
5aaef144cf
Deduplicate post/comment sorting & time filtering.
Ported in from upstream with adjustments for TheMotte, most notably
universal default to 'new' and fixes to 'hot'. Lumped into this PR
because eager comment loading uses it.
2022-11-28 14:33:24 -05:00
TLSM
4d22d9bce2
Eager load get_posts for submission_listings.
Ported in logic from upstream to use SQLAlchemy eager loading instead
of repeated queries when building a submission_listing. Adjusted
loaded relationships to include only those used on TheMotte.

Using test data from seed_db, before and after:

GET /
|----------|--------|--------|--------|--------|--------|------------|
| Database | SELECT | INSERT | UPDATE | DELETE | Totals | Duplicates |
|----------|--------|--------|--------|--------|--------|------------|
| default  |   83   |   0    |   0    |   0    |   83   |     72     |
|----------|--------|--------|--------|--------|--------|------------|
Total queries: 83 in 0.031s

GET /
|----------|--------|--------|--------|--------|--------|------------|
| Database | SELECT | INSERT | UPDATE | DELETE | Totals | Duplicates |
|----------|--------|--------|--------|--------|--------|------------|
| default  |   14   |   0    |   0    |   0    |   14   |     0      |
|----------|--------|--------|--------|--------|--------|------------|
Total queries: 14 in 0.00718s
2022-11-28 12:55:31 -05:00
TLSM
9953c5763c
Port get.py improvements from upstream.
Generally standardizes the get_* helpers:
 - Adds type hinting.
 - Deduplicates block property addition.
 - Respects `graceful` in more contexts.
 - More resilient to invalid user input / less boilerplate necessary
   at call-sites.
2022-11-28 12:36:04 -05:00
justcool393
8a9e1bc54a
titles: use rdrama's title finding code (#425)
* titles: use rdrama's title finding code
this fixes a potential DoS in some really weird pages (seems to be a bug with BS4)
we're not parsing arbitrary HTML
in addition we make some nice checks

* unescape title to fix bug from upstream

* fix nameerror

* Do not proxy requests, since no proxy available.

On the upstream, the `proxies` dict was intended to use a local SOCKS
proxy running on port 18080 with the express purpose of masking the
server IP address. TheMotte isn't running behind a reverse proxy, so
this purpose is moot. Additionally, we don't have a proxy running in
Docker nor do we appear to have one on prod, which breaks autotitle
and thumbnailing regardless--not sure it matters for TheMotte's
use case, but both codepaths have been inoperative because of it.

* use gevent to timeout the function to prevent a
second theoretical DoS by sending data rly slowly
ref: 816389cf28

Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-28 07:52:15 -08:00
justcool393
23e64d176d
discord: remove 2022-11-21 12:39:27 -06:00
Ben Rog-Wilhelm
7e25af2fa0 Fix: Changes to the User table cause unavoidable breakages in the Leaderboard system. 2022-11-21 10:09:17 -06:00
justcool393
2067875c6a themes: remove /r/Drama theme ("classic" and "classic_dark") 2022-11-21 06:13:12 -06:00
justcool393
65fada8155 awards: remove grass 2022-11-19 10:21:30 -06:00
Ben Rog-Wilhelm
12881b02e2 Fix: Users with underscores in their name can't log in by underscore. 2022-11-13 18:20:24 -06:00
Ben Rog-Wilhelm
7c72815dcc
Merge branch 'frost' into remove-more-dramaisms 2022-11-09 20:45:31 -06:00
TLSM
8949b57609 Remove unused ADMINISTRATORS content upload posts.
The ADMINISTRATORS list contained hardcoded post IDs (in the 30000s)
intended to be used for uploading graphical assets onto a production
instance of the site. This functionality is not needed here, and the
special logic to bypass awards when commenting on those posts was
largely removed in 9d4195a89f.
2022-11-09 20:37:04 -06:00
TLSM
3f360bb457 Remove special cases for unused awards.
Removes the following awards / fields on User:
 - flairlock
 - progressivestack
 - bird
 - longpost (pizzashill)
 - marseyawarded
 - rehab
 - deflector
 - mute
 - unmutable
 - eye (All-Seeing Eye)
 - alt (Alt-Seeing Eye)

Primarily motivated by starting to remove some un-Mottelike cruft
from core commenting/posting routes. Cleared out other inapplicable
awards while in the process.
2022-11-09 20:37:04 -06:00
TLSM
9de6f20dea Remove vestigial user ID special cases. 2022-11-09 20:37:04 -06:00
TLSM
010c56a35e Implement #380: remove signatures feature. 2022-11-09 20:37:04 -06:00
TLSM
c85cd469a1 Move post/comment ID boilerplate inside getters.
Borrows code from the upstream which has been working in production
reliably for ~months. Also, most of it was literally copy-pasted,
and the casted ID values aren't used later in the route functions.
2022-11-09 20:37:04 -06:00
justcool393
793273f638 remove beano award (doesn't conflict with @TLSM's commit ☺) 2022-11-07 04:36:41 -06:00
justcool393
37841c9b0f admins are friends not food
paypigs is a bit... lol
2022-11-07 03:56:27 -06:00
justcool393
79b9c08f6c delete marseys route (just 500s) 2022-11-07 03:48:47 -06:00
justcool393
2fabe6d010 remove "meme admin" functionality
(JL1, which doesn't actually have any real use on the site, and their "meme" status is hidden to non-admins anyway)
2022-11-07 03:33:56 -06:00
justcool393
51ef10d7c3 remove vestiges of fart mode 2022-11-07 03:30:31 -06:00
TLSM
1018cf3412 Fix #261: only show lineal parents in contexts. 2022-11-06 03:13:10 -06:00
TLSM
9e2ceb28b0 Fix four routes with auth_desired misimplemented.
PR #374 removed `@auth_required` from a number of routes and changed
those which used their `v` parameters to `v=None` and removed the `v`
parameter from those which didn't internally use it. 1841134b47

PR #392 re-added `@auth_desired` to those routes to ensure the
templates rendered with awareness of the current logged-in user
(matters for search, header bar, etc). 9f042c1aeb

However, 500 errors occurred on /random_post, /random_user, /id/<uid>,
and /u/<username>. Those were the four which had their `v` parameter
removed entirely. This has been re-added, which fixes the bug.

The way to understand auth_required vs auth_desired is that they are
nearly identical, with the sole difference than auth_required
checks if v is None and aborts with 401 if so. This means that
auth_desired routes must handle the v=None case. They are the same in
that they always try to give a `v` kwarg to the decorated function,
which was the root cause of those four routes erroring.

Recommended style: the vast majority of routes which return a rendered
template should be auth_desired, because the top-level templates often
draw extensively from `v` state even when the route handler does not.
When a route is either auth_desired or auth_required, it should have a
`v` parameter, which we typically give as the first positional
parameter.
2022-11-06 03:11:59 -06:00
justcool393
7970b17574 caching: fix CSRF
this removes the ability to do a GET to dump the internal cache but i've added a button to the admin panel that makes it so you can do it
2022-11-02 23:51:33 -05:00
Ben Rog-Wilhelm
387f5e4f62 Fix: Bug introduced with comment security fix 2022-11-02 01:38:43 -05:00
justcool393
7ff138f6f1 modlog: fix 500 when clicking on an action and then clicking on an admin, if that admin doesn't have any admin actions of that specific type 2022-10-30 20:19:09 -05:00
justcool393
0d4662588e
fix bug that could put comments in wrong submissions
this could let users bypass exiles or other checks

see also: Aevann1/rDrama@d61eda8
2022-10-30 20:17:35 -05:00
Ben Rog-Wilhelm
4197aded0e
Support non-logged-in admin contacts. (#377) 2022-10-27 22:16:42 -05:00
electricwhisk
9f042c1aeb
Stay logged in on certain routes (#392)
This commit adds the @auth_desired decorator to
routes that previous had the @auth_required decorator,
but had it removed in #374. This should cause
the user to remain logged in on these routes.
2022-10-27 22:16:22 -05:00
FatherInire
b46ada9f72
Fix some deprecations and factor out a helper function (#387) 2022-10-27 22:15:48 -05:00
DinoInNameOnly
d354b0713d Allow search and other pages for logged out users 2022-10-14 06:26:08 -05:00
Michael House
0bfbf17e45 Implemented collapse bar colorization on the server side 2022-09-23 22:11:55 -05:00
christopher morris
37396d42b5 remove email from admins contact form 2022-09-22 01:09:16 -05:00
Galen Huntington
0889d71647 Fix "view more comments" when not sorting by new. 2022-09-22 00:58:52 -05:00
Ben Rog-Wilhelm
41e5f38d19 Add the Support page. 2022-09-19 06:43:42 -05:00
Michael House
c4b5fe2913 Added filter for logged out users 2022-09-13 09:43:27 -05:00
TLSM
716f078e81 Fix 'hot' sort intermediate value out-of-bounds.
Fixes #321. Due to the extremely large quantity of comments on a
typical Motte post, 'hot' sorting logic underflowed an intermediate
value. Roughly:

  |(-1 000 000) * (103 [votes] + 1 + 2723 [comments] / 1)| > 2^31

We resolve this by reducing the coefficient from 1e6 to 1e5, which
reduces precision of intermediate calculations somewhat, and by
dividing #comments by 10 rather than 1, which better matches Motte
user behavior regardless: Users comment much more often than vote.
This buys us two orders of magnitude more headroom before out-of-
bounds. Shouldn't be an issue until the CW thread reaches ~200k
comments.
2022-09-12 12:16:54 -05:00
TLSM
ccabc8b881 Change default RSS sort to 'new'. 2022-09-12 12:16:54 -05:00
TLSM
2d59865363 Fix #316: restrict access to /badges, remove link. 2022-09-11 23:18:14 -05:00
Michael House
38e263d931 Added filter to make sure new comments only show up on page refresh 2022-09-11 06:10:58 -05:00
TLSM
f5f2c008ad Fix approved filtered comments not notifying.
Moves behavior in api_comment that updates stateful counters and
generates notifications into a function which can also be called
if a filtered comment is approved. Fixes #272.

Incidentally, also fixes #278 by adding another filter to the post
subscribers query during general clean-up/refactoring.

Originally was going to move this function into the Comments model,
since assurances about state (even with side effects) should probably
be made there, but I couldn't find a sane way to untangle the imports.
2022-09-09 23:31:20 -05:00