This commit is contained in:
r888888888
2015-06-25 13:51:05 -07:00
parent 3cc7dbbedc
commit 1d9596d7f2
64 changed files with 244 additions and 140 deletions

View File

@@ -145,4 +145,8 @@ protected
Rails.application.config.session_store :cookie_store, :key => '_danbooru_session', :secure => false Rails.application.config.session_store :cookie_store, :key => '_danbooru_session', :secure => false
end end
end end
def post_approvers_only
CurrentUser.can_approve_posts?
end
end end

View File

@@ -1,7 +1,7 @@
class ForumTopicsController < ApplicationController class ForumTopicsController < ApplicationController
respond_to :html, :xml, :json respond_to :html, :xml, :json
before_filter :member_only, :except => [:index, :show] before_filter :member_only, :except => [:index, :show]
before_filter :janitor_only, :only => [:new_merge, :create_merge] before_filter :moderator_only, :only => [:new_merge, :create_merge]
before_filter :normalize_search, :only => :index before_filter :normalize_search, :only => :index
def new def new

View File

@@ -1,5 +1,5 @@
class IpBansController < ApplicationController class IpBansController < ApplicationController
before_filter :janitor_only before_filter :moderator_only
def new def new
@ip_ban = IpBan.new @ip_ban = IpBan.new

View File

@@ -1,6 +1,6 @@
module Moderator module Moderator
class DashboardsController < ApplicationController class DashboardsController < ApplicationController
before_filter :janitor_only before_filter :moderator_only
helper :post_flags, :post_appeals helper :post_flags, :post_appeals
def show def show

View File

@@ -1,6 +1,6 @@
module Moderator module Moderator
class IpAddrsController < ApplicationController class IpAddrsController < ApplicationController
before_filter :janitor_only before_filter :moderator_only
def index def index
@search = IpAddrSearch.new(params[:search]) @search = IpAddrSearch.new(params[:search])

View File

@@ -1,7 +1,7 @@
module Moderator module Moderator
module Post module Post
class ApprovalsController < ApplicationController class ApprovalsController < ApplicationController
before_filter :janitor_only before_filter :post_approvers_only
def create def create
@post = ::Post.find(params[:post_id]) @post = ::Post.find(params[:post_id])

View File

@@ -1,7 +1,7 @@
module Moderator module Moderator
module Post module Post
class DisapprovalsController < ApplicationController class DisapprovalsController < ApplicationController
before_filter :janitor_only before_filter :post_approvers_only
def create def create
@post = ::Post.find(params[:post_id]) @post = ::Post.find(params[:post_id])

View File

@@ -1,7 +1,7 @@
module Moderator module Moderator
module Post module Post
class PostsController < ApplicationController class PostsController < ApplicationController
before_filter :janitor_only, :only => [:delete, :undelete, :ban, :unban, :confirm_delete, :confirm_ban] before_filter :moderator_only, :only => [:delete, :undelete, :ban, :unban, :confirm_delete, :confirm_ban]
before_filter :admin_only, :only => [:expunge] before_filter :admin_only, :only => [:expunge]
rescue_from ::PostFlag::Error, :with => :rescue_exception rescue_from ::PostFlag::Error, :with => :rescue_exception

View File

@@ -2,7 +2,7 @@ module Moderator
module Post module Post
class QueuesController < ApplicationController class QueuesController < ApplicationController
respond_to :html, :json respond_to :html, :json
before_filter :janitor_only before_filter :post_approvers_only
def show def show
::Post.without_timeout do ::Post.without_timeout do

View File

@@ -1,7 +1,7 @@
class PoolsController < ApplicationController class PoolsController < ApplicationController
respond_to :html, :xml, :json, :js respond_to :html, :xml, :json, :js
before_filter :member_only, :except => [:index, :show, :gallery] before_filter :member_only, :except => [:index, :show, :gallery]
before_filter :janitor_only, :only => [:destroy] before_filter :moderator_only, :only => [:destroy]
def new def new
@pool = Pool.new @pool = Pool.new

View File

@@ -1,5 +1,5 @@
class TagAliasCorrectionsController < ApplicationController class TagAliasCorrectionsController < ApplicationController
before_filter :janitor_only before_filter :builder_only
def create def create
@correction = TagAliasCorrection.new(params[:tag_alias_id]) @correction = TagAliasCorrection.new(params[:tag_alias_id])

View File

@@ -1,7 +1,7 @@
class WikiPagesController < ApplicationController class WikiPagesController < ApplicationController
respond_to :html, :xml, :json, :js respond_to :html, :xml, :json, :js
before_filter :member_only, :except => [:index, :show, :show_or_new] before_filter :member_only, :except => [:index, :show, :show_or_new]
before_filter :janitor_only, :only => [:destroy] before_filter :moderator_only, :only => [:destroy]
before_filter :normalize_search_params, :only => [:index] before_filter :normalize_search_params, :only => [:index]
rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception
rescue_from ActiveRecord::RecordNotFound, :with => :rescue_exception rescue_from ActiveRecord::RecordNotFound, :with => :rescue_exception

View File

@@ -7,7 +7,7 @@ module PostFlagsHelper
html << '<li>' html << '<li>'
html << DText.parse_inline(flag.reason).html_safe html << DText.parse_inline(flag.reason).html_safe
if CurrentUser.is_janitor? if CurrentUser.is_moderator?
html << ' - ' + link_to_user(flag.creator) html << ' - ' + link_to_user(flag.creator)
end end

View File

@@ -108,6 +108,10 @@ class AnonymousUser
false false
end end
def can_approve_posts?
false
end
def blacklisted_tags def blacklisted_tags
"" ""
end end

View File

