Commit Graph

639 Commits

Author SHA1 Message Date
evazion
4deb8aeea2 uploads: disallow uploading new Flash files.
Flash is dead. It's no longer supported by browsers, it's not
well-supported by emulators, and only two Flash posts were uploaded in
the last year anyway. Old Flash files will continue to exist, but new
Flash uploads will no longer be allowed.
2021-03-31 20:47:35 -05:00
evazion
b3c1c753b3 comments: allow admins to remove comment votes (fix #4640)
Allow admins to remove comment votes by other users. This is done by
clicking the comment score to get to the comment vote list, then
clicking the Remove button on every vote.
2021-03-30 00:10:25 -05:00
evazion
6b91e55283 comments: allow votes to be soft deleted.
Make it so that when a user removes their own vote, the vote is soft
deleted (the is_deleted flag is set) instead of hard deleted.

Changes:

* Add is_deleted flag to comment votes.
* Relax uniqueness constraint so you can have multiple deleted votes on
  the same comment. You can still only have one active vote on the comment.
* Add `soft_delete` method to Deletable concern.
2021-03-30 00:10:22 -05:00
evazion
6a84d33409 Fix #4770: Allow flaggers to update flag reason. 2021-03-23 01:27:16 -05:00
evazion
fd09cc5e96 posts: fix Download link not respecting tagged filenames option.
Fix bug reported in forum #182766:

    The Download button on the posts page does not respect the Disable
    tagged filenames user setting. Tags are included in the filename when
    clicking the Download button even when the Disable tagged filenames
    setting is set to Yes. Right click -> Save As on the image still
    respects the setting.
2021-03-20 02:14:23 -05:00
evazion
81fe68d392 bans: change expires_at field to duration.
Changes:

* Change the `expires_at` field to `duration`.
* Make moderators choose from a fixed set of standard ban lengths,
  instead of allowing arbitrary ban lengths.
* List `duration` in seconds in the /bans.json API.
* Dump bans to BigQuery.

Note that some old bans have a negative duration. This is because their
expiration date was before their creation date, which is because in 2013
bans were migrated to Danbooru 2 and the original ban creation dates
were lost.
2021-03-11 02:59:58 -06:00
evazion
28d101eaa7 bans: fix exception when username is blank.
Fix exception when submitting the ban form and the username is blank.
2021-03-07 21:19:32 -06:00
evazion
fee7ed506b comments: put sticky option in popup menu instead of in edit form.
Put the option to sticky a comment in the "..." popup menu instead of
in the comment edit form. This makes it more consistent with deleting or
undeleting a comment.

Also fix a bug where the comment undelete icon didn't show up due to a
typo.
2021-03-07 20:13:38 -06:00
evazion
58e42ee8d3 rate limits: add /rate_limits endpoint.
Allow users to view their own rate limits with /rate_limits.json.

Note that rate limits are only updated after every API call, so this
page only shows the state of the limits after the last call, not the
current state.
2021-03-05 16:47:20 -06: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
4492610dfe rate limits: rework rate limit implementation.
Rework the rate limit implementation to make it more flexible:

* Allow setting different rate limits for different actions. Before we
  had a single rate limit for all write actions. Now different
  controller endpoints can have different limits.

* Allow actions to be rate limited by user ID, by IP address, or both.
  Before actions were only limited by user ID, which meant non-logged-in
  actions like creating new accounts or attempting to login couldn't be rate
  limited. Also, because actions were limited by user ID only, you could
  use multiple accounts with the same IP to get around limits.

Other changes:

* Remove the API Limit field from user profile pages.
* Remove the `remaining_api_limit` field from the `/profile.json` endpoint.
* Rename the `X-Api-Limit` header to `X-Rate-Limit` and change it from a
  number to a JSON object containing all the rate limit info
  (including the refill rate, the burst factor, the cost of the call,
  and the current limits).
* Fix a potential race condition where, if you flooded requests fast
  enough, you could exceed the rate limit. This was because we checked
  and updated the rate limit in two separate steps, which was racy;
  simultaneous requests could pass the check before the update happened.
  The new code uses some tricky SQL to check and update multiple limits
  in a single statement.
2021-03-05 16:00:54 -06:00
evazion
52adf87489 Fix #4666: Broken network link for some IPs. 2021-03-01 20:44:51 -06:00
evazion
c1805cc4e0 views: factor out paginator component.
* Refactor the paginator into a ViewComponent.
* Fix inconsistent spacing between paginator items.
* Fix a bug where the sequential paginator generated the wrong next /
  previous page links in the <link rel="{next|prev}"> tags in the <head>.
* Always include the final page as a hidden html element, so that it can
  be unhidden with custom CSS.
* Make it easier to change the pagination window.
2021-02-18 02:47:21 -06:00
evazion
3d01febcf7 api keys: require reauthentication when working with API keys.
Require the user to re-enter their password before they can view,
create, update, or delete their API keys.

This works by tracking the timestamp of the user's last password
re-entry in a `last_authenticated_at` session cookie, and redirecting
the user to a password confirmation page if they haven't re-entered
their password in the last hour.

This is modeled after Github's Sudo mode.
2021-02-15 00:17:31 -06:00
evazion
d99985160a api keys: add API key usage tracking.
Track when an API key was last used, which IP address last used it, and
how many times it's been used overall.

This is so you can tell when an API key was last used, so you know if
the key is safe to delete, and so you can tell if an unrecognized IP has
used your key.
2021-02-14 21:02:07 -06:00
evazion
25fda1ecc2 api keys: add IP whitelist and API permission system.
Add the ability to restrict API keys so that they can only be used with
certain IP addresses or certain API endpoints.

Restricting your key is useful to limit damage in case it gets leaked or
stolen. For example, if your key is on a remote server and it gets
hacked, or if you accidentally check-in your key to Github.

Restricting your key's API permissions is useful if a third-party app or
script wants your key, but you don't want to give full access to your
account.

If you're an app or userscript developer, and your app needs an API key
from the user, you should only request a key with the minimum
permissions needed by your app.

If you have a privileged account, and you have scripts running under
your account, you are highly encouraged to restrict your key to limit
damage in case your key gets leaked or stolen.
2021-02-14 21:02:07 -06:00
evazion
a6707fbfa2 api keys: allow users to have multiple API keys.
This is useful if you have multiple programs and want to give them
different API keys, or if you want to rotate keys for a single program.
2021-02-14 04:09:47 -06:00
evazion
37061f95a6 api keys: rework API key UI.
* Add an explanation of what an API key is and how to use it.
* Make it possible for the site owner to view all API keys.
* Remove the requirement to re-enter your password before you can view
  your API key (to be reworked).
* Move the API key controller from maintenance/user/api_keys_controller.rb
  to a top level controller.
2021-02-14 04:09:47 -06:00
evazion
7b4bab54af artists: prevent Google from indexing banned artists.
Prevent search engines from indexing artist pages, wiki pages, and tag
searches for banned artists.
2021-02-07 23:28:50 -06:00
evazion
9d60046f1d tests: fixup typo in 520b72948. 2021-02-04 00:41:14 -06:00
evazion
520b72948f Fix #4695: Raise max video length to match Twitter's (2:20). 2021-02-04 00:01:03 -06:00
evazion
1e778dbbf6 posts: factor out post navbar into component.
* Factor out the post navbar into a component. The post navbar is the
  part of the post containing the current search, the list of pools, and
  the list of favgroups, along with next/prev navigation links.

* Change navbar markup: remove various unused CSS classes/IDs, change
  pools to use same markup as favgroups, replace nested <div>'s with
  flat <ul>/<li> list.

* Use CSS to truncate long searches/pool names/favgroup names if they're
  too wide for the screen (especially on mobile).
2021-01-29 21:46:21 -06:00
evazion
d0c9f6e0b8 posts: allow toggling between upvotes and downvotes.
Like 9efb374ae, allow users to toggle between upvoting and downvoting a
post without raising an error or having to manually remove the vote
first. If you upvote a post, then downvote it, the upvote is
automatically removed and replaced by the downvote.

Other changes:

* Tagging a post with `upvote:self` or `downvote:self` is now silently
  ignored when the user doesn't have permission to vote, instead of
  raising an error.
* Undoing a vote that doesn't exist now does nothing instead of
  returning an error. This can happen if you open the same post in two
  tabs, undo the vote in tab 1, then try to undo the vote again in tab 2.

Changes to the /post_votes API:

* `POST /post_votes` and `DELETE /post_votes` now return a post vote
  instead of a post.
* The `score` param in `POST /post_votes` is now 1 or -1, not `up` or
  `down`.
2021-01-29 02:22:23 -06:00
evazion
716cdb0126 tests: fix broken tests.
* Fix a broken Twitter profile image upload test.
* Skip a broken DeviantArt flash file upload test (flash no longer
  supported by DeviantArt?)
* Skip user upgrade tests when Stripe is not configured.
2021-01-27 00:40:53 -06:00
evazion
9a9fbcc398 sessions: fix error when an anonymous user tried to logout.
Fix an exception when a user who was already logged out tried to logout
again.
2021-01-23 18:22:43 -06:00
evazion
9d71ece55d comments: remove 2 comments per hour limit.
Remove the rule that Members could only post 2 bumping comments per
hour.

This was frequently misunderstood as meaning that Members could only
post 2 comments per hour. In fact, Members could post an unlimited
number of comments per hour, but the rest of their comments had to be
non-bumping. The error message we showed to users was misleading. Even
our own code misunderstood what this did when describing the config
option.

Gold users also weren't subject to this limit, which was unfair since
Gold users aren't any better at commenting than regular users. The fact
that a large number of users already ignored bump limits and nobody
really noticed indicates that the limit was unnecessary.
2021-01-22 05:16:45 -06:00
evazion
2eecf4d695 comments: let mods click score to see votes. 2021-01-22 04:26:55 -06:00
evazion
9efb374ae5 comments: allow swapping votes.
Allow users to upvote a comment, then downvote it, without raising an
error or having to manually remove the upvote first. The upvote is
automatically removed and replaced by the downvote.

Changes to the /comment_votes API:

* `POST /comment_votes` and `DELETE /comment_votes` now return a comment
  vote instead of a comment.
* The `score` param in `POST /comment_votes` is now 1 or -1, not
  `up` or `down.`
2021-01-21 07:58:50 -06:00
evazion
e1e3604f46 comments: rework deleted comments.
Let users see when a post has deleted comments. Show normal users a
'[deleted]' placeholder when a comment is deleted. Show the full comment
to moderators.

Also fix it so that the comment creator can't edit or undelete deleted
comments, and users can't vote on or report deleted comments.

Finally, hide the creator_id, updater_id, and body of deleted comments
in the API.
2021-01-19 04:34:51 -06:00
evazion
07bdc6eab0 comments: rework thresholded comments.
Previously thresholded comments were hidden completely. You had to click
the "Show X hidden comments" button to unhide all hidden comments in a
thread. Now it works like this:

* When a comment is below your threshold, the comment text is hidden and
  replaced by a `[hidden]` link, which you can click to unhide the comment.

* When a comment is at half your threshold (for example, your threshold
  is -8 but the comment is at -4), then the comment is greyed out.

This means that comments aren't completely hidden, they're just
collapsed, so you can see the commenter and the score without unhiding
the comment. It also means you don't have to scroll back up to unhide a
comment, and threads aren't disrupted by comments being secretly
hidden (which is confusing when people are replying to hidden comments,
which forces you to go back up and unhide to find).
2021-01-19 04:07:33 -06:00
evazion
32dd14f461 Remove /admin/dashboard page.
This page was just a combination of the forum listing and the bulk
update requests listing. It got zero hits in the last week.
2021-01-16 03:32:11 -06:00
evazion
50a75e2ec5 modreports: allow users to see modreports they've submitted. 2021-01-16 02:19:25 -06:00
evazion
4719a5ed1c users: set default settings in ruby instead of in database.
Specify the default settings for new users inside the User model instead
of inside the database. This makes it easier to change defaults, and it
makes the code clearer.
2021-01-15 02:03:54 -06:00
evazion
b72d249ee3 tests: add user events controller tests. 2021-01-12 19:30:20 -06:00
evazion
1e7a5ba49d Fix ruby warnings about deprecated keyword arguments. 2021-01-11 05:12:09 -06:00
evazion
65adcd09c2 users: track logins, signups, and other user events.
Add tracking of certain important user actions. These events include:

* Logins
* Logouts
* Failed login attempts
* Account creations
* Account deletions
* Password reset requests
* Password changes
* Email address changes

This is similar to the mod actions log, except for account activity
related to a single user.

The information tracked includes the user, the event type (login,
logout, etc), the timestamp, the user's IP address, IP geolocation
information, the user's browser user agent, and the user's session ID
from their session cookie. This information is visible to mods only.

This is done with three models. The UserEvent model tracks the event
type (login, logout, password change, etc) and the user. The UserEvent
is tied to a UserSession, which contains the user's IP address and
browser metadata. Finally, the IpGeolocation model contains the
geolocation information for IPs, including the city, country, ISP, and
whether the IP is a proxy.

This tracking will be used for a few purposes:

* Letting users view their account history, to detect things like logins
  from unrecognized IPs, failed logins attempts, password changes, etc.
* Rate limiting failed login attempts.
* Detecting sockpuppet accounts using their login history.
* Detecting unauthorized account sharing.
2021-01-08 22:34:37 -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
873d719481 tests: fix broken Newgrounds test.
Broken again by the source post being deleted.
2021-01-04 23:54:18 -06:00
evazion
b6f9c9a866 post regenerations: regenerate posts asynchronously.
Regenerate posts asynchronously using a delayed job.

Regenerating a post can be slow because it involves downloading the
original file, regenerating the thumbnails, and redistributing the new
thumbnails back to the image servers. It's better to run this in the
background, especially if a user is trying to regenerate posts in bulk.

The downside is there's no notification to the user when the regeneration
is complete. You have to check the modactions log to see when it's finished.
2021-01-04 21:43:27 -06:00
evazion
df44937c57 post regenerations: replace PostRegeneration model with mod actions.
* Remove the PostRegeneration model. Instead just use a mod action
  to log when a post is regenerated.

* Change it so that IQDB is also updated when the image samples are
  regenerated. This is necessary because when the images samples are
  regenerated, the thumbnail may change, which means IQDB needs to be
  updated too. This can happen when regenerating old images with
  transparent backgrounds where the transparency was flattened to black
  instead of white in the thumbnail.

* Only display one "Regenerate image" option in the post sidebar, to
  regenerate both the images and IQDB. Regenerating IQDB only can be
  done through the API. Having two options in the sidebar is too much
  clutter, and it's too confusing for Mods who don't know the difference
  between an IQDB-only regeneration and a full image regeneration.

* Add a confirm prompt to the "Regenerate image" link.
2021-01-04 21:35:43 -06:00
evazion
913ce88024 tests: factor out upload helper methods. 2021-01-04 20:15:37 -06:00
BrokenEagle
16d6f3bbd5 Add post regenerations 2021-01-04 18:35:50 -06:00
evazion
257fa3d9c1 Fix #4645: Builders can alias empty non-artist tags 2021-01-04 01:02:39 -06:00
evazion
de16d31135 favorites: remove is_favorited attribute from post API.
* Remove the data-is-favorited attribute from post thumbnails.
* Remove the is_favorited attribute from the /posts.json API.
* Remove the fav_string attribute from the /posts.json API (only visible
  to moderators).
* Change `Post#favorited_by?` to not use the fav_string.

Further addresses #4652 by eliminating the last places where fav_string
was used.
2021-01-03 19:58:43 -06:00
evazion
014199ec2b user upgrades: handle the refunded status on show page. 2021-01-02 04:09:43 -06:00
evazion
ecd29c1a66 user upgrades: allow using promo codes during checkout.
Allow promo codes to be used during checkout if a secret promo=true url
param is passed. Allows promo codes to be offered without having the
promo code option always appear even when there aren't any active promos.
2021-01-01 04:24:24 -06:00
evazion
5b7894a8b2 autocomplete: fix exception when type param is missing. 2021-01-01 04:06:38 -06:00
evazion
430ba5dced users: fix exception during signup for IPv6 addresses.
`ip_address.private?` failed on IPv6 addresses.
2021-01-01 03:57:17 -06:00
evazion
d0bb4ed398 user upgrades: add bank payment methods for European countries.
Add the following bank redirect payment methods:

* https://stripe.com/docs/payments/bancontact
* https://stripe.com/docs/payments/eps
* https://stripe.com/docs/payments/giropay
* https://stripe.com/docs/payments/ideal
* https://stripe.com/docs/payments/p24

These methods are used in Austria, Belgium, Germany, the Netherlands,
and Poland.

These methods require payments to be denominated in EUR, which means we
have to set prices in both USD and EUR, and we have to automatically
detect which currency to use based on the user's country. We also have
to automatically detect which payment methods to offer based on the
user's country. We do this by using Cloudflare's CF-IPCountry header to
geolocate the user's country.

This also switches to using prices and products defined in Stripe
instead of generated on-the-fly when creating the checkout.
2020-12-31 06:50:10 -06:00
evazion
4b171bf97e user upgrades: add ability to refund upgrades. 2020-12-29 04:17:32 -06:00