Commit Graph

79 Commits

Author SHA1 Message Date
evazion
153a8339ab Inherit errors from StandardError instead of Exception. 2020-01-11 19:07:28 -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
7694be9cb3 users: remove no_flagging and no_feedback permissions. 2019-12-24 10:24:15 -06:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
d0f060d8eb api: refactor api attribute declarations.
Replace the `method_attributes` and `hidden_attributes` methods with
`api_attributes`. `api_attributes` can be used as a class macro:

    # include only the given attributes.
    api_attributes :id, :created_at, :creator_name, ...

    # include all default attributes plus the `creator_name` method.
    api_attributes including: [:creator_name]

or as an instance method:

    def api_attributes
       [:id, :created_at, :creator_name, ...]
    end

By default, all attributes are included except for IP addresses and
tsvector columns.
2019-09-08 23:28:02 -05: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
6fc4b63fa8 Model#search: factor out post_tags_match. 2019-08-29 20:44:33 -05:00
evazion
9a3e9747d8 users: replace scopes with associations. 2019-08-29 20:42:50 -05:00
Albert Yi
d97622d1bb Merge pull request #4007 from evazion/fix-4004
Fix #4004: Add additional order by metatags for posts
2019-01-09 14:43:15 -08:00
Albert Yi
4706cae114 Add user permissions for flagging and for giving user feedback 2018-12-11 17:08:31 -08:00
evazion
37b2214472 post_tags_match: replace joins with subqueries.
Refactor various post_tag_match methods to use subqueries instead of joins.

This simplifies things inside PostQueryBuilder, since now we can assume
we're always dealing with a Post relation, rather than some other table
joined with the posts table.
2018-12-11 18:10:20 -06:00
evazion
0eff095a3e Refactor searching text attributes.
* Allow using ApplicationRecord#attribute_matches to search text attributes,
and standardize models on using this instead of duplicating code.

* Remove restrictions that limited wildcard searches to Builders only in various places.
2018-08-31 19:50:46 -05:00
evazion
85ae2cda0d optimization: prefer relation.none over relation.where("false")
Using `relation.none` instead of `relation.where("false")` avoids an sql query.
2018-08-23 15:21:51 -05:00
Albert Yi
36a5f684b5 disable post flag brigading check for system user 2018-07-05 17:08:54 -07:00
Albert Yi
cdcd4d4014 Add additional post flag validation preventing targeting 2018-06-26 15:09:39 -07:00
Albert Yi
72f319ccf3 rename lambda references to use shorthand syntax 2018-05-10 11:18:02 -07:00
evazion
216d735f24 Fix #3696: API: handle boolean params consistently
* Use ApplicationRecord#attribute_matches to handle boolean attributes
  consistently in search methods.

* Add support for searching various boolean attributes that previously
  weren't supported.
2018-05-03 19:57:14 -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
BrokenEagle
5b4ab8d80e Disallow a user from seeing flagger's name on own uploads 2017-11-08 00:37:16 -08:00
r888888888
d4c89bccfc potential fix for #3189 2017-06-29 13:09:33 -07:00
evazion
c1834ab8dd Inherit models from ApplicationRecord instead of ActiveRecord::Base. 2017-06-16 13:28:31 -05:00
Albert Yi
f780b32012 Merge pull request #3145 from r888888888/flagger_metatag
Add "flagger:" and "appealer:" metatags (fixes #3142)
2017-06-14 11:02:08 -07:00
Type-kun
d4944d6c11 Avoid using creator_id as a local variable in flag model 2017-06-14 20:56:02 +05:00
Type-kun
1375cc5307 Added privilege check for seeing flagger usernames
Also reworked all places dealing with flagger names to use said privilege
2017-06-14 20:43:25 +05:00
r888888888
d9ea925f4e add support for searching for dup-related flags 2017-06-12 15:25:07 -07:00
r888888888
6eb5a4c017 fixes #3096 2017-05-30 12:13:08 -07:00
evazion
02b3622f12 api: allow search[*_id] params to accept lists of ids in more places. 2017-05-23 15:45:40 -05:00
evazion
2259506bc2 flags: disallow flagging pending posts. 2017-05-19 14:37:38 -05:00
evazion
3570ace017 flags: ignore flagging rate-limits when deleting posts. 2017-05-17 23:48:37 -05:00
evazion
31a38ea39a flags: add flag cooldown test. 2017-05-04 17:37:59 -05:00
evazion
3b37bb6142 flags: add 3 day flagging cooldown period. 2017-05-04 16:51:49 -05:00
evazion
9f64857719 flags: move status locked check to post_flag.rb. 2017-05-04 16:51:49 -05:00
evazion
54b4a2e0c5 /post_{flags,appeals}: default to fulltext search for reason field. 2017-04-16 21:15:23 -05:00
evazion
8d45bb6d52 /post_{flags,appeals}: allow searching by tags. 2017-04-07 19:37:26 -05:00
evazion
652e251040 /post_{flags,appeals}: add uploader, approver, flag/appeal count columns.
Also include '»' links next to uploader/approver names for drilling down
the search by a given user.
2017-04-07 19:37:26 -05:00
evazion
3ae8cc5586 post_flags.rb: add 'rejected' and 'deleted' categories.
Includes a category field in /post_flags.json.

Adds 'rejected' and 'deleted' search categories. Categories:

* unapproved - deleted after going unapproved in first three days
* rejected   - deleted after being manually flagged
* deleted    - either of the above
* banned     - artist requested removal
* normal     - none of the above (a "normal" manual flag)
2017-04-07 19:37:26 -05:00
r888888888
c3c4952e35 do not limit flags for system user 2017-03-17 12:17:27 -07:00
r888888888
ecdea34323 revert e7b3fae215 2017-03-17 12:13:27 -07:00
r888888888
e7b3fae215 change daily flag limit to 5/day 2017-03-16 14:32:04 -07:00
Albert Yi
60eebd9608 fix chaining of hidden_attributes/method_attributes 2016-10-27 14:53:25 -07: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
Type-kun
d5fb37f675 Display flag creator ID in API for Mod+
Completely fixes #2640
2016-08-26 23:18:11 +05:00
r888888888
f5ee618342 fixes #2640: Change some API representations 2016-08-22 10:41:34 -07:00
Toks
aa936a1cac Fix not being able to see list of your own flags
fixes #2535
2015-10-12 10:05:23 -04:00
r888888888
1d9596d7f2 fixes #2417 2015-06-29 18:17:59 -07:00
Toks
38f51306a8 fix #2314 and appeals 2014-11-30 16:10:17 -05:00