forked from e621ng/e621ng
[Users] Don't allow mods to use restricted tag categories
Also prevent them locking tags
This commit is contained in:
parent
cbc0fd3aa1
commit
36712c7872
@ -59,7 +59,7 @@ class TagsController < ApplicationController
|
||||
|
||||
def tag_params
|
||||
permitted_params = [:category]
|
||||
permitted_params << :is_locked if CurrentUser.is_moderator?
|
||||
permitted_params << :is_locked if CurrentUser.is_admin?
|
||||
|
||||
params.require(:tag).permit(permitted_params)
|
||||
end
|
||||
|
@ -34,8 +34,8 @@ class TagCategory
|
||||
@@header_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["header"]]}]
|
||||
end
|
||||
|
||||
def mod_only_mapping
|
||||
@@mod_only_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["mod_only"] || false]}]
|
||||
def admin_only_mapping
|
||||
@@admin_only_mapping ||= Hash[Danbooru.config.full_tag_config_info.map { |k,v| [k, v["admin_only"] || false] }]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -187,8 +187,8 @@ class Tag < ApplicationRecord
|
||||
|
||||
def user_can_change_category?
|
||||
cat = TagCategory.reverse_mapping[category]
|
||||
if !CurrentUser.is_moderator? && TagCategory.mod_only_mapping[cat]
|
||||
errors.add(:category, "can only used by moderators")
|
||||
if !CurrentUser.is_admin? && TagCategory.admin_only_mapping[cat]
|
||||
errors.add(:category, "can only used by admins")
|
||||
return false
|
||||
end
|
||||
if cat == "lore"
|
||||
@ -1092,16 +1092,16 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
def category_editable_by?(user)
|
||||
return true if user.is_moderator?
|
||||
return true if user.is_admin?
|
||||
return false if is_locked?
|
||||
return false if TagCategory.mod_only_mapping[TagCategory.reverse_mapping[category]]
|
||||
return false if TagCategory.admin_only_mapping[TagCategory.reverse_mapping[category]]
|
||||
return true if post_count < Danbooru.config.tag_type_change_cutoff
|
||||
false
|
||||
end
|
||||
|
||||
def user_can_create_tag?
|
||||
if name =~ /\A.*_\(lore\)\z/ && !CurrentUser.user.is_moderator?
|
||||
errors.add(:base, "Can not create lore tags unless moderator")
|
||||
if name =~ /\A.*_\(lore\)\z/ && !CurrentUser.user.is_admin?
|
||||
errors.add(:base, "Can not create lore tags unless admin")
|
||||
errors.add(:name, "is invalid")
|
||||
return false
|
||||
end
|
||||
|
@ -9,7 +9,7 @@
|
||||
<%= f.input :category, :collection => TagCategory.canonical_mapping.to_a, :include_blank => false %>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<%= f.input :is_locked, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
|
||||
<% end %>
|
||||
|
||||
|
@ -428,7 +428,6 @@ module Danbooru
|
||||
"extra" => [],
|
||||
"header" => 'General',
|
||||
"humanized" => nil,
|
||||
"mod_only" => false,
|
||||
},
|
||||
"species" => {
|
||||
"category" => 5,
|
||||
@ -436,7 +435,6 @@ module Danbooru
|
||||
"extra" => [],
|
||||
"header" => 'Species',
|
||||
"humanized" => nil,
|
||||
"mod_only" => false,
|
||||
},
|
||||
"character" => {
|
||||
"category" => 4,
|
||||
@ -449,7 +447,6 @@ module Danbooru
|
||||
"regexmap" => /^(.+?)(?:_\(.+\))?$/,
|
||||
"formatstr" => "%s"
|
||||
},
|
||||
"mod_only" => false,
|
||||
},
|
||||
"copyright" => {
|
||||
"category" => 3,
|
||||
@ -462,7 +459,6 @@ module Danbooru
|
||||
"regexmap" => //,
|
||||
"formatstr" => "(%s)"
|
||||
},
|
||||
"mod_only" => false,
|
||||
},
|
||||
"artist" => {
|
||||
"category" => 1,
|
||||
@ -475,7 +471,6 @@ module Danbooru
|
||||
"regexmap" => //,
|
||||
"formatstr" => "created by %s"
|
||||
},
|
||||
"mod_only" => false,
|
||||
},
|
||||
"invalid" => {
|
||||
"category" => 6,
|
||||
@ -483,7 +478,7 @@ module Danbooru
|
||||
"extra" => [],
|
||||
"header" => 'Invalid',
|
||||
"humanized" => nil,
|
||||
"mod_only" => true,
|
||||
"admin_only" => true,
|
||||
},
|
||||
"lore" => {
|
||||
"category" => 8,
|
||||
@ -491,7 +486,7 @@ module Danbooru
|
||||
'extra' => [],
|
||||
'header' => 'Lore',
|
||||
'humanized' => nil,
|
||||
'mod_only' => true,
|
||||
"admin_only" => true,
|
||||
},
|
||||
"meta" => {
|
||||
"category" => 7,
|
||||
@ -499,7 +494,7 @@ module Danbooru
|
||||
"extra" => [],
|
||||
"header" => 'Meta',
|
||||
"humanized" => nil,
|
||||
"mod_only" => true,
|
||||
"admin_only" => true,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user