FEATURE: New site setting to ensure flags are claimed

This commit is contained in:
Robin Ward 2018-01-12 16:09:46 -05:00
parent d657fc0632
commit 569a87b136
6 changed files with 48 additions and 13 deletions

View File

@ -1,12 +1,20 @@
{{#unless canAct}}
{{#if flaggedPost.topic.assigned_to_user}}
<div class='cant-act-flagged-post'>
<div class='cant-act-message'>
{{i18n "discourse_assign.cant_act"}}
{{#if actableFilter}}
{{#if flaggedPost.topic.assigned_to_user}}
<div class='cant-act-flagged-post'>
<div class='cant-act-message'>
{{i18n "discourse_assign.cant_act"}}
</div>
<div class='assigned-to'>
{{assigned-to user=flaggedPost.topic.assigned_to_user}}
</div>
</div>
<div class='assigned-to'>
{{assigned-to user=flaggedPost.topic.assigned_to_user}}
{{else}}
<div class='cant-act-flagged-post'>
<div class='cant-act-message'>
{{i18n "discourse_assign.cant_act_unclaimed"}}
</div>
</div>
</div>
{{/if}}
{{/if}}
{{/unless}}

View File

@ -40,13 +40,26 @@ function modifySelectKit(api) {
function initialize(api) {
// You can't act on flags claimed by another user
api.modifyClass('component:flagged-post', {
@computed('flaggedPost.topic.assigned_to_user_id', 'filter')
canAct(assignedToUserId, filter) {
if (this.siteSettings.assign_locks_flags && assignedToUserId && this.currentUser.id !== assignedToUserId) {
return false;
@computed('flaggedPost.topic.assigned_to_user_id')
canAct(assignedToUserId) {
let { siteSettings } = this;
if (siteSettings.assign_locks_flags) {
let unassigned = (this.currentUser.id !== assignedToUserId);
// Can never act on another user's flags
if (assignedToUserId && unassigned) {
return false;
}
// If flags require assignment
if (this.siteSettings.flags_require_assign && unassigned) {
return false;
}
}
return this._super(filter);
return this.get('actableFilter');
},
didInsertElement() {

View File

@ -5,6 +5,7 @@ en:
unassigned: "unassigned %{who} %{when}"
discourse_assign:
cant_act: "You cannot act on flags that have been assigned to other users"
cant_act_unclaimed: "You must claim this topic before acting on flags."
assigned: "Assigned"
assigned_to: "Assigned to"
assign_notification: "<i title='assigned' class='fa fa-user-plus'></i><p><span>{{username}}</span> {{description}}</p>"

View File

@ -11,11 +11,13 @@ en:
unassign_on_close: "When a topic is closed unassign topic"
assign_locks_flags: "When a topic is assigned to a staff member, its flags can only be handled by that person"
assign_mailer_enabled: "When enabled, the assigned user will receive a notification email on each assignment"
flags_require_assign: "When enabled, flags cannot be handled unless assigned to a user."
discourse_assign:
assigned_to: "Topic assigned to @%{username}"
unassigned: "Topic was unassigned"
already_claimed: "That topic has already been claimed."
flag_assigned: "Sorry, flag's topic is assigned to another user"
flag_assigned: "Sorry, that flag's topic is assigned to another user"
flag_unclaimed: "You must claim that topic before acting on the flag"
assign_mailer:
title: "Assign Mailer"
subject_template: "[%{email_prefix}] %{assignee_name} assigned you to '%{topic_title}'!"

View File

@ -15,4 +15,7 @@ plugins:
assign_locks_flags:
default: true
client: true
flags_require_assign:
default: false
client: true
assign_mailer_enabled: false

View File

@ -21,6 +21,7 @@ after_initialize do
# not assigned to them
DiscourseEvent.on(:before_staff_flag_action) do |args|
if SiteSetting.assign_locks_flags?
if custom_fields = args[:post].topic.custom_fields
if assigned_to_id = custom_fields['assigned_to_id']
unless assigned_to_id.to_i == args[:user].id
@ -30,8 +31,15 @@ after_initialize do
custom_message: 'discourse_assign.flag_assigned'
)
end
elsif SiteSetting.flags_require_assign?
raise Discourse::InvalidAccess.new(
"Flags must be assigned before they can be acted on",
nil,
custom_message: 'discourse_assign.flag_unclaimed'
)
end
end
end
end