@@ -329,7 +329,7 @@ class Artist < ActiveRecord::Base
end end
def other_names_match(string) def other_names_match(string)
if string =~ /\*/ && CurrentUser.user.is_builder? if string =~ /\*/ && CurrentUser.is_builder?
where("other_names ILIKE ? ESCAPE E'\\\\'", string.to_escaped_for_sql_like) where("other_names ILIKE ? ESCAPE E'\\\\'", string.to_escaped_for_sql_like)
else else
where("other_names_index @@ to_tsquery('danbooru', E?)", Artist.normalize_name(string).to_escaped_for_tsquery) where("other_names_index @@ to_tsquery('danbooru', E?)", Artist.normalize_name(string).to_escaped_for_tsquery)
@@ -352,7 +352,7 @@ class Artist < ActiveRecord::Base
def any_name_matches(name) def any_name_matches(name)
stripped_name = normalize_name(name).to_escaped_for_sql_like stripped_name = normalize_name(name).to_escaped_for_sql_like
if name =~ /\*/ && CurrentUser.user.is_builder? if name =~ /\*/ && CurrentUser.is_builder?
where("(name LIKE ? ESCAPE E'\\\\' OR other_names LIKE ? ESCAPE E'\\\\')", stripped_name, stripped_name) where("(name LIKE ? ESCAPE E'\\\\' OR other_names LIKE ? ESCAPE E'\\\\')", stripped_name, stripped_name)
else else
name_for_tsquery = normalize_name(name).to_escaped_for_tsquery name_for_tsquery = normalize_name(name).to_escaped_for_tsquery
@@ -479,6 +479,6 @@ class Artist < ActiveRecord::Base
end end
def visible? def visible?
!is_banned? || CurrentUser.user.is_janitor? !is_banned? || CurrentUser.is_moderator?
end end
end end

View File

@@ -61,7 +61,7 @@ class BulkUpdateRequest < ActiveRecord::Base
end end
def editable?(user) def editable?(user)
user_id == user.id || user.is_janitor? user_id == user.id || user.is_builder?
end end
def create_forum_topic def create_forum_topic

View File

@@ -165,7 +165,7 @@ class Comment < ActiveRecord::Base
end end
def editable_by?(user) def editable_by?(user)
creator_id == user.id || user.is_janitor? creator_id == user.id || user.is_moderator?
end end
def hidden_attributes def hidden_attributes

View File

@@ -92,7 +92,7 @@ class ForumPost < ActiveRecord::Base
end end
def validate_topic_is_unlocked def validate_topic_is_unlocked
return if CurrentUser.user.is_janitor? return if CurrentUser.user.is_moderator?
return if topic.nil? return if topic.nil?
if topic.is_locked? if topic.is_locked?
@@ -110,7 +110,7 @@ class ForumPost < ActiveRecord::Base
end end
def editable_by?(user) def editable_by?(user)
creator_id == user.id || user.is_janitor? creator_id == user.id || user.is_moderator?
end end
def update_topic_updated_at_on_create def update_topic_updated_at_on_create

View File

@@ -119,7 +119,7 @@ class ForumTopic < ActiveRecord::Base
include SubscriptionMethods include SubscriptionMethods
def editable_by?(user) def editable_by?(user)
creator_id == user.id || user.is_janitor? creator_id == user.id || user.is_moderator?
end end
def initialize_is_deleted def initialize_is_deleted

View File

@@ -1,6 +1,5 @@
class JanitorTrial < ActiveRecord::Base class JanitorTrial < ActiveRecord::Base
belongs_to :user belongs_to :user
before_create :initialize_original_level
after_create :send_dmail after_create :send_dmail
after_create :promote_user after_create :promote_user
validates_presence_of :user validates_presence_of :user
@@ -54,10 +53,6 @@ class JanitorTrial < ActiveRecord::Base
self.creator_id = CurrentUser.id self.creator_id = CurrentUser.id
end end
def initialize_original_level
self.original_level = user.level
end
def user_name def user_name
user.try(:name) user.try(:name)
end end
@@ -67,13 +62,14 @@ class JanitorTrial < ActiveRecord::Base
end end
def send_dmail def send_dmail
body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface. You should reacquaint yourself with the [[howto:upload]] guide to make sure you understand the site rules.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are not quality uploads you will fail the trial period and be demoted back to your original level. You will also receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 1 approval a month to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art.\n\nIf you have any questions please respond to this message." body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface. You should reacquaint yourself with the [[howto:upload]] guide to make sure you understand the site rules.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are not quality uploads you will fail the trial period and lose your approval privileges. You will also receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 1 approval a month to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art.\n\nIf you have any questions please respond to this message."
Dmail.create_split(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id) Dmail.create_split(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
end end
def promote_user def promote_user
user.promote_to!(User::Levels::JANITOR, :skip_dmail => true) user.can_approve_posts = true
user.save
end end
def create_feedback def create_feedback
@@ -88,8 +84,9 @@ class JanitorTrial < ActiveRecord::Base
end end
def demote! def demote!
user.can_approve_posts = false
user.save
update_attribute(:status, "inactive") update_attribute(:status, "inactive")
user.update_column(:level, original_level)
self.create_feedback self.create_feedback
end end

View File

@@ -207,7 +207,7 @@ class Pool < ActiveRecord::Base
end end
def deletable_by?(user) def deletable_by?(user)
user.is_janitor? user.is_moderator?
end end
def create_mod_action_for_delete def create_mod_action_for_delete

View File

@@ -46,11 +46,11 @@ class PostFlag < ActiveRecord::Base
q = q.reason_matches(params[:reason_matches]) q = q.reason_matches(params[:reason_matches])
end end
if params[:creator_id].present? && (CurrentUser.user.is_janitor? || params[:creator_id].to_i == CurrentUser.user.id) if params[:creator_id].present? && (CurrentUser.is_moderator? || params[:creator_id].to_i == CurrentUser.user.id)
q = q.where("creator_id = ?", params[:creator_id].to_i) q = q.where("creator_id = ?", params[:creator_id].to_i)
end end
if params[:creator_name].present? && CurrentUser.user.is_janitor? if params[:creator_name].present? && CurrentUser.is_moderator?
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].mb_chars.downcase.strip.tr(" ", "_")) q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].mb_chars.downcase.strip.tr(" ", "_"))
end end
@@ -84,7 +84,7 @@ class PostFlag < ActiveRecord::Base
end end
def validate_creator_is_not_limited def validate_creator_is_not_limited
if CurrentUser.is_janitor? if CurrentUser.can_approve_posts?
# do nothing # do nothing
elsif creator.created_at > 1.week.ago elsif creator.created_at > 1.week.ago
errors[:creator] << "cannot flag within the first week of sign up" errors[:creator] << "cannot flag within the first week of sign up"

View File

@@ -2,7 +2,7 @@ class Tag < ActiveRecord::Base
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv" METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv"
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm" SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm"
attr_accessible :category, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin] attr_accessible :category, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin]
attr_accessible :is_locked, :as => [:moderator, :janitor, :admin] attr_accessible :is_locked, :as => [:moderator, :admin]
has_one :wiki_page, :foreign_key => "title", :primary_key => "name" has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
module ApiMethods module ApiMethods

View File

