Commit Graph

439 Commits

Author SHA1 Message Date
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
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
9af407c94b comments: set default comment threshold to -8.
* Set the default comment threshold to -8. This means that comments are
  hidden at -8 or lower and greyed out at -4 or lower.

* Reset the comment threshold to -8 for anyone with a threshold greater
  than -8. For reference, only about ~3100 users had a non-default
  threshold. About 1600 of those had their threshold reset to -8.

* Change the comment threshold to a less-than-or-equal comparison
  instead of a less-than comparsion. This means that a threshold of 0
  before is the same as a threshold of -1 now. Since everyone's
  thresholds were reset, this only affects people whose thresholds were
  already less than -8, which is so low that the difference shouldn't
  matter much.

* Set the maximum comment threshold to 5. For reference, less than 1% of
  comments have a score greater than 5.

* Set the minimum comment threshold to -100. For reference, the most
  downvoted comment has a score of -60.
2021-01-19 05:48:25 -06:00
evazion
d408ccbd41 users: remove option to disable autocomplete.
This option was originally added in issue #1747. But only ~350 users
ever disabled autocomplete, only ~120 of these were seen in the last
year, and only 9 new users who signed up in the last year disabled it.

Users wishing to disable autocomplete can use this CSS:

    .ui-autocomplete { display: none !important: }

or this Javascript:

    $("[data-autocomplete]").autocomplete("disable");
2021-01-15 02:03:54 -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
99d447279b users: remove option to disable keyboard shortcuts.
Remove the enable_post_navigation option. This option was originally
added to disable the next/prev post navbar beneath posts. It was later
repurposed to disable keyboard shortcuts.

Users who don't want keyboard shortcuts are advised to not press random
buttons on the keyboard like a caveman.

Only ~1200 users disabled this option and only ~600 were seen in the
last year.
2021-01-15 02:03:54 -06:00
evazion
b6fef7f3f3 users: remove option to disable search navbar.
Remove the enable_sequential_post_navigation option. This option was
used to disable the next/previous post navbar below posts.

This option was originally added in issue #674 because of people
complaining about the navbar when it was originally added. Also there
were complaints about URLs being uglier because of search params in the
URL (e.g. /posts/1234?q=touhou). There were also various minor bugs with
it at the time, such as keyboard shortcuts not working correctly, or the
page not remembering your search after a tag edit.

These complaints are irrelevant nowadays because a) people are used to
the navbar by now (and more often complain about it *not* being there
for order:score searches), b) post URLs always contain the search now,
this option hasn't disabled that for years, and c) the initial bugs with
it were fixed years ago.

Only ~1000 users disabled this option and only ~600 were seen in the last year.

Users still wishing to hide the search navbar can use custom CSS instead.
2021-01-15 02:03:54 -06:00
evazion
ceeed1e692 pagination: refactor page limits.
Refactor page limits to a) be explicitly listed in the User class (not
hidden away in the Danbooru config) and b) explicitly depend on the
CurrentUser (not implicitly by way of Danbooru.config.max_numbered_pages).
2021-01-11 21:09:06 -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
890c793d9b Fix #4644: Give unlimited searches for builders
Give Builders unlimited searches, favgroups, and saved searches.
2021-01-02 04:09:41 -06:00
evazion
0b2f9fafa8 users: refactor limit methods.
* Refactor various user limit methods to class methods from instance
  methods so they can be used outside the context of a single user.

* Remove the Danbooru.config.base_tag_query_limit option.
2021-01-01 19:24:37 -06:00
evazion
1d15ce2bcd Remove Danbooru Winter Sale. 2021-01-01 04:16:38 -06:00
evazion
fd18291382 Add Danbooru Winter Sale. 2020-12-25 06:07:21 -06:00
evazion
74ed2a8b96 user upgrades: add UserUpgrade model.
Add a model to store the status of user upgrades.

* Store the upgrade purchaser and the upgrade receiver (these are
  different for a gifted upgrade, the same for a self upgrade).
* Store the upgrade type: gold, platinum, or gold-to-platinum upgrades.
* Store the upgrade status:
** pending: User is still on the Stripe checkout page, no payment
   received yet.
** processing: User has completed checkout, but the checkout status in
   Stripe is still 'unpaid'.
** complete: We've received notification from Stripe that the payment
   has gone through and the user has been upgraded.
* Store the Stripe checkout ID, to cross-reference the upgrade record on
  Danbooru with the checkout record on Stripe.

This is the upgrade flow:

* When the user clicks the upgrade button on the upgrade page, we call
  POST /user_upgrades and create a pending UserUpgrade.
* We redirect the user to the checkout page on Stripe.
* When the user completes checkout on Stripe, Stripe sends us a webhook
  notification at POST /webhooks/receive.
