:s/moderator?/staff/g ... our naming was kind of crazy, renamed moderator? to staff

This commit is contained in:
Sam 2013-05-02 17:22:27 +10:00
parent 65cd00cf25
commit 5ec52bd2e9
19 changed files with 82 additions and 96 deletions

View file

@ -13,7 +13,7 @@ Discourse.UserController = Discourse.ObjectController.extend({
}).property('content.username', 'Discourse.currentUser.username'), }).property('content.username', 'Discourse.currentUser.username'),
canSeePrivateMessages: (function() { canSeePrivateMessages: (function() {
return this.get('viewingSelf') || Discourse.get('currentUser.moderator'); return this.get('viewingSelf') || Discourse.get('currentUser.staff');
}).property('viewingSelf', 'Discourse.currentUser') }).property('viewingSelf', 'Discourse.currentUser')
}); });

View file

@ -65,26 +65,18 @@
<section class='d-dropdown' id='site-map-dropdown'> <section class='d-dropdown' id='site-map-dropdown'>
<ul> <ul>
{{#if Discourse.currentUser.moderator}} {{#if Discourse.currentUser.staff}}
<li><a href="/admin"><i class='icon-cog'></i>{{i18n admin_title}}</a></li> <li><a href="/admin"><i class='icon icon-cog'></i>{{i18n admin_title}}</a></li>
<li><a href="/admin/flags/active"><i class='icon-flag'></i>{{i18n flags_title}}</a></li> <li><a href="/admin/flags/active"><i class='icon icon-flag'></i>{{i18n flags_title}}</a>
{{#if view.currentUser.site_flagged_posts_count}}
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{view.currentUser.site_flagged_posts_count}}</a>
{{/if}}
</li>
{{/if}} {{/if}}
<li> <li>
{{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}} {{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}}
</li> </li>
<li>{{#linkTo 'faq'}}{{i18n faq}}{{/linkTo}}</li> <li>{{#linkTo 'faq'}}{{i18n faq}}{{/linkTo}}</li>
{{#if Discourse.currentUser.admin}}
<li title="{{i18n filters.favorited.help}}">
{{#linkTo "list.favorited"}}
<i class='icon-star'></i>{{i18n filters.favorited.title}}
{{/linkTo}}
</li>
<li title="{{i18n filters.read.help}}">
{{#linkTo "list.read"}}
<i class='icon-bookmark'></i>{{i18n filters.read.title}}
{{/linkTo}}
</li>
{{/if}}
{{#if view.categories}} {{#if view.categories}}
<li class='heading' title="{{i18n filters.categories.help}}"> <li class='heading' title="{{i18n filters.categories.help}}">
{{#linkTo "list.categories"}}{{i18n filters.categories.title}}{{/linkTo}} {{#linkTo "list.categories"}}{{i18n filters.categories.title}}{{/linkTo}}

View file

@ -7,7 +7,7 @@
{{#if viewingSelf}} {{#if viewingSelf}}
<button {{action "logout" target="Discourse"}} class='btn'>{{i18n user.log_out}}</button> <button {{action "logout" target="Discourse"}} class='btn'>{{i18n user.log_out}}</button>
{{/if}} {{/if}}
{{#if Discourse.currentUser.moderator}} {{#if Discourse.currentUser.staff}}
<a href="{{unbound content.adminPath}}" class='btn'><i class="icon-wrench"></i>&nbsp;{{i18n admin.user.show_admin_profile}}</a> <a href="{{unbound content.adminPath}}" class='btn'><i class="icon-wrench"></i>&nbsp;{{i18n admin.user.show_admin_profile}}</a>
{{/if}} {{/if}}
<ul class="nav nav-pills"> <ul class="nav nav-pills">

View file

@ -129,9 +129,9 @@
left: -4px; left: -4px;
background-color: #00953A; background-color: #00953A;
} }
.flagged-posts { }
background-color: #E53B2E; .flagged-posts {
} background-color: #E53B2E;
} }
} }
@ -170,6 +170,9 @@
padding: 5px; padding: 5px;
font-size: 13px; font-size: 13px;
line-height: 16px; line-height: 16px;
.icon {
margin-right: 3px;
}
} }
.heading { .heading {
border-top: 1px solid #c5c5c5; border-top: 1px solid #c5c5c5;

View file

@ -1,7 +1,7 @@
class Admin::AdminController < ApplicationController class Admin::AdminController < ApplicationController
before_filter :ensure_logged_in before_filter :ensure_logged_in
before_filter :ensure_is_moderator before_filter :ensure_staff
def index def index
render nothing: true render nothing: true
@ -9,8 +9,9 @@ class Admin::AdminController < ApplicationController
protected protected
def ensure_is_moderator # this is not really necessary cause the routes are secure
raise Discourse::InvalidAccess.new unless current_user.moderator? def ensure_staff
end raise Discourse::InvalidAccess.new unless current_user.staff?
end
end end

View file

@ -38,6 +38,10 @@ module ApplicationHelper
current_user.try(:moderator?) current_user.try(:moderator?)
end end
def staff?
current_user.try(:staff?)
end
# Creates open graph and twitter card meta data # Creates open graph and twitter card meta data
def crawlable_meta_data(opts=nil) def crawlable_meta_data(opts=nil)

View file

@ -25,7 +25,7 @@ class PostAction < ActiveRecord::Base
'topics.deleted_at' => nil).count('DISTINCT posts.id') 'topics.deleted_at' => nil).count('DISTINCT posts.id')
$redis.set('posts_flagged_count', posts_flagged_count) $redis.set('posts_flagged_count', posts_flagged_count)
user_ids = User.where("admin = 't' or moderator = 't'").select(:id).map {|u| u.id} user_ids = User.staff.select(:id).map {|u| u.id}
MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: user_ids }) MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: user_ids })
end end

View file

@ -54,6 +54,7 @@ class User < ActiveRecord::Base
scope :admins, ->{ where(admin: true) } scope :admins, ->{ where(admin: true) }
scope :moderators, ->{ where(moderator: true) } scope :moderators, ->{ where(moderator: true) }
scope :staff, ->{ where("moderator = 't' or admin = 't'") }
module NewTopicDuration module NewTopicDuration
ALWAYS = -1 ALWAYS = -1
@ -267,10 +268,8 @@ class User < ActiveRecord::Base
User.select(:username).order('last_posted_at desc').limit(20) User.select(:username).order('last_posted_at desc').limit(20)
end end
def moderator? # any user that is either a moderator or an admin
# this saves us from checking both, admins are always moderators def staff?
#
# in future we may split this out
admin || moderator admin || moderator
end end

View file

@ -190,7 +190,7 @@ LEFT JOIN categories c on c.id = t.category_id
builder.where("t.archetype != :archetype", archetype: Archetype::private_message) builder.where("t.archetype != :archetype", archetype: Archetype::private_message)
end end
unless guardian.is_moderator? unless guardian.is_staff?
allowed = guardian.secure_category_ids allowed = guardian.secure_category_ids
if allowed.present? if allowed.present?
builder.where("( c.secure IS NULL OR builder.where("( c.secure IS NULL OR

View file

@ -7,6 +7,7 @@ class CurrentUserSerializer < BasicUserSerializer
:notification_channel_position, :notification_channel_position,
:site_flagged_posts_count, :site_flagged_posts_count,
:moderator?, :moderator?,
:staff?,
:reply_count, :reply_count,
:topic_count, :topic_count,
:enable_quoting, :enable_quoting,
@ -15,15 +16,8 @@ class CurrentUserSerializer < BasicUserSerializer
# we probably want to move this into site, but that json is cached so hanging it off current user seems okish # we probably want to move this into site, but that json is cached so hanging it off current user seems okish
def moderator
# TODO we probably want better terminology
#
# we have admins / moderators and users who are either moderators or admins denoted by moderator?
object.moderator?
end
def include_site_flagged_posts_count? def include_site_flagged_posts_count?
object.moderator? object.staff?
end end
def topic_count def topic_count
@ -34,10 +28,6 @@ class CurrentUserSerializer < BasicUserSerializer
object.posts.where("post_number > 1").count object.posts.where("post_number > 1").count
end end
def moderator?
object.moderator?
end
def site_flagged_posts_count def site_flagged_posts_count
PostAction.flagged_posts_count PostAction.flagged_posts_count
end end

View file

@ -88,7 +88,7 @@ class PostSerializer < ApplicationSerializer
end end
def cooked def cooked
if object.hidden && !scope.is_moderator? if object.hidden && !scope.is_staff?
if scope.current_user && object.user_id == scope.current_user.id if scope.current_user && object.user_id == scope.current_user.id
I18n.t('flagging.you_must_edit') I18n.t('flagging.you_must_edit')
else else
@ -154,7 +154,7 @@ class PostSerializer < ApplicationSerializer
# The following only applies if you're logged in # The following only applies if you're logged in
if action_summary[:can_act] && scope.current_user.present? if action_summary[:can_act] && scope.current_user.present?
action_summary[:can_clear_flags] = scope.is_moderator? && PostActionType.flag_types.values.include?(id) action_summary[:can_clear_flags] = scope.is_staff? && PostActionType.flag_types.values.include?(id)
end end
if post_actions.present? && post_actions.has_key?(id) if post_actions.present? && post_actions.has_key?(id)
@ -163,7 +163,7 @@ class PostSerializer < ApplicationSerializer
end end
# anonymize flags # anonymize flags
if !scope.is_moderator? && PostActionType.flag_types.values.include?(id) if !scope.is_staff? && PostActionType.flag_types.values.include?(id)
action_summary[:count] = action_summary[:acted] ? 1 : 0 action_summary[:count] = action_summary[:acted] ? 1 : 0
end end

View file

@ -18,7 +18,7 @@
<%# load the selected locale before any other scripts %> <%# load the selected locale before any other scripts %>
<%= javascript_include_tag "locales/#{I18n.locale}" %> <%= javascript_include_tag "locales/#{I18n.locale}" %>
<%= javascript_include_tag "application" %> <%= javascript_include_tag "application" %>
<%- if moderator? %> <%- if staff? %>
<%= javascript_include_tag "admin"%> <%= javascript_include_tag "admin"%>
<%- end %> <%- end %>

View file

@ -2,7 +2,7 @@
<%=stylesheet_link_tag "application"%> <%=stylesheet_link_tag "application"%>
<%- end %> <%- end %>
<%- if moderator? %> <%- if staff? %>
<%= stylesheet_link_tag "admin"%> <%= stylesheet_link_tag "admin"%>
<%-end%> <%-end%>
<%=SiteCustomization.custom_stylesheet(session[:preview_style])%> <%=SiteCustomization.custom_stylesheet(session[:preview_style])%>

View file

@ -1,7 +1,7 @@
require 'sidekiq/web' require 'sidekiq/web'
require_dependency 'admin_constraint' require_dependency 'admin_constraint'
require_dependency 'moderator_constraint' require_dependency 'staff_constraint'
require_dependency 'homepage_constraint' require_dependency 'homepage_constraint'
# This used to be User#username_format, but that causes a preload of the User object # This used to be User#username_format, but that causes a preload of the User object
@ -22,7 +22,7 @@ Discourse::Application.routes.draw do
end end
get 'srv/status' => 'forums#status' get 'srv/status' => 'forums#status'
namespace :admin, constraints: ModeratorConstraint.new do namespace :admin, constraints: StaffConstraint.new do
get '' => 'admin#index' get '' => 'admin#index'
resources :site_settings, constraints: AdminConstraint.new resources :site_settings, constraints: AdminConstraint.new

View file

@ -15,8 +15,8 @@ class Guardian
@user && @user.admin? @user && @user.admin?
end end
def is_moderator? def is_staff?
@user && @user.moderator? @user && @user.staff?
end end
# Can the user see the object? # Can the user see the object?
@ -54,7 +54,7 @@ class Guardian
def can_moderate?(obj) def can_moderate?(obj)
return false if obj.blank? return false if obj.blank?
return false if @user.blank? return false if @user.blank?
@user.moderator? @user.staff?
end end
alias :can_move_posts? :can_moderate? alias :can_move_posts? :can_moderate?
alias :can_see_flags? :can_moderate? alias :can_see_flags? :can_moderate?
@ -103,7 +103,7 @@ class Guardian
return false if target.blank? return false if target.blank?
return false if @user.blank? return false if @user.blank?
return false if target.approved? return false if target.approved?
@user.moderator? @user.staff?
end end
def can_ban?(user) def can_ban?(user)
@ -116,7 +116,7 @@ class Guardian
def can_clear_flags?(post) def can_clear_flags?(post)
return false if @user.blank? return false if @user.blank?
return false if post.blank? return false if post.blank?
@user.moderator? @user.staff?
end end
def can_revoke_admin?(admin) def can_revoke_admin?(admin)
@ -136,32 +136,30 @@ class Guardian
end end
def can_revoke_moderation?(moderator) def can_revoke_moderation?(moderator)
return false unless @user.try(:admin?) return false unless is_admin?
return false if moderator.blank? return false if moderator.blank?
return false if @user.id == moderator.id return false if @user.id == moderator.id
return false unless moderator.moderator?
true true
end end
def can_grant_moderation?(user) 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.blank?
return false if @user.id == user.id return false if @user.id == user.id
return false if user.admin? return false if user.staff?
return false if user.moderator?
true true
end end
def can_delete_user?(user_to_delete) def can_delete_user?(user_to_delete)
return false unless @user.try(:admin?) return false unless is_admin?
return false if user_to_delete.blank? return false unless user_to_delete
return false if user_to_delete.post_count > 0 return false if user_to_delete.post_count > 0
true true
end end
# Can we see who acted on a post in a particular way? # Can we see who acted on a post in a particular way?
def can_see_post_actors?(topic, post_action_type_id) 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] type_symbol = PostActionType.types[post_action_type_id]
return false if type_symbol == :bookmark return false if type_symbol == :bookmark
@ -178,37 +176,36 @@ class Guardian
# Support sites that have to approve users # Support sites that have to approve users
def can_access_forum? def can_access_forum?
return true unless SiteSetting.must_approve_users? 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 # Staff can't lock themselves out of a site
return true if user.admin? return true if is_staff?
user.approved? @user.approved?
end end
def can_see_pending_invites_from?(user) def can_see_pending_invites_from?(user)
return false if user.blank? return false unless user && @user
return false if @user.blank?
return user == @user return user == @user
end end
# For now, can_invite_to is basically can_see? # For now, can_invite_to is basically can_see?
def can_invite_to?(object) def can_invite_to?(object)
return false if @user.blank? return false unless @user
return false unless can_see?(object) return false unless can_see?(object)
return false if SiteSetting.must_approve_users? return false if SiteSetting.must_approve_users?
@user.has_trust_level?(:regular) || @user.moderator? @user.has_trust_level?(:regular) || @user.staff?
end end
def can_see_deleted_posts? def can_see_deleted_posts?
return true if is_admin? return true if is_staff?
false false
end end
def can_see_private_messages?(user_id) def can_see_private_messages?(user_id)
return true if is_moderator? return true if is_staff?
return false if @user.blank? return false unless @user
@user.id == user_id @user.id == user_id
end end
@ -240,11 +237,11 @@ class Guardian
# Creating Methods # Creating Methods
def can_create_category?(parent) def can_create_category?(parent)
@user.moderator? is_staff?
end end
def can_create_post_on_topic?(topic) 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.closed?
return false if topic.archived? return false if topic.archived?
true true
@ -252,22 +249,22 @@ class Guardian
# Editing Methods # Editing Methods
def can_edit_category?(category) def can_edit_category?(category)
@user.moderator? is_staff?
end end
def can_edit_post?(post) def can_edit_post?(post)
return true if @user.moderator? return true if is_staff?
return false if post.topic.archived? return false if post.topic.archived?
(post.user == @user) (post.user == @user)
end end
def can_edit_user?(user) def can_edit_user?(user)
return true if user == @user return true if user == @user
@user.moderator? is_staff?
end end
def can_edit_topic?(topic) def can_edit_topic?(topic)
return true if @user.moderator? return true if is_staff?
return true if topic.user == @user return true if topic.user == @user
false false
end end
@ -280,22 +277,22 @@ class Guardian
# You can delete your own posts # You can delete your own posts
return !post.user_deleted? if post.user == @user return !post.user_deleted? if post.user == @user
@user.moderator? is_staff?
end end
# Recovery Method # Recovery Method
def can_recover_post?(post) def can_recover_post?(post)
return false if @user.blank? return false unless @user
@user.moderator? is_staff?
end end
def can_delete_category?(category) def can_delete_category?(category)
return false unless @user.moderator? return false unless is_staff?
return category.topic_count == 0 return category.topic_count == 0
end end
def can_delete_topic?(topic) def can_delete_topic?(topic)
return false unless @user.moderator? return false unless is_staff?
return false if Category.exists?(topic_id: topic.id) return false if Category.exists?(topic_id: topic.id)
true true
end end
@ -313,7 +310,7 @@ class Guardian
def can_send_private_message?(target) def can_send_private_message?(target)
return false unless User === target || Group === target return false unless User === target || Group === target
return false if @user.blank? return false unless @user
# Can't send message to yourself # Can't send message to yourself
return false if User === target && @user.id == target.id return false if User === target && @user.id == target.id
@ -325,8 +322,8 @@ class Guardian
end end
def can_reply_as_new_topic?(topic) def can_reply_as_new_topic?(topic)
return false if @user.blank? return false unless @user
return false if topic.blank? return false unless topic
return false if topic.private_message? return false if topic.private_message?
@user.has_trust_level?(:basic) @user.has_trust_level?(:basic)
@ -335,7 +332,7 @@ class Guardian
def can_see_topic?(topic) def can_see_topic?(topic)
return false unless topic return false unless topic
return true if @user && @user.moderator? return true if @user && is_staff?
return false if topic.deleted_at return false if topic.deleted_at
if topic.category && topic.category.secure if topic.category && topic.category.secure
@ -353,7 +350,7 @@ class Guardian
def can_see_post?(post) def can_see_post?(post)
return false unless post return false unless post
return true if @user && @user.moderator? return true if @user && is_staff?
return false if post.deleted_at.present? return false if post.deleted_at.present?
can_see_topic?(post.topic) can_see_topic?(post.topic)

View file

@ -22,7 +22,7 @@ class RateLimiter
def can_perform? def can_perform?
return true if RateLimiter.disabled? return true if RateLimiter.disabled?
return true if @user.moderator? return true if @user.staff?
result = $redis.get(@key) result = $redis.get(@key)
return true if result.blank? return true if result.blank?
@ -32,7 +32,7 @@ class RateLimiter
def performed! def performed!
return if RateLimiter.disabled? return if RateLimiter.disabled?
return if @user.moderator? return if @user.staff?
result = $redis.incr(@key).to_i result = $redis.incr(@key).to_i
$redis.expire(@key, @secs) if result == 1 $redis.expire(@key, @secs) if result == 1

View file

@ -1,6 +1,6 @@
require_dependency 'current_user' require_dependency 'current_user'
class ModeratorConstraint class StaffConstraint
def matches?(request) def matches?(request)
return false unless request.session[:current_user_id].present? return false unless request.session[:current_user_id].present?

View file

@ -23,7 +23,7 @@ class TopicView
@limit = options[:limit] || SiteSetting.posts_per_page; @limit = options[:limit] || SiteSetting.posts_per_page;
@filtered_posts = @topic.posts @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? @filtered_posts = @filtered_posts.best_of if options[:best_of].present?
if options[:username_filters].present? if options[:username_filters].present?
@ -299,7 +299,7 @@ class TopicView
.includes(:user) .includes(:user)
.includes(:reply_to_user) .includes(:reply_to_user)
.order('sort_order') .order('sort_order')
@posts = @posts.with_deleted if @user.try(:admin?) @posts = @posts.with_deleted if @user.try(:staff?)
@posts @posts
end end

View file

@ -311,9 +311,9 @@ describe User do
user.has_trust_level?(:elder).should be_true user.has_trust_level?(:elder).should be_true
end end
it "is a moderator if the user is an admin" do it "is staff if the user is an admin" do
user.admin = true user.admin = true
user.moderator?.should be_true user.staff?.should be_true
end end
end end