@@ -224,7 +224,7 @@ class TagAlias < ActiveRecord::Base
def deletable_by?(user) def deletable_by?(user)
return true if user.is_admin? return true if user.is_admin?
return true if is_pending? && user.is_janitor? return true if is_pending? && user.can_approve_posts?
return true if is_pending? && user.id == creator_id return true if is_pending? && user.id == creator_id
return false return false
end end

View File

@@ -207,7 +207,7 @@ class TagImplication < ActiveRecord::Base
def deletable_by?(user) def deletable_by?(user)
return true if user.is_admin? return true if user.is_admin?
return true if is_pending? && user.is_janitor? return true if is_pending? && user.is_builder?
return true if is_pending? && user.id == creator_id return true if is_pending? && user.id == creator_id
return false return false
end end

View File

@@ -29,7 +29,8 @@ class User < ActiveRecord::Base
:style_usernames => 0x0200, :style_usernames => 0x0200,
:enable_auto_complete => 0x0400, :enable_auto_complete => 0x0400,
:show_deleted_children => 0x0800, :show_deleted_children => 0x0800,
:has_saved_searches => 0x1000 :has_saved_searches => 0x1000,
:can_approve_posts => 0x2000
} }
attr_accessor :password, :old_password attr_accessor :password, :old_password

View File

@@ -9,7 +9,7 @@ class WikiPage < ActiveRecord::Base
belongs_to :updater, :class_name => "User" belongs_to :updater, :class_name => "User"
validates_uniqueness_of :title, :case_sensitive => false validates_uniqueness_of :title, :case_sensitive => false
validates_presence_of :title validates_presence_of :title
validate :validate_locker_is_janitor validate :validate_locker_is_moderator
validate :validate_not_locked validate :validate_not_locked
attr_accessible :title, :body, :is_locked, :other_names attr_accessible :title, :body, :is_locked, :other_names
has_one :tag, :foreign_key => "name", :primary_key => "title" has_one :tag, :foreign_key => "name", :primary_key => "title"
@@ -112,15 +112,15 @@ class WikiPage < ActiveRecord::Base
titled(title).select("title, id").first titled(title).select("title, id").first
end end
def validate_locker_is_janitor def validate_locker_is_moderator
if is_locked_changed? && !CurrentUser.is_janitor? if is_locked_changed? && !CurrentUser.is_moderator?
errors.add(:is_locked, "can be modified by janitors only") errors.add(:is_locked, "can be modified by moderators only")
return false return false
end end
end end
def validate_not_locked def validate_not_locked
if is_locked? && !CurrentUser.is_janitor? if is_locked? && !CurrentUser.is_moderator?
errors.add(:is_locked, "and cannot be updated") errors.add(:is_locked, "and cannot be updated")
return false return false
end end
@@ -230,7 +230,7 @@ class WikiPage < ActiveRecord::Base
end end
def visible? def visible?
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor? artist.blank? || !artist.is_banned? || CurrentUser.is_moderator?
end end
def other_names_array def other_names_array

View File

@@ -40,7 +40,7 @@ class WikiPageVersion < ActiveRecord::Base
end end
def visible? def visible?
artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor? artist.blank? || !artist.is_banned? || CurrentUser.is_moderator?
end end
def other_names_array def other_names_array

View File

@@ -8,7 +8,7 @@
<th width="5%">Post</th> <th width="5%">Post</th>
<th>Original</th> <th>Original</th>
<th>Translated</th> <th>Translated</th>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<th width="10%">IP Address</th> <th width="10%">IP Address</th>
<% end %> <% end %>
<th width="10%">Edited By</th> <th width="10%">Edited By</th>
@@ -30,7 +30,7 @@
<h3><%= h(commentary_version.translated_title) %></h3> <h3><%= h(commentary_version.translated_title) %></h3>
<%= h(commentary_version.translated_description) %> <%= h(commentary_version.translated_description) %>
</td> </td>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<td> <td>
<%= commentary_version.updater_ip_addr %> <%= commentary_version.updater_ip_addr %>
</td> </td>

View File

@@ -11,7 +11,7 @@
<th>Group</th> <th>Group</th>
<th>Updated</th> <th>Updated</th>
<th>Updated by</th> <th>Updated by</th>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<th>IP Address</th> <th>IP Address</th>
<% end %> <% end %>
<th>Active</th> <th>Active</th>
@@ -31,7 +31,7 @@
<td><%= artist_version.group_name %></td> <td><%= artist_version.group_name %></td>
<td><%= compact_time artist_version.created_at %></td> <td><%= compact_time artist_version.created_at %></td>
<td><%= link_to_user artist_version.updater %></td> <td><%= link_to_user artist_version.updater %></td>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<td> <td>
<%= artist_version.updater_ip_addr %> <%= artist_version.updater_ip_addr %>
</td> </td>

View File

@@ -1,4 +1,4 @@
<% if CurrentUser.is_janitor? || !forum_post.is_deleted? %> <% if CurrentUser.is_moderator? || !forum_post.is_deleted? %>
<article class="forum-post" id="forum_post_<%= forum_post.id %>" data-forum-post-id="<%= forum_post.id %>" data-creator="<%= forum_post.creator.name %>"> <article class="forum-post" id="forum_post_<%= forum_post.id %>" data-forum-post-id="<%= forum_post.id %>" data-creator="<%= forum_post.creator.name %>">
<div class="author"> <div class="author">
<h4> <h4>
@@ -23,7 +23,7 @@
<% if CurrentUser.is_member? && @forum_topic %> <% if CurrentUser.is_member? && @forum_topic %>
<li><%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %></li> <li><%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %></li>
<% end %> <% end %>
<% if CurrentUser.is_janitor? && !forum_post.is_original_post? %> <% if CurrentUser.is_moderator? && !forum_post.is_original_post? %>
<% if forum_post.is_deleted %> <% if forum_post.is_deleted %>
<li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %></li> <li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %></li>
<% else %> <% else %>

View File

@@ -11,7 +11,7 @@
</thead> </thead>
<tbody> <tbody>
<% @forum_posts.each do |forum_post| %> <% @forum_posts.each do |forum_post| %>
<% if CurrentUser.is_janitor? || !forum_post.is_deleted? %> <% if CurrentUser.is_moderator? || !forum_post.is_deleted? %>
<tr> <tr>
<td><%= link_to forum_post.topic.title, forum_topic_path(forum_post.topic) %></td> <td><%= link_to forum_post.topic.title, forum_topic_path(forum_post.topic) %></td>
<td> <td>

View File

