mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Internal renaming of elder,leader,regular,basic to numbers
Changed internals so trust levels are referred to with TrustLevel[1], TrustLevel[2] etc. This gives us much better flexibility naming trust levels, these names are meant to be controlled by various communities.
This commit is contained in:
parent
c8d3ffb1ee
commit
59d04c0695
49 changed files with 276 additions and 274 deletions
|
@ -127,8 +127,7 @@ class Admin::UsersController < Admin::AdminController
|
|||
|
||||
def trust_level
|
||||
guardian.ensure_can_change_trust_level!(@user)
|
||||
level = TrustLevel.levels[params[:level].to_i]
|
||||
@user.change_trust_level!(level, log_action_for: current_user)
|
||||
@user.change_trust_level!(params[:level].to_i, log_action_for: current_user)
|
||||
|
||||
render_serialized(@user, AdminUserSerializer)
|
||||
rescue Discourse::InvalidAccess => e
|
||||
|
|
|
@ -6,23 +6,23 @@ module Jobs
|
|||
def execute(args)
|
||||
# Demotions
|
||||
demoted_user_ids = []
|
||||
User.real.where(trust_level: TrustLevel.levels[:leader]).find_each do |u|
|
||||
User.real.where(trust_level: TrustLevel[3]).find_each do |u|
|
||||
# Don't demote too soon after being promoted
|
||||
next if UserHistory.for(u, :auto_trust_level_change)
|
||||
.where('created_at >= ?', SiteSetting.leader_promotion_min_duration.to_i.days.ago)
|
||||
.where(previous_value: TrustLevel.levels[:regular].to_s)
|
||||
.where(new_value: TrustLevel.levels[:leader].to_s)
|
||||
.where(previous_value: TrustLevel[2].to_s)
|
||||
.where(new_value: TrustLevel[3].to_s)
|
||||
.exists?
|
||||
|
||||
if Promotion.leader_lost?(u)
|
||||
if Promotion.tl3_lost?(u)
|
||||
demoted_user_ids << u.id
|
||||
Promotion.new(u).change_trust_level!(:regular)
|
||||
Promotion.new(u).change_trust_level!(TrustLevel[2])
|
||||
end
|
||||
end
|
||||
|
||||
# Promotions
|
||||
User.real.where(trust_level: TrustLevel.levels[:regular]).where.not(id: demoted_user_ids).find_each do |u|
|
||||
Promotion.new(u).review_regular
|
||||
User.real.where(trust_level: TrustLevel[2]).where.not(id: demoted_user_ids).find_each do |u|
|
||||
Promotion.new(u).review_tl2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -153,7 +153,7 @@ class Post < ActiveRecord::Base
|
|||
return raw if cook_method == Post.cook_methods[:raw_html]
|
||||
|
||||
# Default is to cook posts
|
||||
cooked = if !self.user || SiteSetting.tl3_links_no_follow || !self.user.has_trust_level?(:leader)
|
||||
cooked = if !self.user || SiteSetting.tl3_links_no_follow || !self.user.has_trust_level?(TrustLevel[3])
|
||||
post_analyzer.cook(*args)
|
||||
else
|
||||
# At trust level 3, we don't apply nofollow to links
|
||||
|
@ -213,7 +213,7 @@ class Post < ActiveRecord::Base
|
|||
|
||||
# Prevent new users from posting the same hosts too many times.
|
||||
def has_host_spam?
|
||||
return false if acting_user.present? && acting_user.has_trust_level?(:basic)
|
||||
return false if acting_user.present? && acting_user.has_trust_level?(TrustLevel[1])
|
||||
|
||||
total_hosts_usage.each do |_, count|
|
||||
return true if count >= SiteSetting.newuser_spam_host_threshold
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# This class performs calculations to determine if a user qualifies for
|
||||
# the Leader (3) trust level.
|
||||
class LeaderRequirements
|
||||
class TrustLevel3Requirements
|
||||
|
||||
include ActiveModel::Serialization
|
||||
|
||||
|
@ -75,7 +75,7 @@ class LeaderRequirements
|
|||
end
|
||||
|
||||
def min_topics_viewed
|
||||
(LeaderRequirements.num_topics_in_time_period.to_i * (SiteSetting.tl3_requires_topics_viewed.to_f / 100.0)).round
|
||||
(TrustLevel3Requirements.num_topics_in_time_period.to_i * (SiteSetting.tl3_requires_topics_viewed.to_f / 100.0)).round
|
||||
end
|
||||
|
||||
def posts_read
|
||||
|
@ -83,7 +83,7 @@ class LeaderRequirements
|
|||
end
|
||||
|
||||
def min_posts_read
|
||||
(LeaderRequirements.num_posts_in_time_period.to_i * (SiteSetting.tl3_requires_posts_read.to_f / 100.0)).round
|
||||
(TrustLevel3Requirements.num_posts_in_time_period.to_i * (SiteSetting.tl3_requires_posts_read.to_f / 100.0)).round
|
||||
end
|
||||
|
||||
def topics_viewed_all_time
|
|
@ -11,6 +11,6 @@ class TrustLevelSetting < EnumSiteSetting
|
|||
end
|
||||
|
||||
def self.valid_values
|
||||
TrustLevel.levels.values.sort
|
||||
TrustLevel.valid_range.to_a
|
||||
end
|
||||
end
|
||||
|
|
|
@ -298,7 +298,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def new_user?
|
||||
created_at >= 24.hours.ago || trust_level == TrustLevel.levels[:newuser]
|
||||
created_at >= 24.hours.ago || trust_level == TrustLevel[0]
|
||||
end
|
||||
|
||||
def seen_before?
|
||||
|
@ -405,7 +405,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
# Does not apply to staff, non-new members or your own topics
|
||||
return false if staff? ||
|
||||
(trust_level != TrustLevel.levels[:newuser]) ||
|
||||
(trust_level != TrustLevel[0]) ||
|
||||
Topic.where(id: topic_id, user_id: id).exists?
|
||||
|
||||
last_action_in_topic = UserAction.last_action_in_topic(id, topic_id)
|
||||
|
@ -438,7 +438,7 @@ class User < ActiveRecord::Base
|
|||
# Use this helper to determine if the user has a particular trust level.
|
||||
# Takes into account admin, etc.
|
||||
def has_trust_level?(level)
|
||||
raise "Invalid trust level #{level}" unless TrustLevel.valid_level?(level)
|
||||
raise "Invalid trust level #{level}" unless TrustLevel.valid?(level)
|
||||
admin? || moderator? || TrustLevel.compare(trust_level, level)
|
||||
end
|
||||
|
||||
|
@ -562,7 +562,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def leader_requirements
|
||||
@lq ||= LeaderRequirements.new(self)
|
||||
@lq ||= TrustLevel3Requirements.new(self)
|
||||
end
|
||||
|
||||
def should_be_redirected_to_top
|
||||
|
|
|
@ -9,12 +9,12 @@ class UserProfile < ActiveRecord::Base
|
|||
|
||||
def bio_excerpt
|
||||
excerpt = PrettyText.excerpt(bio_cooked, 350)
|
||||
return excerpt if excerpt.blank? || user.has_trust_level?(:basic)
|
||||
return excerpt if excerpt.blank? || user.has_trust_level?(TrustLevel[1])
|
||||
PrettyText.strip_links(excerpt)
|
||||
end
|
||||
|
||||
def bio_processed
|
||||
return bio_cooked if bio_cooked.blank? || user.has_trust_level?(:basic)
|
||||
return bio_cooked if bio_cooked.blank? || user.has_trust_level?(TrustLevel[1])
|
||||
PrettyText.strip_links(bio_cooked)
|
||||
end
|
||||
|
||||
|
@ -65,7 +65,7 @@ class UserProfile < ActiveRecord::Base
|
|||
|
||||
def cooked
|
||||
if self.bio_raw.present?
|
||||
PrettyText.cook(self.bio_raw, omit_nofollow: user.has_trust_level?(:leader) && !SiteSetting.tl3_links_no_follow)
|
||||
PrettyText.cook(self.bio_raw, omit_nofollow: user.has_trust_level?(TrustLevel[3]) && !SiteSetting.tl3_links_no_follow)
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ class AdminDetailedUserSerializer < AdminUserSerializer
|
|||
has_one :approved_by, serializer: BasicUserSerializer, embed: :objects
|
||||
has_one :api_key, serializer: ApiKeySerializer, embed: :objects
|
||||
has_one :suspended_by, serializer: BasicUserSerializer, embed: :objects
|
||||
has_one :leader_requirements, serializer: LeaderRequirementsSerializer, embed: :objects
|
||||
has_one :leader_requirements, serializer: TrustLevel3RequirementsSerializer, embed: :objects
|
||||
has_many :groups, embed: :object, serializer: BasicGroupSerializer
|
||||
|
||||
def can_revoke_admin
|
||||
|
@ -70,7 +70,7 @@ class AdminDetailedUserSerializer < AdminUserSerializer
|
|||
end
|
||||
|
||||
def include_leader_requirements?
|
||||
object.has_trust_level?(:regular)
|
||||
object.has_trust_level?(TrustLevel[2])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class LeaderRequirementsSerializer < ApplicationSerializer
|
||||
class TrustLevel3RequirementsSerializer < ApplicationSerializer
|
||||
attributes :time_period,
|
||||
:requirements_met,
|
||||
:days_visited, :min_days_visited,
|
||||
|
@ -13,7 +13,7 @@ class LeaderRequirementsSerializer < ApplicationSerializer
|
|||
:num_likes_received, :min_likes_received
|
||||
|
||||
def time_period
|
||||
LeaderRequirements::TIME_PERIOD
|
||||
TrustLevel3Requirements::TIME_PERIOD
|
||||
end
|
||||
|
||||
def requirements_met
|
|
@ -18,7 +18,7 @@ class SpamRule::AutoBlock
|
|||
|
||||
def block?
|
||||
@user.blocked? or
|
||||
(!@user.has_trust_level?(:basic) and
|
||||
(!@user.has_trust_level?(TrustLevel[1]) and
|
||||
SiteSetting.num_flags_to_block_new_user > 0 and
|
||||
SiteSetting.num_users_to_block_new_user > 0 and
|
||||
num_spam_flags_against_user >= SiteSetting.num_flags_to_block_new_user and
|
||||
|
|
|
@ -17,8 +17,8 @@ class StaffActionLogger
|
|||
|
||||
def log_trust_level_change(user, old_trust_level, new_trust_level, opts={})
|
||||
raise Discourse::InvalidParameters.new('user is nil') unless user and user.is_a?(User)
|
||||
raise Discourse::InvalidParameters.new('old trust level is invalid') unless TrustLevel.levels.values.include? old_trust_level
|
||||
raise Discourse::InvalidParameters.new('new trust level is invalid') unless TrustLevel.levels.values.include? new_trust_level
|
||||
raise Discourse::InvalidParameters.new('old trust level is invalid') unless TrustLevel.valid? old_trust_level
|
||||
raise Discourse::InvalidParameters.new('new trust level is invalid') unless TrustLevel.valid? new_trust_level
|
||||
UserHistory.create!( params(opts).merge({
|
||||
action: UserHistory.actions[:change_trust_level],
|
||||
target_user_id: user.id,
|
||||
|
|
|
@ -19,7 +19,7 @@ User.seed do |u|
|
|||
u.email_direct = false
|
||||
u.approved = true
|
||||
u.email_private_messages = false
|
||||
u.trust_level = TrustLevel.levels[:elder]
|
||||
u.trust_level = TrustLevel[4]
|
||||
end
|
||||
|
||||
Group.user_trust_level_change!(-1 ,TrustLevel.levels[:elder])
|
||||
Group.user_trust_level_change!(-1 ,TrustLevel[4])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class RemoveTrustLevels < ActiveRecord::Migration
|
||||
def up
|
||||
drop_table :trust_levels
|
||||
change_column_default :users, :trust_level_id, TrustLevel.levels[:new]
|
||||
change_column_default :users, :trust_level_id, TrustLevel[0]
|
||||
rename_column :users, :trust_level_id, :trust_level
|
||||
|
||||
update "UPDATE users set trust_level = 1"
|
||||
|
|
|
@ -44,7 +44,7 @@ class ComposerMessagesFinder
|
|||
def check_avatar_notification
|
||||
|
||||
# A user has to be basic at least to be considered for an avatar notification
|
||||
return unless @user.has_trust_level?(:basic)
|
||||
return unless @user.has_trust_level?(TrustLevel[1])
|
||||
|
||||
# We don't notify users who have avatars or who have been notified already.
|
||||
return if @user.uploaded_avatar_id || UserHistory.exists_for_user?(@user, :notified_about_avatar)
|
||||
|
|
|
@ -61,7 +61,7 @@ module Email
|
|||
end
|
||||
|
||||
raise UserNotFoundError if @user.blank?
|
||||
raise UserNotSufficientTrustLevelError.new @user unless @allow_strangers || @user.has_trust_level?(TrustLevel.levels[SiteSetting.email_in_min_trust.to_i])
|
||||
raise UserNotSufficientTrustLevelError.new @user unless @allow_strangers || @user.has_trust_level?(TrustLevel[SiteSetting.email_in_min_trust.to_i])
|
||||
|
||||
create_new_topic
|
||||
else
|
||||
|
|
|
@ -103,7 +103,7 @@ class Guardian
|
|||
end
|
||||
|
||||
def can_moderate?(obj)
|
||||
obj && authenticated? && (is_staff? || (obj.is_a?(Topic) && @user.has_trust_level?(:elder)))
|
||||
obj && authenticated? && (is_staff? || (obj.is_a?(Topic) && @user.has_trust_level?(TrustLevel[4])))
|
||||
end
|
||||
alias :can_move_posts? :can_moderate?
|
||||
alias :can_see_flags? :can_moderate?
|
||||
|
@ -196,7 +196,7 @@ class Guardian
|
|||
!SiteSetting.enable_sso &&
|
||||
SiteSetting.enable_local_logins &&
|
||||
(
|
||||
(!SiteSetting.must_approve_users? && @user.has_trust_level?(:regular)) ||
|
||||
(!SiteSetting.must_approve_users? && @user.has_trust_level?(TrustLevel[2])) ||
|
||||
is_staff?
|
||||
) &&
|
||||
(groups.blank? || is_admin?)
|
||||
|
@ -232,7 +232,7 @@ class Guardian
|
|||
# Can't send message to yourself
|
||||
is_not_me?(target) &&
|
||||
# Have to be a basic level at least
|
||||
@user.has_trust_level?(:basic) &&
|
||||
@user.has_trust_level?(TrustLevel[1]) &&
|
||||
# PMs are enabled
|
||||
(SiteSetting.enable_private_messages ||
|
||||
@user.username == SiteSetting.site_contact_username ||
|
||||
|
|
|
@ -10,7 +10,7 @@ module PostGuardian
|
|||
|
||||
if authenticated? && post
|
||||
# we allow flagging for trust level 1 and higher
|
||||
(is_flag && @user.has_trust_level?(:basic) && not(already_did_flagging)) ||
|
||||
(is_flag && @user.has_trust_level?(TrustLevel[1]) && not(already_did_flagging)) ||
|
||||
|
||||
# not a flagging action, and haven't done it already
|
||||
not(is_flag || already_taken_this_action) &&
|
||||
|
@ -25,7 +25,7 @@ module PostGuardian
|
|||
not(action_key == :like && is_my_own?(post)) &&
|
||||
|
||||
# new users can't notify_user because they are not allowed to send private messages
|
||||
not(action_key == :notify_user && !@user.has_trust_level?(:basic)) &&
|
||||
not(action_key == :notify_user && !@user.has_trust_level?(TrustLevel[1])) &&
|
||||
|
||||
# no voting more than once on single vote topics
|
||||
not(action_key == :vote && opts[:voted_in_topic] && post.topic.has_meta_data_boolean?(:single_vote))
|
||||
|
@ -76,7 +76,7 @@ module PostGuardian
|
|||
return false
|
||||
end
|
||||
|
||||
if is_staff? || @user.has_trust_level?(:elder)
|
||||
if is_staff? || @user.has_trust_level?(TrustLevel[4])
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -149,7 +149,7 @@ module PostGuardian
|
|||
end
|
||||
|
||||
authenticated? &&
|
||||
(is_staff? || @user.has_trust_level?(:elder) || @user.id == post.user_id) &&
|
||||
(is_staff? || @user.has_trust_level?(TrustLevel[4]) || @user.id == post.user_id) &&
|
||||
can_see_post?(post)
|
||||
end
|
||||
|
||||
|
@ -162,7 +162,7 @@ module PostGuardian
|
|||
end
|
||||
|
||||
def can_wiki?
|
||||
is_staff? || @user.has_trust_level?(:elder)
|
||||
is_staff? || @user.has_trust_level?(TrustLevel[4])
|
||||
end
|
||||
|
||||
def can_see_flagged_posts?
|
||||
|
|
|
@ -22,13 +22,13 @@ module TopicGuardian
|
|||
# No users can create posts on deleted topics
|
||||
return false if topic.trashed?
|
||||
|
||||
is_staff? || (authenticated? && user.has_trust_level?(:elder)) || (not(topic.closed? || topic.archived? || topic.trashed?) && can_create_post?(topic))
|
||||
is_staff? || (authenticated? && user.has_trust_level?(TrustLevel[4])) || (not(topic.closed? || topic.archived? || topic.trashed?) && can_create_post?(topic))
|
||||
end
|
||||
|
||||
# Editing Method
|
||||
def can_edit_topic?(topic)
|
||||
return false if Discourse.static_doc_topic_ids.include?(topic.id) && !is_admin?
|
||||
return true if is_staff? || user.has_trust_level?(:leader)
|
||||
return true if is_staff? || user.has_trust_level?(TrustLevel[3])
|
||||
return false if topic.archived
|
||||
is_my_own?(topic)
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ module TopicGuardian
|
|||
end
|
||||
|
||||
def can_reply_as_new_topic?(topic)
|
||||
authenticated? && topic && not(topic.private_message?) && @user.has_trust_level?(:basic)
|
||||
authenticated? && topic && not(topic.private_message?) && @user.has_trust_level?(TrustLevel[1])
|
||||
end
|
||||
|
||||
def can_see_deleted_topics?
|
||||
|
|
|
@ -15,37 +15,36 @@ class Promotion
|
|||
return false if @user.blank?
|
||||
|
||||
# Promotion beyond basic requires some expensive queries, so don't do that here.
|
||||
return false if @user.trust_level >= TrustLevel.levels[:regular]
|
||||
return false if @user.trust_level >= TrustLevel[2]
|
||||
|
||||
trust_key = TrustLevel.levels[@user.trust_level]
|
||||
|
||||
review_method = :"review_#{trust_key}"
|
||||
review_method = :"review_tl#{@user.trust_level}"
|
||||
return send(review_method) if respond_to?(review_method)
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def review_newuser
|
||||
Promotion.basic_met?(@user) && change_trust_level!(:basic)
|
||||
def review_tl0
|
||||
Promotion.tl1_met?(@user) && change_trust_level!(TrustLevel[1])
|
||||
end
|
||||
|
||||
def review_basic
|
||||
Promotion.regular_met?(@user) && change_trust_level!(:regular)
|
||||
def review_tl1
|
||||
Promotion.tl2_met?(@user) && change_trust_level!(TrustLevel[2])
|
||||
end
|
||||
|
||||
def review_regular
|
||||
Promotion.leader_met?(@user) && change_trust_level!(:leader)
|
||||
def review_tl2
|
||||
Promotion.tl3_met?(@user) && change_trust_level!(TrustLevel[3])
|
||||
end
|
||||
|
||||
def change_trust_level!(level, opts = {})
|
||||
raise "Invalid trust level #{level}" unless TrustLevel.valid_level?(level)
|
||||
raise "Invalid trust level #{level}" unless TrustLevel.valid?(level)
|
||||
|
||||
old_level = @user.trust_level
|
||||
new_level = TrustLevel.levels[level]
|
||||
new_level = level
|
||||
|
||||
if new_level < old_level
|
||||
next_up = TrustLevel.levels[new_level+1]
|
||||
key = "#{next_up}_met?"
|
||||
next_up = new_level+1
|
||||
key = "tl#{next_up}_met?"
|
||||
if self.class.respond_to?(key) && self.class.send(key, @user)
|
||||
raise Discourse::InvalidAccess.new, I18n.t('trust_levels.change_failed_explanation',
|
||||
user_name: @user.name,
|
||||
|
@ -79,7 +78,7 @@ class Promotion
|
|||
end
|
||||
|
||||
|
||||
def self.regular_met?(user)
|
||||
def self.tl2_met?(user)
|
||||
stat = user.user_stat
|
||||
return false if stat.topics_entered < SiteSetting.tl2_requires_topics_entered
|
||||
return false if stat.posts_read_count < SiteSetting.tl2_requires_read_posts
|
||||
|
@ -92,7 +91,7 @@ class Promotion
|
|||
true
|
||||
end
|
||||
|
||||
def self.basic_met?(user)
|
||||
def self.tl1_met?(user)
|
||||
stat = user.user_stat
|
||||
return false if stat.topics_entered < SiteSetting.tl1_requires_topics_entered
|
||||
return false if stat.posts_read_count < SiteSetting.tl1_requires_read_posts
|
||||
|
@ -100,12 +99,12 @@ class Promotion
|
|||
return true
|
||||
end
|
||||
|
||||
def self.leader_met?(user)
|
||||
LeaderRequirements.new(user).requirements_met?
|
||||
def self.tl3_met?(user)
|
||||
TrustLevel3Requirements.new(user).requirements_met?
|
||||
end
|
||||
|
||||
def self.leader_lost?(user)
|
||||
LeaderRequirements.new(user).requirements_lost?
|
||||
def self.tl3_lost?(user)
|
||||
TrustLevel3Requirements.new(user).requirements_lost?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -94,7 +94,7 @@ class TopicQuery
|
|||
score = "#{period}_score"
|
||||
create_list(:top, unordered: true) do |topics|
|
||||
topics = topics.joins(:top_topic).where("top_topics.#{score} > 0")
|
||||
if period == :yearly && @user.try(:trust_level) == TrustLevel.levels[:newuser]
|
||||
if period == :yearly && @user.try(:trust_level) == TrustLevel[0]
|
||||
topics.order(TopicQuerySQL.order_top_with_pinned_category_for(score))
|
||||
else
|
||||
topics.order(TopicQuerySQL.order_top_for(score))
|
||||
|
|
|
@ -6,11 +6,11 @@ class TrustLevel
|
|||
|
||||
class << self
|
||||
|
||||
def[](val)
|
||||
if val < 0 || val > 4
|
||||
def[](level)
|
||||
if !valid?(level)
|
||||
raise InvalidTrustLevel
|
||||
end
|
||||
val
|
||||
level
|
||||
end
|
||||
|
||||
def levels
|
||||
|
@ -25,12 +25,16 @@ class TrustLevel
|
|||
end
|
||||
end
|
||||
|
||||
def valid_level?(level)
|
||||
levels.valid?(level)
|
||||
def valid?(level)
|
||||
valid_range === level
|
||||
end
|
||||
|
||||
def valid_range
|
||||
(0..4)
|
||||
end
|
||||
|
||||
def compare(current_level, level)
|
||||
(current_level || levels[:newuser]) >= levels[level] rescue binding.pry
|
||||
(current_level || 0) >= level
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ class Validators::PostValidator < ActiveModel::Validator
|
|||
private
|
||||
|
||||
def acting_user_is_trusted?(post)
|
||||
post.acting_user.present? && post.acting_user.has_trust_level?(:basic)
|
||||
post.acting_user.present? && post.acting_user.has_trust_level?(TrustLevel[1])
|
||||
end
|
||||
|
||||
def add_error_if_count_exceeded(post, key_for_translation, current_count, max_count)
|
||||
|
|
|
@ -159,7 +159,7 @@ class ImportScripts::Base
|
|||
admin.password = SecureRandom.uuid
|
||||
admin.save!
|
||||
admin.grant_admin!
|
||||
admin.change_trust_level!(:regular)
|
||||
admin.change_trust_level!(TrustLevel[4])
|
||||
admin.email_tokens.update_all(confirmed: true)
|
||||
admin
|
||||
end
|
||||
|
@ -280,7 +280,7 @@ class ImportScripts::Base
|
|||
opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email])
|
||||
end
|
||||
opts[:email] = opts[:email].downcase
|
||||
opts[:trust_level] = TrustLevel.levels[:basic] unless opts[:trust_level]
|
||||
opts[:trust_level] = TrustLevel[1] unless opts[:trust_level]
|
||||
opts[:active] = true
|
||||
opts[:import_mode] = true
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class ImportScripts::Vanilla < ImportScripts::Base
|
|||
}
|
||||
|
||||
# if @comments.select { |c| c[:insert_user_id] == user[:user_id] }.map { |c| c[:discussion_id] }.uniq.count > 3
|
||||
# u[:trust_level] = TrustLevel.levels[:regular]
|
||||
# u[:trust_level] = TrustLevel[2]
|
||||
# end
|
||||
|
||||
u
|
||||
|
|
|
@ -49,7 +49,7 @@ def create_admin(seq)
|
|||
admin.password = "password"
|
||||
admin.save
|
||||
admin.grant_admin!
|
||||
admin.change_trust_level!(:regular)
|
||||
admin.change_trust_level!(TrustLevel[4])
|
||||
admin.email_tokens.update_all(confirmed: true)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -107,7 +107,7 @@ describe ComposerMessagesFinder do
|
|||
end
|
||||
|
||||
it "doesn't return notifications for new users" do
|
||||
user.trust_level = TrustLevel.levels[:newuser]
|
||||
user.trust_level = TrustLevel[0]
|
||||
finder.check_avatar_notification.should be_blank
|
||||
end
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ greatest show ever created. Everyone should watch it.
|
|||
to = "some@email.com"
|
||||
|
||||
Fabricate(:category, email_in_allow_strangers: false, email_in: to)
|
||||
SiteSetting.email_in_min_trust = TrustLevel.levels[:elder].to_s
|
||||
SiteSetting.email_in_min_trust = TrustLevel[4].to_s
|
||||
|
||||
# no email in for user
|
||||
expect{
|
||||
|
|
|
@ -64,22 +64,22 @@ describe Guardian do
|
|||
|
||||
describe "trust levels" do
|
||||
it "returns true for a new user liking something" do
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.trust_level = TrustLevel[0]
|
||||
Guardian.new(user).post_can_act?(post, :like).should be_true
|
||||
end
|
||||
|
||||
it "returns false for a new user flagging something as spam" do
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.trust_level = TrustLevel[0]
|
||||
Guardian.new(user).post_can_act?(post, :spam).should be_false
|
||||
end
|
||||
|
||||
it "returns false for a new user flagging something as off topic" do
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.trust_level = TrustLevel[0]
|
||||
Guardian.new(user).post_can_act?(post, :off_topic).should be_false
|
||||
end
|
||||
|
||||
it "returns false for a new user flagging with notify_user" do
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.trust_level = TrustLevel[0]
|
||||
Guardian.new(user).post_can_act?(post, :notify_user).should be_false # because new users can't send private messages
|
||||
end
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ describe Guardian do
|
|||
end
|
||||
|
||||
it "returns false when you are untrusted" do
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.trust_level = TrustLevel[0]
|
||||
Guardian.new(user).can_send_private_message?(another_user).should be_false
|
||||
end
|
||||
|
||||
|
@ -174,7 +174,7 @@ describe Guardian do
|
|||
end
|
||||
|
||||
it "returns false for an untrusted user" do
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.trust_level = TrustLevel[0]
|
||||
Guardian.new(user).can_reply_as_new_topic?(topic).should be_false
|
||||
end
|
||||
|
||||
|
|
|
@ -6,16 +6,16 @@ describe Promotion do
|
|||
describe "review" do
|
||||
it "skips regular users" do
|
||||
# Reviewing users at higher trust levels is expensive, so trigger those reviews in a background job.
|
||||
regular = Fabricate.build(:user, trust_level: TrustLevel.levels[:regular])
|
||||
regular = Fabricate.build(:user, trust_level: TrustLevel[2])
|
||||
promotion = described_class.new(regular)
|
||||
promotion.expects(:review_regular).never
|
||||
promotion.expects(:review_tl2).never
|
||||
promotion.review
|
||||
end
|
||||
end
|
||||
|
||||
context "newuser" do
|
||||
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser])}
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel[0])}
|
||||
let(:promotion) { Promotion.new(user) }
|
||||
|
||||
it "doesn't raise an error with a nil user" do
|
||||
|
@ -30,7 +30,7 @@ describe Promotion do
|
|||
end
|
||||
|
||||
it "has not changed the user's trust level" do
|
||||
user.trust_level.should == TrustLevel.levels[:newuser]
|
||||
user.trust_level.should == TrustLevel[0]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,7 +49,7 @@ describe Promotion do
|
|||
end
|
||||
|
||||
it "has upgraded the user to basic" do
|
||||
user.trust_level.should == TrustLevel.levels[:basic]
|
||||
user.trust_level.should == TrustLevel[1]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -57,7 +57,7 @@ describe Promotion do
|
|||
|
||||
context "basic" do
|
||||
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:basic])}
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel[1])}
|
||||
let(:promotion) { Promotion.new(user) }
|
||||
|
||||
context 'that has done nothing' do
|
||||
|
@ -68,7 +68,7 @@ describe Promotion do
|
|||
end
|
||||
|
||||
it "has not changed the user's trust level" do
|
||||
user.trust_level.should == TrustLevel.levels[:basic]
|
||||
user.trust_level.should == TrustLevel[1]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -92,57 +92,57 @@ describe Promotion do
|
|||
end
|
||||
|
||||
it "has upgraded the user to regular" do
|
||||
user.trust_level.should == TrustLevel.levels[:regular]
|
||||
user.trust_level.should == TrustLevel[2]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "regular" do
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:regular])}
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel[2])}
|
||||
let(:promotion) { Promotion.new(user) }
|
||||
|
||||
context "doesn't qualify for promotion" do
|
||||
before do
|
||||
LeaderRequirements.any_instance.expects(:requirements_met?).at_least_once.returns(false)
|
||||
TrustLevel3Requirements.any_instance.expects(:requirements_met?).at_least_once.returns(false)
|
||||
end
|
||||
|
||||
it "review_regular returns false" do
|
||||
it "review_tl2 returns false" do
|
||||
expect {
|
||||
promotion.review_regular.should == false
|
||||
promotion.review_tl2.should == false
|
||||
}.to_not change { user.reload.trust_level }
|
||||
end
|
||||
|
||||
it "doesn't promote" do
|
||||
expect {
|
||||
promotion.review_regular
|
||||
promotion.review_tl2
|
||||
}.to_not change { user.reload.trust_level }
|
||||
end
|
||||
|
||||
it "doesn't log a trust level change" do
|
||||
expect {
|
||||
promotion.review_regular
|
||||
promotion.review_tl2
|
||||
}.to_not change { UserHistory.count }
|
||||
end
|
||||
end
|
||||
|
||||
context "qualifies for promotion" do
|
||||
before do
|
||||
LeaderRequirements.any_instance.expects(:requirements_met?).at_least_once.returns(true)
|
||||
TrustLevel3Requirements.any_instance.expects(:requirements_met?).at_least_once.returns(true)
|
||||
end
|
||||
|
||||
it "review_regular returns true" do
|
||||
promotion.review_regular.should == true
|
||||
it "review_tl2 returns true" do
|
||||
promotion.review_tl2.should == true
|
||||
end
|
||||
|
||||
it "promotes to leader" do
|
||||
promotion.review_regular.should == true
|
||||
user.reload.trust_level.should == TrustLevel.levels[:leader]
|
||||
it "promotes to tl3" do
|
||||
promotion.review_tl2.should == true
|
||||
user.reload.trust_level.should == TrustLevel[3]
|
||||
end
|
||||
|
||||
it "logs a trust level change" do
|
||||
expect {
|
||||
promotion.review_regular
|
||||
promotion.review_tl2
|
||||
}.to change { UserHistory.where(action: UserHistory.actions[:auto_trust_level_change]).count }.by(1)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ describe TopicCreator do
|
|||
end
|
||||
|
||||
context 'regular user' do
|
||||
before { SiteSetting.stubs(:min_trust_to_create_topic).returns(TrustLevel.levels[:newuser]) }
|
||||
before { SiteSetting.stubs(:min_trust_to_create_topic).returns(TrustLevel[0]) }
|
||||
|
||||
it "should be possible for a regular user to create a topic" do
|
||||
TopicCreator.create(user, Guardian.new(user), valid_attrs).should be_valid
|
||||
|
|
|
@ -194,8 +194,8 @@ describe Admin::UsersController do
|
|||
stat.posts_read_count = SiteSetting.tl1_requires_read_posts + 1
|
||||
stat.time_read = SiteSetting.tl1_requires_time_spent_mins * 60
|
||||
stat.save!
|
||||
@another_user.update_attributes(trust_level: TrustLevel.levels[:basic])
|
||||
xhr :put, :trust_level, user_id: @another_user.id, level: TrustLevel.levels[:newuser]
|
||||
@another_user.update_attributes(trust_level: TrustLevel[1])
|
||||
xhr :put, :trust_level, user_id: @another_user.id, level: TrustLevel[0]
|
||||
response.should_not be_success
|
||||
end
|
||||
end
|
||||
|
|
|
@ -622,7 +622,7 @@ describe TopicsController do
|
|||
end
|
||||
|
||||
it "reviews the user for a promotion if they're new" do
|
||||
user.update_column(:trust_level, TrustLevel.levels[:newuser])
|
||||
user.update_column(:trust_level, TrustLevel[0])
|
||||
Promotion.any_instance.expects(:review)
|
||||
get :show, topic_id: topic.id, slug: topic.slug
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ Fabricator(:user) do
|
|||
username { sequence(:username) { |i| "bruce#{i}" } }
|
||||
email { sequence(:email) { |i| "bruce#{i}@wayne.com" } }
|
||||
password 'myawesomepassword'
|
||||
trust_level TrustLevel.levels[:basic]
|
||||
trust_level TrustLevel[1]
|
||||
ip_address { sequence(:ip_address) { |i| "99.232.23.#{i%254}"} }
|
||||
active true
|
||||
end
|
||||
|
@ -50,7 +50,7 @@ Fabricator(:newuser, from: :user) do
|
|||
name 'Newbie Newperson'
|
||||
username 'newbie'
|
||||
email 'newbie@new.com'
|
||||
trust_level TrustLevel.levels[:newuser]
|
||||
trust_level TrustLevel[0]
|
||||
end
|
||||
|
||||
Fabricator(:active_user, from: :user) do
|
||||
|
@ -58,7 +58,7 @@ Fabricator(:active_user, from: :user) do
|
|||
username { sequence(:username) { |i| "luke#{i}" } }
|
||||
email { sequence(:email) { |i| "luke#{i}@skywalker.com" } }
|
||||
password 'myawesomepassword'
|
||||
trust_level TrustLevel.levels[:basic]
|
||||
trust_level TrustLevel[1]
|
||||
|
||||
after_create do |user|
|
||||
user.user_profile.bio_raw = "Don't ask me about my dad!"
|
||||
|
@ -70,12 +70,12 @@ Fabricator(:leader, from: :user) do
|
|||
name 'Veteran McVeteranish'
|
||||
username { sequence(:username) { |i| "leader#{i}" } }
|
||||
email { sequence(:email) { |i| "leader#{i}@leaderfun.com" } }
|
||||
trust_level TrustLevel.levels[:leader]
|
||||
trust_level TrustLevel[3]
|
||||
end
|
||||
|
||||
Fabricator(:elder, from: :user) do
|
||||
name 'Elder McElderson'
|
||||
username { sequence(:username) { |i| "elder#{i}" } }
|
||||
email { sequence(:email) { |i| "elder#{i}@elderfun.com" } }
|
||||
trust_level TrustLevel.levels[:elder]
|
||||
trust_level TrustLevel[4]
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ describe SpamRulesEnforcer do
|
|||
end
|
||||
|
||||
context 'first user is not new' do
|
||||
Given!(:old_user) { Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel.levels[:basic]) }
|
||||
Given!(:old_user) { Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel[1]) }
|
||||
|
||||
context 'first user starts a topic' do
|
||||
Given!(:first_post) { create_post(user: old_user) }
|
||||
|
|
|
@ -17,7 +17,7 @@ describe SpamRulesEnforcer do
|
|||
Given(:user2) { Fabricate(:user) }
|
||||
|
||||
context 'spammer is a new user' do
|
||||
Given(:spammer) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
Given(:spammer) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
|
||||
context 'spammer post is not flagged enough times' do
|
||||
Given!(:spam_post) { create_post(user: spammer) }
|
||||
|
@ -64,7 +64,7 @@ describe SpamRulesEnforcer do
|
|||
end
|
||||
|
||||
context "spammer becomes trust level 1" do
|
||||
When { spammer.change_trust_level!(:basic); spammer.reload }
|
||||
When { spammer.change_trust_level!(TrustLevel[1]); spammer.reload }
|
||||
Then { expect(spammer.reload).to be_blocked }
|
||||
end
|
||||
end
|
||||
|
@ -79,7 +79,7 @@ describe SpamRulesEnforcer do
|
|||
end
|
||||
|
||||
context "spammer has trust level basic" do
|
||||
Given(:spammer) { Fabricate(:user, trust_level: TrustLevel.levels[:basic]) }
|
||||
Given(:spammer) { Fabricate(:user, trust_level: TrustLevel[1]) }
|
||||
|
||||
context 'one spam post is flagged enough times by enough users' do
|
||||
Given!(:spam_post) { Fabricate(:post, user: spammer) }
|
||||
|
@ -93,7 +93,7 @@ describe SpamRulesEnforcer do
|
|||
end
|
||||
end
|
||||
|
||||
[[:user, trust_level: TrustLevel.levels[:regular]], [:admin], [:moderator]].each do |spammer_args|
|
||||
[[:user, trust_level: TrustLevel[2]], [:admin], [:moderator]].each do |spammer_args|
|
||||
context "spammer is trusted #{spammer_args[0]}" do
|
||||
Given!(:spammer) { Fabricate(*spammer_args) }
|
||||
Given!(:spam_post) { Fabricate(:post, user: spammer) }
|
||||
|
|
|
@ -5,25 +5,25 @@ describe Jobs::LeaderPromotions do
|
|||
subject(:run_job) { described_class.new.execute({}) }
|
||||
|
||||
it "promotes tl2 user who qualifies for tl3" do
|
||||
tl2_user = Fabricate(:user, trust_level: TrustLevel.levels[:regular])
|
||||
LeaderRequirements.any_instance.stubs(:requirements_met?).returns(true)
|
||||
Promotion.any_instance.expects(:change_trust_level!).with(:leader, anything).once
|
||||
_tl2_user = Fabricate(:user, trust_level: TrustLevel[2])
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
|
||||
Promotion.any_instance.expects(:change_trust_level!).with(TrustLevel[3], anything).once
|
||||
run_job
|
||||
end
|
||||
|
||||
it "doesn't promote tl1 and tl0 users who have met tl3 requirements" do
|
||||
tl1_user = Fabricate(:user, trust_level: TrustLevel.levels[:basic])
|
||||
tl0_user = Fabricate(:user, trust_level: TrustLevel.levels[:newuser])
|
||||
LeaderRequirements.any_instance.expects(:requirements_met?).never
|
||||
_tl1_user = Fabricate(:user, trust_level: TrustLevel[1])
|
||||
_tl0_user = Fabricate(:user, trust_level: TrustLevel[0])
|
||||
TrustLevel3Requirements.any_instance.expects(:requirements_met?).never
|
||||
Promotion.any_instance.expects(:change_trust_level!).never
|
||||
run_job
|
||||
end
|
||||
|
||||
context "tl3 user who doesn't qualify for tl3 anymore" do
|
||||
def create_leader_user
|
||||
user = Fabricate(:user, trust_level: TrustLevel.levels[:regular])
|
||||
LeaderRequirements.any_instance.stubs(:requirements_met?).returns(true)
|
||||
Promotion.new(user).review_regular.should == true
|
||||
user = Fabricate(:user, trust_level: TrustLevel[2])
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
|
||||
Promotion.new(user).review_tl2.should == true
|
||||
user
|
||||
end
|
||||
|
||||
|
@ -37,10 +37,10 @@ describe Jobs::LeaderPromotions do
|
|||
user = create_leader_user
|
||||
end
|
||||
|
||||
LeaderRequirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
LeaderRequirements.any_instance.stubs(:requirements_lost?).returns(true)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
||||
run_job
|
||||
user.reload.trust_level.should == TrustLevel.levels[:regular]
|
||||
user.reload.trust_level.should == TrustLevel[2]
|
||||
end
|
||||
|
||||
it "doesn't demote if user was promoted recently" do
|
||||
|
@ -49,10 +49,10 @@ describe Jobs::LeaderPromotions do
|
|||
user = create_leader_user
|
||||
end
|
||||
|
||||
LeaderRequirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
LeaderRequirements.any_instance.stubs(:requirements_lost?).returns(true)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
||||
run_job
|
||||
user.reload.trust_level.should == TrustLevel.levels[:leader]
|
||||
user.reload.trust_level.should == TrustLevel[3]
|
||||
end
|
||||
|
||||
it "doesn't demote if user hasn't lost requirements (low water mark)" do
|
||||
|
@ -61,10 +61,10 @@ describe Jobs::LeaderPromotions do
|
|||
user = create_leader_user
|
||||
end
|
||||
|
||||
LeaderRequirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
LeaderRequirements.any_instance.stubs(:requirements_lost?).returns(false)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(false)
|
||||
run_job
|
||||
user.reload.trust_level.should == TrustLevel.levels[:leader]
|
||||
user.reload.trust_level.should == TrustLevel[3]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -95,7 +95,7 @@ describe Jobs::PollMailbox do
|
|||
SiteSetting.reply_by_email_address = "reply+%{reply_key}@appmail.adventuretime.ooo"
|
||||
category.email_in = 'incoming+amazing@appmail.adventuretime.ooo'
|
||||
category.save
|
||||
user.change_trust_level! :regular
|
||||
user.change_trust_level! 2
|
||||
user.username = 'Jake'
|
||||
user.email = 'jake@adventuretime.ooo'
|
||||
user.save
|
||||
|
@ -127,7 +127,7 @@ describe Jobs::PollMailbox do
|
|||
|
||||
describe "with insufficient trust" do
|
||||
before do
|
||||
user.change_trust_level! :newuser
|
||||
user.change_trust_level! 0
|
||||
end
|
||||
|
||||
it "raises a UserNotSufficientTrustLevelError" do
|
||||
|
|
|
@ -13,12 +13,12 @@ describe CategoryFeaturedTopic do
|
|||
it "should feature topics for a secure category" do
|
||||
|
||||
# so much dancing, I am thinking fixures make sense here.
|
||||
user.change_trust_level!(:basic)
|
||||
user.change_trust_level!(TrustLevel[1])
|
||||
|
||||
category.set_permissions(:trust_level_1 => :full)
|
||||
category.save
|
||||
|
||||
uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
|
||||
_uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
|
||||
|
||||
CategoryFeaturedTopic.feature_topics_for(category)
|
||||
CategoryFeaturedTopic.count.should == 1
|
||||
|
|
|
@ -81,17 +81,17 @@ describe Group do
|
|||
user = Fabricate(:user)
|
||||
Group[:trust_level_0].user_ids.should include user.id
|
||||
|
||||
user.change_trust_level!(:basic)
|
||||
user.change_trust_level!(TrustLevel[1])
|
||||
|
||||
Group[:trust_level_1].user_ids.should include user.id
|
||||
|
||||
user.change_trust_level!(:regular)
|
||||
user.change_trust_level!(TrustLevel[2])
|
||||
|
||||
Group[:trust_level_1].user_ids.should include user.id
|
||||
Group[:trust_level_2].user_ids.should include user.id
|
||||
|
||||
user2 = Fabricate(:coding_horror)
|
||||
user2.change_trust_level!(:regular)
|
||||
user2.change_trust_level!(TrustLevel[3])
|
||||
|
||||
Group[:trust_level_2].user_ids.sort.should == [-1, user.id, user2.id].sort
|
||||
end
|
||||
|
@ -99,7 +99,7 @@ describe Group do
|
|||
it "Correctly updates all automatic groups upon request" do
|
||||
Fabricate(:admin)
|
||||
user = Fabricate(:user)
|
||||
user.change_trust_level!(:regular)
|
||||
user.change_trust_level!(TrustLevel[2])
|
||||
|
||||
Group.exec_sql("update groups set user_count=0 where id = #{Group::AUTO_GROUPS[:trust_level_2]}")
|
||||
|
||||
|
|
|
@ -158,8 +158,8 @@ describe Invite do
|
|||
|
||||
context "invite trust levels" do
|
||||
it "returns the trust level in default_invitee_trust_level" do
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel.levels[:leader])
|
||||
invite.redeem.trust_level.should == TrustLevel.levels[:leader]
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel[3])
|
||||
invite.redeem.trust_level.should == TrustLevel[3]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ describe Post do
|
|||
end
|
||||
|
||||
describe "maximum images" do
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
let(:post_no_images) { Fabricate.build(:post, post_args.merge(user: newuser)) }
|
||||
let(:post_one_image) { post_with_body("![sherlock](http://bbc.co.uk/sherlock.jpg)", newuser) }
|
||||
let(:post_two_images) { post_with_body("<img src='http://discourse.org/logo.png'> <img src='http://bbc.co.uk/sherlock.jpg'>", newuser) }
|
||||
|
@ -158,7 +158,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "doesn't allow a new user to edit their post to insert an image" do
|
||||
post_no_images.user.trust_level = TrustLevel.levels[:new]
|
||||
post_no_images.user.trust_level = TrustLevel[0]
|
||||
post_no_images.save
|
||||
-> {
|
||||
post_no_images.revise(post_no_images.user, post_two_images.raw)
|
||||
|
@ -168,7 +168,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "allows more images from a not-new account" do
|
||||
post_two_images.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_two_images.user.trust_level = TrustLevel[1]
|
||||
post_two_images.should be_valid
|
||||
end
|
||||
|
||||
|
@ -177,7 +177,7 @@ describe Post do
|
|||
end
|
||||
|
||||
describe "maximum attachments" do
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
let(:post_no_attachments) { Fabricate.build(:post, post_args.merge(user: newuser)) }
|
||||
let(:post_one_attachment) { post_with_body('<a class="attachment" href="/uploads/default/1/2082985.txt">file.txt</a>', newuser) }
|
||||
let(:post_two_attachments) { post_with_body('<a class="attachment" href="/uploads/default/2/20947092.log">errors.log</a> <a class="attachment" href="/uploads/default/3/283572385.3ds">model.3ds</a>', newuser) }
|
||||
|
@ -206,7 +206,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "doesn't allow a new user to edit their post to insert an attachment" do
|
||||
post_no_attachments.user.trust_level = TrustLevel.levels[:new]
|
||||
post_no_attachments.user.trust_level = TrustLevel[0]
|
||||
post_no_attachments.save
|
||||
-> {
|
||||
post_no_attachments.revise(post_no_attachments.user, post_two_attachments.raw)
|
||||
|
@ -216,7 +216,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "allows more attachments from a not-new account" do
|
||||
post_two_attachments.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_two_attachments.user.trust_level = TrustLevel[1]
|
||||
post_two_attachments.should be_valid
|
||||
end
|
||||
|
||||
|
@ -225,7 +225,7 @@ describe Post do
|
|||
end
|
||||
|
||||
context "links" do
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
let(:no_links) { post_with_body("hello world my name is evil trout", newuser) }
|
||||
let(:one_link) { post_with_body("[jlawr](http://www.imdb.com/name/nm2225369)", newuser) }
|
||||
let(:two_links) { post_with_body("<a href='http://disneyland.disney.go.com/'>disney</a> <a href='http://reddit.com'>reddit</a>", newuser)}
|
||||
|
@ -292,7 +292,7 @@ describe Post do
|
|||
|
||||
|
||||
describe "maximum links" do
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
let(:post_one_link) { post_with_body("[sherlock](http://www.bbc.co.uk/programmes/b018ttws)", newuser) }
|
||||
let(:post_two_links) { post_with_body("<a href='http://discourse.org'>discourse</a> <a href='http://twitter.com'>twitter</a>", newuser) }
|
||||
let(:post_with_mentions) { post_with_body("hello @#{newuser.username} how are you doing?", newuser) }
|
||||
|
@ -330,7 +330,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "allows multiple images for basic accounts" do
|
||||
post_two_links.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_two_links.user.trust_level = TrustLevel[1]
|
||||
post_two_links.should be_valid
|
||||
end
|
||||
|
||||
|
@ -382,7 +382,7 @@ describe Post do
|
|||
|
||||
context "max mentions" do
|
||||
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
let(:post_with_one_mention) { post_with_body("@Jake is the person I'm mentioning", newuser) }
|
||||
let(:post_with_two_mentions) { post_with_body("@Jake @Finn are the people I'm mentioning", newuser) }
|
||||
|
||||
|
@ -408,12 +408,12 @@ describe Post do
|
|||
end
|
||||
|
||||
it "allows vmax_mentions_per_post mentions" do
|
||||
post_with_one_mention.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_with_one_mention.user.trust_level = TrustLevel[1]
|
||||
post_with_one_mention.should be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow to have more than max_mentions_per_post mentions" do
|
||||
post_with_two_mentions.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_with_two_mentions.user.trust_level = TrustLevel[1]
|
||||
post_with_two_mentions.should_not be_valid
|
||||
end
|
||||
end
|
||||
|
|
|
@ -131,16 +131,16 @@ describe Report do
|
|||
|
||||
context "with users at different trust levels" do
|
||||
before do
|
||||
3.times { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
2.times { Fabricate(:user, trust_level: TrustLevel.levels[:regular]) }
|
||||
Fabricate(:user, trust_level: TrustLevel.levels[:elder])
|
||||
3.times { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
2.times { Fabricate(:user, trust_level: TrustLevel[2]) }
|
||||
Fabricate(:user, trust_level: TrustLevel[4])
|
||||
end
|
||||
|
||||
it "returns a report with data" do
|
||||
report.data.should be_present
|
||||
report.data.find {|d| d[:x] == TrustLevel.levels[:newuser]}[:y].should == 3
|
||||
report.data.find {|d| d[:x] == TrustLevel.levels[:regular]}[:y].should == 2
|
||||
report.data.find {|d| d[:x] == TrustLevel.levels[:elder]}[:y].should == 1
|
||||
report.data.find {|d| d[:x] == TrustLevel[0]}[:y].should == 3
|
||||
report.data.find {|d| d[:x] == TrustLevel[2]}[:y].should == 2
|
||||
report.data.find {|d| d[:x] == TrustLevel[4]}[:y].should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe LeaderRequirements do
|
||||
describe TrustLevel3Requirements do
|
||||
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
subject(:leader_requirements) { described_class.new(user) }
|
||||
subject(:tl3_requirements) { described_class.new(user) }
|
||||
|
||||
before do
|
||||
described_class.clear_cache
|
||||
end
|
||||
|
||||
def make_view(id, at, user_id)
|
||||
TopicViewItem.add(id, '11.22.33.44', user_id, at)
|
||||
TopicViewItem.add(id, '11.22.33.44', user_id, at, _skip_redis=true)
|
||||
end
|
||||
|
||||
describe "requirements" do
|
||||
it "min_days_visited uses site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_days_visited).returns(66)
|
||||
leader_requirements.min_days_visited.should == 66
|
||||
tl3_requirements.min_days_visited.should == 66
|
||||
end
|
||||
|
||||
it "min_topics_replied_to uses site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_topics_replied_to).returns(12)
|
||||
leader_requirements.min_topics_replied_to.should == 12
|
||||
tl3_requirements.min_topics_replied_to.should == 12
|
||||
end
|
||||
|
||||
it "min_topics_viewed depends on site setting and number of topics created" do
|
||||
SiteSetting.stubs(:tl3_requires_topics_viewed).returns(75)
|
||||
described_class.stubs(:num_topics_in_time_period).returns(31)
|
||||
leader_requirements.min_topics_viewed.should == 23
|
||||
tl3_requirements.min_topics_viewed.should == 23
|
||||
end
|
||||
|
||||
it "min_posts_read depends on site setting and number of posts created" do
|
||||
SiteSetting.stubs(:tl3_requires_posts_read).returns(66)
|
||||
described_class.stubs(:num_posts_in_time_period).returns(1234)
|
||||
leader_requirements.min_posts_read.should == 814
|
||||
tl3_requirements.min_posts_read.should == 814
|
||||
end
|
||||
|
||||
it "min_topics_viewed_all_time depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_topics_viewed_all_time).returns(75)
|
||||
leader_requirements.min_topics_viewed_all_time.should == 75
|
||||
tl3_requirements.min_topics_viewed_all_time.should == 75
|
||||
end
|
||||
|
||||
it "min_posts_read_all_time depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_posts_read_all_time).returns(1001)
|
||||
leader_requirements.min_posts_read_all_time.should == 1001
|
||||
tl3_requirements.min_posts_read_all_time.should == 1001
|
||||
end
|
||||
|
||||
it "max_flagged_posts depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_max_flagged).returns(3)
|
||||
leader_requirements.max_flagged_posts.should == 3
|
||||
tl3_requirements.max_flagged_posts.should == 3
|
||||
end
|
||||
|
||||
it "min_likes_given depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_likes_given).returns(30)
|
||||
leader_requirements.min_likes_given.should == 30
|
||||
tl3_requirements.min_likes_given.should == 30
|
||||
end
|
||||
|
||||
it "min_likes_received depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_likes_received).returns(20)
|
||||
leader_requirements.min_likes_received.should == 20
|
||||
tl3_requirements.min_likes_received.should == 20
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -69,7 +69,7 @@ describe LeaderRequirements do
|
|||
user.update_posts_read!(1, 3.days.ago)
|
||||
user.update_posts_read!(0, 4.days.ago)
|
||||
user.update_posts_read!(3, 101.days.ago)
|
||||
leader_requirements.days_visited.should == 2
|
||||
tl3_requirements.days_visited.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,16 +77,16 @@ describe LeaderRequirements do
|
|||
it "counts topics in which user replied in last 100 days" do
|
||||
user.save
|
||||
|
||||
not_a_reply = create_post(user: user) # user created the topic, so it doesn't count
|
||||
_not_a_reply = create_post(user: user) # user created the topic, so it doesn't count
|
||||
|
||||
topic1 = create_post.topic
|
||||
reply1 = create_post(topic: topic1, user: user)
|
||||
reply_again = create_post(topic: topic1, user: user) # two replies in one topic
|
||||
_reply1 = create_post(topic: topic1, user: user)
|
||||
_reply_again = create_post(topic: topic1, user: user) # two replies in one topic
|
||||
|
||||
topic2 = create_post(created_at: 101.days.ago).topic
|
||||
reply2 = create_post(topic: topic2, user: user, created_at: 101.days.ago) # topic is over 100 days old
|
||||
_reply2 = create_post(topic: topic2, user: user, created_at: 101.days.ago) # topic is over 100 days old
|
||||
|
||||
leader_requirements.num_topics_replied_to.should == 1
|
||||
tl3_requirements.num_topics_replied_to.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -97,7 +97,7 @@ describe LeaderRequirements do
|
|||
make_view(9, 3.days.ago, user.id) # same topic, different day
|
||||
make_view(3, 4.days.ago, user.id)
|
||||
make_view(2, 101.days.ago, user.id) # too long ago
|
||||
leader_requirements.topics_viewed.should == 2
|
||||
tl3_requirements.topics_viewed.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -108,7 +108,7 @@ describe LeaderRequirements do
|
|||
user.update_posts_read!(1, 3.days.ago)
|
||||
user.update_posts_read!(0, 4.days.ago)
|
||||
user.update_posts_read!(5, 101.days.ago)
|
||||
leader_requirements.posts_read.should == 4
|
||||
tl3_requirements.posts_read.should == 4
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -118,7 +118,7 @@ describe LeaderRequirements do
|
|||
make_view(10, 1.day.ago, user.id)
|
||||
make_view(9, 100.days.ago, user.id)
|
||||
make_view(8, 101.days.ago, user.id)
|
||||
leader_requirements.topics_viewed_all_time.should == 3
|
||||
tl3_requirements.topics_viewed_all_time.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -127,7 +127,7 @@ describe LeaderRequirements do
|
|||
user.save
|
||||
user.update_posts_read!(3, 2.days.ago)
|
||||
user.update_posts_read!(1, 101.days.ago)
|
||||
leader_requirements.posts_read_all_time.should == 4
|
||||
tl3_requirements.posts_read_all_time.should == 4
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -138,11 +138,11 @@ describe LeaderRequirements do
|
|||
Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], agreed_at: 1.minute.ago)
|
||||
end
|
||||
|
||||
deferred_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t|
|
||||
_deferred_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t|
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], deferred_at: 1.minute.ago)
|
||||
end
|
||||
|
||||
deleted_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t|
|
||||
_deleted_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t|
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], deleted_at: 1.minute.ago)
|
||||
end
|
||||
|
||||
|
@ -157,8 +157,8 @@ describe LeaderRequirements do
|
|||
end
|
||||
|
||||
it "num_flagged_posts and num_flagged_by_users count spam and inappropriate agreed flags in the last 100 days" do
|
||||
leader_requirements.num_flagged_posts.should == 2
|
||||
leader_requirements.num_flagged_by_users.should == 3
|
||||
tl3_requirements.num_flagged_posts.should == 2
|
||||
tl3_requirements.num_flagged_by_users.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -174,7 +174,7 @@ describe LeaderRequirements do
|
|||
Fabricate(:like, user: user, post: recent_post2, created_at: 5.days.ago)
|
||||
Fabricate(:like, user: user, post: old_post, created_at: 101.days.ago)
|
||||
|
||||
leader_requirements.num_likes_given.should == 2
|
||||
tl3_requirements.num_likes_given.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -192,103 +192,103 @@ describe LeaderRequirements do
|
|||
Fabricate(:like, user: liker, post: recent_post2, created_at: 5.days.ago)
|
||||
Fabricate(:like, user: liker, post: old_post, created_at: 101.days.ago)
|
||||
|
||||
leader_requirements.num_likes_received.should == 2
|
||||
tl3_requirements.num_likes_received.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "requirements" do
|
||||
|
||||
before do
|
||||
leader_requirements.stubs(:min_days_visited).returns(50)
|
||||
leader_requirements.stubs(:min_topics_replied_to).returns(10)
|
||||
leader_requirements.stubs(:min_topics_viewed).returns(25)
|
||||
leader_requirements.stubs(:min_posts_read).returns(25)
|
||||
leader_requirements.stubs(:min_topics_viewed_all_time).returns(200)
|
||||
leader_requirements.stubs(:min_posts_read_all_time).returns(500)
|
||||
leader_requirements.stubs(:max_flagged_posts).returns(5)
|
||||
leader_requirements.stubs(:max_flagged_by_users).returns(5)
|
||||
leader_requirements.stubs(:min_likes_given).returns(30)
|
||||
leader_requirements.stubs(:min_likes_received).returns(20)
|
||||
tl3_requirements.stubs(:min_days_visited).returns(50)
|
||||
tl3_requirements.stubs(:min_topics_replied_to).returns(10)
|
||||
tl3_requirements.stubs(:min_topics_viewed).returns(25)
|
||||
tl3_requirements.stubs(:min_posts_read).returns(25)
|
||||
tl3_requirements.stubs(:min_topics_viewed_all_time).returns(200)
|
||||
tl3_requirements.stubs(:min_posts_read_all_time).returns(500)
|
||||
tl3_requirements.stubs(:max_flagged_posts).returns(5)
|
||||
tl3_requirements.stubs(:max_flagged_by_users).returns(5)
|
||||
tl3_requirements.stubs(:min_likes_given).returns(30)
|
||||
tl3_requirements.stubs(:min_likes_received).returns(20)
|
||||
|
||||
leader_requirements.stubs(:days_visited).returns(50)
|
||||
leader_requirements.stubs(:num_topics_replied_to).returns(10)
|
||||
leader_requirements.stubs(:topics_viewed).returns(25)
|
||||
leader_requirements.stubs(:posts_read).returns(25)
|
||||
leader_requirements.stubs(:topics_viewed_all_time).returns(200)
|
||||
leader_requirements.stubs(:posts_read_all_time).returns(500)
|
||||
leader_requirements.stubs(:num_flagged_posts).returns(0)
|
||||
leader_requirements.stubs(:num_flagged_by_users).returns(0)
|
||||
leader_requirements.stubs(:num_likes_given).returns(30)
|
||||
leader_requirements.stubs(:num_likes_received).returns(20)
|
||||
tl3_requirements.stubs(:days_visited).returns(50)
|
||||
tl3_requirements.stubs(:num_topics_replied_to).returns(10)
|
||||
tl3_requirements.stubs(:topics_viewed).returns(25)
|
||||
tl3_requirements.stubs(:posts_read).returns(25)
|
||||
tl3_requirements.stubs(:topics_viewed_all_time).returns(200)
|
||||
tl3_requirements.stubs(:posts_read_all_time).returns(500)
|
||||
tl3_requirements.stubs(:num_flagged_posts).returns(0)
|
||||
tl3_requirements.stubs(:num_flagged_by_users).returns(0)
|
||||
tl3_requirements.stubs(:num_likes_given).returns(30)
|
||||
tl3_requirements.stubs(:num_likes_received).returns(20)
|
||||
end
|
||||
|
||||
it "are met when all requirements are met" do
|
||||
leader_requirements.requirements_met?.should == true
|
||||
tl3_requirements.requirements_met?.should == true
|
||||
end
|
||||
|
||||
it "are not met if too few days visited" do
|
||||
leader_requirements.stubs(:days_visited).returns(49)
|
||||
leader_requirements.requirements_met?.should == false
|
||||
tl3_requirements.stubs(:days_visited).returns(49)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
end
|
||||
|
||||
it "are not lost if requirements are close" do
|
||||
leader_requirements.stubs(:days_visited).returns(45)
|
||||
leader_requirements.stubs(:num_topics_replied_to).returns(9)
|
||||
leader_requirements.stubs(:topics_viewed).returns(23)
|
||||
leader_requirements.stubs(:posts_read).returns(23)
|
||||
leader_requirements.stubs(:num_likes_given).returns(29)
|
||||
leader_requirements.stubs(:num_likes_received).returns(19)
|
||||
leader_requirements.requirements_lost?.should == false
|
||||
tl3_requirements.stubs(:days_visited).returns(45)
|
||||
tl3_requirements.stubs(:num_topics_replied_to).returns(9)
|
||||
tl3_requirements.stubs(:topics_viewed).returns(23)
|
||||
tl3_requirements.stubs(:posts_read).returns(23)
|
||||
tl3_requirements.stubs(:num_likes_given).returns(29)
|
||||
tl3_requirements.stubs(:num_likes_received).returns(19)
|
||||
tl3_requirements.requirements_lost?.should == false
|
||||
end
|
||||
|
||||
it "are lost if not enough visited" do
|
||||
leader_requirements.stubs(:days_visited).returns(44)
|
||||
leader_requirements.requirements_lost?.should == true
|
||||
tl3_requirements.stubs(:days_visited).returns(44)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
end
|
||||
|
||||
it "are lost if not enough topics replied to" do
|
||||
leader_requirements.stubs(:num_topics_replied_to).returns(8)
|
||||
leader_requirements.requirements_lost?.should == true
|
||||
tl3_requirements.stubs(:num_topics_replied_to).returns(8)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
end
|
||||
|
||||
it "are lost if not enough topics viewed" do
|
||||
leader_requirements.stubs(:topics_viewed).returns(22)
|
||||
leader_requirements.requirements_lost?.should == true
|
||||
tl3_requirements.stubs(:topics_viewed).returns(22)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
end
|
||||
|
||||
it "are lost if not enough posts read" do
|
||||
leader_requirements.stubs(:posts_read).returns(22)
|
||||
leader_requirements.requirements_lost?.should == true
|
||||
tl3_requirements.stubs(:posts_read).returns(22)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
end
|
||||
|
||||
it "are not met if not enough likes given" do
|
||||
leader_requirements.stubs(:num_likes_given).returns(29)
|
||||
leader_requirements.requirements_met?.should == false
|
||||
tl3_requirements.stubs(:num_likes_given).returns(29)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
end
|
||||
|
||||
it "are not met if not enough likes received" do
|
||||
leader_requirements.stubs(:num_likes_received).returns(19)
|
||||
leader_requirements.requirements_met?.should == false
|
||||
tl3_requirements.stubs(:num_likes_received).returns(19)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
end
|
||||
|
||||
it "are lost if not enough likes given" do
|
||||
leader_requirements.stubs(:num_likes_given).returns(26)
|
||||
leader_requirements.requirements_lost?.should == true
|
||||
tl3_requirements.stubs(:num_likes_given).returns(26)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
end
|
||||
|
||||
it "are lost if not enough likes received" do
|
||||
leader_requirements.stubs(:num_likes_received).returns(17)
|
||||
leader_requirements.requirements_lost?.should == true
|
||||
tl3_requirements.stubs(:num_likes_received).returns(17)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
end
|
||||
|
||||
it "are not met if suspended" do
|
||||
user.stubs(:suspended?).returns(true)
|
||||
leader_requirements.requirements_met?.should == false
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
end
|
||||
|
||||
it "are lost if suspended" do
|
||||
user.stubs(:suspended?).returns(true)
|
||||
leader_requirements.requirements_lost?.should == true
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
end
|
||||
end
|
||||
|
|
@ -92,7 +92,7 @@ describe UserProfile do
|
|||
end
|
||||
|
||||
it 'removes the link if the user is new' do
|
||||
user.trust_level = TrustLevel.levels[:newuser]
|
||||
user.trust_level = TrustLevel[0]
|
||||
user_profile.send(:cook)
|
||||
expect(user_profile.bio_excerpt).to match_html("I love http://discourse.org")
|
||||
expect(user_profile.bio_processed).to eq("<p>I love http://discourse.org</p>")
|
||||
|
@ -102,22 +102,22 @@ describe UserProfile do
|
|||
before { SiteSetting.stubs(:tl3_links_no_follow).returns(false) }
|
||||
|
||||
it 'includes the link without nofollow if the user is trust level 3 or higher' do
|
||||
user.trust_level = TrustLevel.levels[:leader]
|
||||
user.trust_level = TrustLevel[3]
|
||||
user_profile.send(:cook)
|
||||
expect(user_profile.bio_excerpt).to match_html("I love <a href='http://discourse.org'>http://discourse.org</a>")
|
||||
expect(user_profile.bio_processed).to match_html("<p>I love <a href=\"http://discourse.org\">http://discourse.org</a></p>")
|
||||
end
|
||||
|
||||
it 'removes nofollow from links in bio when trust level is increased' do
|
||||
created_user.change_trust_level!(:leader)
|
||||
created_user.change_trust_level!(TrustLevel[3])
|
||||
expect(created_user.user_profile.bio_excerpt).to match_html("I love <a href='http://discourse.org'>http://discourse.org</a>")
|
||||
expect(created_user.user_profile.bio_processed).to match_html("<p>I love <a href=\"http://discourse.org\">http://discourse.org</a></p>")
|
||||
end
|
||||
|
||||
it 'adds nofollow to links in bio when trust level is decreased' do
|
||||
created_user.trust_level = TrustLevel.levels[:leader]
|
||||
created_user.trust_level = TrustLevel[3]
|
||||
created_user.save
|
||||
created_user.change_trust_level!(:regular)
|
||||
created_user.change_trust_level!(TrustLevel[2])
|
||||
expect(created_user.user_profile.bio_excerpt).to match_html("I love <a href='http://discourse.org' rel='nofollow'>http://discourse.org</a>")
|
||||
expect(created_user.user_profile.bio_processed).to match_html("<p>I love <a href=\"http://discourse.org\" rel=\"nofollow\">http://discourse.org</a></p>")
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ describe UserProfile do
|
|||
before { SiteSetting.stubs(:tl3_links_no_follow).returns(true) }
|
||||
|
||||
it 'includes the link with nofollow if the user is trust level 3 or higher' do
|
||||
user.trust_level = TrustLevel.levels[:leader]
|
||||
user.trust_level = TrustLevel[3]
|
||||
user_profile.send(:cook)
|
||||
expect(user_profile.bio_excerpt).to match_html("I love <a href='http://discourse.org' rel='nofollow'>http://discourse.org</a>")
|
||||
expect(user_profile.bio_processed).to match_html("<p>I love <a href=\"http://discourse.org\" rel=\"nofollow\">http://discourse.org</a></p>")
|
||||
|
|
|
@ -262,11 +262,11 @@ describe User do
|
|||
describe "trust levels" do
|
||||
|
||||
# NOTE be sure to use build to avoid db calls
|
||||
let(:user) { Fabricate.build(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:user) { Fabricate.build(:user, trust_level: TrustLevel[0]) }
|
||||
|
||||
it "sets to the default trust level setting" do
|
||||
SiteSetting.expects(:default_trust_level).returns(TrustLevel.levels[:elder])
|
||||
User.new.trust_level.should == TrustLevel.levels[:elder]
|
||||
SiteSetting.default_trust_level = TrustLevel[4]
|
||||
User.new.trust_level.should == TrustLevel[4]
|
||||
end
|
||||
|
||||
describe 'has_trust_level?' do
|
||||
|
@ -276,22 +276,22 @@ describe User do
|
|||
end
|
||||
|
||||
it "is true for your basic level" do
|
||||
user.has_trust_level?(:newuser).should be_true
|
||||
user.has_trust_level?(TrustLevel[0]).should be_true
|
||||
end
|
||||
|
||||
it "is false for a higher level" do
|
||||
user.has_trust_level?(:regular).should be_false
|
||||
user.has_trust_level?(TrustLevel[2]).should be_false
|
||||
end
|
||||
|
||||
it "is true if you exceed the level" do
|
||||
user.trust_level = TrustLevel.levels[:elder]
|
||||
user.has_trust_level?(:newuser).should be_true
|
||||
user.trust_level = TrustLevel[4]
|
||||
user.has_trust_level?(TrustLevel[1]).should be_true
|
||||
end
|
||||
|
||||
it "is true for an admin even with a low trust level" do
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.trust_level = TrustLevel[0]
|
||||
user.admin = true
|
||||
user.has_trust_level?(:elder).should be_true
|
||||
user.has_trust_level?(TrustLevel[1]).should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -303,7 +303,7 @@ describe User do
|
|||
|
||||
it "is a moderator if the user level is moderator" do
|
||||
user.moderator = true
|
||||
user.has_trust_level?(:elder).should be_true
|
||||
user.has_trust_level?(TrustLevel[4]).should be_true
|
||||
end
|
||||
|
||||
it "is staff if the user is an admin" do
|
||||
|
@ -844,7 +844,7 @@ describe User do
|
|||
end
|
||||
|
||||
describe "posted too much in topic" do
|
||||
let!(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let!(:user) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
let!(:topic) { Fabricate(:post).topic }
|
||||
|
||||
before do
|
||||
|
@ -877,7 +877,7 @@ describe User do
|
|||
|
||||
it "returns false for a user who created the topic" do
|
||||
topic_user = topic.user
|
||||
topic_user.trust_level = TrustLevel.levels[:newuser]
|
||||
topic_user.trust_level = TrustLevel[0]
|
||||
topic.user.posted_too_much_in_topic?(topic.id).should be_false
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ describe SpamRule::AutoBlock do
|
|||
end
|
||||
|
||||
describe 'perform' do
|
||||
let(:post) { Fabricate.build(:post, user: Fabricate.build(:user, trust_level: TrustLevel.levels[:newuser])) }
|
||||
let(:post) { Fabricate.build(:post, user: Fabricate.build(:user, trust_level: TrustLevel[0])) }
|
||||
subject { described_class.new(post.user) }
|
||||
|
||||
it 'takes no action if user should not be blocked' do
|
||||
|
@ -148,9 +148,9 @@ describe SpamRule::AutoBlock do
|
|||
end
|
||||
end
|
||||
|
||||
[:basic, :regular, :leader, :elder].each do |trust_level|
|
||||
(1..4).each do |trust_level|
|
||||
context "user has trust level #{trust_level}" do
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[trust_level]) }
|
||||
let(:user) { Fabricate(:user, trust_level: trust_level) }
|
||||
include_examples "can't be blocked"
|
||||
end
|
||||
end
|
||||
|
@ -167,7 +167,7 @@ describe SpamRule::AutoBlock do
|
|||
end
|
||||
|
||||
context 'new user' do
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser]) }
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
subject { described_class.new(user) }
|
||||
|
||||
it 'returns false if there are no spam flags' do
|
||||
|
@ -210,7 +210,7 @@ describe SpamRule::AutoBlock do
|
|||
end
|
||||
|
||||
context "blocked, but has higher trust level now" do
|
||||
let(:user) { Fabricate(:user, blocked: true, trust_level: TrustLevel.levels[:basic]) }
|
||||
let(:user) { Fabricate(:user, blocked: true, trust_level: TrustLevel[1]) }
|
||||
subject { described_class.new(user) }
|
||||
|
||||
it 'returns false' do
|
||||
|
|
|
@ -169,11 +169,11 @@ describe BadgeGranter do
|
|||
end
|
||||
|
||||
it "grants and revokes trust level badges" do
|
||||
user.change_trust_level!(:elder)
|
||||
user.change_trust_level!(TrustLevel[4])
|
||||
BadgeGranter.process_queue!
|
||||
UserBadge.where(user_id: user.id, badge_id: Badge.trust_level_badge_ids).count.should eq(4)
|
||||
|
||||
user.change_trust_level!(:basic)
|
||||
user.change_trust_level!(TrustLevel[1])
|
||||
BadgeGranter.backfill(Badge.find(1))
|
||||
BadgeGranter.backfill(Badge.find(2))
|
||||
UserBadge.where(user_id: user.id, badge_id: 1).first.should_not be_nil
|
||||
|
|
|
@ -79,26 +79,26 @@ describe SpamRule::FlagSockpuppets do
|
|||
end
|
||||
|
||||
it 'is true if first post user was created over 24 hours ago and has trust level higher than 0' do
|
||||
old_user = Fabricate(:user, ip_address: '182.189.119.174', created_at: 25.hours.ago, trust_level: TrustLevel.levels[:basic])
|
||||
old_user = Fabricate(:user, ip_address: '182.189.119.174', created_at: 25.hours.ago, trust_level: TrustLevel[1])
|
||||
first_post = Fabricate(:post, user: old_user, topic: Fabricate(:topic, user: old_user))
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: old_user.ip_address), topic: first_post.topic)
|
||||
described_class.new(post2).reply_is_from_sockpuppet?.should eq(true)
|
||||
end
|
||||
|
||||
it 'is false if second post user was created over 24 hours ago and has trust level higher than 0' do
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: user1.ip_address, created_at: 25.hours.ago, trust_level: TrustLevel.levels[:basic]), topic: post1.topic)
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: user1.ip_address, created_at: 25.hours.ago, trust_level: TrustLevel[1]), topic: post1.topic)
|
||||
described_class.new(post2).reply_is_from_sockpuppet?.should eq(false)
|
||||
end
|
||||
|
||||
it 'is true if first post user was created less that 24 hours ago and has trust level higher than 0' do
|
||||
new_user = Fabricate(:user, ip_address: '182.189.119.174', created_at: 1.hour.ago, trust_level: TrustLevel.levels[:basic])
|
||||
new_user = Fabricate(:user, ip_address: '182.189.119.174', created_at: 1.hour.ago, trust_level: TrustLevel[1])
|
||||
first_post = Fabricate(:post, user: new_user, topic: Fabricate(:topic, user: new_user))
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: new_user.ip_address), topic: first_post.topic)
|
||||
described_class.new(post2).reply_is_from_sockpuppet?.should eq(true)
|
||||
end
|
||||
|
||||
it 'is true if second user was created less that 24 hours ago and has trust level higher than 0' do
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: user1.ip_address, created_at: 23.hours.ago, trust_level: TrustLevel.levels[:basic]), topic: post1.topic)
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: user1.ip_address, created_at: 23.hours.ago, trust_level: TrustLevel[1]), topic: post1.topic)
|
||||
described_class.new(post2).reply_is_from_sockpuppet?.should eq(true)
|
||||
end
|
||||
|
||||
|
@ -126,7 +126,7 @@ describe SpamRule::FlagSockpuppets do
|
|||
end
|
||||
|
||||
it "doesn't flag the first post if the user is not new" do
|
||||
old_user = Fabricate(:user, ip_address: '182.189.119.174', created_at: 25.hours.ago, trust_level: TrustLevel.levels[:basic])
|
||||
old_user = Fabricate(:user, ip_address: '182.189.119.174', created_at: 25.hours.ago, trust_level: TrustLevel[1])
|
||||
first_post = Fabricate(:post, user: old_user, topic: Fabricate(:topic, user: old_user))
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: old_user.ip_address), topic: first_post.topic)
|
||||
PostAction.expects(:act).with(anything, post2, anything, anything).once
|
||||
|
|
|
@ -35,8 +35,8 @@ describe StaffActionLogger do
|
|||
|
||||
describe 'log_trust_level_change' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:old_trust_level) { TrustLevel.levels[:newuser] }
|
||||
let(:new_trust_level) { TrustLevel.levels[:basic] }
|
||||
let(:old_trust_level) { TrustLevel[0] }
|
||||
let(:new_trust_level) { TrustLevel[1] }
|
||||
|
||||
subject(:log_trust_level_change) { described_class.new(admin).log_trust_level_change(user, old_trust_level, new_trust_level) }
|
||||
|
||||
|
@ -51,7 +51,7 @@ describe StaffActionLogger do
|
|||
end
|
||||
|
||||
it 'raises an error when new trust level is not a Trust Level' do
|
||||
max_level = TrustLevel.levels.values.max
|
||||
max_level = TrustLevel.valid_range.max
|
||||
expect { logger.log_trust_level_change(user, old_trust_level, max_level + 1) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue