Commit Graph

44 Commits

Author SHA1 Message Date
evazion
1653392361 posts: stop updating fav_string attribute.
Stop updating the fav_string attribute on posts. The column still exists
on the table, but is no longer used or updated.

Like the pool_string in 7d503f08, the fav_string was used in the past to
facilitate `fav:X` searches. Posts had a hidden fav_string column that
contained a list of every user who favorited the post. These were
treated like fake hidden tags on the post so that a search for `fav:X`
was treated like a tag search.

The fav_string attribute has been unused for search purposes for a while
now. It was only kept because of technicalities that required
departitioning the favorites table first (340e1008e) before it could be
removed. Basically, removing favorites with `@favorite.destroy` was
slow because Rails always deletes object by ID, but we didn't have an
index on favorites.id, and we couldn't easily add one until the
favorites table was departitioned.

Fixes #4652. See https://github.com/danbooru/danbooru/issues/4652#issuecomment-754993802
for more discussion of issues caused by the fav_string (in short: write
amplification, post table bloat, and favorite inconsistency problems).
2021-10-09 22:36:26 -05:00
evazion
413cd34c45 rate limits: adjust limits for various actions.
* Tie rate limits to both the user's ID and their IP address.

* Make each endpoint have separate rate limits. This means that, for
  example, your post edit rate limit is separate from your post vote
  rate limit. Before all write actions had a shared rate limit.

* Make all write endpoints have rate limits. Before some endpoints, such
  as voting, favoriting, commenting, or forum posting, weren't subject
  to rate limits.

* Add stricter rate limits for some endpoints:

** 1 per 5 minutes for creating new accounts.
** 1 per minute for login attempts, changing your email address, or
   for creating mod reports.
** 1 per minute for sending dmails, creating comments, creating forum
   posts, or creating forum topics.
** 1 per second for voting, favoriting, or disapproving posts.
** These rate limits all have burst factors high enough that they
   shouldn't affect normal, non-automated users.

* Raise the default write rate limit for Gold users from 2 per second to
  4 per second, for all other actions not listed above.

* Raise the default burst factor to 200 for all other actions not listed
  above. Before it was 10 for Members, 30 for Gold, and 60 for Platinum.
2021-03-05 16:02:57 -06:00
evazion
6ca007ee1f Fix #4670: Replace RequestStore with AS::CurrentAttributes.
This also requires replacing CurrentUser.name with CurrentUser.user.name
because the `name` method had a conflict with CurrentAttributes.
2021-01-16 12:43:20 -06:00
evazion
94e125709c users: add Restricted user level.
Add a Restricted user level. Restricted users are level 10, below
Members. New users start out as Restricted if they sign up from a proxy
or an IP recently used by another user.

Restricted users can't update or edit any public content on the site
until they verify their email address, at which point they're promoted
to Member. Restricted users are only allowed to do personal actions
like keep favorites, keep favgroups and saved searches, mark dmails as
read or deleted, or mark forum posts as read.

The restricted state already existed before, the only change here is
that now it's an actual user level instead of a hidden state. Before it
was based on two hidden flags on the user, the `requires_verification`
flag (set when a user signs up from a proxy, etc), and the `is_verified`
flag (set after the user verifies their email). Making it a user level
means that now the Restricted status will be shown publicly.

Introducing a new level below Member means that we have to change every
`is_member?` check to `!is_anonymous` for every place where we used
`is_member?` to check that the current user is logged in.
2021-01-07 17:10:29 -06:00
evazion
f1f489c40b pundit: convert favorites to pundit. 2020-03-20 18:03:01 -05:00
evazion
7c71311eef Add /favorites.json endpoint. 2020-02-24 22:42:59 -06:00
evazion
99a1a408cd /artists/banned, /favorites: fix redirects for non-html requests.
ref: https://danbooru.donmai.us/forum_topics/9127?page=287#forum_post_161549
2019-12-11 02:27:41 -06:00
evazion
b77eebf136 /favorites: replace favorites view with ordfav: search.
Make /favorites redirect to a ordfav:<user> search instead of having a
separate view just for favorites. This duplicated a lot of code for no
good reason.
2019-08-31 19:58:38 -05:00
evazion
00239c4901 favorites: fix error handling.
* Return HTTP 422 instead of HTTP 500 on "You have already favorited
  this post" errors.

* Log unexpected errors in Ajax requests to the console.
2019-08-13 21:30:20 -05:00
evazion
eef8b9c323 posts/show: fix flash message when faving/unfaving posts.
Bug: if you faved a post, then opened another page in a separate tab,
then the "You have favorited this post" flash message would appear in
the separate tab.

Fixes regression in bcaee199.
2018-08-15 20:14:51 -05:00
evazion
bcaee199f5 favorites: unify create.js.erb & destory.js.erb code paths. 2018-08-12 15:51:18 -05:00
evazion
fb91bbc6c5 Fix #3813: Favorite limit can be bypassed. 2018-08-12 14:22:08 -05:00
r888888888
abce4d2551 Raise error on unpermitted params.
Fail loudly if we forget to whitelist a param instead of silently
ignoring it.

misc models: convert to strong params.

artist commentaries: convert to strong params.

* Disallow changing or setting post_id to a nonexistent post.

artists: convert to strong params.

* Disallow setting `is_banned` in create/update actions. Changing it
  this way instead of with the ban/unban actions would leave the artist in
  a partially banned state.