@@ -17,7 +17,7 @@
<%= dtext_field "forum_post", "body", :input_name => "forum_topic[original_post_attributes][body]", :value => forum_topic.original_post.body, :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %> <%= dtext_field "forum_post", "body", :input_name => "forum_topic[original_post_attributes][body]", :value => forum_topic.original_post.body, :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %>
<% end %> <% end %>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<%= f.input :is_sticky %> <%= f.input :is_sticky %>
<%= f.input :is_locked %> <%= f.input :is_locked %>
<% end %> <% end %>

View File

@@ -20,7 +20,7 @@
<% end %> <% end %>
<% if !@forum_topic.new_record? && @forum_topic.editable_by?(CurrentUser.user) %> <% if !@forum_topic.new_record? && @forum_topic.editable_by?(CurrentUser.user) %>
<li><%= link_to "Edit", edit_forum_topic_path(@forum_topic) %></li> <li><%= link_to "Edit", edit_forum_topic_path(@forum_topic) %></li>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<% if @forum_topic.is_deleted? %> <% if @forum_topic.is_deleted? %>
<li><%= link_to "Undelete", undelete_forum_topic_path(@forum_topic), :method => :post %></li> <li><%= link_to "Undelete", undelete_forum_topic_path(@forum_topic), :method => :post %></li>
<% else %> <% else %>

View File

@@ -18,7 +18,7 @@
<%= render "forum_posts/listing", :forum_posts => @forum_posts %> <%= render "forum_posts/listing", :forum_posts => @forum_posts %>
<% if CurrentUser.is_member? %> <% if CurrentUser.is_member? %>
<% if CurrentUser.is_janitor? || !@forum_topic.is_locked? %> <% if CurrentUser.is_moderator? || !@forum_topic.is_locked? %>
<p><%= link_to "Reply &raquo;".html_safe, new_forum_post_path(:topic_id => @forum_topic.id), :id => "new-response-link" %></p> <p><%= link_to "Reply &raquo;".html_safe, new_forum_post_path(:topic_id => @forum_topic.id), :id => "new-response-link" %></p>
<div style="display: none;" id="topic-response"> <div style="display: none;" id="topic-response">

View File

@@ -1,5 +1,5 @@
<menu class="main"> <menu class="main">
<% if CurrentUser.user.is_anonymous? %> <% if CurrentUser.is_anonymous? %>
<%= nav_link_to("Sign in", new_session_path, :class => "login") %> <%= nav_link_to("Sign in", new_session_path, :class => "login") %>
<% else %> <% else %>
<%= nav_link_to("My Account #{CurrentUser.dmail_count}", user_path(CurrentUser.user)) %> <%= nav_link_to("My Account #{CurrentUser.dmail_count}", user_path(CurrentUser.user)) %>
@@ -15,8 +15,8 @@
<% end %> <% end %>
<%= nav_link_to("Pools", pools_path) %> <%= nav_link_to("Pools", pools_path) %>
<%= nav_link_to("Wiki", wiki_pages_path(:title => "help:home")) %> <%= nav_link_to("Wiki", wiki_pages_path(:title => "help:home")) %>
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.user.has_forum_been_updated? ? "forum-updated" : nil)) %> <%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.has_forum_been_updated? ? "forum-updated" : nil)) %>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<%= nav_link_to("Dashboard", moderator_dashboard_path) %> <%= nav_link_to("Dashboard", moderator_dashboard_path) %>
<% end %> <% end %>
<%= nav_link_to("More &raquo;".html_safe, site_map_path, :id => "site-map-link") %> <%= nav_link_to("More &raquo;".html_safe, site_map_path, :id => "site-map-link") %>

View File

@@ -74,7 +74,7 @@
| <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %> | <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %>
<% end %> <% end %>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_builder? %>
| <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %> | <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %>
<% end %> <% end %>
</td> </td>

View File

@@ -10,7 +10,7 @@
<th width="5%">Note</th> <th width="5%">Note</th>
<th>Body</th> <th>Body</th>
<th width="5%">Position</th> <th width="5%">Position</th>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<th width="10%">IP Address</th> <th width="10%">IP Address</th>
<% end %> <% end %>
<th width="10%">Edited By</th> <th width="10%">Edited By</th>
@@ -36,7 +36,7 @@
<td> <td>
<%= note_version_position_diff(note_version) %> <%= note_version_position_diff(note_version) %>
</td> </td>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<td> <td>
<%= note_version.updater_ip_addr %> <%= note_version.updater_ip_addr %>
</td> </td>

View File

@@ -9,7 +9,7 @@
<th>Post Count</th> <th>Post Count</th>
<th>Changes</th> <th>Changes</th>
<th>Updater</th> <th>Updater</th>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<th>IP Address</th> <th>IP Address</th>
<% end %> <% end %>
<th>Date</th> <th>Date</th>
@@ -25,7 +25,7 @@
<td><%= link_to pool_version.post_id_array.size, pool_versions_path(:search => {:pool_id => pool_version.pool_id}) %></td> <td><%= link_to pool_version.post_id_array.size, pool_versions_path(:search => {:pool_id => pool_version.pool_id}) %></td>
<td><%= pool_version_diff(pool_version) %></td> <td><%= pool_version_diff(pool_version) %></td>
<td><%= link_to_user pool_version.updater%></td> <td><%= link_to_user pool_version.updater%></td>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<td> <td>
<%= pool_version.updater_ip_addr %> <%= pool_version.updater_ip_addr %>
</td> </td>

View File

@@ -19,7 +19,7 @@
</td> </td>
</tr> </tr>
<% if CurrentUser.user.is_janitor? %> <% if CurrentUser.user.is_moderator? %>
<tr> <tr>
<th><label for="search_creator_name">Creator</th> <th><label for="search_creator_name">Creator</th>
<td> <td>

View File

@@ -7,7 +7,7 @@
<thead> <thead>
<tr> <tr>
<th width="1%"></th> <th width="1%"></th>
<% if CurrentUser.user.is_janitor? %> <% if CurrentUser.user.is_moderator? %>
<th width="10%">Creator</th> <th width="10%">Creator</th>
<% end %> <% end %>
<th>Reason</th> <th>Reason</th>
@@ -18,7 +18,7 @@
<% @post_flags.each do |post_flag| %> <% @post_flags.each do |post_flag| %>
<tr class="resolved-<%= post_flag.is_resolved? %>"> <tr class="resolved-<%= post_flag.is_resolved? %>">
<td><%= PostPresenter.preview(post_flag.post, :tags => "status:any") %></td> <td><%= PostPresenter.preview(post_flag.post, :tags => "status:any") %></td>
<% if CurrentUser.user.is_janitor? %> <% if CurrentUser.user.is_moderator? %>
<td> <td>
<%= link_to_user post_flag.creator %> <%= link_to_user post_flag.creator %>
</td> </td>

