Commit Graph
100 Commits
Author SHA1 Message Date
evazion 83915a5d46 modqueue: avoid N+1 queries for disapprovals, uploaders.
Fixes an N+1 queries problem in the /moderator/post/queue view by
prefetching disapprovals and uploaders.

Also the way disapproval messages were previously rendered triggered a bunch
of sql queries for each post:

    SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 [["post_id", 52]]
    SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND "post_disapprovals"."reason" = $2  [["post_id", 52], ["reason", "breaks_rules"]]
    SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND "post_disapprovals"."reason" = $2  [["post_id", 52], ["reason", "poor_quality"]]
    SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND "post_disapprovals"."reason" IN ('disinterest', 'legacy')  [["post_id", 52]]
    SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND (message is not null and message <> '')  [["post_id", 52]]
    SELECT "post_disapprovals".* FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND (message is not null and message <> '')  [["post_id", 52]]

This refactors to bring it down to one:

    SELECT "post_disapprovals".* FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1  [["post_id", 52]]
2017-02-24 21:03:14 -06:00
evazion 9b40016895 /posts/NNN, modqueue: allow dtext in disapproval reasons. 2017-02-24 21:03:14 -06:00
evazion 6704e71377 dmails: add tests for automated dmails. 2017-02-23 22:51:17 -06:00
evazion b1af644f67 dmails: send automated dmails from Danbooru.config.system_user.
Sends automated dmails from `Danbooru.config.system_user`, rather than
whichever user is performing the action happens to be (usually User.admins.first).

Also adds a notice in the view that the dmail was automated.
2017-02-23 22:51:17 -06:00
evazion 1400f64338 dmails_controller.rb: convert to strong params. 2017-02-23 22:51:17 -06:00
evazion 0c4b687880 user_name_change_requests.rb: remove unused notify_admins callback. 2017-02-23 22:51:17 -06:00
evazion 865211b0b5 dmails: remove unused edit template and update route. 2017-02-23 22:51:17 -06:00
evazion 2d8a7ed93b /dmails: add help:dmail link to subnavbar. 2017-02-23 22:51:17 -06:00
evazion d852f98e4f /dmails: remove unused search[owner_id] param.
/dmails is restricted to viewing dmails for CurrentUser only (due to
Dmail.visible in the index action). Remove owner_id from subnavbar links
in /dmails, and don't support it in /dmails?search[owner_id], since it
doesn't actually do anything.

Also removes related dead methods and fixes tests that didn't test owner_id properly.
2017-02-23 22:51:17 -06:00
evazion 6de350cd7d dmail.rb: remove dead new_blank method. 2017-02-23 22:51:17 -06:00
evazion 35bf995276 dmail.rb: make to_name= use User.name_to_id cache. 2017-02-23 22:51:17 -06:00
evazion 2736d31c67 dmail.rb: validate only on creation.
to/from/title/body don't need to be revalidated after creation since
they never change.
2017-02-23 22:51:16 -06:00
evazion abae71c060 layouts/default.html.erb: optimize dmail notice sql.
* CurrentUser.dmail_count caused an unnecessary COUNT(*).
* CurrentUser.dmails.unread.present? caused *all* unread dmails to be
  loaded. We want to only load the first one.
2017-02-18 05:54:46 -06:00
evazion d9349704c7 dmails: add indexes on is_read and is_deleted (fix #2886). 2017-02-18 05:54:40 -06:00
evazion 17d4feaf15 dmail_notice.html.erb: use absolute urls in dtext links. 2017-02-18 03:11:35 -06:00
evazion d78c537ec2 Add user mailer previewer.
Usage: open /rails/mailers in your browser.
2017-02-18 03:10:49 -06:00
evazion ebff8d04f7 config/application.rb: set hostname so root_url works. 2017-02-18 03:10:42 -06:00
evazion c926f75918 fixup! post.rb: validate newly added tags. 2017-02-09 02:14:48 -06:00
evazion f971f927fd post_test.rb: add tag name validation tests. 2017-02-08 23:31:30 -06:00
evazion facf819620 post.rb: validate newly added tags.
Existing tags with invalid names are still permitted. This is to allow
for a gradual transition to good tag names.
2017-02-08 23:31:30 -06:00
evazion 347f11b935 post.rb: group validation methods together. 2017-02-08 23:31:30 -06:00
evazion 8e3296f3ea tag.rb: don't strip '%' or ',' from tags; split on unicode spaces.
Allows '%' and ',' in tag names. There's no technical need to forbid
these characters.

Fixes an issue with these characters being stripped away inside metatags
(e.g. tagging a post with `pool:ichigo_100%` strips away the '%').
2017-02-08 23:31:30 -06:00
evazion 853ddc7cda tag.rb: validate tag names.
Makes these tag names invalid when tagging posts:

* Blank names (e.g. ___).
* Non-ASCII characters (Japanese text).
* Non-printable characters (e.g. control characters < 0x20).
* Leading or trailing underscores, or consecutive underscores. Reason:
  `_foo__bar_` and `foo_bar` both render as `foo bar` in the tag list.
* Leading `-` or `~`, or '*' (-foo, ~foo, foo*bar). Previously
  these were silently stripped, but that meant tagging a post with e.g.
  `*-foo` tagged the post with the invalid tag `-foo`.
* Tag type prefixes (e.g. `character:character:hatsune_miku` no longer creates
  the literal tag `character:hatsune_miku`).
* Metatags (order:score, user:evazion, etc).
2017-02-08 23:30:23 -06:00
evazion 951e6d4b5f Remove unused arbitrary_sql_order_clause.
Unused since f87c71c.
2017-02-06 19:07:04 -06:00
evazion cf54cd1480 core_extensions.rb: remove unused String#to_escaped_js. 2017-02-06 19:07:04 -06:00
evazion b5bf9b8678 post.rb: remove assorted unused methods. 2017-02-06 19:07:03 -06:00
evazion 74b8ebe580 tag.rb: remove unused find_suggestions, increment_view_count.
find_suggestions unused since ca3e9bb.
2017-02-06 19:07:03 -06:00
evazion 23038de470 posts_controller.rb: remove unused /posts/home action.
Unused since a4911e3.
2017-02-06 19:07:03 -06:00
evazion 7e1f63de6a landings_controller.rb: remove unused /landing route.
Broken since PopularPostExplorer was removed in 7269ec0.
2017-02-06 19:07:03 -06:00
evazion 38355b4839 posts_helper.rb: remove unused resize_image_links.
Unused since 1ef7ef4.
2017-02-06 19:07:03 -06:00
evazion 4ded9c6b2a app/helpers: remove unused helpers. 2017-02-06 19:07:02 -06:00
evazion ec653dce71 app/presenters: remove unused forum_post/note/post_version presenters. 2017-02-06 19:07:02 -06:00
evazion 35b3398142 post_test.rb: add more metatag search tests. 2017-02-06 18:48:39 -06:00
evazion cac5eae3c4 tests: add more tags controller/model tests. 2017-02-06 18:48:39 -06:00
evazion 2b4c722bd1 tests: add more notes controller tests. 2017-02-06 18:48:38 -06:00
evazion 0890c6320b tests: add more comments controller tests. 2017-02-06 18:48:38 -06:00
evazion 73e274b2e0 tests: add more moderator/post/queues controller tests. 2017-02-06 18:48:38 -06:00
evazion a120a63d3b tests: add more moderator/post/posts controller tests. 2017-02-06 18:48:38 -06:00
evazion cdafbc849d tests: add more artist commentary controller tests. 2017-02-06 18:48:38 -06:00
evazion 2d62fff89b tests: add more wiki page versions controller tests. 2017-02-06 18:48:37 -06:00
evazion 43591e0c2d tests: add more wiki pages controller tests. 2017-02-06 18:48:37 -06:00
evazion 5c871aee64 tests: add more pools controller tests. 2017-02-06 18:48:37 -06:00
evazion dfb8d0106d tests: add more posts controller tests. 2017-02-06 18:48:37 -06:00
evazion 09ffac07ea tests: add more users controller tests. 2017-02-06 18:48:37 -06:00
evazion 3edd814be5 tests: add iqdb queries controller tests. 2017-02-06 18:48:37 -06:00
evazion e26fb61ee9 tests: add explore/posts controller tests. 2017-02-06 18:48:36 -06:00
evazion 443c41cff2 tests: add meta searches controller tests. 2017-02-06 18:48:36 -06:00
evazion 30c3a52187 tests: add mod actions controller test. 2017-02-06 18:48:36 -06:00
evazion 101a03e797 tests: add related tags controller tests. 2017-02-06 18:48:36 -06:00
evazion 423dfc13b8 tests: add sources controller tests. 2017-02-06 18:48:36 -06:00
evazion 142dc05d0c tests: add note previews controller tests. 2017-02-06 18:48:35 -06:00
evazion 77b4dfcdfb tests: add artist controller tests. 2017-02-06 18:48:35 -06:00
evazion 490864e24d tests: add saved searches controller tests. 2017-02-06 18:48:35 -06:00
evazion 64b4004bbf tests: add favorite groups controller tests. 2017-02-06 18:48:35 -06:00
evazion ed451b7199 tests: add reports controller tests. 2017-02-06 18:48:35 -06:00
evazion d74503ae05 tests: add misc controller tests. 2017-02-06 18:48:35 -06:00
evazion 8c75f74ca5 tests: update simplecov config. 2017-02-04 22:17:39 -06:00
evazion e8cf417e9c tests: update gems to latest versions.
Also fix a few things that broke under shoulda-matchers 3.1.1.
2017-02-04 22:17:15 -06:00
evazion dd5974bf8c test_helper.rb: use MemcacheMock. 2017-02-04 17:18:52 -06:00
evazion 9b16c45edc test_helper.rb: factor out upload test helpers. 2017-02-04 17:18:52 -06:00
evazion 1511118bba test_helper.rb: remove unused assert_authentication_* helpers. 2017-02-04 17:18:51 -06:00
evazion beddc34958 tests: set Delayed::Worker.delay_jobs = false globally. 2017-02-04 17:18:51 -06:00
evazion 98b0b2c5d8 tests: fix Net::HTTP::Persistent::Error: too many connection resets.
Works around connection reset errors in the test suite by disabling
persistent connections.

  20) Error:
