Convert builder -> janitor for user rank

This commit is contained in:
Kira 2019-06-29 12:58:28 -07:00
parent 55e57edab8
commit 4024108f1c
37 changed files with 73 additions and 73 deletions

View File

@ -1,7 +1,7 @@
class ArtistsController < ApplicationController
respond_to :html, :xml, :json, :js
before_action :member_only, :except => [:index, :show, :show_or_new, :banned]
before_action :builder_only, :only => [:destroy]
before_action :janitor_only, :only => [:destroy]
before_action :admin_only, :only => [:ban, :unban]
before_action :load_artist, :only => [:ban, :unban, :show, :edit, :update, :destroy, :undelete]
@ -106,7 +106,7 @@ private
def artist_params(context = nil)
permitted_params = %i[name other_names other_names_string group_name url_string notes]
permitted_params << :is_active if CurrentUser.is_builder?
permitted_params << :is_active if CurrentUser.is_janitor?
permitted_params << :source if context == :new
params.fetch(:artist, {}).permit(permitted_params)

View File

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

View File

@ -127,7 +127,7 @@ private
rating old_rating
has_embedded_notes
]
permitted_params += %i[is_rating_locked is_note_locked] if CurrentUser.is_builder?
permitted_params += %i[is_rating_locked is_note_locked] if CurrentUser.is_janitor?
permitted_params += %i[is_status_locked locked_tags hide_from_anonymous hide_from_search_engines] if CurrentUser.is_admin?
params.require(:post).permit(permitted_params)

View File

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

View File

@ -1,12 +1,12 @@
class TagCorrectionsController < ApplicationController
respond_to :html, :json, :xml
before_action :builder_only, only: [:new, :create]
before_action :janitor_only, only: [:new, :create]
def new
@correction = TagCorrection.new(params[:tag_id])
respond_with(@correction)
end
def show
@correction = TagCorrection.new(params[:tag_id])
respond_with(@correction)

View File

@ -19,7 +19,7 @@ class TagsController < ApplicationController
end
def autocomplete
if CurrentUser.is_builder?
if CurrentUser.is_janitor?
# limit rollout
@tags = TagAutocomplete.search(params[:search][:name_matches])
else

View File

@ -1,9 +1,9 @@
class WikiPagesController < ApplicationController
respond_to :html, :xml, :json, :js
before_action :member_only, :except => [:index, :search, :show, :show_or_new]
before_action :builder_only, :only => [:destroy]
before_action :janitor_only, :only => [:destroy]
before_action :normalize_search_params, :only => [:index]
def new
@wiki_page = WikiPage.new(wiki_page_params(:create))
respond_with(@wiki_page)
@ -49,7 +49,7 @@ class WikiPagesController < ApplicationController
return
end
end
respond_with(@wiki_page)
end
@ -100,8 +100,8 @@ class WikiPagesController < ApplicationController
def wiki_page_params(context)
permitted_params = %i[body other_names other_names_string skip_secondary_validations]
permitted_params += %i[is_locked is_deleted] if CurrentUser.is_builder?
permitted_params += %i[title] if context == :create || CurrentUser.is_builder?
permitted_params += %i[is_locked is_deleted] if CurrentUser.is_janitor?
permitted_params += %i[title] if context == :create || CurrentUser.is_janitor?
params.fetch(:wiki_page, {}).permit(permitted_params)
end

View File

@ -4,7 +4,7 @@ module Admin::UsersHelper
["Member", User::Levels::MEMBER],
["Privileged", User::Levels::PRIVILEGED],
["Contributor", User::Levels::CONTRIBUTOR],
["Builder", User::Levels::JANITOR],
["Janitor", User::Levels::JANITOR],
["Moderator", User::Levels::MODERATOR],
["Admin", User::Levels::ADMIN]
]

View File

@ -78,7 +78,7 @@ module PostsHelper
source_link = source
end
if CurrentUser.is_builder? && !source_search.blank?
if CurrentUser.is_janitor? && !source_search.blank?
source_link + "&nbsp;".html_safe + link_to("&raquo;".html_safe, posts_path(:tags => source_search), :rel => "nofollow")
else
source_link

View File