View File

@@ -7,7 +7,7 @@
<th width="10%">User</th> <th width="10%">User</th>
<th width="5%">Rating</th> <th width="5%">Rating</th>
<th width="5%">Parent</th> <th width="5%">Parent</th>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<th width="10%">IP Address</th> <th width="10%">IP Address</th>
<% end %> <% end %>
<th>Tags</th> <th>Tags</th>
@@ -28,7 +28,7 @@
</td> </td>
<td><%= post_version.rating %></td> <td><%= post_version.rating %></td>
<td><%= post_version.parent_id %></td> <td><%= post_version.parent_id %></td>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<td> <td>
<%= post_version.updater_ip_addr %> <%= post_version.updater_ip_addr %>
</td> </td>

View File

@@ -7,13 +7,13 @@
<% unless CurrentUser.is_anonymous? %> <% unless CurrentUser.is_anonymous? %>
<li><%= link_to "Favorites", favorites_path %></li> <li><%= link_to "Favorites", favorites_path %></li>
<li><%= link_to "Favorite groups", favorite_groups_path %></li> <li><%= link_to "Favorite groups", favorite_groups_path %></li>
<% if CurrentUser.user.has_saved_searches? %> <% if CurrentUser.has_saved_searches? %>
<li><%= link_to "Saved searches", saved_searches_path %></li> <li><%= link_to "Saved searches", saved_searches_path %></li>
<% end %> <% end %>
<li><%= link_to "Subscriptions", posts_path(:tags => "sub:#{CurrentUser.name}") %></li> <li><%= link_to "Subscriptions", posts_path(:tags => "sub:#{CurrentUser.name}") %></li>
<% end %> <% end %>
<li class="nonessential"><%= link_to "Changes", post_versions_path %></li> <li class="nonessential"><%= link_to "Changes", post_versions_path %></li>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.can_approve_posts? %>
<li class="nonessential"><%= link_to "Moderate", moderator_post_queue_path %></li> <li class="nonessential"><%= link_to "Moderate", moderator_post_queue_path %></li>
<% end %> <% end %>
<li class="nonessential"><%= link_to "Help", wiki_pages_path(:title => "help:posts") %></li> <li class="nonessential"><%= link_to "Help", wiki_pages_path(:title => "help:posts") %></li>

View File

@@ -17,7 +17,7 @@
<option value="lock-rating">Lock rating</option> <option value="lock-rating">Lock rating</option>
<option value="lock-note">Lock notes</option> <option value="lock-note">Lock notes</option>
<% end %> <% end %>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.can_approve_posts? %>
<option value="approve">Approve</option> <option value="approve">Approve</option>
<% end %> <% end %>
</select> </select>

View File

@@ -27,7 +27,7 @@
<div class="ui-corner-all ui-state-highlight notice notice-pending" id="pending-approval-notice"> <div class="ui-corner-all ui-state-highlight notice notice-pending" id="pending-approval-notice">
This post is pending approval (<%= link_to "learn more", wiki_pages_path(:title => "about:mod_queue") %>) This post is pending approval (<%= link_to "learn more", wiki_pages_path(:title => "about:mod_queue") %>)
<% if CurrentUser.is_janitor? && !post.disapproved_by?(CurrentUser.user) %> <% if CurrentUser.can_approve_posts? && !post.disapproved_by?(CurrentUser.user) %>
<div class="quick-mod"> <div class="quick-mod">
<% unless post.is_status_locked? %> <% unless post.is_status_locked? %>
<%= link_to "Approve", moderator_post_approval_path(:post_id => post.id), :method => :post, :remote => true, :class => "btn" %> | <%= link_to "Approve", moderator_post_approval_path(:post_id => post.id), :method => :post, :remote => true, :class => "btn" %> |

View File

@@ -28,7 +28,7 @@
<li><%= link_to "Appeal", new_post_appeal_path(:post_id => post.id), :id => "appeal" %></li> <li><%= link_to "Appeal", new_post_appeal_path(:post_id => post.id), :id => "appeal" %></li>
<% end %> <% end %>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.can_approve_posts? %>
<% if post.is_deleted? %> <% if post.is_deleted? %>
<li><%= link_to "Undelete", undelete_moderator_post_post_path(:post_id => post.id), :remote => true, :method => :post, :id => "undelete" %></li> <li><%= link_to "Undelete", undelete_moderator_post_post_path(:post_id => post.id), :remote => true, :method => :post, :id => "undelete" %></li>
<% else %> <% else %>

View File

@@ -11,7 +11,7 @@
<li><%= link_to("Upload Listing", uploads_path) %></li> <li><%= link_to("Upload Listing", uploads_path) %></li>
<li><%= link_to("Appeals", post_appeals_path) %></li> <li><%= link_to("Appeals", post_appeals_path) %></li>
<li><%= link_to("Flags", post_flags_path) %></li> <li><%= link_to("Flags", post_flags_path) %></li>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.can_approve_posts? %>
<li><%= link_to("Moderate", moderator_post_queue_path) %></li> <li><%= link_to("Moderate", moderator_post_queue_path) %></li>
<% end %> <% end %>
<% if CurrentUser.is_admin? %> <% if CurrentUser.is_admin? %>
@@ -87,7 +87,7 @@
<section> <section>
<ul> <ul>
<li><h1>Users</h1></li> <li><h1>Users</h1></li>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.can_approve_posts? %>
<li><%= link_to("Dashboard", moderator_dashboard_path) %></li> <li><%= link_to("Dashboard", moderator_dashboard_path) %></li>
<% end %> <% end %>
<li><%= link_to("Help", wiki_pages_path(:title => "help:users")) %></li> <li><%= link_to("Help", wiki_pages_path(:title => "help:users")) %></li>

View File

@@ -36,7 +36,7 @@
| <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %> | <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %>
<% end %> <% end %>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_builder? %>
| <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %> | <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %>
<% end %> <% end %>
</td> </td>

View File

@@ -9,7 +9,7 @@
<%= f.input :category, :collection => Danbooru.config.canonical_tag_category_mapping.to_a, :include_blank => false %> <%= f.input :category, :collection => Danbooru.config.canonical_tag_category_mapping.to_a, :include_blank => false %>
<% end %> <% end %>
<% if CurrentUser.user.is_janitor? %> <% if CurrentUser.is_moderator? %>
<%= f.input :is_locked, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> <%= f.input :is_locked, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
<% end %> <% end %>