Sources::PixivTest#test_: in all cases fetching source data for a new manga image should get the tags. :
Net::HTTP::Persistent::Error: too many connection resets (due to closed stream - IOError) after 0 requests on 47071328584700, last used 1.842702476 seconds ago
  app/logical/pixiv_web_agent.rb:46:in `build'
  app/logical/sources/strategies/pixiv.rb:104:in `agent'
  app/logical/sources/strategies/pixiv.rb:72:in `get'
  app/logical/sources/site.rb:6:in `get'
  test/unit/sources/pixiv_test.rb:7:in `get_source'
  test/unit/sources/pixiv_test.rb:64:in `block (3 levels) in <class:PixivTest>'

ref: github.com/sparklemotion/mechanize/issues/123
ref: http://www.rubydoc.info/gems/mechanize/Mechanize#retry_change_requests%3D-instance_method
2017-02-04 17:07:00 -06:00
evazion cd3b09b10a tag_alias_correction_test.rb: fix assert_nil deprecation warning.
Use assert_nil if expecting nil from /home/danbooru/src/danbooru/test/unit/tag_alias_correction_test.rb:29
in `block (3 levels) in <class:TagAliasCorrectionTest>'. This will fail in MT6.
2017-02-04 17:06:59 -06:00
evazion 9429f54632 alias_and_implication_importer_test.rb: fix test failures.
1) Error:
AliasAndImplicationImporterTest#test_: The alias and implication importer given a valid list should process it. :
NoMethodError: undefined method `role' for nil:NilClass
  app/models/tag_alias.rb:124:in `rescue in process!'
  app/models/tag_alias.rb:135:in `process!'
  app/models/tag_alias.rb:93:in `approve!'
  app/logical/alias_and_implication_importer.rb:90:in `block (2 levels) in parse'
  app/logical/alias_and_implication_importer.rb:82:in `map'
  app/logical/alias_and_implication_importer.rb:82:in `block in parse'
  app/logical/alias_and_implication_importer.rb:81:in `parse'
  app/logical/alias_and_implication_importer.rb:13:in `process!'
  test/unit/alias_and_implication_importer_test.rb:24:in `block (4 levels) in <class:AliasAndImplicationImporterTest>'
  test/unit/alias_and_implication_importer_test.rb:23:in `block (3 levels) in <class:AliasAndImplicationImporterTest>'
