Only show the icon when they have notes
This commit is contained in:
parent
71d0b4c784
commit
bc9057073b
|
@ -8,4 +8,3 @@ export default RestAdapter.extend({
|
||||||
return ajax(`${path}?user_id=${userId}`, { method: 'DELETE' });
|
return ajax(`${path}?user_id=${userId}`, { method: 'DELETE' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,12 @@ export default {
|
||||||
if (!siteSettings.staff_notes_enabled) { return; }
|
if (!siteSettings.staff_notes_enabled) { return; }
|
||||||
|
|
||||||
withPluginApi('0.2', api => {
|
withPluginApi('0.2', api => {
|
||||||
api.decorateWidget('poster-name:after', dec => dec.attach('staff-notes-icon'));
|
api.decorateWidget('poster-name:after', dec => {
|
||||||
|
const cfs = dec.attrs.userCustomFields || {};
|
||||||
|
if (cfs.has_staff_notes) {
|
||||||
|
return dec.attach('staff-notes-icon');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
api.createWidget('staff-notes-icon', {
|
api.createWidget('staff-notes-icon', {
|
||||||
tagName: 'span.staff-notes-icon',
|
tagName: 'span.staff-notes-icon',
|
||||||
|
|
34
plugin.rb
34
plugin.rb
|
@ -7,6 +7,8 @@ enabled_site_setting :staff_notes_enabled
|
||||||
|
|
||||||
register_asset 'stylesheets/staff_notes.scss'
|
register_asset 'stylesheets/staff_notes.scss'
|
||||||
|
|
||||||
|
STAFF_NOTES_FIELD = "has_staff_notes"
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
||||||
require_dependency 'user'
|
require_dependency 'user'
|
||||||
|
@ -25,25 +27,29 @@ after_initialize do
|
||||||
PluginStore.get('staff_notes', key_for(user_id)) || []
|
PluginStore.get('staff_notes', key_for(user_id)) || []
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_note(user_id, raw, created_by)
|
def self.add_note(user, raw, created_by)
|
||||||
notes = notes_for(user_id)
|
notes = notes_for(user.id)
|
||||||
record = { id: SecureRandom.hex(16), user_id: user_id, raw: raw, created_by: created_by, created_at: Time.now }
|
record = { id: SecureRandom.hex(16), user_id: user.id, raw: raw, created_by: created_by, created_at: Time.now }
|
||||||
notes << record
|
notes << record
|
||||||
::PluginStore.set("staff_notes", key_for(user_id), notes)
|
::PluginStore.set("staff_notes", key_for(user.id), notes)
|
||||||
|
|
||||||
|
user.custom_fields[STAFF_NOTES_FIELD] = true
|
||||||
|
user.save_custom_fields
|
||||||
|
|
||||||
record
|
record
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.remove_note(user_id, note_id)
|
def self.remove_note(user, note_id)
|
||||||
notes = notes_for(user_id)
|
notes = notes_for(user.id)
|
||||||
notes.reject! {|n| n[:id] == note_id}
|
notes.reject! {|n| n[:id] == note_id}
|
||||||
|
|
||||||
if notes.size > 0
|
if notes.size > 0
|
||||||
::PluginStore.set("staff_notes", key_for(user_id), notes)
|
::PluginStore.set("staff_notes", key_for(user.id), notes)
|
||||||
else
|
else
|
||||||
::PluginStore.remove("staff_notes", key_for(user_id))
|
::PluginStore.remove("staff_notes", key_for(user.id))
|
||||||
|
user.custom_fields.delete(STAFF_NOTES_FIELD)
|
||||||
|
user.save_custom_fields
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -93,11 +99,9 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
user_id = params[:staff_note][:user_id]
|
user = User.where(id: params[:staff_note][:user_id]).first
|
||||||
|
|
||||||
user = User.where(id: user_id).first
|
|
||||||
raise Discourse::NotFound if user.blank?
|
raise Discourse::NotFound if user.blank?
|
||||||
staff_note = ::DiscourseStaffNotes.add_note(user.id, params[:staff_note][:raw], current_user.id)
|
staff_note = ::DiscourseStaffNotes.add_note(user, params[:staff_note][:raw], current_user.id)
|
||||||
|
|
||||||
render json: serialize_data(staff_note, ::StaffNoteSerializer)
|
render json: serialize_data(staff_note, ::StaffNoteSerializer)
|
||||||
end
|
end
|
||||||
|
@ -106,12 +110,14 @@ 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?
|
||||||
|
|
||||||
::DiscourseStaffNotes.remove_note(user.id, params[:id])
|
::DiscourseStaffNotes.remove_note(user, params[:id])
|
||||||
render json: success_json
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
whitelist_staff_user_custom_field(STAFF_NOTES_FIELD)
|
||||||
|
|
||||||
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