View File

@@ -94,14 +94,14 @@
<td><%= presenter.comment_count(self) %> in <%= presenter.commented_posts_count(self) %> posts</td> <td><%= presenter.comment_count(self) %> in <%= presenter.commented_posts_count(self) %> posts</td>
</tr> </tr>
<% if CurrentUser.user.id == user.id || CurrentUser.user.is_janitor? %> <% if CurrentUser.user.id == user.id || CurrentUser.is_moderator? %>
<tr> <tr>
<th>Appeals</th> <th>Appeals</th>
<td><%= presenter.appeal_count(self) %></td> <td><%= presenter.appeal_count(self) %></td>
</tr> </tr>
<% end %> <% end %>
<% if CurrentUser.user.id == user.id || CurrentUser.user.is_janitor? %> <% if CurrentUser.user.id == user.id || CurrentUser.is_moderator? %>
<tr> <tr>
<th>Flags</th> <th>Flags</th>
<td><%= presenter.flag_count(self) %></td> <td><%= presenter.flag_count(self) %></td>
@@ -126,7 +126,7 @@
</td> </td>
</tr> </tr>
<% if CurrentUser.user.is_janitor? && presenter.previous_names.present? %> <% if CurrentUser.is_moderator? && presenter.previous_names.present? %>
<tr> <tr>
<th>Previous Names</th> <th>Previous Names</th>
<td><%= presenter.previous_names %></td> <td><%= presenter.previous_names %></td>

View File

@@ -14,7 +14,7 @@
<th>Name</th> <th>Name</th>
<th>Posts</th> <th>Posts</th>
<th>Deleted</th> <th>Deleted</th>
<% if CurrentUser.user.is_janitor? %> <% if CurrentUser.is_moderator? %>
<th><abbr title="3+ Score Binomial Confidence Interval">5+ SBCI</abbr></th> <th><abbr title="3+ Score Binomial Confidence Interval">5+ SBCI</abbr></th>
<th><abbr title="6+ Score Binomial Confidence Interval">10+ SBCI</abbr></th> <th><abbr title="6+ Score Binomial Confidence Interval">10+ SBCI</abbr></th>
<% end %> <% end %>
@@ -40,7 +40,7 @@
</td> </td>
<td><%= link_to user.posts.count, posts_path(:tags => "user:#{user.name}") %></td> <td><%= link_to user.posts.count, posts_path(:tags => "user:#{user.name}") %></td>
<td><%= user.posts.deleted.count %></td> <td><%= user.posts.deleted.count %></td>
<% if CurrentUser.user.is_janitor? %> <% if CurrentUser.is_moderator? %>
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 3), :precision => 0 %></td> <td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 3), :precision => 0 %></td>
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 6), :precision => 0 %></td> <td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 6), :precision => 0 %></td>
<% end %> <% end %>

View File

@@ -16,7 +16,7 @@
<% end %> <% end %>
<th>Title</th> <th>Title</th>
<th width="5%"></th> <th width="5%"></th>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<th width="10%">IP Address</th> <th width="10%">IP Address</th>
<% end %> <% end %>
<th width="26%">Last edited</th> <th width="26%">Last edited</th>
@@ -50,7 +50,7 @@
<% end %> <% end %>
<td class="category-<%= wiki_page_version.category_name %>"><%= link_to wiki_page_version.title, wiki_page_version_path(wiki_page_version) %></td> <td class="category-<%= wiki_page_version.category_name %>"><%= link_to wiki_page_version.title, wiki_page_version_path(wiki_page_version) %></td>
<td><%= link_to "wiki", wiki_page_path(wiki_page_version.wiki_page_id) %></td> <td><%= link_to "wiki", wiki_page_path(wiki_page_version.wiki_page_id) %></td>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<td> <td>
<%= wiki_page_version.updater_ip_addr %> <%= wiki_page_version.updater_ip_addr %>
</td> </td>

View File

@@ -18,7 +18,7 @@
<%= dtext_field "wiki_page", "body" %> <%= dtext_field "wiki_page", "body" %>
<% if CurrentUser.user.is_janitor? %> <% if CurrentUser.is_moderator? %>
<%= f.input :is_locked %> <%= f.input :is_locked %>
<% end %> <% end %>

View File

@@ -18,7 +18,7 @@
<% if CurrentUser.is_member? %> <% if CurrentUser.is_member? %>
<li><%= link_to "Edit", edit_wiki_page_path(@wiki_page), :id => "wiki-page-edit-link" %></li> <li><%= link_to "Edit", edit_wiki_page_path(@wiki_page), :id => "wiki-page-edit-link" %></li>
<% end %> <% end %>
<% if CurrentUser.is_janitor? %> <% if CurrentUser.is_moderator? %>
<li><%= link_to "Delete", wiki_page_path(@wiki_page), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this wiki page?"} %></li> <li><%= link_to "Delete", wiki_page_path(@wiki_page), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this wiki page?"} %></li>
<% end %> <% end %>
<% end %> <% end %>

View File

@@ -0,0 +1,5 @@
class RemoveNotNullOnJanitorTrials < ActiveRecord::Migration
def change
change_column :janitor_trials, :original_level, :integer, :null => true
end
end

View File

