Commit Graph

108 Commits

Author SHA1 Message Date
evazion
88ac91f5f3 search: refactor to pass in the current user explicitly. 2022-09-22 04:31:21 -05:00
evazion
3114ef3daf searchable: standardize the <field>_matches operator for text fields.
Standardize it so that all fields of type `text` are searchable with
`search[<field>_matches]`.

Before, the `<field>_matches` param was handled manually and some fields
were left out or handled inconsistently. Now it applies to all columns
of type `text`.

This does a full-text search on the field, so for example, searching
`/artist_commentaries?search[translated_description_matches]=smiling`
will match translated commentaries containing either the word "smiling",
"smiles", "smiled", or "smile".

Note that this only applies to columns defined as type `text`, not to
columns defined as `character varying`. The difference is that `text` is
used for fields containing free-form natural language, such as comments,
notes, forum posts, wiki pages, pool descriptions, etc, while `character
varying` is used for short strings not containing free-form language,
such as tag names, wiki page titles, urls, status fields, etc.

API changes:

* Add the `search[original_title_matches]`, `search[original_description_matches]`,
  `search[translated_title_matches]`, `search[translated_description_matches]` params
  to /artist_commentaries and /artist_commentary_versions.
* Remove the `search[name_matches]` and `search[group_name_matches]` params from /artist_versions.
* Remove the `search[title_matches]` param from /wiki_page_versions.
* Change the `search[name_matches]` param on /pools, /favorite_groups, and /pool_versions
  to do a full-text search instead of a substring match.
2022-09-22 01:52:13 -05:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
9a9649bee8 BURs: change default order on index page to newest BURs first.
Change the /bulk_update_requests page to show the newest BURs first
instead of pending BURs first. This is more consistent with index pages
on the rest of the site, which normally default to newest first. Fixes
an issue where failed BURs would be shown first forever unless they were
manually approved or rejected.
2021-11-02 04:16:33 -05:00
evazion
21f0c2acc3 BURs: add processing and failed states.
When a BUR is approved, put it in a `processing` state. After it
successfully finishes processing, put it in the `approved` state. If it
fails processing, put it in the `failed` state.

If approving the BUR fails with a validation error, for example because
the alias already exists or an implication lacks a wiki, then leave the
BUR in the `pending` state. The `failed` state is only for unexpected
errors during processing.
2021-09-20 01:12:14 -05:00
evazion
9ba84efc07 BURs: process BURs sequentially in a single job.
Change the way BURs are processed. Before, we spawned a background job
for each line of the BUR, then processed each job sequentially. Now, we
process the entire BUR sequentially in a single background job.

This means that:

* BURs are truly sequential now. Before certain things like removing
  aliases weren't actually performed in a background job, so they were
  performed out-of-order before everything else in the BUR.

* Before, if an alias or implication line failed, then subsequent alias
  or implication lines would still be processed. This was because each
  alias or implication line was queued as a separate job, so a failure
  of one job didn't block another. Now, if any alias or implication
  fails, the entire BUR will fail and stop processing after that line.
  This may be good or bad, depending on whether we actually need the BUR
  to be processed in order or not.

* Before, BURs were processed inside a database transaction (except for the
  actual updating of posts). Now they're not. This is because we can't
  afford to hold transactions open while processing long-running aliases
  or implications. This means that if BUR fails in the middle when it is
  initially approved, it will be left in a half-complete state. Before
  it would be rolled back and left in a pending state with no changes
  performed.

* Before, only one BUR at a time could be processed. If multiple BURs
  were approved at the same time, then they would queue up and be
  processed one at a time. Now, multiple BURs can be processed at the
  same time. This may be undesirable when processing large BURs, or BURs
  that must be approved in a specific order.

* Before, large tag category changes could time out. This was because
  they weren't actually performed in a background job. Now they are, so
  they shouldn't time out.