bans: convert to strong params.

* Disallow changing the user_id after the ban has been created.

comments: convert to strong params.

favorite groups: convert to strong params.

news updates: convert to strong params.

post appeals: convert to strong params.

post flags: convert to strong params.

* Disallow users from setting the `is_deleted` / `is_resolved` flags.

ip bans: convert to strong params.

user feedbacks: convert to strong params.

* Disallow users from setting `disable_dmail_notification` when creating feedbacks.
* Disallow changing the user_id after the feedback has been created.

notes: convert to strong params.

wiki pages: convert to strong params.

* Also fix non-Builders being able to delete wiki pages.

saved searches: convert to strong params.

pools: convert to strong params.

* Disallow setting `post_count` or `is_deleted` in create/update actions.

janitor trials: convert to strong params.

post disapprovals: convert to strong params.

* Factor out quick-mod bar to shared partial.
* Fix quick-mod bar to use `Post#is_approvable?` to determine visibility
  of Approve button.

dmail filters: convert to strong params.

password resets: convert to strong params.

user name change requests: convert to strong params.

posts: convert to strong params.

users: convert to strong params.

* Disallow setting password_hash, last_logged_in_at, last_forum_read_at,
  has_mail, and dmail_filter_attributes[user_id].

* Remove initialize_default_image_size (dead code).

uploads: convert to strong params.

* Remove `initialize_status` because status already defaults to pending
  in the database.

tag aliases/implications: convert to strong params.

tags: convert to strong params.

forum posts: convert to strong params.

* Disallow changing the topic_id after creating the post.
* Disallow setting is_deleted (destroy/undelete actions should be used instead).
* Remove is_sticky / is_locked (nonexistent attributes).

forum topics: convert to strong params.

* merges https://github.com/evazion/danbooru/tree/wip-rails-5.1
* lock pg gem to 0.21 (1.0.0 is incompatible with rails 5.1.4)
* switch to factorybot and change all references

Co-authored-by: r888888888 <r888888888@gmail.com>
Co-authored-by: evazion <noizave@gmail.com>

add diffs
2018-04-06 18:09:57 -07:00
r888888888
31e36cf9eb remove unused mobile layouts 2017-11-17 13:59:14 -08:00
r888888888
d48ed95191 favoritescontroller#destroy should work even if the post doesn't exist, remove from favorites on expunge (fixes #3222) 2017-07-19 13:39:24 -07:00
evazion
f5209c7fb9 /favorites: make available to anonymous users. 2017-07-06 19:22:57 -05:00
Albert Yi
f2a5d45db0 implement token bucket rate limiting 2017-01-09 17:31:14 -08:00
r888888888
caf4a28b02 enable user privacy mode for displaying favorites 2016-02-22 12:18:19 -08:00
r888888888
ed3bbbe177 fixes #1412: When creating or deleting favorites through the API, return some form of response 2015-07-29 17:50:59 -07:00
r888888888
dec92a67c4 fix favoriting 2014-09-05 16:50:34 -07:00
r888888888
0e203c5cda add favorite/unfavorite links to mobile page 2014-09-05 16:46:22 -07:00
Toks
03aee0f664 Fix document title when viewing other users' favorites 2013-07-14 19:44:35 -04:00
Toks
acfbf260aa fixes #1410; fix user argument for favorite post set 2013-05-05 07:36:07 -04:00
Toks
6ab405c142 fixes #1403 2013-05-03 19:54:01 -04:00
Toks
222bc8786b fixes #1430 2013-04-24 11:21:53 -04:00
Toks
c9400e404d fixes #449 2013-04-14 12:56:35 -04:00
albert
fd9ca8d2fc fixes #987 2013-03-22 09:58:31 -07:00
小太
cba839ba76 Kill trailing whitespace in ruby files 2013-03-19 23:10:10 +11:00
albert
caacd3f86f fixes #733 2013-03-03 15:37:20 -05:00
albert
6a1db1197b fixes #670 2013-03-01 07:33:19 -08:00
albert
66fc05e30b change privileged accounts to gold accounts, add platinum accounts, add favorite and tag query limiting based on level 2013-02-20 00:02:43 -05:00
albert
779ff94944 fixes #208 2012-01-06 18:58:01 -05:00
albert
c8afd34d15 added ip addr search 2011-07-29 18:04:50 -04:00
albert
5d05769c2c fix tests 2011-07-22 19:02:53 -04:00
albert
4e19d98047 changes 2011-06-26 01:52:42 -04:00
albert
739e28919a refactoring 2011-06-25 19:31:39 -04:00
albert
9c0a961ab2 major refactoring of javascripts 2011-03-10 17:59:42 -05:00
albert
76a7594a97 implemented favorites on post/show page 2011-02-07 18:57:33 -05:00
albert
46164eab4f finished dmails and favorites functional tests 2010-12-05 22:27:45 -05:00
albert
39dd2e277a * Refactored PostSet, splitting it into PostSets::Post and PostSets::Favorite
* Additional functional tests
2010-12-01 17:21:05 -05:00
albert
f8ab736677 fixed tests 2010-11-19 17:20:13 -05:00
albert
f051e04550 sync 2010-10-08 18:42:26 -04:00
albert
5610731b35 sync 2010-08-18 18:42:33 -04:00
albert
ac98d7db37 stubbed in blank controllers/helpers/functional tests 2010-03-10 18:21:43 -05:00