@ -10,7 +10,7 @@ a.user-contributor.with-style {
color: purple;
}
a.user-builder.with-style {
a.user-janitor.with-style {
color: #6633FF;
}

View File

@ -578,11 +578,11 @@ class Artist < ApplicationRecord
end
def deletable_by?(user)
user.is_builder?
user.is_janitor?
end
def editable_by?(user)
user.is_builder? || (!is_banned? && is_active?)
user.is_janitor? || (!is_banned? && is_active?)
end
def visible?

View File

@ -89,8 +89,8 @@ class BulkUpdateRequest < ApplicationRecord
nil
end
ForumUpdater.new(
forum_topic,
forum_post: post,
forum_topic,
forum_post: post,
expected_title: title,
skip_update: !TagRelationship::SUPPORT_HARD_CODED
)
@ -179,7 +179,7 @@ class BulkUpdateRequest < ApplicationRecord
end
def editable?(user)
user_id == user.id || user.is_builder?
user_id == user.id || user.is_janitor?
end
def approvable?(user)

View File

@ -197,7 +197,7 @@ class Pool < ApplicationRecord
end
def deletable_by?(user)
user.is_builder?
user.is_janitor?
end
def updater_can_edit_deleted
@ -348,7 +348,7 @@ class Pool < ApplicationRecord
end
def category_changeable_by?(user)
user.is_builder? || (user.is_member? && post_count <= Danbooru.config.pool_category_change_limit)
user.is_janitor? || (user.is_member? && post_count <= Danbooru.config.pool_category_change_limit)
end
def updater_can_change_category

View File

@ -951,10 +951,10 @@ class Post < ApplicationRecord
self.rating = $1
when /^(-?)locked:notes?$/i
self.is_note_locked = ($1 != "-") if CurrentUser.is_builder?
self.is_note_locked = ($1 != "-") if CurrentUser.is_janitor?
when /^(-?)locked:rating$/i
self.is_rating_locked = ($1 != "-") if CurrentUser.is_builder?
self.is_rating_locked = ($1 != "-") if CurrentUser.is_janitor?
when /^(-?)locked:status$/i
self.is_status_locked = ($1 != "-") if CurrentUser.is_admin?

View File

@ -88,7 +88,7 @@ class PostSet < ApplicationRecord
end
def can_make_public
if is_public && creator.created_at > 3.days.ago && !creator.is_builder?
if is_public && creator.created_at > 3.days.ago && !creator.is_janitor?
errors.add(:base, "Can't make a set public until your account is at least three days old")
false
else
@ -105,7 +105,7 @@ class PostSet < ApplicationRecord
end
def set_per_hour_limit
if where("created_at > ? AND creator_id = ?", 1.hour.ago, creator.id).count() > 6 && !creator.is_builder?
if where("created_at > ? AND creator_id = ?", 1.hour.ago, creator.id).count() > 6 && !creator.is_janitor?
first = where("created_at > ? AND creator_id = ?", 1.hour.ago, creator.id).order(:created_at).first()
errors.add(:base, "You have already created 6 sets in the last hour. You can make a new set in #{time_ago_in_words(first.created_at)}")
false

View File

@ -994,7 +994,7 @@ class Tag < ApplicationRecord
end
def category_editable_by_implicit?(user)
return false unless user.is_builder?
return false unless user.is_janitor?
return false if is_locked?
return false if post_count >= Danbooru.config.tag_type_change_cutoff
true

View File

@ -70,7 +70,7 @@ class TagRelationship < ApplicationRecord
def deletable_by?(user)
return true if user.is_admin?
return true if is_pending? && user.is_builder?
return true if is_pending? && user.is_janitor?
return true if is_pending? && user.id == creator_id
return false
end

View File

@ -136,7 +136,7 @@ class WikiPage < ApplicationRecord
end
def validate_not_locked
if is_locked? && !CurrentUser.is_builder?
if is_locked? && !CurrentUser.is_janitor?
errors.add(:is_locked, "and cannot be updated")
return false
end
@ -252,6 +252,6 @@ class WikiPage < ApplicationRecord
end
def visible?
artist.blank? || !artist.is_banned? || CurrentUser.is_builder?
artist.blank? || !artist.is_banned? || CurrentUser.is_janitor?
end
end

View File

@ -5,7 +5,7 @@
<%= text_field "artist", "name" %>
<span id="check-name-result"></span>
<% elsif CurrentUser.user.is_builder? %>
<% elsif CurrentUser.user.is_janitor? %>
<%= text_field "artist", "name" %>
<span id="check-name-result"></span>
<span class="hint">Change to rename this artist entry and its wiki page</span>

View File

@ -1,5 +1,5 @@
<div id="p-index-by-post">
<% if !CurrentUser.user.is_builder? %>
<% if !CurrentUser.user.is_janitor? %>
<div style="margin-bottom: 1em;">
<h2>Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.</h2>
</div>

View File

@ -10,7 +10,7 @@
<%= nav_link_to("Artists", artists_path) %>
<%= nav_link_to("Tags", tags_path) %>
<%= nav_link_to("Blips", blips_path) %>
<% if CurrentUser.is_builder? %>
<% if CurrentUser.is_janitor? %>
<%= nav_link_to("Aliases", tag_aliases_path) %>
<%= nav_link_to("Implications", tag_implications_path) %>
<% end %>

View File

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

View File

@ -11,7 +11,7 @@
<option value="vote-down">Vote down</option>
<option value="tag-script">Tag script</option>
<% end %>
<% if CurrentUser.is_builder? %>
<% if CurrentUser.is_janitor? %>
<option value="lock-rating">Lock rating</option>
<option value="lock-note">Lock notes</option>
<% end %>

View File

@ -1,4 +1,4 @@
<% unless CurrentUser.user.is_builder? %>
<% unless CurrentUser.user.is_janitor? %>
<div style="margin-bottom: 1em;">
<p>Before editing, read the <%= link_to "how to tag guide", wiki_page_path(:id => "howto:tag") %>.</p>
</div>
@ -39,7 +39,7 @@
</div>
<% end %>
<% if CurrentUser.is_builder? %>
<% if CurrentUser.is_janitor? %>
<div class="input">
<%= f.label :blank, "Lock" %>
@ -107,7 +107,7 @@
<%= f.text_area :locked_tags, :size => "60x2", :spellcheck => false, :"data-autocomplete" => "tag-edit", :"data-shortcut" => "e", :value => (post.locked_tags || ""), disabled: !CurrentUser.is_admin? %>
</div>
</div>
<div class="input">
<%= submit_tag "Submit", :class => "ui-button ui-widget ui-corner-all" %>
</div>

View File

@ -114,7 +114,7 @@
<% end %>
<section id="comments">
<% if !CurrentUser.user.is_builder? %>
<% if !CurrentUser.user.is_janitor? %>
<h2>Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.</h2>
<% end %>
<%= render "comments/partials/index/list", :comments => @post.comments.visible(CurrentUser.user), :post => @post, :show_header => false %>

View File

@ -1,4 +1,4 @@
<% if CurrentUser.user.try(:is_builder?) && @exception.present? %>
<% if CurrentUser.user.try(:is_janitor?) && @exception.present? %>
<h1><%= @exception.class.to_s %> exception raised</h1>
<p><%= @exception.message.dup.force_encoding("utf-8") %></p>

View File

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

View File

@ -22,7 +22,7 @@
<%= link_to "edit", edit_tag_path(tag) %>
<% end %>
| <%= link_to "history", tag_type_versions_path(search: {tag: tag.name}) %>
<% if CurrentUser.is_builder? %>
<% if CurrentUser.is_janitor? %>
| <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %>
<% end %>
</td>

View File

@ -29,7 +29,7 @@
<p>This upload is a duplicate: <%= link_to "post ##{@upload.duplicate_post_id}", post_path(@upload.duplicate_post_id) %></p>
<% else %>
<p>An error occurred: <%= render_status(@upload) %></p>
<% if CurrentUser.user.is_builder? %>
<% if CurrentUser.user.is_janitor? %>
<%= render "static/backtrace", backtrace: @upload.backtrace.to_s.split(/\n/) %>
<% end %>
<% end %>

View File

@ -4,7 +4,7 @@
<%= simple_form_for(@wiki_page) do |f| %>
<% if @wiki_page.new_record? %>
<%= f.input :title, error: false, input_html: { data: { autocomplete: "tag" } } %>
<% elsif CurrentUser.is_builder? %>
<% elsif CurrentUser.is_janitor? %>
<%= f.input :title, error: false, input_html: { data: { autocomplete: "tag" } }, hint: "Change to rename this wiki page. Move the tag and update any wikis linking to this page first." %>
<% else %>
<h1 id="wiki-page-title"><%= @wiki_page.pretty_title %></h1>
@ -14,11 +14,11 @@
<%= dtext_field "wiki_page", "body" %>
<% if CurrentUser.is_builder? && @wiki_page.is_deleted? %>
<% if CurrentUser.is_janitor? && @wiki_page.is_deleted? %>
<%= f.input :is_deleted, :label => "Deleted", :hint => "Uncheck to restore this wiki page" %>
<% end %>
<% if CurrentUser.is_builder? %>
<% if CurrentUser.is_janitor? %>
<%= f.input :is_locked, :label => "Locked" %>
<% end %>

View File

@ -28,7 +28,7 @@
<%= subnav_link_to "Edit", edit_wiki_page_path(@wiki_page), "data-shortcut": "e" %>
<% end %>
<% if CurrentUser.is_builder? && !@wiki_page.is_deleted? %>
<% if CurrentUser.is_janitor? && !@wiki_page.is_deleted? %>
<%= subnav_link_to "Delete", wiki_page_path(@wiki_page), :remote => true, :method => :delete, :"data-shortcut" => "shift+d", :"data-confirm" => "Are you sure you want to delete this wiki page?" %>
<% end %>

View File

@ -31,8 +31,8 @@ FactoryBot.define do
level 31
end
factory(:builder_user) do
level 32
factory(:janitor_user) do
level 35
end
factory(:contributor_user) do

View File

@ -188,16 +188,16 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
end
should "delete an artist" do
@builder = create(:builder_user)
delete_auth artist_path(@artist.id), @builder
@janitor = create(:janitor_user)
delete_auth artist_path(@artist.id), @janitor
assert_redirected_to(artist_path(@artist.id))
@artist.reload
assert_equal(false, @artist.is_active)
end
should "undelete an artist" do
@builder = create(:builder_user)
put_auth artist_path(@artist.id), @builder, params: {artist: {is_active: true}}
@janitor = create(:janitor_user)
put_auth artist_path(@artist.id), @janitor, params: {artist: {is_active: true}}
assert_redirected_to(artist_path(@artist.id))
assert_equal(true, @artist.reload.is_active)
end

View File

@ -3,7 +3,7 @@ require 'test_helper'
class TagsControllerTest < ActionDispatch::IntegrationTest
context "The tags controller" do
setup do
@user = create(:builder_user)
@user = create(:janitor_user)
as_user do
@tag = create(:tag, name: "touhou", category: Tag.categories.copyright, post_count: 1)
end

View File

@ -181,8 +181,8 @@ class PoolTest < ActiveSupport::TestCase
context "to a deleted pool" do
setup do
# must be a builder to update deleted pools.
CurrentUser.user = FactoryBot.create(:builder_user)
# must be a janitor to update deleted pools.
CurrentUser.user = FactoryBot.create(:janitor_user)
@pool.update_attribute(:is_deleted, true)
@pool.post_ids += [@p2.id]
@ -266,9 +266,9 @@ class PoolTest < ActiveSupport::TestCase
assert_equal(["You cannot change the category of pools with greater than 1 posts"], @pool.errors[:base])
end
should "allow Builders to change the category of large pools" do
@builder = FactoryBot.create(:builder_user)
as(@builder) { @pool.update(category: "collection") }
should "allow janitors to change the category of large pools" do
@janitor = FactoryBot.create(:janitor_user)
as(@janitor) { @pool.update(category: "collection") }
assert_equal(true, @pool.valid?)
assert_equal("collection", @pool.category)

View File

@ -93,8 +93,8 @@ class PostTest < ActiveSupport::TestCase
context "that belongs to a pool" do
setup do
# must be a builder to update deleted pools. must be >1 week old to remove posts from pools.
CurrentUser.user = FactoryBot.create(:builder_user, created_at: 1.month.ago)
# must be a janitor to update deleted pools. must be >1 week old to remove posts from pools.
CurrentUser.user = FactoryBot.create(:janitor_user, created_at: 1.month.ago)
SqsService.any_instance.stubs(:send_message)
@pool = FactoryBot.create(:pool)
@ -574,7 +574,7 @@ class PostTest < ActiveSupport::TestCase
context "with an artist tag that is then changed to copyright" do
setup do
CurrentUser.user = FactoryBot.create(:builder_user)
CurrentUser.user = FactoryBot.create(:janitor_user)
@post = Post.find(@post.id)
@post.update(:tag_string => "art:abc")
@post = Post.find(@post.id)
@ -1032,7 +1032,7 @@ class PostTest < ActiveSupport::TestCase
context "of" do
setup do
@builder = FactoryBot.create(:builder_user)
@janitor = FactoryBot.create(:janitor_user)
end
context "locked:notes" do
@ -1043,9 +1043,9 @@ class PostTest < ActiveSupport::TestCase
end
end
context "by a builder" do
context "by a janitor" do
should "lock/unlock the notes" do
CurrentUser.scoped(@builder) do
CurrentUser.scoped(@janitor) do
@post.update(:tag_string => "locked:notes")
assert_equal(true, @post.is_note_locked)
@ -1064,9 +1064,9 @@ class PostTest < ActiveSupport::TestCase
end
end
context "by a builder" do
context "by a janitor" do
should "lock/unlock the rating" do
CurrentUser.scoped(@builder) do
CurrentUser.scoped(@janitor) do
@post.update(:tag_string => "locked:rating")
assert_equal(true, @post.is_rating_locked)

View File

@ -2,8 +2,8 @@ require 'test_helper'
class TagTest < ActiveSupport::TestCase
setup do
@builder = FactoryBot.create(:builder_user)
CurrentUser.user = @builder
@janitor = FactoryBot.create(:janitor_user)
CurrentUser.user = @janitor
CurrentUser.ip_addr = "127.0.0.1"
end
@ -194,9 +194,9 @@ class TagTest < ActiveSupport::TestCase
assert_equal(0, tag.category)
end
should "not change category when the tag is too large to be changed by a builder" do
should "not change category when the tag is too large to be changed by a janitor" do
tag = FactoryBot.create(:tag, post_count: 1001)
Tag.find_or_create_by_name("artist:#{tag.name}", creator: @builder)
Tag.find_or_create_by_name("artist:#{tag.name}", creator: @janitor)
assert_equal(0, tag.reload.category)
end