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
This commit is contained in:
r888888888
2018-04-02 10:51:26 -07:00
committed by Albert Yi
parent 01eda51020
commit abce4d2551
362 changed files with 4796 additions and 4799 deletions

View File

@@ -15,7 +15,7 @@ class User < ApplicationRecord
ADMIN = 50
end
# Used for `before_filter :<role>_only`. Must have a corresponding `is_<role>?` method.
# Used for `before_action :<role>_only`. Must have a corresponding `is_<role>?` method.
Roles = Levels.constants.map(&:downcase) + [
:anonymous,
:banned,
@@ -64,11 +64,10 @@ class User < ApplicationRecord
has_bit_flags BOOLEAN_ATTRIBUTES, :field => "bit_prefs"
attr_accessor :password, :old_password
attr_accessible :dmail_filter_attributes, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :disable_categorized_saved_searches, :disable_tagged_filenames, :enable_recent_searches, :disable_cropped_thumbnails, :disable_mobile_gestures, :enable_safe_mode, :disable_responsive_mode, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
attr_accessible :level, :as => :admin
after_initialize :initialize_attributes, if: :new_record?
validates :name, user_name: true, on: :create
validates_uniqueness_of :email, :case_sensitive => false, :if => lambda {|rec| rec.email.present? && rec.email_changed? }
validates_uniqueness_of :email, :case_sensitive => false, :if => lambda {|rec| rec.email.present? && rec.saved_change_to_email? }
validates_length_of :password, :minimum => 5, :if => lambda {|rec| rec.new_record? || rec.password.present?}
validates_inclusion_of :default_image_size, :in => %w(large original)
validates_inclusion_of :per_page, :in => 1..100
@@ -82,7 +81,6 @@ class User < ApplicationRecord
before_validation :normalize_email
before_create :encrypt_password_on_create
before_update :encrypt_password_on_update
before_create :initialize_default_boolean_attributes
after_save :update_cache
after_update :update_remote_cache
before_create :promote_to_admin_if_first_user
@@ -105,7 +103,7 @@ class User < ApplicationRecord
has_many :saved_searches
has_many :forum_posts, lambda {order("forum_posts.created_at, forum_posts.id")}, :foreign_key => "creator_id"
has_many :user_name_change_requests, lambda {visible.order("user_name_change_requests.created_at desc")}
belongs_to :inviter, :class_name => "User"
belongs_to :inviter, class_name: "User", optional: true
after_update :create_mod_action
accepts_nested_attributes_for :dmail_filter
@@ -191,7 +189,7 @@ class User < ApplicationRecord
end
def update_remote_cache
if name_changed?
if saved_change_to_name?
Danbooru.config.other_server_hosts.each do |server|
HTTParty.delete("http://#{server}/users/#{id}/cache", Danbooru.config.httparty_options)
end
@@ -223,7 +221,7 @@ class User < ApplicationRecord
self.bcrypt_password_hash = User.bcrypt(password)
return true
else
errors[:old_password] = "is incorrect"
errors[:old_password] << "is incorrect"
return false
end
end
@@ -385,6 +383,10 @@ class User < ApplicationRecord
level_string.downcase.to_sym
end
def level_string_before_last_save
level_string(level_before_last_save)
end
def level_string_was
level_string(level_was)
end
@@ -438,8 +440,8 @@ class User < ApplicationRecord
end
def create_mod_action
if level_changed?
ModAction.log(%{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}},:user_level)
if saved_change_to_level?
ModAction.log(%{"#{name}":/users/#{id} level changed #{level_string_before_last_save} -> #{level_string}},:user_level)
end
end
@@ -916,8 +918,8 @@ class User < ApplicationRecord
extend SearchMethods
include StatisticsMethods
def initialize_default_image_size
self.default_image_size = "large"
def as_current(&block)
CurrentUser.as(self, &block)
end
def can_update?(object, foreign_key = :user_id)
@@ -936,7 +938,8 @@ class User < ApplicationRecord
!CurrentUser.is_admin? && enable_privacy_mode? && CurrentUser.user.id != id
end
def initialize_default_boolean_attributes
def initialize_attributes
self.last_ip_addr ||= CurrentUser.ip_addr
self.enable_post_navigation = true
self.new_post_navigation_layout = true
self.enable_sequential_post_navigation = true