Commit Graph

61 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
a229a6f5c4 models: remove ignored_columns declarations.
These columns have been removed from the underlying database.
2022-09-20 23:09:32 -05:00
evazion
0c919a6bc8 versions: remove 'subsequent' version comparison option.
This option was rarely used and what it actually did was usually
difficult to understand.
2022-09-18 15:56:10 -05:00
evazion
d4da8499ce models: stop saving IP addresses in version tables.
Mark various `creator_ip_addr` and `updater_ip_addr` columns as ignored
and stop updating them in preparation for dropping them.
2022-09-18 03:49:17 -05:00
evazion
7786fbaca6 Fix #5181: Old post versions have null ratings which causes a KeyError. 2022-05-22 23:50:45 -05:00
evazion
141044d352 posts: refactor hardcoded ratings.
Refactor ratings to not be hardcoded in various places. Make it so
all ratings are defined in Post::RATINGS.

Also make it so that you can search multiple ratings at once with `rating:q,e`.
2022-05-18 13:04:15 -05:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
79fdfa86ae Fix various rubocop warnings. 2021-09-27 00:46:13 -05:00
evazion
5af21f03de versions: default ARCHIVE_DATABASE_URL to DATABASE_URL.
Make it so that when ARCHIVE_DATABASE_URL isn't set, it defaults to
DATABASE_URL. In other words, if you don't have a separate archive
database configured, then default to using the main database for
post/pool versions.

Fixes an issue where running the test suite would fail if you didn't
explicitly set ARCHIVE_DATABASE_URL because it tried to use
`archive_test` as the post/pool versions database name.
2021-09-22 00:34:28 -05:00
evazion
07e23204b6 rubocop: fix various Rubocop warnings. 2021-06-17 04:17:53 -05: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
cbadfb3817 post versions: remove dead check_for_retry method. 2020-08-13 02:24:13 -05:00
evazion
70f345fd7b post versions: add back support for changed_tags param.
Fix broken links on various pages:

* The 'History' link in the sidebar on the post index page.
* The 'History' links on the tags index page.
* The 'Tag History' link in the sidebar on the wiki show page.
2020-08-13 02:21:38 -05:00
BrokenEagle
5d88d09d93 Add search for a list of any changed tags
This will facilitate users being able to monitor tag changes from
a list of tags they are interested in. Currently, the only way to
do this is 2 separate queries on the added_tags and removed_tags.
2020-07-29 00:36:52 +00:00
BrokenEagle
1a87935764 Fix the tag matches option
The split function was mistakenly used instead of the match function.
2020-06-23 06:58:03 +00: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
BrokenEagle
4d9eae0038 Add additional advanced search operators
- Tag matches allows a user to search for a single tag
-- Since testing for multiple tags would require converting the "tags"
   string to an array which would most likely fail even for single tags
- Is new for quick searching of uploads or not uploads
2020-03-28 06:29:46 +00:00
BrokenEagle
6aa0adb738 Make the post versions more like the old format
- "Current" is now most like the old format
-- It is therefore now the default for post versions
- Only show the actual edits in their own column
- Show the current state at that version in another column
- On the "previous" view, don't double-show full list of tags for
  the first post versions, so leave edits blank
2020-03-28 06:29:41 +00:00
evazion
94ae10b1a6 tests: fix post and pool version tests helpers.
* Fix the pool version SQS service to always be mocked before every
  test. Before we had to manually set it up before every test dealing
  with pool versions.

* Fix it so that we reconnect to the post/pool version databases before
  every test. Before using $ARCHIVE_DATABASE_URL to set the database url
  failed because environment variables weren't loaded by dotenv yet when
  connections were first established.