2021-09-20 01:12:14 -05:00
evazion
b4dc7487ee BURs: reduce autorejection timeout from 60 days to 45 days. 2021-08-15 04:51:48 -05:00
evazion
e5cfb7904c CurrentUser: remove #as method.
Replace with CurrentUser#scoped.
2021-06-22 23:39:30 -05:00
evazion
07e23204b6 rubocop: fix various Rubocop warnings. 2021-06-17 04:17:53 -05:00
evazion
dbb66ace90 routes: replace hardcoded routes in models with route helpers.
Add a Routes module that gives models access to route helpers outside of
views, and use it to replace various hardcoded routes.
2020-12-24 00:17:19 -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
8d87b1a0c0 models: fix deprecated errors[:base] << "message" calls.
Replace the idiom `errors[:base] << "message"` with
`errors.add(:base, "message")`. The former is deprecated in Rails 6.1.
2020-12-13 04:10:48 -06:00
evazion
8a52d8ed5f BURs: remove dead error handling code.
This is a 'this should never happen' error. This error is only raised if
we add a new bulk update request type and forget to handle it somewhere.
2020-12-03 17:15:24 -06:00
evazion
35d26e92e9 BURs: don't update OP when approving BUR.
When approving or rejecting a BUR, don't edit the OP forum post to add
an EDIT: line stating the request has been approved. Instead just let
the embedded BUR state who it was approved by, and post a reply saying
that the request has been approved.
2020-12-03 17:15:24 -06:00
evazion
6275e85148 BURs: refactor implication wiki page validations.
Move the validation that the tags in an implication must have wiki pages
back into the TagImplication model. Use validation contexts to only run
the validation when the BUR is created, not when the BUR is approved.
2020-12-02 14:30:18 -06:00
evazion
7f90bc4216 BURs: remove ability to skip secondary validations.
Remove the ability to skip secondary validations when creating a BUR.
The only skippable validation that still existed was the requirement
that both tags in an implication must have wiki pages. It's now
mandatory to write wiki pages for tags before you can request an
implication. This doesn't apply to empty tags.
2020-11-12 20:15:14 -06:00
evazion
d9085877be BURs: fix normalization of uppercase characters in scripts.
Only downcase tags in aliases, implications, and category change
commands. Don't downcase mass update commands. Mass updates are
potentially case sensitive (for example: `mass update source:imageboard -> source:Imageboard`).
2020-08-24 17:54:53 -05:00
evazion
1ddcc661e1 BURs: clean up parsing and error handling.
* Don't raise exceptions when a BUR is invalid. Instead, use Rails
  validations to return errors. Fixes invalid BURs potentially raising
  exceptions in views. Also makes it so that each error in a BUR is
  reported, not just the first one.

* Revalidate the BUR whenever the script is edited, not just when the
  BUR is created. Ensures the BUR can't be broken by editing. Fixes a bug
  where forum threads could be broken by someone editing a BUR and
  breaking the syntax, thereby causing the BUR to raise an unparseable
  script error when the forum thread was viewed.

* Validate that removed aliases and implication actually exist.

* Validate that the tag actually exists when changing a tag's category.

* Combine bulk update request processor unit tests with main bulk update
  request unit tests.
2020-08-24 17:10:48 -05:00
BrokenEagle
c4009efccd Convert models to use new search includes mechanism 2020-07-27 19:29:18 +00:00
evazion
d136a12a65 Fix #4359: Allow builders to move small (artist) tags manually.
Allow builders to approve artist alias BURs. The BUR must contain only
artist aliases or mass updates and each artist must have less than 100
posts.
2020-05-11 00:37:37 -05:00
evazion
49383d393a BURs: rename AliasAndImplicationImporter to BulkUpdateRequestProcessor.
The name AliasAndImplicationImporter is a holdover from the time before
bulk update requests existed. This was a bad name because it doesn't do
any actual importing, instead it's used for parsing and executing bulk
update requests.
2020-05-10 22:18:47 -05:00
evazion
71a3cc89fd BURs: don't try to move wikis/artists twice.
* Remove unnecessary rename_aliased_pages option. This option was always enabled.
* Don't try to rename the artist and wiki page inside AliasAndImplicationImporter
  when an alias is approved. This is already handled by TagAlias#process!.
2020-05-10 21:22:22 -05:00
evazion
5feb29ba57 Fix #4441: BUR form: display original request in the error page. 2020-05-04 03:39:41 -05:00
evazion
12d83408ab BURs: make the reason required. 2020-05-04 03:39:41 -05:00
evazion
08fe1c453c BURs: remove "Reason: " prefix from forum posts.
Don't automatically prepend "Reason: " in front of the BUR reason since
this isn't always desirable.
2020-05-04 03:39:41 -05:00
evazion
d5a7fafca1 posts/index: fix several "This tag is under discussion" issues.
Several fixes for the "This tag is under discussion" notice on the post
index page:

* Fix the notice appearing for BURs that aren't pending.
* Fix the notice never going away because of the cache never expiring.
* List all topics when a tag is involved in multiple BURs.
* Link to the forum post instead of the forum topic (fix #4421).
* Optimization: don't check for BURs when the search isn't a simple
  single tag search.
* Add a `tags` field to the bulk update requests table for tracking all
  tags involved in the request (excluding tags in mass updates that are
  negated/optional/wildcards). Known issue: doesn't handle tag type
  prefixes in mass updates correctly (e.g. `mass update foo -> artist:bar`
  doesn't detect the tag `bar`).
* Allow searching the /bulk_update_requests page by tags.

We don't really need to cache the notice here, but we do it anyway to
reduce queries on the post index page.
2020-04-27 19:11:47 -05:00
evazion
79a365abe0 pundit: convert bulk update requests to pundit. 2020-03-20 18:03:00 -05:00
evazion
db63b6d44f pundit: convert forum topics / forum posts to pundit.
Fix it being possible for users to delete or undelete their own forum
posts and topics, even if they were deleted by a mod.
2020-03-20 18:03:00 -05:00
BrokenEagle
09445cb28b Drop unused BUR title column 2020-03-18 23:16:43 +00:00
BrokenEagle
c16ad4f126 Add additional checks for BURs on forum topics 2020-03-18 23:05:12 +00:00
evazion
8253df84d9 forum: make status labels into clickable filters.
* Make it so that you can click the stickied / locked / deleted icons or
  the new / approved / pending / rejected labels to filter topics by
  that status.

* Replace the `mod_only` search param with `is_private`.
2020-03-16 21:23:27 -05:00
evazion
6fecf5db0e BURs: remove old single alias/implication pruning code.
* Rename TagChangeRequestPruner to BulkUpdateRequestPruner.
* Remove old code for pruning individual alias / implication requests.
2020-03-10 21:23:46 -05:00
evazion
be585060f4 BURs: don't add [APPROVED] / [REJECTED] tags to titles. 2020-03-10 21:02:12 -05:00
evazion
0e7632ed8a aliases/implications: remove forum topic updating code.
Remove code for updating forum topics when an alias or implication is
approved or rejected. This code was only used when approving single
alias or implication requests. This is no longer used now that all
alias/implication requests are done through BURs.
2020-03-10 20:55:20 -05:00
evazion
e47d0e0d05 models: set more creator names explicitly.
Set creators explicitly for bans, BURs, comment votes, and posts.
2020-02-23 17:26:08 -06:00
evazion
c1f7b76bdb dtext: refactor parsing of embedded BUR pseudo tags. 2020-02-22 01:37:12 -06:00
evazion
5817af4014 burs/show: remove BUR update count estimate.
Remove the post update count estimate from BUR show pages. This was
complex, slow, and usually inaccurate since it assumed that requests in
a BUR had no overlap with each other, which usually wasn't the case.
2020-02-16 19:21:56 -06:00
BrokenEagle
63b3503bfc Add ability to use nested only parameter
- The only string works much the same as before with its comma separation
-- Nested includes are indicated with square brackets "[ ]"
-- The nested include is the value immediately preceding the square brackets
-- The only string is the comma separated string inside those brackets
- Default includes are split between format types when necessary
-- This prevents unnecessary includes from being added on page load
- Available includes are those items which are allowed to be accessible to the user
-- Some aren't because they are sensitive, such as the creator of a flag
-- Some aren't because the number of associated items is too large
- The amount of times the same model can be included to prevent recursions
-- One exception is the root model may include the same model once
--- e.g. the user model can include the inviter which is also the user model
-- Another exception is if the include is a has_many association
--- e.g. artist urls can include the artist, and then artist urls again
2020-02-12 23:58:53 +00:00
evazion
1aadd19663 BURs: fix broken [bur:<id>] links in forum posts.
Fix bulk update requests generating invalid [bur:<id>] links in forum
posts. The id was missing because the BUR created the forum topic in a
before_create hook, which created the post before the BUR was saved so
the BUR didn't have an id yet. Fix regression caused by b4ce2d83.
2020-01-21 19:56:04 -06:00
evazion
b4ce2d83a6 models: remove belongs_to_creator macro.
The belongs_to_creator macro was used to initialize the creator_id field
to the CurrentUser. This made tests complicated because it meant you had
to create and set the current user every time you wanted to create an
object, when lead to the current user being set over and over again. It
also meant you had to constantly be aware of what the CurrentUser was in
many different contexts, which was often confusing. Setting creators
explicitly simplifies everything greatly.
2020-01-21 00:09:38 -06:00
evazion
895199ecfc models: include all int/bool columns as html data attributes by default. 2020-01-05 22:57:47 -06:00
BrokenEagle
223a6df5d8 Add API data to show/index views 2020-01-04 22:02:44 +00:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
2bffad9311 BURs: credit tag edits to DanbooruBot.
Credit tag edits that are performed as part of an alias, implication, or
mass update to DanbooruBot instead of the admin who approved the BUR.
2019-12-06 22:54:08 -06:00
evazion
67100f26eb Fix #4149: Add missing post search options on applicable models. 2019-09-01 13:10:37 -05:00
evazion
7b8584e3b0 Model#search: refactor searching for attributes. 2019-08-29 20:44:33 -05:00
evazion
c3ad7f6112 Model#search: factor out username search. 2019-08-29 20:44:27 -05:00
evazion
9163b3cb1c validations: drop superfluous return statements.
Returning true or false in a validation callback doesn't do anything, so
drop these superfluous return statements.
2019-08-04 15:45:05 -05:00
evazion
a926b162be models: drop unnecessary presence validations.
In rails 5, belongs_to associations automatically validate that the
associated item is present, meaning that we don't need to validate these
things manually any more.
2019-08-04 14:40:37 -05:00