* When we receive the webhook, we check the payment status, and if it's
  paid we mark the UserUpgrade as complete and upgrade the user.
* After Stripe sees that we have successfully processed the webhook,
  they redirect the user to the /user_upgrades/:id page, where we show
  the user their upgrade receipt.
2020-12-24 21:15:04 -06:00
evazion
ca742db07a routes: remove legacy /user/index and /artist/index API endpoints.
These endpoints get zero traffic.
2020-12-24 00:17:26 -06:00
evazion
ee4516f5fe searchable: refactor searchable_includes.
Pass searchable associations directly to search_attributes instead of
defining them separately in searchable_includes.
2020-12-16 23:57:07 -06:00
evazion
e771c0fca8 searchable: don't automatically include id, created_at, updated_at.
Don't make search methods on models call super in order to search
certain default attributes (id, created_at, updated_at). Simplifies some
magic.
2020-12-16 23:57:07 -06:00
evazion
852c67f1b7 users: fix #owner method. 2020-12-14 14:13:11 -06:00
evazion
c82e05d828 users: add stricter checks for user promotions.
New rules for user promotions:

* Moderators can no longer promote other users to moderator level. Only
  Admins can promote users to Mod level. Mods can only promote up to Builder level.
* Admins can no longer promote other users to Admin level. Only Owners
  can promote users to Admin. Admins can only promote up to Mod level.
* Admins can no longer demote themselves or other admins.

These rules are being changed to account for the new Owner user level.

Also change it so that when a user upgrades their account, the promotion
is done by DanbooruBot. This means that the inviter and the mod action
will show DanbooruBot as the promoter instead of the user themselves.
2020-12-13 21:21:08 -06:00
evazion
b3ad13e6e3 users: add new owner level.
Add a new Owner user level for the site owner. Highly sensitive
operations like manually changing the passwords of other users will be
restricted to the site owner.
2020-12-13 21:18:24 -06:00
evazion
f4f25cf0c8 aliases: fix blacklists when aliasing tags.
When aliasing a tag, update any blacklists containing the old tag to use
the new tag.
2020-08-26 17:06:00 -05:00
evazion
5db11a0b5f Merge branch 'master' into attribute-searching 2020-08-17 14:23:00 -05:00
evazion
f53fa2adb4 Fix #4587: "Max 5 flags per 3 days" should account for reapproved flags. 2020-08-14 21:57:08 -05:00
evazion
dd8c3fad2c flags: adjust limit to 5 flags at once. 2020-08-12 13:11:33 -05:00
evazion
3210da1a23 flags: raise flag limits.
The old flag limits were:

* 1 flag per day for regular members.
* 10 flags per day for Gold users.
* Unlimited flags for approvers.

The new flag limits are:

* 10 flags in the modqueue at once for regular users.
* Unlimited flags for approvers.
* Unlimited flags for users with a high enough flag success rate. If you
  have at least 30 flags in the last 3 months, and you have at least a
  70% flag success rate, then you get unlimited flags.

10 flags at once means you can have up to 10 flagged posts in the
modqueue at the same time. Because flags stay in the modqueue for 3
days, this means you can flag on average 10 posts every 3 days, or just
over 3 posts per day.
2020-08-08 15:22:13 -05:00
evazion
e8dcc9c56e appeals: raise appeal limits.
The old limit was one appeal per day. The new limit is based on your
upload limit. Each appeal costs 3 upload slots. If you have 15 upload
slots, then you can appeal up to 5 posts at once, but you won't be able
to appeal or upload more until your appeals are approved or rejected. If
you have unlimited uploads, then you have unlimited appeals.
2020-08-08 12:39:20 -05:00
evazion
baf0cf87af Fix #4571: Show banner when email verification is required.
* Show a banner if the user is restricted because they signed up from a
  proxy or VPN.

* Add an option to resend the confirmation email if your account has an
  unverified email address.
2020-08-02 16:48:45 -05:00
BrokenEagle
3eb90105df Remove obsolete includes 2020-07-27 19:29:19 +00:00
BrokenEagle
c938119eae Add additional includes 2020-07-27 19:29:18 +00:00
BrokenEagle
c4009efccd Convert models to use new search includes mechanism 2020-07-27 19:29:18 +00:00
evazion
b1ccc44c91 users: allow searching for banned users. 2020-07-13 13:48:39 -05:00
evazion
eacb4d4df3 models: factor out api_attributes to policies.
Refactor models so that we define attribute API permissions in policy
files instead of directly in models.

This is cleaner because a) permissions are better handled by policies
and b) which attributes are visible to the API is an API-level concern
that models shouldn't have to care about.