2017-02-04 17:06:59 -06:00
evazion a327854017 Fix post_update_count increment test.
7) Failure:
PostTest#test_: Tagging: A post that has been updated should increment the updater's post_update_count. [/home/danbooru/src/danbooru/test/unit/post_test.rb:1010]:
"CurrentUser.post_update_count" didn't change by 1.
Expected: 1
  Actual: 3
2017-02-03 04:04:02 -06:00
evazion e98e7f1ea7 Fix note_update_count increment test.
5) Failure:
NoteTest#test_: In all cases updating a note should increment the updater's note_update_count. [/home/danbooru/src/danbooru/test/unit/note_test.rb:113]:
"CurrentUser.note_update_count" didn't change by 1.
Expected: 1
  Actual: 0
2017-02-03 04:03:44 -06:00
evazion 27817cffcf Fix saved search test.
16) Failure:
SavedSearchTest#test_: Fetching the post ids for a search with a name should return a list of ids. [/home/danbooru/src/danbooru/test/unit/saved_search_test.rb:31]:
Expected: [1, 2, 3, 4]
  Actual: []
2017-02-03 04:03:44 -06:00
evazion ace7d0c12d Fix moving saved searches tests.
4) Failure:
TagAliasTest#test_: A tag alias should move saved searches. [/home/danbooru/src/danbooru/test/unit/tag_alias_test.rb:80]:
Expected: "123 bbb 456"
  Actual: "123 ... 456"

 36) Failure:
Moderator::TagBatchChangeTest#test_: a tag batch change should move saved searches. [/home/danbooru/src/danbooru/test/unit/moderator/tag_batch_change_test.rb:40]:
Expected: "123 456 bbb"
  Actual: "123 ... 456"
2017-02-03 04:03:44 -06:00
evazion 72502dbe2f Fix comment voting tests.
2) Error:
CommentTest#test_: A comment created by an unlimited user should not allow duplicate votes. :
ActiveRecord::RecordInvalid: Validation failed: You have already voted for this comment
    app/models/comment.rb:142:in `vote!'
    test/unit/comment_test.rb:164:in `block (3 levels) in <class:CommentTest>'

  3) Error:
CommentTest#test_: A comment created by an unlimited user should not allow upvotes by the creator. :
ActiveRecord::RecordInvalid: Validation failed: You cannot upvote your own comments
    app/models/comment.rb:142:in `vote!'
    test/unit/comment_test.rb:179:in `block (3 levels) in <class:CommentTest>'
2017-02-03 04:03:44 -06:00
evazion 3ee7f0770f Fix posts controller api test.
1) Failure:
    PostsControllerTest#test_: The posts controller for api calls passing the api limit should work. [/home/danbooru/src/danbooru/test/functional/posts_controller_test.rb:34]:
    Expected response to be a <429>, but was <200>.
    Expected: 429
      Actual: 200
2017-02-03 04:03:43 -06:00
evazion 43086634cf hotkeys: fix shift+r => mark forum as read.
Also fix issue with a note handler being rebound instead of unbound.
2017-02-03 03:48:22 -06:00
evazion d71136ce72 Disable left/right for prev/next page on /posts/:id.
Interferes with horizontal scrolling of wide images.
2017-02-03 03:40:32 -06:00
evazion 50b793d129 Don't send failed uploads to IQDB (possible fix for #2867). 2017-02-02 01:26:59 -06:00
evazion 558e4e5443 Add filetype: metatag. 2017-02-02 00:53:56 -06:00
evazion 74cbcb3f80 Update json, rubyracer gems for ruby-2.4.
Fixes a couple incompatibilities with ruby 2.4.

ref: github.com/flori/json/issues/303.
ref: github.com/cowboyd/therubyracer/issues/430
2017-01-27 05:22:05 -06:00
evazion 8d65ae840b hotkeys: document new bindings. 2017-01-24 02:46:01 -06:00
evazion cfeb95c8a8 hotkeys: add left arrow, right arrow bindings for prev/next page. 2017-01-24 02:46:01 -06:00
evazion 7571cda640 hotkeys: add E to edit, shift+D to delete to artists, pools, wiki, forum. 2017-01-24 02:46:00 -06:00
evazion c3fa653fc5 hotkeys: refactor to use .on(), namespaces.
* Use .on() instead of .bind() because bind is deprecated in jquery 3.0.
* Ensure enable-js-navigation is always respected.
* Namespace keybindings so they may be disabled by userscripts with
  e.g. $(document).off("keydown.danbooru") or $(document).off("next_page").
2017-01-24 02:45:55 -06:00
evazion ecf22adc7d /comments/search: add more search params; style as inline form. 2017-01-23 22:13:00 -06:00
evazion caaff24112 /comments?group_by=comment: add is_sticky/is_deleted/do_not_bump_post/order params. 2017-01-23 22:13:00 -06:00
evazion a7333f4069 dotenv: add sample .env file. 2017-01-23 18:07:52 -06:00
evazion 74bbd45cdf dotenv: enable overriding database settings. 2017-01-23 18:07:52 -06:00
evazion 1aa2316a9e dotenv: enable overriding rails secret token / session key. 2017-01-23 18:07:51 -06:00
evazion f33108416e dotenv: enable overriding danbooru_local_config.rb with env vars. 2017-01-23 18:07:51 -06:00
evazion a72df4133e dotenv: add config/unicorn/unicorn.rb, Procfile. 2017-01-23 18:07:51 -06:00
evazion 3eb525ad01 dotenv: add gem. 2017-01-23 16:38:14 -06:00
evazion 601b439f96 Add order:comment_bumped, order:comment_bumped_asc metatags. 2017-01-21 11:10:40 +00:00
evazion c6966268a2 Remove 'reason' from name change request form; update copy. 2017-01-19 23:42:39 +00:00
evazion afb8eeea30 Fix exploit making user name change reasons being public in API. 2017-01-19 23:41:36 +00:00
evazion 7486bb0add Fix #2851: Account deletion should remove name change requests.
Hides name change requests for deleted users (username matches /user_[0-9]+~*/).
2017-01-19 22:32:13 +00:00
evazion f0bdf565fe Name changes: add listing/new/help links to subnav. 2017-01-15 05:03:09 +00:00
evazion d31a0c23f3 Name changes: add API endpoints for /user_name_change_requests. 2017-01-15 05:03:09 +00:00
evazion 9e9fdcb55d Name changes: make /user_name_change_requests member+; add reason/status/date. 2017-01-15 05:03:09 +00:00
evazion 047d3675e9 Name changes: don't show user feedback/stats for processed requests. 2017-01-15 05:03:09 +00:00
evazion 66e30b323c Name changes: remove delete request button. 2017-01-15 05:03:08 +00:00
evazion f57f352838 Name changes: format processed requests more nicely. 2017-01-15 04:22:00 +00:00
evazion 5f4535c408 Fix #2839: "Original" tag shows up twice in Pixiv source data 2017-01-14 21:14:06 +00:00
evazion cf046eecbf Fix ip addr search tests. 2017-01-12 09:28:52 +00:00