2020-03-21 19:28:10 -05:00
evazion
ffae64f127 pundit: convert post versions to pundit. 2020-03-20 18:03:01 -05:00
BrokenEagle
e23ee170f5 Add alternate comparison types to versions
- The types are:
-- Previous: The default and the previously used type
-- Subsequent: Compares against the next version
-- Current: Compares against the current version
- Allow switching between comparison types in index and diff views
-- Have links vary depending upon current comparison type
2020-03-17 18:31:20 +00:00
BrokenEagle
a95e57d938 Move more logic to the helper modules
- Diff view changes
-- Only show pool description changes in diff view
-- Conditionally render diff link when applicable values are changed
-- Conditionally show diff view sections when values are changed
- Show renames on index view
-- There is plenty of space
-- This wasn't shown at all for wikis
-- Having to navigate to an alternate page is unwieldy for pools
- Show "posts" as a status on pools
-- This is so all changes among versions are quantified as a status
- Standardize diff/index titles
2020-03-17 18:31:20 +00:00
evazion
9caa9d8117 post versions: drop unused presenter method. 2020-02-16 05:38:53 -06:00
evazion
60ff2ae929 models: rename post/pool archives to post/pool versions. 2020-02-15 06:52:10 -06:00
evazion
51f3f7338a models: remove old post version and pool version models. 2020-02-15 06:21:00 -06:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
59b277ead1 users: drop id_to_name, name_to_id caching.
Changes:

* Drop Users.id_to_name.
* Don't cache Users.name_to_id.
* Replace calls to name_to_id with find_by_name when possible.
* Don't autodefine creator_name in belongs_to_creator.
* Don't autodefine updater_name in belongs_to_updater.
* Instead manually define creator_name / updater_name only on models that need
  to return these fields in the api.

id_to_name was cached to reduce the impact of N+1 query patterns in
certain places, especially in api responses that return creator_name /
updater_name fields. But it still meant we were doing N calls to
memcache. Using `includes` to prefetch users avoids this N+1 pattern.

name_to_id had no need be cached, it was never used in any performance-
sensitive contexts.

Avoiding caching also avoids the need to keep these caches consistent.
2019-08-18 11:24:42 -05:00
evazion
03abbd0683 Fix #2894: Use [[:space:]] instead of \s in regexes. 2018-09-20 19:24:38 -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
BrokenEagle
d829ab3a00 Move all order logic to models
- Have a default order for each model
-- The overall default is ID DESC
- Allow for custom orderings
-- When comma-separated IDs are used
2018-01-29 11:42:53 -08:00
evazion
0ca726802f Fix #3430: Accept the search[id] param in all controllers.
* Allow every controller to take the `search[id]` param.

* Parse the `search[id]` param the same way that the `id:<N>` metatag is
  parsed. So `search[id]=1,2,3`, `search[id]=<42`, `search[id]=1..10`, for
  example, are all accepted.
2017-12-17 17:36:52 -06:00
evazion
c1834ab8dd Inherit models from ApplicationRecord instead of ActiveRecord::Base. 2017-06-16 13:28:31 -05:00
Albert Yi
5404c1d231 implement postarchive 2017-02-21 13:40:52 -08:00
evazion
ec653dce71 app/presenters: remove unused forum_post/note/post_version presenters. 2017-02-06 19:07:02 -06:00
Albert Yi
79842f7a3b restrict min level constraints for forum topics to mod+admin and restrict options based on current user's level. check privileges for visiblity in forum posts and topics. deprecate serializable_hash (undocumented, internal) for as_json, refactor to use hidden_attributes and method_attributes #2658 2016-10-25 15:05:55 -07:00
r888888888
aab03422bc performance tweaks for rails 4.1 2014-04-24 22:24:42 -07:00
r888888888
fad0ab7c93 fixes #2133 2014-04-16 17:43:34 -07:00
r888888888
b77c5ee62c fixes #1955 2014-03-19 15:35:09 -07:00
Toks
347561c838 fixes #1439 2013-12-09 15:05:12 -05:00
Toks
2c80f9bcc4 fixes #357 2013-08-13 13:15:07 -04:00
Toks
d4060a647d Fix undo not undoing parent additions 2013-08-13 13:03:48 -04:00
Toks
2d0c3d16a3 fix #1724 for posts 2013-06-09 15:18:09 -04:00
Toks
9d8330e905 fixes #748 2013-04-20 12:17:13 -04:00
Toks
92177ae240 fixes #1370 2013-04-18 21:17:54 -04:00
Toks
eff0041729 adds proper obsolete rating/parent/source logic 2013-04-05 20:34:02 -04:00
Toks
fab493bf40 fixes #1162 2013-04-01 20:53:39 -04:00
albert
85a5fcc658 fixes #1133 2013-03-29 16:45:59 -04:00
小太
cba839ba76 Kill trailing whitespace in ruby files 2013-03-19 23:10:10 +11:00
albert
7ca8635051 fixes #691 2013-03-02 21:13:21 -05:00
albert
8911738909 fix post version diff method 2013-02-23 16:04:09 -05:00