Add user permissions for flagging and for giving user feedback
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
class UserFeedbacksController < ApplicationController
|
||||
before_action :gold_only, :only => [:new, :edit, :create, :update, :destroy]
|
||||
before_action :check_no_feedback, only: [:new, :edit, :create, :update, :destroy]
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def new
|
||||
@@ -53,6 +54,12 @@ class UserFeedbacksController < ApplicationController
|
||||
raise User::PrivilegeError unless user_feedback.editable_by?(CurrentUser.user)
|
||||
end
|
||||
|
||||
def check_no_feedback
|
||||
if CurrentUser.no_feedback?
|
||||
raise User::PrivilegeError
|
||||
end
|
||||
end
|
||||
|
||||
def user_feedback_params(context)
|
||||
permitted_params = %i[body category]
|
||||
permitted_params += %i[user_id user_name] if context == :create
|
||||
|
||||
@@ -57,7 +57,9 @@ class PopularSearchService
|
||||
|
||||
rescue => e
|
||||
Rails.logger.error(e.to_s)
|
||||
NewRelic::Agent.notice_error(e)
|
||||
if defined?(NewRelic)
|
||||
NewRelic::Agent.notice_error(e)
|
||||
end
|
||||
return []
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class UserPromotion
|
||||
attr_reader :user, :promoter, :new_level, :options, :old_can_approve_posts, :old_can_upload_free
|
||||
attr_reader :user, :promoter, :new_level, :options, :old_can_approve_posts, :old_can_upload_free, :old_no_flagging, :old_no_feedback
|
||||
|
||||
def initialize(user, promoter, new_level, options = {})
|
||||
@user = user
|
||||
@@ -13,6 +13,8 @@ class UserPromotion
|
||||
|
||||
@old_can_approve_posts = user.can_approve_posts?
|
||||
@old_can_upload_free = user.can_upload_free?
|
||||
@old_no_flagging = user.no_flagging?
|
||||
@old_no_feedback = user.no_feedback?
|
||||
|
||||
user.level = new_level
|
||||
|
||||
@@ -23,6 +25,14 @@ class UserPromotion
|
||||
if options.has_key?(:can_upload_free)
|
||||
user.can_upload_free = options[:can_upload_free]
|
||||
end
|
||||
|
||||
if options.has_key?(:no_feedback)
|
||||
user.no_feedback = options[:no_feedback]
|
||||
end
|
||||
|
||||
if options.has_key?(:no_flagging)
|
||||
user.no_flagging = options[:no_flagging]
|
||||
end
|
||||
|
||||
user.inviter_id = promoter.id
|
||||
|
||||
@@ -44,6 +54,14 @@ private
|
||||
ModAction.log("\"#{promoter.name}\":/users/#{promoter.id} changed unlimited upload privileges for \"#{user.name}\":/users/#{user.id} from #{old_can_upload_free} to [b]#{user.can_upload_free?}[/b]",:user_upload_privilege)
|
||||
end
|
||||
|
||||
if old_no_flagging != user.no_flagging?
|
||||
ModAction.log("\"#{promoter.name}\":/users/#{promoter.id} changed banned from flagging for \"#{user.name}\":/users/#{user.id} from #{old_no_flagging} to [b]#{user.no_flagging?}[/b]",:user_approval_privilege)
|
||||
end
|
||||
|
||||
if old_no_feedback != user.no_feedback?
|
||||
ModAction.log("\"#{promoter.name}\":/users/#{promoter.id} changed banned from feedback for \"#{user.name}\":/users/#{user.id} from #{old_no_feedback} to [b]#{user.no_feedback?}[/b]",:user_approval_privilege)
|
||||
end
|
||||
|
||||
if user.level_changed?
|
||||
category = options[:is_upgrade] ? :user_account_upgrade : :user_level_change
|
||||
ModAction.log(%{"#{user.name}":/users/#{user.id} level changed #{user.level_string_was} -> #{user.level_string}}, category)
|
||||
@@ -84,6 +102,18 @@ private
|
||||
messages << "You lost the ability to upload posts without limit."
|
||||
end
|
||||
|
||||
if user.no_feedback? && !old_no_feedback
|
||||
messages << "You lost the ability to give user feedback."
|
||||
elsif !user.no_feedback? && old_no_feedback
|
||||
messages << "You gained the ability to give user feedback."
|
||||
end
|
||||
|
||||
if user.no_flagging? && !old_no_flagging
|
||||
messages << "You lost the ability to flag posts."
|
||||
elsif !user.no_flagging? && old_no_flagging
|
||||
messages << "You gained the ability to flag posts."
|
||||
end
|
||||
|
||||
messages.join("\n")
|
||||
end
|
||||
|
||||
|
||||
@@ -146,6 +146,10 @@ class PostFlag < ApplicationRecord
|
||||
def validate_creator_is_not_limited
|
||||
return if is_deletion
|
||||
|
||||
if creator.no_flagging?
|
||||
errors[:creator] << "cannot flag posts"
|
||||
end
|
||||
|
||||
if creator_id != User.system.id && PostFlag.for_creator(creator_id).where("created_at > ?", 30.days.ago).count >= CREATION_THRESHOLD
|
||||
report = Reports::PostFlags.new(user_id: post.uploader_id, date_range: 90.days.ago)
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ class User < ApplicationRecord
|
||||
disable_post_tooltips
|
||||
enable_recommended_posts
|
||||
opt_out_mixpanel
|
||||
no_flagging
|
||||
no_feedback
|
||||
)
|
||||
|
||||
include Danbooru::HasBitFlags
|
||||
|
||||
@@ -101,6 +101,9 @@ class UserFeedback < ApplicationRecord
|
||||
if !creator.is_gold?
|
||||
errors[:creator] << "must be gold"
|
||||
return false
|
||||
elsif creator.no_feedback?
|
||||
errors[:creator] << "cannot submit feedback"
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -20,6 +20,16 @@
|
||||
<%= select(:user, :can_approve_posts, [["Yes", true], ["No", false]]) %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label for="user_no_flagging" class="optional">Banned From Flagging</label>
|
||||
<%= select(:user, :no_flagging, [["Yes", true], ["No", false]]) %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label for="user_no_feedback" class="optional">Banned From Giving Feedback</label>
|
||||
<%= select(:user, :no_feedback, [["Yes", true], ["No", false]]) %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag "Update" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -21,10 +21,12 @@
|
||||
<% if post.is_status_locked? %>
|
||||
<li><span id="status-locked-notice">Status locked</span></li>
|
||||
<% else %>
|
||||
<% if !post.is_deleted? && !post.is_pending? && !post.is_flagged? %>
|
||||
<li><%= link_to "Flag", new_post_flag_path(post_flag: { post_id: post.id }), id: "flag", remote: true %></li>
|
||||
<% elsif post.is_flagged? || post.is_deleted? %>
|
||||
<li><%= link_to "Appeal", new_post_appeal_path(post_appeal: { post_id: post.id }), id: "appeal", remote: true %></li>
|
||||
<% unless CurrentUser.no_flagging? %>
|
||||
<% if !post.is_deleted? && !post.is_pending? && !post.is_flagged? %>
|
||||
<li><%= link_to "Flag", new_post_flag_path(post_flag: { post_id: post.id }), id: "flag", remote: true %></li>
|
||||
<% elsif post.is_flagged? || post.is_deleted? %>
|
||||
<li><%= link_to "Appeal", new_post_appeal_path(post_appeal: { post_id: post.id }), id: "appeal", remote: true %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.can_approve_posts? %>
|
||||
|
||||
@@ -167,5 +167,22 @@ class PostFlagTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a user with no_flag=true" do
|
||||
setup do
|
||||
travel_to(2.weeks.ago) do
|
||||
@bob = create(:user, no_flagging: true)
|
||||
end
|
||||
end
|
||||
|
||||
should "not be able to flag more than 1 post in 24 hours" do
|
||||
@post_flag = PostFlag.new(post: @post, reason: "aaa", is_resolved: false)
|
||||
@post_flag.expects(:flag_count_for_creator).returns(1)
|
||||
assert_difference("PostFlag.count", 0) do
|
||||
as(@bob) { @post_flag.save }
|
||||
end
|
||||
assert_equal(["You cannot flag posts"], @post_flag.errors.full_messages.grep(/cannot flag posts/))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,6 +37,19 @@ class UserFeedbackTest < ActiveSupport::TestCase
|
||||
assert_equal(["You cannot submit feedback for yourself"], feedback.errors.full_messages)
|
||||
end
|
||||
|
||||
context "with a no_feedback user" do
|
||||
setup do
|
||||
@gold_user = FactoryBot.create(:gold_user, no_feedback: true)
|
||||
CurrentUser.user = @gold_user
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
feedback = FactoryBot.build(:user_feedback, :user => @gold_user)
|
||||
feedback.save
|
||||
assert_equal(["You cannot submit feedback"], feedback.errors.full_messages.grep(/^You cannot submit feedback$/))
|
||||
end
|
||||
end
|
||||
|
||||
should "not validate if the creator is not gold" do
|
||||
user = FactoryBot.create(:user)
|
||||
gold = FactoryBot.create(:gold_user)
|
||||
|
||||
Reference in New Issue
Block a user