:s/moderator?/staff/g ... our naming was kind of crazy, renamed moderator? to staff
This commit is contained in:
+37
-40
@@ -15,8 +15,8 @@ class Guardian
|
||||
@user && @user.admin?
|
||||
end
|
||||
|
||||
def is_moderator?
|
||||
@user && @user.moderator?
|
||||
def is_staff?
|
||||
@user && @user.staff?
|
||||
end
|
||||
|
||||
# Can the user see the object?
|
||||
@@ -54,7 +54,7 @@ class Guardian
|
||||
def can_moderate?(obj)
|
||||
return false if obj.blank?
|
||||
return false if @user.blank?
|
||||
@user.moderator?
|
||||
@user.staff?
|
||||
end
|
||||
alias :can_move_posts? :can_moderate?
|
||||
alias :can_see_flags? :can_moderate?
|
||||
@@ -103,7 +103,7 @@ class Guardian
|
||||
return false if target.blank?
|
||||
return false if @user.blank?
|
||||
return false if target.approved?
|
||||
@user.moderator?
|
||||
@user.staff?
|
||||
end
|
||||
|
||||
def can_ban?(user)
|
||||
@@ -116,7 +116,7 @@ class Guardian
|
||||
def can_clear_flags?(post)
|
||||
return false if @user.blank?
|
||||
return false if post.blank?
|
||||
@user.moderator?
|
||||
@user.staff?
|
||||
end
|
||||
|
||||
def can_revoke_admin?(admin)
|
||||
@@ -136,32 +136,30 @@ class Guardian
|
||||
end
|
||||
|
||||
def can_revoke_moderation?(moderator)
|
||||
return false unless @user.try(:admin?)
|
||||
return false unless is_admin?
|
||||
return false if moderator.blank?
|
||||
return false if @user.id == moderator.id
|
||||
return false unless moderator.moderator?
|
||||
true
|
||||
end
|
||||
|
||||
def can_grant_moderation?(user)
|
||||
return false unless @user.try(:admin?)
|
||||
return false unless is_admin?
|
||||
return false if user.blank?
|
||||
return false if @user.id == user.id
|
||||
return false if user.admin?
|
||||
return false if user.moderator?
|
||||
return false if user.staff?
|
||||
true
|
||||
end
|
||||
|
||||
def can_delete_user?(user_to_delete)
|
||||
return false unless @user.try(:admin?)
|
||||
return false if user_to_delete.blank?
|
||||
return false unless is_admin?
|
||||
return false unless user_to_delete
|
||||
return false if user_to_delete.post_count > 0
|
||||
true
|
||||
end
|
||||
|
||||
# Can we see who acted on a post in a particular way?
|
||||
def can_see_post_actors?(topic, post_action_type_id)
|
||||
return false unless topic.present?
|
||||
return false unless topic
|
||||
|
||||
type_symbol = PostActionType.types[post_action_type_id]
|
||||
return false if type_symbol == :bookmark
|
||||
@@ -178,37 +176,36 @@ class Guardian
|
||||
# Support sites that have to approve users
|
||||
def can_access_forum?
|
||||
return true unless SiteSetting.must_approve_users?
|
||||
return false if user.blank?
|
||||
return false unless @user
|
||||
|
||||
# Admins can't lock themselves out of a site
|
||||
return true if user.admin?
|
||||
# Staff can't lock themselves out of a site
|
||||
return true if is_staff?
|
||||
|
||||
user.approved?
|
||||
@user.approved?
|
||||
end
|
||||
|
||||
def can_see_pending_invites_from?(user)
|
||||
return false if user.blank?
|
||||
return false if @user.blank?
|
||||
return false unless user && @user
|
||||
return user == @user
|
||||
end
|
||||
|
||||
# For now, can_invite_to is basically can_see?
|
||||
def can_invite_to?(object)
|
||||
return false if @user.blank?
|
||||
return false unless @user
|
||||
return false unless can_see?(object)
|
||||
return false if SiteSetting.must_approve_users?
|
||||
@user.has_trust_level?(:regular) || @user.moderator?
|
||||
@user.has_trust_level?(:regular) || @user.staff?
|
||||
end
|
||||
|
||||
|
||||
def can_see_deleted_posts?
|
||||
return true if is_admin?
|
||||
return true if is_staff?
|
||||
false
|
||||
end
|
||||
|
||||
def can_see_private_messages?(user_id)
|
||||
return true if is_moderator?
|
||||
return false if @user.blank?
|
||||
return true if is_staff?
|
||||
return false unless @user
|
||||
@user.id == user_id
|
||||
end
|
||||
|
||||
@@ -240,11 +237,11 @@ class Guardian
|
||||
|
||||
# Creating Methods
|
||||
def can_create_category?(parent)
|
||||
@user.moderator?
|
||||
is_staff?
|
||||
end
|
||||
|
||||
def can_create_post_on_topic?(topic)
|
||||
return true if @user.moderator?
|
||||
return true if is_staff?
|
||||
return false if topic.closed?
|
||||
return false if topic.archived?
|
||||
true
|
||||
@@ -252,22 +249,22 @@ class Guardian
|
||||
|
||||
# Editing Methods
|
||||
def can_edit_category?(category)
|
||||
@user.moderator?
|
||||
is_staff?
|
||||
end
|
||||
|
||||
def can_edit_post?(post)
|
||||
return true if @user.moderator?
|
||||
return true if is_staff?
|
||||
return false if post.topic.archived?
|
||||
(post.user == @user)
|
||||
end
|
||||
|
||||
def can_edit_user?(user)
|
||||
return true if user == @user
|
||||
@user.moderator?
|
||||
is_staff?
|
||||
end
|
||||
|
||||
def can_edit_topic?(topic)
|
||||
return true if @user.moderator?
|
||||
return true if is_staff?
|
||||
return true if topic.user == @user
|
||||
false
|
||||
end
|
||||
@@ -280,22 +277,22 @@ class Guardian
|
||||
# You can delete your own posts
|
||||
return !post.user_deleted? if post.user == @user
|
||||
|
||||
@user.moderator?
|
||||
is_staff?
|
||||
end
|
||||
|
||||
# Recovery Method
|
||||
def can_recover_post?(post)
|
||||
return false if @user.blank?
|
||||
@user.moderator?
|
||||
return false unless @user
|
||||
is_staff?
|
||||
end
|
||||
|
||||
def can_delete_category?(category)
|
||||
return false unless @user.moderator?
|
||||
return false unless is_staff?
|
||||
return category.topic_count == 0
|
||||
end
|
||||
|
||||
def can_delete_topic?(topic)
|
||||
return false unless @user.moderator?
|
||||
return false unless is_staff?
|
||||
return false if Category.exists?(topic_id: topic.id)
|
||||
true
|
||||
end
|
||||
@@ -313,7 +310,7 @@ class Guardian
|
||||
|
||||
def can_send_private_message?(target)
|
||||
return false unless User === target || Group === target
|
||||
return false if @user.blank?
|
||||
return false unless @user
|
||||
|
||||
# Can't send message to yourself
|
||||
return false if User === target && @user.id == target.id
|
||||
@@ -325,8 +322,8 @@ class Guardian
|
||||
end
|
||||
|
||||
def can_reply_as_new_topic?(topic)
|
||||
return false if @user.blank?
|
||||
return false if topic.blank?
|
||||
return false unless @user
|
||||
return false unless topic
|
||||
return false if topic.private_message?
|
||||
|
||||
@user.has_trust_level?(:basic)
|
||||
@@ -335,7 +332,7 @@ class Guardian
|
||||
def can_see_topic?(topic)
|
||||
return false unless topic
|
||||
|
||||
return true if @user && @user.moderator?
|
||||
return true if @user && is_staff?
|
||||
return false if topic.deleted_at
|
||||
|
||||
if topic.category && topic.category.secure
|
||||
@@ -353,7 +350,7 @@ class Guardian
|
||||
def can_see_post?(post)
|
||||
return false unless post
|
||||
|
||||
return true if @user && @user.moderator?
|
||||
return true if @user && is_staff?
|
||||
return false if post.deleted_at.present?
|
||||
|
||||
can_see_topic?(post.topic)
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ class RateLimiter
|
||||
|
||||
def can_perform?
|
||||
return true if RateLimiter.disabled?
|
||||
return true if @user.moderator?
|
||||
return true if @user.staff?
|
||||
|
||||
result = $redis.get(@key)
|
||||
return true if result.blank?
|
||||
@@ -32,7 +32,7 @@ class RateLimiter
|
||||
|
||||
def performed!
|
||||
return if RateLimiter.disabled?
|
||||
return if @user.moderator?
|
||||
return if @user.staff?
|
||||
|
||||
result = $redis.incr(@key).to_i
|
||||
$redis.expire(@key, @secs) if result == 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require_dependency 'current_user'
|
||||
|
||||
class ModeratorConstraint
|
||||
class StaffConstraint
|
||||
|
||||
def matches?(request)
|
||||
return false unless request.session[:current_user_id].present?
|
||||
+2
-2
@@ -23,7 +23,7 @@ class TopicView
|
||||
@limit = options[:limit] || SiteSetting.posts_per_page;
|
||||
|
||||
@filtered_posts = @topic.posts
|
||||
@filtered_posts = @filtered_posts.with_deleted if user.try(:admin?)
|
||||
@filtered_posts = @filtered_posts.with_deleted if user.try(:staff?)
|
||||
@filtered_posts = @filtered_posts.best_of if options[:best_of].present?
|
||||
|
||||
if options[:username_filters].present?
|
||||
@@ -299,7 +299,7 @@ class TopicView
|
||||
.includes(:user)
|
||||
.includes(:reply_to_user)
|
||||
.order('sort_order')
|
||||
@posts = @posts.with_deleted if @user.try(:admin?)
|
||||
@posts = @posts.with_deleted if @user.try(:staff?)
|
||||
|
||||
@posts
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user