FEATURE: Option to disallow moderators from removing staff notes
This commit is contained in:
parent
5480079fb2
commit
3444a161b9
|
@ -41,7 +41,7 @@ export default Ember.Controller.extend({
|
||||||
const notes = this.get('model');
|
const notes = this.get('model');
|
||||||
notes.removeObject(note);
|
notes.removeObject(note);
|
||||||
this._refreshCount();
|
this._refreshCount();
|
||||||
});
|
}).catch(popupAjaxError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,14 +12,15 @@
|
||||||
<span class='username'>{{n.created_by.username}}</span>
|
<span class='username'>{{n.created_by.username}}</span>
|
||||||
<span class='post-date'>{{age-with-tooltip n.created_at}}</span>
|
<span class='post-date'>{{age-with-tooltip n.created_at}}</span>
|
||||||
|
|
||||||
<span class='controls'>
|
{{#if n.can_delete}}
|
||||||
{{d-button action="removeNote"
|
<span class='controls'>
|
||||||
actionParam=n
|
{{d-button action="removeNote"
|
||||||
icon="times"
|
actionParam=n
|
||||||
class="btn-small btn-danger"
|
icon="times"
|
||||||
title="staff_notes.remove"}}
|
class="btn-small btn-danger"
|
||||||
</span>
|
title="staff_notes.remove"}}
|
||||||
|
</span>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='cooked'>
|
<div class='cooked'>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
en:
|
en:
|
||||||
site_settings:
|
site_settings:
|
||||||
staff_notes_enabled: "Allow staff users to attach notes to users"
|
staff_notes_enabled: "Allow staff users to attach notes to users"
|
||||||
|
staff_notes_moderators_delete: "Allow moderators to delete staff notes"
|
||||||
|
|
|
@ -2,3 +2,6 @@ plugins:
|
||||||
staff_notes_enabled:
|
staff_notes_enabled:
|
||||||
default: false
|
default: false
|
||||||
client: true
|
client: true
|
||||||
|
staff_notes_moderators_delete:
|
||||||
|
default: true
|
||||||
|
client: false
|
||||||
|
|
12
plugin.rb
12
plugin.rb
|
@ -56,7 +56,7 @@ after_initialize do
|
||||||
|
|
||||||
require_dependency 'application_serializer'
|
require_dependency 'application_serializer'
|
||||||
class ::StaffNoteSerializer < ApplicationSerializer
|
class ::StaffNoteSerializer < ApplicationSerializer
|
||||||
attributes :id, :user_id, :raw, :created_by, :created_at
|
attributes :id, :user_id, :raw, :created_by, :created_at, :can_delete
|
||||||
|
|
||||||
def id
|
def id
|
||||||
object[:id]
|
object[:id]
|
||||||
|
@ -77,6 +77,10 @@ after_initialize do
|
||||||
def created_at
|
def created_at
|
||||||
object[:created_at]
|
object[:created_at]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_delete
|
||||||
|
scope.can_delete_staff_notes?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency 'application_controller'
|
require_dependency 'application_controller'
|
||||||
|
@ -107,6 +111,8 @@ after_initialize do
|
||||||
user = User.where(id: params[:user_id]).first
|
user = User.where(id: params[:user_id]).first
|
||||||
raise Discourse::NotFound if user.blank?
|
raise Discourse::NotFound if user.blank?
|
||||||
|
|
||||||
|
raise Discourse::InvalidAccess.new unless guardian.can_delete_staff_notes?
|
||||||
|
|
||||||
::DiscourseStaffNotes.remove_note(user, params[:id])
|
::DiscourseStaffNotes.remove_note(user, params[:id])
|
||||||
render json: success_json
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
@ -131,6 +137,10 @@ after_initialize do
|
||||||
|
|
||||||
whitelist_staff_user_custom_field(STAFF_NOTE_COUNT_FIELD)
|
whitelist_staff_user_custom_field(STAFF_NOTE_COUNT_FIELD)
|
||||||
|
|
||||||
|
add_to_class(Guardian, :can_delete_staff_notes?) do
|
||||||
|
(SiteSetting.staff_notes_moderators_delete? && user.staff?) || user.admin?
|
||||||
|
end
|
||||||
|
|
||||||
DiscourseStaffNotes::Engine.routes.draw do
|
DiscourseStaffNotes::Engine.routes.draw do
|
||||||
get '/' => 'staff_notes#index'
|
get '/' => 'staff_notes#index'
|
||||||
post '/' => 'staff_notes#create'
|
post '/' => 'staff_notes#create'
|
||||||
|
|
Loading…
Reference in New Issue