From 6480864718a09689d2684d3e53df35450b528dfe Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 15 Oct 2015 15:24:24 -0700 Subject: [PATCH] fixes #2469 --- app/controllers/application_controller.rb | 2 +- .../moderator/invitations_controller.rb | 2 +- app/helpers/admin/users_helper.rb | 1 - app/helpers/application_helper.rb | 2 +- app/helpers/moderator/dashboards_helper.rb | 2 +- app/helpers/moderator/invitations_helper.rb | 2 +- app/logical/anonymous_user.rb | 6 ++++- app/logical/daily_maintenance.rb | 1 - app/logical/reports/contributors.rb | 2 +- app/logical/reports/user_promotions.rb | 2 +- app/logical/user_upload_clamper.rb | 27 ------------------- app/models/artist.rb | 4 +-- app/models/dmail_filter.rb | 2 +- app/models/favorite_group.rb | 2 +- app/models/forum_post.rb | 2 +- app/models/forum_topic.rb | 2 +- app/models/janitor_trial.rb | 2 +- app/models/pool.rb | 2 +- app/models/post.rb | 4 +-- app/models/tag.rb | 2 +- app/models/upload.rb | 2 +- app/models/user.rb | 27 ++++++++----------- app/presenters/user_presenter.rb | 2 +- app/views/moderator/invitations/new.html.erb | 5 ++++ app/views/uploads/new.html.erb | 6 ++--- doc/api.txt | 1 - script/fixes/037_enable_can_upload_free.rb | 14 ++++++++++ test/factories/user.rb | 3 ++- .../moderator/invitations_controller_test.rb | 5 ++-- test/unit/user_test.rb | 27 +++++-------------- 30 files changed, 70 insertions(+), 93 deletions(-) delete mode 100644 app/logical/user_upload_clamper.rb create mode 100644 script/fixes/037_enable_can_upload_free.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42de71490..7b329fb07 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -116,7 +116,7 @@ protected end end - %w(member banned builder gold platinum contributor janitor moderator admin).each do |level| + %w(member banned builder gold platinum janitor moderator admin).each do |level| define_method("#{level}_only") do if !CurrentUser.user.is_banned? && CurrentUser.user.__send__("is_#{level}?") true diff --git a/app/controllers/moderator/invitations_controller.rb b/app/controllers/moderator/invitations_controller.rb index 2d475756f..c0caf36e1 100644 --- a/app/controllers/moderator/invitations_controller.rb +++ b/app/controllers/moderator/invitations_controller.rb @@ -6,7 +6,7 @@ module Moderator end def create - User.find(params[:invitation][:user_id]).invite!(params[:invitation][:level]) + User.find(params[:invitation][:user_id]).invite!(params[:invitation][:level], params[:invitation][:can_upload_free]) redirect_to moderator_invitations_path end diff --git a/app/helpers/admin/users_helper.rb b/app/helpers/admin/users_helper.rb index 8728fff09..e078bf9f2 100644 --- a/app/helpers/admin/users_helper.rb +++ b/app/helpers/admin/users_helper.rb @@ -5,7 +5,6 @@ module Admin::UsersHelper ["Gold", User::Levels::GOLD], ["Platinum", User::Levels::PLATINUM], ["Builder", User::Levels::BUILDER], - ["Contributor", User::Levels::CONTRIBUTOR], ["Janitor", User::Levels::JANITOR], ["Moderator", User::Levels::MODERATOR], ["Admin", User::Levels::ADMIN] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a9dff7022..f701150c2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -96,7 +96,7 @@ module ApplicationHelper html << " [" + link_to("+", new_user_feedback_path(:user_feedback => {:category => "positive", :user_id => user.id})) + "]" unless user.is_gold? - html << " [" + link_to("invite", new_moderator_invitation_path(:invitation => {:name => user.name, :level => User::Levels::CONTRIBUTOR})) + "]" + html << " [" + link_to("invite", new_moderator_invitation_path(:invitation => {:name => user.name}, :flag => "can_upload_free")) + "]" end else html << " [" + link_to("–".html_safe, new_user_feedback_path(:user_feedback => {:category => "negative", :user_id => user.id})) + "]" diff --git a/app/helpers/moderator/dashboards_helper.rb b/app/helpers/moderator/dashboards_helper.rb index e7c872280..ea966ad41 100644 --- a/app/helpers/moderator/dashboards_helper.rb +++ b/app/helpers/moderator/dashboards_helper.rb @@ -5,7 +5,7 @@ module Moderator ["", ""], ["Member", 20], ["Gold", 30], - ["Contributor", 33], + ["Platinum", 31], ["Janitor", 35], ["Moderator", 40], ["Admin", 50] diff --git a/app/helpers/moderator/invitations_helper.rb b/app/helpers/moderator/invitations_helper.rb index dc5e893d2..14f1cd60a 100644 --- a/app/helpers/moderator/invitations_helper.rb +++ b/app/helpers/moderator/invitations_helper.rb @@ -3,7 +3,7 @@ module Moderator def level_select choices = [] choices << ["Gold", User::Levels::GOLD] - choices << ["Contributor", User::Levels::CONTRIBUTOR] + choices << ["Platinum", User::Levels::PLATINUM] select(:invitation, :level, choices) end end diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index 1e8393f82..752999fc4 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -229,7 +229,11 @@ class AnonymousUser [] end - %w(member banned gold builder platinum contributor janitor moderator admin).each do |name| + def can_upload_free? + false + end + + %w(member banned gold builder platinum janitor moderator admin).each do |name| define_method("is_#{name}?") do false end diff --git a/app/logical/daily_maintenance.rb b/app/logical/daily_maintenance.rb index c703397fe..fc7802d5b 100644 --- a/app/logical/daily_maintenance.rb +++ b/app/logical/daily_maintenance.rb @@ -8,7 +8,6 @@ class DailyMaintenance Delayed::Job.delete_all(['created_at < ?', 7.days.ago]) PostVote.delete_all(['created_at < ?', 1.month.ago]) CommentVote.delete_all(['created_at < ?', 1.month.ago]) - # UserUploadClamper.new.clamp_all! TagSubscription.process_all ApiCacheGenerator.new.generate_tag_cache PostDisapproval.prune! diff --git a/app/logical/reports/contributors.rb b/app/logical/reports/contributors.rb index 1a8b69392..e4ecbb072 100644 --- a/app/logical/reports/contributors.rb +++ b/app/logical/reports/contributors.rb @@ -3,7 +3,7 @@ require 'statistics2' module Reports class Contributors < User def users - ::User.where("users.level >= ? and users.post_upload_count >= 250", ::User::Levels::CONTRIBUTOR).order("created_at desc").map {|x| Reports::UserPromotions::User.new(x)} + ::User.where("users.bit_prefs & ? > 0 and users.post_upload_count >= 250", ::User.flag_value_for("can_upload_free")).order("created_at desc").map {|x| Reports::UserPromotions::User.new(x)} end end end diff --git a/app/logical/reports/user_promotions.rb b/app/logical/reports/user_promotions.rb index a1d535452..0df34befe 100644 --- a/app/logical/reports/user_promotions.rb +++ b/app/logical/reports/user_promotions.rb @@ -66,7 +66,7 @@ module Reports end def users - ::User.where("users.level < ? and users.post_upload_count >= 250", ::User::Levels::CONTRIBUTOR).order("created_at desc").map {|x| Reports::UserPromotions::User.new(x)} + ::User.where("users.bit_prefs & ? > 0 and users.post_upload_count >= 250", ::User.flag_value_for("can_upload_free")).order("created_at desc").map {|x| Reports::UserPromotions::User.new(x)} end end end diff --git a/app/logical/user_upload_clamper.rb b/app/logical/user_upload_clamper.rb deleted file mode 100644 index a6962c64a..000000000 --- a/app/logical/user_upload_clamper.rb +++ /dev/null @@ -1,27 +0,0 @@ -class UserUploadClamper - def clamp_all! - users.each do |user| - if clamp_user?(user) - clamp_user!(user) - end - end - end - - def users - User.where("post_upload_count >= 5000 and base_upload_limit is null and level <= ?", User::Levels::CONTRIBUTOR).limit(50) - end - - def clamp_user?(user) - Reports::UserPromotions.deletion_confidence_interval_for(user) >= 7 - end - - def clamp_user!(user) - upload_limit = (Post.for_user(user).deleted.where("is_banned = false").count / 4) + 10 - user.update_attribute(:base_upload_limit, upload_limit) - CurrentUser.scoped(User.admins.first, "127.0.0.1") do - user.promote_to!(User::Levels::BUILDER) if user.is_contributor? - Dmail.create_split(:to_id => user.id, :title => "Post Upload Limit", :body => "You are receiving this message because a large percentage of your uploads are being deleted. For this reason you will now be limited to 10 uploads a day.") - ModAction.create(:description => "user ##{user.id} (#{user.name}) clamped") - end - end -end diff --git a/app/models/artist.rb b/app/models/artist.rb index 405f688bb..a6d7b1387 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -14,8 +14,8 @@ class Artist < ActiveRecord::Base has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name" has_one :tag, :foreign_key => "name", :primary_key => "name" accepts_nested_attributes_for :wiki_page - attr_accessible :body, :name, :url_string, :other_names, :other_names_comma, :group_name, :wiki_page_attributes, :notes, :as => [:member, :gold, :builder, :platinum, :contributor, :janitor, :moderator, :default, :admin] - attr_accessible :is_active, :as => [:builder, :contributor, :janitor, :moderator, :default, :admin] + attr_accessible :body, :name, :url_string, :other_names, :other_names_comma, :group_name, :wiki_page_attributes, :notes, :as => [:member, :gold, :builder, :platinum, :janitor, :moderator, :default, :admin] + attr_accessible :is_active, :as => [:builder, :janitor, :moderator, :default, :admin] attr_accessible :is_banned, :as => :admin module UrlMethods diff --git a/app/models/dmail_filter.rb b/app/models/dmail_filter.rb index 4bdefc671..b35a9a238 100644 --- a/app/models/dmail_filter.rb +++ b/app/models/dmail_filter.rb @@ -1,6 +1,6 @@ class DmailFilter < ActiveRecord::Base belongs_to :user - attr_accessible :user_id, :words, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin] + attr_accessible :user_id, :words, :as => [:moderator, :janitor, :gold, :member, :anonymous, :default, :builder, :admin] validates_presence_of :user before_validation :initialize_user diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index c1e0425a0..1d776d9d1 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -11,7 +11,7 @@ class FavoriteGroup < ActiveRecord::Base validate :creator_can_create_favorite_groups, :on => :create validate :validate_number_of_posts before_save :update_post_count - attr_accessible :name, :post_ids, :post_id_array, :as => [:member, :gold, :platinum, :builder, :contributor, :janitor, :moderator, :admin, :default] + attr_accessible :name, :post_ids, :post_id_array, :as => [:member, :gold, :platinum, :builder, :janitor, :moderator, :admin, :default] module SearchMethods def for_creator(user_id) diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index d7a9f5b44..281c1cedf 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -1,7 +1,7 @@ class ForumPost < ActiveRecord::Base include Mentionable - attr_accessible :body, :topic_id, :as => [:member, :builder, :janitor, :gold, :platinum, :contributor, :admin, :moderator, :default] + attr_accessible :body, :topic_id, :as => [:member, :builder, :janitor, :gold, :platinum, :admin, :moderator, :default] attr_accessible :is_locked, :is_sticky, :is_deleted, :as => [:admin, :moderator] attr_readonly :topic_id belongs_to :creator, :class_name => "User" diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index bc0046a3e..2a801ea50 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -5,7 +5,7 @@ class ForumTopic < ActiveRecord::Base 2 => "Bugs & Features" } - attr_accessible :title, :original_post_attributes, :category_id, :as => [:member, :builder, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default] + attr_accessible :title, :original_post_attributes, :category_id, :as => [:member, :builder, :gold, :platinum, :janitor, :moderator, :admin, :default] attr_accessible :is_sticky, :is_locked, :is_deleted, :as => [:admin, :moderator] belongs_to :creator, :class_name => "User" belongs_to :updater, :class_name => "User" diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb index 361f77a51..e2ee26556 100644 --- a/app/models/janitor_trial.rb +++ b/app/models/janitor_trial.rb @@ -27,7 +27,7 @@ class JanitorTrial < ActiveRecord::Base def self.message_candidates! admin = User.admins.first - User.where("last_logged_in_at >= ? and created_at <= ? and email is not null and (favorite_count >= 400 OR post_upload_count >= 400) and level between ? and ?", 1.week.ago, 6.months.ago, User::Levels::MEMBER, User::Levels::CONTRIBUTOR).order("random()").limit(10).each do |user| + User.where("last_logged_in_at >= ? and created_at <= ? and email is not null and (favorite_count >= 400 OR post_upload_count >= 400) and bit_prefs & ? = 0", 1.week.ago, 6.months.ago, User.flag_value_for("can_approve_posts")).order("random()").limit(10).each do |user| if !Dmail.where("from_id = ? and to_id = ? and title = ?", admin.id, user.id, "Test Janitor Invitation").exists? favorites = user.favorites.order("random()").limit(400).map(&:post_id) uploads = user.posts.order("random()").limit(400).map(&:id) diff --git a/app/models/pool.rb b/app/models/pool.rb index 8f310bf26..bc3f0db37 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -18,7 +18,7 @@ class Pool < ActiveRecord::Base after_save :create_version after_create :synchronize! before_destroy :create_mod_action_for_destroy - attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :category, :as => [:member, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default] + attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :category, :as => [:member, :gold, :platinum, :janitor, :moderator, :admin, :default] attr_accessible :is_deleted, :as => [:moderator, :admin] module SearchMethods diff --git a/app/models/post.rb b/app/models/post.rb index 651776144..03c2be53e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -42,8 +42,8 @@ class Post < ActiveRecord::Base has_many :favorites, :dependent => :destroy validates_uniqueness_of :md5 validate :post_is_not_its_own_parent - attr_accessible :source, :rating, :tag_string, :old_tag_string, :old_parent_id, :old_source, :old_rating, :last_noted_at, :parent_id, :has_embedded_notes, :as => [:member, :builder, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default] - attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :contributor, :janitor, :moderator, :admin] + attr_accessible :source, :rating, :tag_string, :old_tag_string, :old_parent_id, :old_source, :old_rating, :last_noted_at, :parent_id, :has_embedded_notes, :as => [:member, :builder, :gold, :platinum, :janitor, :moderator, :admin, :default] + attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :janitor, :moderator, :admin] attr_accessible :is_status_locked, :as => [:admin] module FileMethods diff --git a/app/models/tag.rb b/app/models/tag.rb index 0dfb4c635..f08a3c421 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,7 +1,7 @@ class Tag < ActiveRecord::Base METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv" SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm" - attr_accessible :category, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin] + attr_accessible :category, :as => [:moderator, :janitor, :gold, :member, :anonymous, :default, :builder, :admin] attr_accessible :is_locked, :as => [:moderator, :admin] has_one :wiki_page, :foreign_key => "title", :primary_key => "name" diff --git a/app/models/upload.rb b/app/models/upload.rb index cf5be2e70..084f44bc2 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -178,7 +178,7 @@ class Upload < ActiveRecord::Base p.uploader_ip_addr = uploader_ip_addr p.parent_id = parent_id - if !uploader.is_contributor? || upload_as_pending? + if !uploader.can_upload_free? || upload_as_pending? p.is_pending = true end end diff --git a/app/models/user.rb b/app/models/user.rb index 34e89792c..1b464e9e5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,7 +11,6 @@ class User < ActiveRecord::Base GOLD = 30 PLATINUM = 31 BUILDER = 32 - CONTRIBUTOR = 33 JANITOR = 35 MODERATOR = 40 ADMIN = 50 @@ -32,13 +31,14 @@ class User < ActiveRecord::Base show_deleted_children has_saved_searches can_approve_posts + can_upload_free ) include Danbooru::HasBitFlags 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, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin] + 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, :as => [:moderator, :janitor, :gold, :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" @@ -90,8 +90,14 @@ class User < ActiveRecord::Base end module InvitationMethods - def invite!(level) - if level.to_i <= Levels::CONTRIBUTOR + def invite!(level, can_upload_free) + if can_upload_free + self.can_upload_free = true + else + self.can_upload_free = false + end + + if level.to_i <= Levels::BUILDER self.level = level self.inviter_id = CurrentUser.id save @@ -274,7 +280,6 @@ class User < ActiveRecord::Base "Gold" => Levels::GOLD, "Platinum" => Levels::PLATINUM, "Builder" => Levels::BUILDER, - "Contributor" => Levels::CONTRIBUTOR, "Janitor" => Levels::JANITOR, "Moderator" => Levels::MODERATOR, "Admin" => Levels::ADMIN @@ -307,9 +312,6 @@ class User < ActiveRecord::Base when Levels::BUILDER :builder - when Levels::CONTRIBUTOR - :contributor - when Levels::MODERATOR :moderator @@ -342,9 +344,6 @@ class User < ActiveRecord::Base when Levels::PLATINUM "Platinum" - when Levels::CONTRIBUTOR - "Contributor" - when Levels::JANITOR "Janitor" @@ -379,10 +378,6 @@ class User < ActiveRecord::Base level >= Levels::PLATINUM end - def is_contributor? - level >= Levels::CONTRIBUTOR - end - def is_janitor? level >= Levels::JANITOR end @@ -472,7 +467,7 @@ class User < ActiveRecord::Base end def can_upload? - if is_contributor? + if can_upload_free? true elsif created_at > 1.week.ago false diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index ed3c8a268..50f22a331 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -50,7 +50,7 @@ class UserPresenter end def upload_limit - if user.is_contributor? + if user.can_upload_free? return "none" end diff --git a/app/views/moderator/invitations/new.html.erb b/app/views/moderator/invitations/new.html.erb index f95c9c195..519b11fe9 100644 --- a/app/views/moderator/invitations/new.html.erb +++ b/app/views/moderator/invitations/new.html.erb @@ -13,6 +13,11 @@ <%= level_select %> +
+ + <%= check_box :invitation, :can_upload_free %> +
+ <%= submit_tag %> <% end %> diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index 3bd6a3866..67ffcf25c 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -2,12 +2,12 @@

Upload

- <% if CurrentUser.user.can_upload? %> + <% if CurrentUser.can_upload? %>

Before uploading, please read the <%= link_to "how to upload guide", wiki_pages_path(:title => "howto:upload") %>.

- <% unless CurrentUser.is_contributor? %> + <% unless CurrentUser.can_upload_free? %>

You can upload <%= pluralize CurrentUser.upload_limit, "more post" %> today.

<% end %> @@ -27,7 +27,7 @@ <%= hidden_field_tag :normalized_url, @normalized_url %> <%= f.hidden_field :referer_url, :value => @source.try(:referer_url) %> - <% if CurrentUser.is_contributor? %> + <% if CurrentUser.can_upload_free? %>