@@ -668,8 +668,7 @@ CREATE TABLE artist_versions (
url_string text, url_string text,
is_banned boolean DEFAULT false NOT NULL, is_banned boolean DEFAULT false NOT NULL,
created_at timestamp without time zone, created_at timestamp without time zone,
updated_at timestamp without time zone, updated_at timestamp without time zone
normalized_url_string text
); );
@@ -979,6 +978,40 @@ CREATE SEQUENCE dmails_id_seq
ALTER SEQUENCE dmails_id_seq OWNED BY dmails.id; ALTER SEQUENCE dmails_id_seq OWNED BY dmails.id;
--
-- Name: favorite_groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE favorite_groups (
id integer NOT NULL,
name text NOT NULL,
creator_id integer NOT NULL,
post_ids text DEFAULT ''::text NOT NULL,
post_count integer DEFAULT 0 NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: favorite_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE favorite_groups_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: favorite_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE favorite_groups_id_seq OWNED BY favorite_groups.id;
-- --
-- Name: favorites; Type: TABLE; Schema: public; Owner: -; Tablespace: -- Name: favorites; Type: TABLE; Schema: public; Owner: -; Tablespace:
-- --
@@ -2190,7 +2223,7 @@ CREATE TABLE janitor_trials (
id integer NOT NULL, id integer NOT NULL,
creator_id integer NOT NULL, creator_id integer NOT NULL,
user_id integer NOT NULL, user_id integer NOT NULL,
original_level integer NOT NULL, original_level integer,
created_at timestamp without time zone, created_at timestamp without time zone,
updated_at timestamp without time zone, updated_at timestamp without time zone,
status character varying(255) DEFAULT 'active'::character varying NOT NULL status character varying(255) DEFAULT 'active'::character varying NOT NULL
@@ -3346,6 +3379,13 @@ ALTER TABLE ONLY dmail_filters ALTER COLUMN id SET DEFAULT nextval('dmail_filter
ALTER TABLE ONLY dmails ALTER COLUMN id SET DEFAULT nextval('dmails_id_seq'::regclass); ALTER TABLE ONLY dmails ALTER COLUMN id SET DEFAULT nextval('dmails_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY favorite_groups ALTER COLUMN id SET DEFAULT nextval('favorite_groups_id_seq'::regclass);
-- --
-- Name: id; Type: DEFAULT; Schema: public; Owner: - -- Name: id; Type: DEFAULT; Schema: public; Owner: -
-- --
@@ -4412,6 +4452,14 @@ ALTER TABLE ONLY dmails
ADD CONSTRAINT dmails_pkey PRIMARY KEY (id); ADD CONSTRAINT dmails_pkey PRIMARY KEY (id);
--
-- Name: favorite_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY favorite_groups
ADD CONSTRAINT favorite_groups_pkey PRIMARY KEY (id);
-- --
-- Name: favorites_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- Name: favorites_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
-- --
@@ -4915,6 +4963,20 @@ CREATE INDEX index_dmails_on_message_index ON dmails USING gin (message_index);
CREATE INDEX index_dmails_on_owner_id ON dmails USING btree (owner_id); CREATE INDEX index_dmails_on_owner_id ON dmails USING btree (owner_id);
--
-- Name: index_favorite_groups_on_creator_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_favorite_groups_on_creator_id ON favorite_groups USING btree (creator_id);
--
-- Name: index_favorite_groups_on_lower_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_favorite_groups_on_lower_name ON favorite_groups USING btree (lower(name));
-- --
-- Name: index_favorites_0_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- Name: index_favorites_0_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
-- --
@@ -6672,6 +6734,13 @@ CREATE INDEX index_posts_on_last_noted_at ON posts USING btree (last_noted_at);
CREATE UNIQUE INDEX index_posts_on_md5 ON posts USING btree (md5); CREATE UNIQUE INDEX index_posts_on_md5 ON posts USING btree (md5);
--
-- Name: index_posts_on_mpixels; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_posts_on_mpixels ON posts USING btree (((((image_width * image_height))::numeric / 1000000.0)));
-- --
-- Name: index_posts_on_parent_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- Name: index_posts_on_parent_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
-- --
@@ -7179,10 +7248,6 @@ INSERT INTO schema_migrations (version) VALUES ('20141017231608');
INSERT INTO schema_migrations (version) VALUES ('20141120045943'); INSERT INTO schema_migrations (version) VALUES ('20141120045943');
INSERT INTO schema_migrations (version) VALUES ('20141203230229');
INSERT INTO schema_migrations (version) VALUES ('20150116013315');
INSERT INTO schema_migrations (version) VALUES ('20150119191042'); INSERT INTO schema_migrations (version) VALUES ('20150119191042');
INSERT INTO schema_migrations (version) VALUES ('20150120005624'); INSERT INTO schema_migrations (version) VALUES ('20150120005624');
@@ -7193,3 +7258,7 @@ INSERT INTO schema_migrations (version) VALUES ('20150403224949');
INSERT INTO schema_migrations (version) VALUES ('20150613010904'); INSERT INTO schema_migrations (version) VALUES ('20150613010904');
INSERT INTO schema_migrations (version) VALUES ('20150623191904');
INSERT INTO schema_migrations (version) VALUES ('20150629235905');

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
CurrentUser.user = User.admins.first
CurrentUser.ip_addr = "127.0.0.1"
User.where("level >= ?", User::Levels::JANITOR).find_each do |user|
user.can_approve_posts = true
user.save
end

View File

@@ -1,34 +1,36 @@
require 'test_helper' require 'test_helper'
class UserUpgradesControllerTest < ActionController::TestCase class UserUpgradesControllerTest < ActionController::TestCase
setup do if Danbooru.config.coinbase_secret
@admin = FactoryGirl.create(:admin_user)
@user = FactoryGirl.create(:user)
end
context "#create" do
setup do setup do
@encrypted = ActiveSupport::MessageEncryptor.new(Danbooru.config.coinbase_secret).encrypt_and_sign("#{@user.id},#{User::Levels::GOLD}") @admin = FactoryGirl.create(:admin_user)
@user = FactoryGirl.create(:user)
end end
context "for basic -> gold" do context "#create" do
should "promote the account" do setup do
post :create, {:order => {:status => "completed", :custom => @encrypted}} @encrypted = ActiveSupport::MessageEncryptor.new(Danbooru.config.coinbase_secret).encrypt_and_sign("#{@user.id},#{User::Levels::GOLD}")
end
context "for basic -> gold" do
should "promote the account" do
post :create, {:order => {:status => "completed", :custom => @encrypted}}
assert_response :success
@user.reload
assert_equal(User::Levels::GOLD, @user.level)
end
end
end
context "#new" do
setup do
Coinbase::Client.any_instance.stubs(:create_button).returns(OpenStruct.new)
end
should "render" do
get :new, {}, {:user_id => @user.id}
assert_response :success assert_response :success
@user.reload
assert_equal(User::Levels::GOLD, @user.level)
end end
end end
end end
context "#new" do
setup do
Coinbase::Client.any_instance.stubs(:create_button).returns(OpenStruct.new)
end
should "render" do
get :new, {}, {:user_id => @user.id}
assert_response :success
end
end
end end

View File

@@ -34,14 +34,17 @@ FactoryGirl.define do
factory(:janitor_user) do factory(:janitor_user) do
level 35 level 35
can_approve_posts true
end end
factory(:moderator_user) do factory(:moderator_user) do
level 40 level 40
can_approve_posts true
end end
factory(:admin_user) do factory(:admin_user) do
level 50 level 50
can_approve_posts true
end end
end end
end end

View File

@@ -36,7 +36,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
should "promote the janitor trial" do should "promote the janitor trial" do
post :promote, {:id => @janitor_trial.id}, {:user_id => @admin.id} post :promote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
@user.reload @user.reload
assert(@user.is_janitor?) assert(@user.can_approve_posts?)
@janitor_trial.reload @janitor_trial.reload
assert_equal(false, @janitor_trial.active?) assert_equal(false, @janitor_trial.active?)
end end
@@ -50,7 +50,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
should "demote the janitor trial" do should "demote the janitor trial" do
post :demote, {:id => @janitor_trial.id}, {:user_id => @admin.id} post :demote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
@user.reload @user.reload
assert(!@user.is_janitor?) assert(!@user.can_approve_posts?)
@janitor_trial.reload @janitor_trial.reload
assert_equal(false, @janitor_trial.active?) assert_equal(false, @janitor_trial.active?)
end end

View File

@@ -4,6 +4,7 @@ class PostsControllerTest < ActionController::TestCase
context "The posts controller" do context "The posts controller" do
setup do setup do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
@api_key = ApiKey.generate!(@user)
CurrentUser.user = @user CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1" CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "aaaa") @post = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "aaaa")
@@ -19,7 +20,6 @@ class PostsControllerTest < ActionController::TestCase
context "passing the api limit" do context "passing the api limit" do
setup do setup do
User.any_instance.stubs(:api_hourly_limit).returns(5) User.any_instance.stubs(:api_hourly_limit).returns(5)
ApiKey.generate!(@user)
end end
should "work" do should "work" do
@@ -35,30 +35,30 @@ class PostsControllerTest < ActionController::TestCase
context "using http basic auth" do context "using http basic auth" do
should "succeed for password matches" do should "succeed for password matches" do
@basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@user.bcrypt_cookie_password_hash}")}" @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@api_key.key}")}"
@request.env['HTTP_AUTHORIZATION'] = @basic_auth_string @request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
get :index, {:format => "json"} get :index, {:format => "json"}
assert_response :success assert_response :success
end end
# should "fail for password mismatches" do should "fail for password mismatches" do
# @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:badpassword")}" @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:badpassword")}"
# @request.env['HTTP_AUTHORIZATION'] = @basic_auth_string @request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
# get :index, {:format => "json"} get :index, {:format => "json"}
# assert_response 403 assert_response 401
# end end
end end
context "using the api_key parameter" do context "using the api_key parameter" do
should "succeed for password matches" do should "succeed for password matches" do
get :index, {:format => "json", :login => @user.name, :api_key => @user.bcrypt_cookie_password_hash} get :index, {:format => "json", :login => @user.name, :api_key => @api_key.key}
assert_response :success assert_response :success
end end
# should "fail for password mismatches" do should "fail for password mismatches" do
# get :index, {:format => "json", :login => @user.name, :api_key => "bad"} get :index, {:format => "json", :login => @user.name, :api_key => "bad"}
# assert_response 403 assert_response 401
# end end
end end
context "using the password_hash parameter" do context "using the password_hash parameter" do

View File

@@ -22,10 +22,10 @@ class JanitorTrialTest < ActiveSupport::TestCase
end end
end end
should "toggle the janitor flag on the user" do should "toggle the can_approve_posts flag on the user" do
janitor_trial = JanitorTrial.create(:user_id => @user.id) janitor_trial = JanitorTrial.create(:user_id => @user.id)
@user.reload @user.reload
assert(@user.is_janitor?) assert(@user.can_approve_posts?)
end end
end end
@@ -39,6 +39,12 @@ class JanitorTrialTest < ActiveSupport::TestCase
@janitor_trial.demote! @janitor_trial.demote!
end end
end end
should "revoke approval privileges" do
@janitor_trial.demote!
@user.reload
assert_equal(false, @user.can_approve_posts?)
end
end end
context "upon promotion" do context "upon promotion" do

View File

@@ -102,9 +102,9 @@ class TagTest < ActiveSupport::TestCase
MEMCACHE.flush_all MEMCACHE.flush_all
end end
should "be lockable by a janitor" do should "be lockable by a moderator" do
@tag = FactoryGirl.create(:tag) @tag = FactoryGirl.create(:tag)
@tag.update_attributes({:is_locked => true}, :as => :janitor) @tag.update_attributes({:is_locked => true}, :as => :moderator)
@tag.reload @tag.reload
assert_equal(true, @tag.is_locked?) assert_equal(true, @tag.is_locked?)
end end

View File

@@ -14,25 +14,25 @@ class WikiPageTest < ActiveSupport::TestCase
context "A wiki page" do context "A wiki page" do
context "that is locked" do context "that is locked" do
should "not be editable by a member" do should "not be editable by a member" do
CurrentUser.user = FactoryGirl.create(:janitor_user) CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true) @wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryGirl.create(:user) CurrentUser.user = FactoryGirl.create(:user)
@wiki_page.update_attributes(:body => "hello") @wiki_page.update_attributes(:body => "hello")
assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages) assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
end end
should "be editable by a janitor" do should "be editable by a moderator" do
CurrentUser.user = FactoryGirl.create(:janitor_user) CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true) @wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryGirl.create(:janitor_user) CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page.update_attributes(:body => "hello") @wiki_page.update_attributes(:body => "hello")
assert_equal([], @wiki_page.errors.full_messages) assert_equal([], @wiki_page.errors.full_messages)
end end
end end
context "updated by a janitor" do context "updated by a moderator" do
setup do setup do
@user = FactoryGirl.create(:janitor_user) @user = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user CurrentUser.user = @user
@wiki_page = FactoryGirl.create(:wiki_page) @wiki_page = FactoryGirl.create(:wiki_page)
end end
@@ -53,7 +53,7 @@ class WikiPageTest < ActiveSupport::TestCase
should "not allow the is_locked attribute to be updated" do should "not allow the is_locked attribute to be updated" do
@wiki_page.update_attributes(:is_locked => true) @wiki_page.update_attributes(:is_locked => true)
assert_equal(["Is locked can be modified by janitors only", "Is locked and cannot be updated"], @wiki_page.errors.full_messages) assert_equal(["Is locked can be modified by moderators only", "Is locked and cannot be updated"], @wiki_page.errors.full_messages)
@wiki_page.reload @wiki_page.reload
assert_equal(false, @wiki_page.is_locked?) assert_equal(false, @wiki_page.is_locked?)
end end