mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
admins can now clear flags inline
This commit is contained in:
parent
0f5bef61dc
commit
c7461622a9
10 changed files with 86 additions and 10 deletions
|
@ -259,6 +259,9 @@ Discourse.TopicController = Ember.ObjectController.extend Discourse.Presence,
|
|||
post.toggleProperty('bookmarked')
|
||||
false
|
||||
|
||||
clearFlags: (actionType) ->
|
||||
actionType.clearFlags()
|
||||
|
||||
# Who acted on a particular post / action type
|
||||
whoActed: (actionType) ->
|
||||
actionType.loadUsers()
|
||||
|
|
|
@ -58,6 +58,18 @@ window.Discourse.ActionSummary = Em.Object.extend Discourse.Presence,
|
|||
data:
|
||||
post_action_type_id: @get('id')
|
||||
|
||||
clearFlags: ->
|
||||
$.ajax
|
||||
url: "/post_actions/clear_flags"
|
||||
type: "POST"
|
||||
data:
|
||||
post_action_type_id: @get('id')
|
||||
id: @get('post.id')
|
||||
success: (result) =>
|
||||
@set('post.hidden', result.hidden)
|
||||
@set('count', 0)
|
||||
|
||||
|
||||
loadUsers: ->
|
||||
$.getJSON "/post_actions/users",
|
||||
id: @get('post.id'),
|
||||
|
|
|
@ -36,11 +36,19 @@ window.Discourse.ActionsHistoryView = Em.View.extend Discourse.Presence,
|
|||
if c.get('can_undo')
|
||||
alsoName = Em.String.i18n("post.actions.undo", alsoName: c.get('actionType.alsoNameLower'))
|
||||
buffer.push(" <a href='#' data-undo='#{c.get('id')}'>#{alsoName}</a>.")
|
||||
|
||||
if c.get('can_clear_flags')
|
||||
buffer.push(" <a href='#' data-clear-flags='#{c.get('id')}'>#{Em.String.i18n("post.actions.clear_flags",count: c.count)}</a>.")
|
||||
|
||||
buffer.push("</div>")
|
||||
|
||||
click: (e) ->
|
||||
$target = $(e.target)
|
||||
|
||||
if actionTypeId = $target.data('clear-flags')
|
||||
@get('controller').clearFlags(@content.findProperty('id', actionTypeId))
|
||||
return false
|
||||
|
||||
# User wants to know who actioned it
|
||||
if actionTypeId = $target.data('who-acted')
|
||||
@get('controller').whoActed(@content.findProperty('id', actionTypeId))
|
||||
|
|
|
@ -45,6 +45,21 @@ class PostActionsController < ApplicationController
|
|||
render nothing: true
|
||||
end
|
||||
|
||||
def clear_flags
|
||||
requires_parameter(:post_action_type_id)
|
||||
raise Discourse::InvalidAccess unless guardian.is_admin?
|
||||
|
||||
PostAction.clear_flags!(@post, current_user.id, params[:post_action_type_id].to_i)
|
||||
@post.reload
|
||||
|
||||
if @post.is_flagged?
|
||||
render json: {success: true, hidden: true}
|
||||
else
|
||||
@post.unhide!
|
||||
render json: {success: true, hidden: false}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_post_from_params
|
||||
|
|
|
@ -250,6 +250,17 @@ class Post < ActiveRecord::Base
|
|||
result
|
||||
end
|
||||
|
||||
def is_flagged?
|
||||
post_actions.where('post_action_type_id in (?) and deleted_at is null', PostActionType.FlagTypes).count != 0
|
||||
end
|
||||
|
||||
def unhide!
|
||||
self.hidden = false
|
||||
self.hidden_reason_id = nil
|
||||
self.topic.update_attributes(visible: true)
|
||||
self.save
|
||||
end
|
||||
|
||||
# Update the body of a post. Will create a new version when appropriate
|
||||
def revise(updated_by, new_raw, opts={})
|
||||
|
||||
|
|
|
@ -47,10 +47,14 @@ class PostAction < ActiveRecord::Base
|
|||
user_actions
|
||||
end
|
||||
|
||||
def self.clear_flags!(post, moderator_id)
|
||||
def self.clear_flags!(post, moderator_id, action_type_id = nil)
|
||||
|
||||
# -1 is the automatic system cleary
|
||||
actions = moderator_id == -1 ? PostActionType.AutoActionFlagTypes : PostActionType.FlagTypes
|
||||
actions = if action_type_id
|
||||
[action_type_id]
|
||||
else
|
||||
moderator_id == -1 ? PostActionType.AutoActionFlagTypes : PostActionType.FlagTypes
|
||||
end
|
||||
|
||||
PostAction.exec_sql('update post_actions set deleted_at = ?, deleted_by = ?
|
||||
where post_id = ? and deleted_at is null and post_action_type_id in (?)',
|
||||
|
|
|
@ -140,6 +140,8 @@ class PostSerializer < ApplicationSerializer
|
|||
|
||||
next if !action_summary[:can_act] && !scope.current_user
|
||||
|
||||
action_summary[:can_clear_flags] = scope.is_admin? && PostActionType.FlagTypes.include?(id)
|
||||
|
||||
if post_actions.present? and post_actions.has_key?(id)
|
||||
action_summary[:acted] = true
|
||||
action_summary[:can_undo] = scope.can_delete?(post_actions[id])
|
||||
|
|
|
@ -853,6 +853,9 @@ en:
|
|||
|
||||
actions:
|
||||
flag: 'Flag'
|
||||
clear_flags:
|
||||
one: "Clear flag"
|
||||
other: "Clear flags"
|
||||
it_too: "{{alsoName}} it too"
|
||||
undo: "Undo {{alsoName}}"
|
||||
by_you_and_others:
|
||||
|
|
|
@ -133,6 +133,7 @@ Discourse::Application.routes.draw do
|
|||
resources :post_actions do
|
||||
collection do
|
||||
get 'users' => 'post_actions#users'
|
||||
post 'clear_flags' => 'post_actions#clear_flags'
|
||||
end
|
||||
end
|
||||
resources :user_actions
|
||||
|
|
|
@ -54,12 +54,29 @@ describe Post do
|
|||
topic.user.trust_level = TrustLevel.Levels[:moderator]
|
||||
Fabricate.build(:post, post_args).should be_valid
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'flagging helpers' do
|
||||
it 'isFlagged is accurate' do
|
||||
post = Fabricate(:post)
|
||||
user = Fabricate(:coding_horror)
|
||||
PostAction.act(user, post, PostActionType.Types[:off_topic])
|
||||
PostAction.act(post.user, post, PostActionType.Types[:spam])
|
||||
|
||||
post.reload
|
||||
post.is_flagged?.should == true
|
||||
|
||||
PostAction.remove_act(post.user, post, PostActionType.Types[:spam])
|
||||
post.reload
|
||||
post.is_flagged?.should == true
|
||||
|
||||
PostAction.remove_act(user, post, PostActionType.Types[:off_topic])
|
||||
post.reload
|
||||
post.is_flagged?.should == false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'message bus' do
|
||||
it 'enqueues the post on the message bus' do
|
||||
|
|
Loading…
Reference in a new issue