diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index 91fd06aba..2772b420a 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -172,6 +172,10 @@ class AnonymousUser def statement_timeout 3_000 end + + def per_page + Danbooru.config.posts_per_page + end %w(member banned privileged builder platinum contributor janitor moderator admin).each do |name| define_method("is_#{name}?") do diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index c569503b2..7d5b89df0 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -5,7 +5,7 @@ module PostSets def initialize(tags, page = 1, per_page = nil) @tag_array = Tag.scan_query(tags) @page = page - @per_page = (per_page || Danbooru.config.posts_per_page).to_i + @per_page = (per_page || CurrentUser.per_page).to_i @per_page = 200 if @per_page > 200 end diff --git a/app/models/user.rb b/app/models/user.rb index 9e04de7b9..2c7f31f08 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,7 +17,7 @@ class User < ActiveRecord::Base end attr_accessor :password, :old_password - attr_accessible :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, :as => [:moderator, :janitor, :contributor, :privileged, :member, :anonymous, :default, :builder, :admin] + attr_accessible :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, :as => [:moderator, :janitor, :contributor, :privileged, :member, :anonymous, :default, :builder, :admin] attr_accessible :level, :as => :admin validates_length_of :name, :within => 2..100, :on => :create validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons" @@ -25,11 +25,13 @@ class User < ActiveRecord::Base validates_uniqueness_of :email, :case_sensitive => false, :if => lambda {|rec| rec.email.present?} 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 => [20, 50, 100] validates_confirmation_of :password validates_presence_of :email, :if => lambda {|rec| rec.new_record? && Danbooru.config.enable_email_verification?} validates_presence_of :comment_threshold validate :validate_ip_addr_is_not_banned, :on => :create before_validation :normalize_blacklisted_tags + before_validation :set_per_page before_create :encrypt_password_on_create before_update :encrypt_password_on_update after_save :update_cache @@ -345,6 +347,10 @@ class User < ActiveRecord::Base ModAction.create(:description => "#{name} level changed #{level_string(level_was)} -> #{level_string} by #{CurrentUser.name}") end end + + def set_per_page + self.per_page = Danbooru.config.posts_per_page unless is_privileged? + end end module EmailMethods diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 39d16ee61..dbadcd76d 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -17,6 +17,10 @@ <%= f.input :enable_post_navigation, :as => :select, :include_blank => false, :label => "Enable keyboard shortcuts" %> <%= f.input :new_post_navigation_layout, :as => :select, :label => "Pool links", :include_blank => false, :collection => [["Bottom", "true"], ["Top", "false"]], :hint => "When browsing pools, where do you want the navigation links to be placed?" %> <%= f.input :enable_sequential_post_navigation, :as => :select, :label => "Enable slideshow mode", :hint => "Show prev/next links when viewing a post", :include_blank => false %> + + <% if CurrentUser.is_privileged? %> + <%= f.input :per_page, :as => :select, :label => "Posts per page", :collection => [20, 50, 100], :include_blank => false %> + <% end %>