This fixes an issue with not being able to precompile CSS/JS assets
unless the database was up and running. This was a problem when building
Docker images because we don't have a database at build time. We needed
the database because `api_attributes` was a class-level macro in some
places, which meant it ran at boot time, but this triggered a database
call because api_attributes used database introspection to get the list
of allowed API attributes.
2020-06-08 18:38:02 -05:00
evazion
47e6821a31 config: remove customize_new_user config option. 2020-06-02 18:25:45 -05:00
evazion
565e02c7ab Revert "search: temporarily raise tag limit to 12 for Danbirthday celebration."
This reverts commit af50e10c3a.
2020-06-01 23:32:25 -05:00
evazion
af50e10c3a search: temporarily raise tag limit to 12 for Danbirthday celebration. 2020-05-23 22:09:38 -05:00
evazion
be27423afd search: fix invalid username searches returning wrong results.
Partial fix for #4389.

* Fix invalid username searches returning all posts instead of no posts.
* Fix "user:A user:B" returning results for user:B instead of no results.
* Fix "approver:A approver:B" returning results for approver:B instead of no results.
* Add support for negated -commenter, -noter, -noteupdater, -upvote, -downvote metatags.
* Add support for "any" and "none" values for all username metatags,
  including negated metatags that didn't support "any" or "none" before.
* Change noter:any and commenter:any to include posts with deleted notes
  or comments. Note that commenter:<username> already included deleted
  comments before. This is so that commenter:any has the same behavior
  as commenter:<username>
2020-04-15 01:18:41 -05:00
evazion
e9b33dbd48 api: remove legacy password_hash login method.
Remove the ability to authenticate to the API with the `login` and
`password_hash` url parameters. This is a legacy authentication method
from Danbooru 1. How to actually generate the password_hash for this
method hasn't been fully documented for many years now. It required
taking the SHA1 hash of your password combined with an undocumented salt
value (i.e., password_hash = sha1("choujin-steiner--#{password}")).

This authentication method was also slow because it required checking
the password on every API call. Checking passwords is deliberately slow
because passwords are hashed with BCrypt. BCrypt takes about ~200ms per
request, so using this method effectively limited you to ~5 requests per
second in a single thread.
2020-03-25 18:48:43 -05:00
evazion
b2cf765d6d users: refactor login and authentication logic.
* Make authentication methods into User instance methods instead of
  class methods.
* Fix API key authentication to use a secure string comparison. Fixes a
  hypothetical (unlikely to be exploitable) timing attack.
* Move login logic from SessionCreator to SessionLoader.
2020-03-25 18:48:43 -05:00
evazion
9e455695a1 sessions: remove legacy user_name / password_hash cookies.
Remove support for logging in with the deprecated user_name /
password_hash cookies. Followup to 320ff01e0.
2020-03-25 18:48:43 -05:00
evazion
cbd713dea8 users: move sockpuppet detection from model to controller. 2020-03-24 18:41:27 -05:00
evazion
b7bd6c8fdd users: require email verification for signups from proxies.
Require users who signup using proxies to verify their email addresses
before they can perform any edits. For verification purposes, the email
must be a nondisposable address from a whitelist of trusted email
providers.
2020-03-24 17:25:35 -05:00
evazion
5faa323729 users: clean up password update logic.
Pull the password reauthentication logic out of the user model and put
it in the password update controller where it belongs.

This fixes an issue where when a new user was created the user model had
an incorrect password error set on it by `encrypt_password_on_update`.
It was trying to verify the old password even though we don't have one
when creating a new user. This error caused the user create action to
redirect back to the signup page because `respond_with` thought that
creating the user failed.
2020-03-24 17:25:35 -05:00
evazion
4a5bec71f6 signup: don't send welcome emails to invalid addresses.
Fix attempting to send welcome emails when user didn't provide a valid
email address.
2020-03-24 00:26:47 -05:00
evazion
f464163885 users: allow all users to use the posts per page setting. 2020-03-21 23:06:50 -05:00
evazion
88a8f459ed comments: remove 10 comment votes per hour limit. 2020-03-21 23:06:47 -05:00
evazion
63f7311489 comments: allow new users to comment.
Remove the rule that users less than a week old can't leave comments.
2020-03-21 23:06:47 -05:00
evazion
aefbed57b8 pools: allow new users to remove posts from pools.
Remove the rule that users less than a week old can't remove posts from
pools.
2020-03-21 23:06:47 -05:00
evazion
2445e8b82f favorites: convert user.hide_favorites? to pundit. 2020-03-21 23:06:42 -05:00
evazion
5bc82bf07b users: remove user is not ip banned validation.
This is handled on the controller level now.
2020-03-21 23:06:42 -05:00