diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 710aaa79a..4bf4ce4a3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -147,7 +147,7 @@ module ApplicationHelper def link_to_user(user, options = {}) return "anonymous" if user.blank? - user_class = user.level_class + user_class = "user-#{user.level_string.downcase}" user_class = user_class + " user-post-approver" if user.can_approve_posts? user_class = user_class + " user-post-uploader" if user.can_upload_free? user_class = user_class + " user-super-voter" if user.is_super_voter? diff --git a/app/models/user.rb b/app/models/user.rb index ff64278e0..954d602ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,7 +7,6 @@ class User < ApplicationRecord module Levels ANONYMOUS = 0 - BLOCKED = 10 MEMBER = 20 GOLD = 30 PLATINUM = 31 @@ -77,7 +76,6 @@ class User < ApplicationRecord validates_inclusion_of :default_image_size, :in => %w(large original) validates_inclusion_of :per_page, :in => 1..100 validates_confirmation_of :password - validates_presence_of :email, :if => ->(rec) { rec.new_record? && Danbooru.config.enable_email_verification?} validates_presence_of :comment_threshold validate :validate_ip_addr_is_not_banned, :on => :create validate :validate_sock_puppets, :on => :create, :if => -> { Danbooru.config.enable_sock_puppet_validation? } @@ -89,7 +87,6 @@ class User < ApplicationRecord after_save :update_cache before_create :promote_to_admin_if_first_user before_create :customize_new_user - #after_create :notify_sock_puppets has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy has_many :posts, :foreign_key => "uploader_id" has_many :post_approvals, :dependent => :destroy @@ -294,9 +291,6 @@ class User < ApplicationRecord when Levels::ANONYMOUS "Anonymous" - when Levels::BLOCKED - "Banned" - when Levels::MEMBER "Member" @@ -342,10 +336,6 @@ class User < ApplicationRecord Danbooru.config.customize_new_user(self) end - def role - level_string.downcase.to_sym - end - def level_string_was level_string(level_was) end @@ -362,10 +352,6 @@ class User < ApplicationRecord level >= Levels::MEMBER end - def is_blocked? - is_banned? - end - def is_builder? level >= Levels::BUILDER end @@ -382,10 +368,6 @@ class User < ApplicationRecord level >= Levels::MODERATOR end - def is_mod? - level >= Levels::MODERATOR - end - def is_admin? level >= Levels::ADMIN end @@ -403,29 +385,9 @@ class User < ApplicationRecord self.per_page = Danbooru.config.posts_per_page end end - - def level_class - "user-#{level_string.downcase}" - end end module EmailMethods - def is_verified? - email_verification_key.blank? - end - - def generate_email_verification_key - self.email_verification_key = Digest::SHA1.hexdigest("#{Time.now.to_f}--#{name}--#{rand(1_000_000)}--") - end - - def verify!(key) - if email_verification_key == key - self.update_column(:email_verification_key, nil) - else - raise User::Error.new("Verification key does not match") - end - end - def normalize_email self.email = nil if email.blank? end @@ -458,10 +420,6 @@ class User < ApplicationRecord end end - def show_saved_searches? - true - end - def can_upload? if can_upload_free? true @@ -760,14 +718,6 @@ class User < ApplicationRecord end end - def find_for_password_reset(name, email) - if email.blank? - where("FALSE") - else - where(["name = ? AND email = ?", name, email]) - end - end - def search(params) q = super @@ -880,10 +830,6 @@ class User < ApplicationRecord CurrentUser.as(self, &block) end - def can_update?(object, foreign_key = :user_id) - is_moderator? || is_admin? || object.__send__(foreign_key) == id - end - def dmail_count if has_mail? "(#{unread_dmail_count})" diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 4172b1e7d..75987077b 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -413,11 +413,6 @@ module Danbooru #END TAG - # If enabled, users must verify their email addresses. - def enable_email_verification? - false - end - # Any custom code you want to insert into the default layout without # having to modify the templates. def custom_html_header_content diff --git a/db/populate.rb b/db/populate.rb index c7162525b..37602c794 100644 --- a/db/populate.rb +++ b/db/populate.rb @@ -47,7 +47,7 @@ if User.count == 0 ) CurrentUser.user = user - User::Levels.constants.reject{|x| [:ADMIN, :BLOCKED].include?(x)}.each do |level| + User::Levels.constants.reject{ |x| x == :ADMIN }.each do |level| newuser = User.create( :name => level.to_s.downcase, :password => "password1", diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index d6985dc77..c8fd9170f 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -94,17 +94,6 @@ class UserTest < ActiveSupport::TestCase assert(@user.is_comment_limited?) end - should "verify" do - assert(@user.is_verified?) - @user = FactoryBot.create(:user) - @user.generate_email_verification_key - @user.save - assert(!@user.is_verified?) - assert_raise(User::Error) {@user.verify!("bbb")} - assert_nothing_raised {@user.verify!(@user.email_verification_key)} - assert(@user.is_verified?) - end - should "authenticate" do assert(User.authenticate(@user.name, "password"), "Authentication should have succeeded") assert(!User.authenticate(@user.name, "password2"), "Authentication should not have succeeded")