diff --git a/assets/javascripts/discourse-staff-notes/templates/connectors/admin-user-controls-after/add-staff-notes-button.hbs b/assets/javascripts/discourse-staff-notes/templates/connectors/admin-user-controls-after/add-staff-notes-button.hbs
deleted file mode 100644
index 15c8b7b..0000000
--- a/assets/javascripts/discourse-staff-notes/templates/connectors/admin-user-controls-after/add-staff-notes-button.hbs
+++ /dev/null
@@ -1 +0,0 @@
-{{show-staff-notes show="showStaffNotes" count=staffNotesCount}}
diff --git a/assets/javascripts/discourse-staff-notes/templates/connectors/flagged-post-controls/show-staff-notes-on-flags.hbs b/assets/javascripts/discourse-staff-notes/templates/connectors/flagged-post-controls/show-staff-notes-on-flags.hbs
deleted file mode 100644
index b04de64..0000000
--- a/assets/javascripts/discourse-staff-notes/templates/connectors/flagged-post-controls/show-staff-notes-on-flags.hbs
+++ /dev/null
@@ -1,3 +0,0 @@
-{{#if staffNotesCount}}
- {{show-staff-notes show="showStaffNotes" count=staffNotesCount}}
-{{/if}}
diff --git a/assets/javascripts/discourse-staff-notes/templates/connectors/user-card-post-names/show-staff-notes-on-card.hbs b/assets/javascripts/discourse-staff-notes/templates/connectors/user-card-post-names/show-staff-notes-on-card.hbs
deleted file mode 100644
index 3243569..0000000
--- a/assets/javascripts/discourse-staff-notes/templates/connectors/user-card-post-names/show-staff-notes-on-card.hbs
+++ /dev/null
@@ -1,9 +0,0 @@
-{{#if staffNotesCount}}
-
- {{#if emojiEnabled}}
-
- {{else}}
- {{d-icon "sticky-note"}}
- {{/if}}
-
-{{/if}}
diff --git a/assets/javascripts/discourse-staff-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs b/assets/javascripts/discourse-staff-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs
deleted file mode 100644
index fa4c53d..0000000
--- a/assets/javascripts/discourse-staff-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs
+++ /dev/null
@@ -1 +0,0 @@
-
+
{{#user-link user=n.created_by}}
{{avatar n.created_by imageSize="small"}}
@@ -19,7 +19,7 @@
{{d-button action=(action "removeNote" n)
icon="far-trash-alt"
class="btn-small btn-danger"
- title="staff_notes.remove"}}
+ title="user_notes.remove"}}
{{/if}}
@@ -30,7 +30,7 @@
{{#if n.post_id}}
- {{i18n "staff_notes.show_post"}}
+ {{i18n "user_notes.show_post"}}
{{/if}}
diff --git a/assets/stylesheets/staff_notes.scss b/assets/stylesheets/user_notes.scss
similarity index 88%
rename from assets/stylesheets/staff_notes.scss
rename to assets/stylesheets/user_notes.scss
index 55a01f3..081ea2c 100644
--- a/assets/stylesheets/staff_notes.scss
+++ b/assets/stylesheets/user_notes.scss
@@ -1,10 +1,10 @@
#discourse-modal {
- .modal-body.staff-notes-modal {
+ .modal-body.user-notes-modal {
max-height: 80vh !important;
}
}
-.modal-body.staff-notes-modal {
+.modal-body.user-notes-modal {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
@@ -36,7 +36,7 @@
}
}
- .staff-note {
+ .user-note {
border-top: 1px solid $primary-low;
padding-top: 1em;
@@ -53,7 +53,7 @@
}
}
-.staff-notes-icon {
+.user-notes-icon {
.mobile-view & {
order: 2;
margin-left: 10px;
@@ -61,7 +61,7 @@
cursor: pointer;
}
-.admin-report.staff-notes {
+.admin-report.user-notes {
grid-column: span 12;
.admin-report-table {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 2bc4296..6ed1964 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1,6 +1,6 @@
en:
js:
- staff_notes:
+ user_notes:
title: "User Notes"
attach: "Add User Note"
remove: "Remove User Note"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 166385d..4aa464b 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -3,13 +3,13 @@ en:
user_notes_enabled: "Allow staff users to attach notes to users"
user_notes_moderators_delete: "Allow moderators to delete user notes"
- staff_notes:
+ user_notes:
official_warning: "Received an official warning from @%{username} -- %{warning_link}"
user_suspended: "@%{username} suspended this account until %{suspended_till}. Reason: %{reason}"
user_silenced: "@%{username} silenced this account until %{silenced_till}. Reason: %{reason}"
reports:
- staff_notes:
+ user_notes:
title: "User notes"
description: "List most recent user notes."
labels:
diff --git a/db/migrate/20190725020422_rename_staff_notes_rows_and_fields.rb b/db/migrate/20190725020422_rename_staff_notes_rows_and_fields.rb
new file mode 100644
index 0000000..70bb56b
--- /dev/null
+++ b/db/migrate/20190725020422_rename_staff_notes_rows_and_fields.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class RenameStaffNotesRowsAndFields < ActiveRecord::Migration[5.2]
+ def change
+ execute "UPDATE user_custom_fields SET name = 'user_notes_count' WHERE name = 'staff_notes_count'"
+ execute "UPDATE plugin_store_rows SET plugin_name = 'user_notes' WHERE plugin_name = 'staff_notes'"
+ end
+end
diff --git a/plugin.rb b/plugin.rb
index 0f96178..9d069e3 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -4,24 +4,24 @@
# about: Gives the ability for staff members to attach notes to users
# version: 0.0.2
# authors: Robin Ward
-# url: https://github.com/discourse/discourse-staff-notes
+# url: https://github.com/discourse/discourse-user-notes
enabled_site_setting :user_notes_enabled
-register_asset 'stylesheets/staff_notes.scss'
+register_asset 'stylesheets/user_notes.scss'
register_svg_icon "sticky-note" if respond_to?(:register_svg_icon)
-STAFF_NOTE_COUNT_FIELD = "staff_notes_count"
+COUNT_FIELD = "user_notes_count"
after_initialize do
require_dependency 'user'
- module ::DiscourseStaffNotes
+ module ::DiscourseUserNotes
class Engine < ::Rails::Engine
- engine_name "discourse_staff_notes"
- isolate_namespace DiscourseStaffNotes
+ engine_name "discourse_user_notes"
+ isolate_namespace DiscourseUserNotes
end
def self.key_for(user_id)
@@ -29,7 +29,7 @@ after_initialize do
end
def self.notes_for(user_id)
- PluginStore.get('staff_notes', key_for(user_id)) || []
+ PluginStore.get('user_notes', key_for(user_id)) || []
end
def self.add_note(user, raw, created_by, opts = nil)
@@ -45,9 +45,9 @@ after_initialize do
}.merge(opts)
notes << record
- ::PluginStore.set("staff_notes", key_for(user.id), notes)
+ ::PluginStore.set("user_notes", key_for(user.id), notes)
- user.custom_fields[STAFF_NOTE_COUNT_FIELD] = notes.size
+ user.custom_fields[COUNT_FIELD] = notes.size
user.save_custom_fields
record
@@ -58,18 +58,18 @@ after_initialize do
notes.reject! { |n| n[:id] == note_id }
if notes.size > 0
- ::PluginStore.set("staff_notes", key_for(user.id), notes)
+ ::PluginStore.set("user_notes", key_for(user.id), notes)
else
- ::PluginStore.remove("staff_notes", key_for(user.id))
+ ::PluginStore.remove("user_notes", key_for(user.id))
end
- user.custom_fields[STAFF_NOTE_COUNT_FIELD] = notes.size
+ user.custom_fields[COUNT_FIELD] = notes.size
user.save_custom_fields
end
end
require_dependency 'application_serializer'
- class ::StaffNoteSerializer < ApplicationSerializer
+ class ::UserNoteSerializer < ApplicationSerializer
attributes(
:id,
:user_id,
@@ -103,7 +103,7 @@ after_initialize do
end
def can_delete
- scope.can_delete_staff_notes?
+ scope.can_delete_user_notes?
end
def post_id
@@ -131,7 +131,7 @@ after_initialize do
end
require_dependency 'application_controller'
- class DiscourseStaffNotes::StaffNotesController < ::ApplicationController
+ class DiscourseUserNotes::UserNotesController < ::ApplicationController
before_action :ensure_logged_in
before_action :ensure_staff
@@ -139,38 +139,38 @@ after_initialize do
user = User.where(id: params[:user_id]).first
raise Discourse::NotFound if user.blank?
- notes = ::DiscourseStaffNotes.notes_for(params[:user_id])
+ notes = ::DiscourseUserNotes.notes_for(params[:user_id])
render json: {
extras: { username: user.username },
- staff_notes: create_json(notes.reverse)
+ user_notes: create_json(notes.reverse)
}
end
def create
- user = User.where(id: params[:staff_note][:user_id]).first
+ user = User.where(id: params[:user_note][:user_id]).first
raise Discourse::NotFound if user.blank?
extras = {}
- if post_id = params[:staff_note][:post_id]
+ if post_id = params[:user_note][:post_id]
extras[:post_id] = post_id
end
- staff_note = ::DiscourseStaffNotes.add_note(
+ user_note = ::DiscourseUserNotes.add_note(
user,
- params[:staff_note][:raw],
+ params[:user_note][:raw],
current_user.id,
extras
)
- render json: create_json(staff_note)
+ render json: create_json(user_note)
end
def destroy
user = User.where(id: params[:user_id]).first
raise Discourse::NotFound if user.blank?
- raise Discourse::InvalidAccess.new unless guardian.can_delete_staff_notes?
+ raise Discourse::InvalidAccess.new unless guardian.can_delete_user_notes?
- ::DiscourseStaffNotes.remove_note(user, params[:id])
+ ::DiscourseUserNotes.remove_note(user, params[:id])
render json: success_json
end
@@ -196,36 +196,36 @@ after_initialize do
obj[:post] = Post.with_deleted.where(id: obj[:post_id]).first
end
- serialize_data(obj, ::StaffNoteSerializer)
+ serialize_data(obj, ::UserNoteSerializer)
end
end
- whitelist_staff_user_custom_field(STAFF_NOTE_COUNT_FIELD)
+ whitelist_staff_user_custom_field(COUNT_FIELD)
- add_to_class(Guardian, :can_delete_staff_notes?) do
+ add_to_class(Guardian, :can_delete_user_notes?) do
(SiteSetting.user_notes_moderators_delete? && user.staff?) || user.admin?
end
- add_to_serializer(:admin_detailed_user, :staff_notes_count, false) do
- object.custom_fields && object.custom_fields['staff_notes_count'].to_i
+ add_to_serializer(:admin_detailed_user, :user_notes_count, false) do
+ object.custom_fields && object.custom_fields['user_notes_count'].to_i
end
- DiscourseStaffNotes::Engine.routes.draw do
- get '/' => 'staff_notes#index'
- post '/' => 'staff_notes#create'
- delete '/:id' => 'staff_notes#destroy'
+ DiscourseUserNotes::Engine.routes.draw do
+ get '/' => 'user_notes#index'
+ post '/' => 'user_notes#create'
+ delete '/:id' => 'user_notes#destroy'
end
Discourse::Application.routes.append do
- mount ::DiscourseStaffNotes::Engine, at: "/staff_notes"
+ mount ::DiscourseUserNotes::Engine, at: "/user_notes"
end
add_model_callback(UserWarning, :after_commit, on: :create) do
user = User.find_by_id(self.user_id)
created_by_user = User.find_by_id(self.created_by_id)
warning_topic = Topic.find_by_id(self.topic_id)
- raw_note = I18n.t("staff_notes.official_warning", username: created_by_user.username, warning_link: "[#{warning_topic.title}](#{warning_topic.url})")
- ::DiscourseStaffNotes.add_note(
+ raw_note = I18n.t("user_notes.official_warning", username: created_by_user.username, warning_link: "[#{warning_topic.title}](#{warning_topic.url})")
+ ::DiscourseUserNotes.add_note(
user,
raw_note,
Discourse::SYSTEM_USER_ID,
@@ -237,8 +237,8 @@ after_initialize do
return unless self.action == UserHistory.actions[:suspend_user]
target_user = User.find_by_id(self.target_user_id)
created_by_user = User.find_by_id(self.acting_user_id)
- raw_note = I18n.t("staff_notes.user_suspended", username: created_by_user.username, suspended_till: I18n.l(target_user.suspended_till, format: :date_only), reason: self.details)
- ::DiscourseStaffNotes.add_note(
+ raw_note = I18n.t("user_notes.user_suspended", username: created_by_user.username, suspended_till: I18n.l(target_user.suspended_till, format: :date_only), reason: self.details)
+ ::DiscourseUserNotes.add_note(
target_user,
raw_note,
Discourse::SYSTEM_USER_ID,
@@ -249,7 +249,7 @@ after_initialize do
on(:user_silenced) do |details|
raw_note = I18n.t(
- "staff_notes.user_silenced",
+ "user_notes.user_silenced",
username: details[:silenced_by]&.username || '',
silenced_till: I18n.l(details[:silenced_till], format: :date_only),
reason: details[:reason]
@@ -259,7 +259,7 @@ after_initialize do
note_args = { post_id: post.id, topic_id: post.topic_id }
end
- ::DiscourseStaffNotes.add_note(
+ ::DiscourseUserNotes.add_note(
details[:user],
raw_note,
Discourse::SYSTEM_USER_ID,
@@ -268,7 +268,7 @@ after_initialize do
end
if respond_to? :add_report
- add_report('staff_notes') do |report|
+ add_report('user_notes') do |report|
report.modes = [:table]
report.data = []
@@ -281,7 +281,7 @@ after_initialize do
id: :user_id,
avatar: :user_avatar_template,
},
- title: I18n.t("reports.staff_notes.labels.user")
+ title: I18n.t("reports.user_notes.labels.user")
},
{
type: :user,
@@ -290,35 +290,38 @@ after_initialize do
id: :moderator_id,
avatar: :moderator_avatar_template,
},
- title: I18n.t("reports.staff_notes.labels.moderator")
+ title: I18n.t("reports.user_notes.labels.moderator")
},
- { type: :text, property: :note, title: I18n.t("reports.staff_notes.labels.note") }
+ { type: :text, property: :note, title: I18n.t("reports.user_notes.labels.note") }
]
values = []
- values = PluginStoreRow.where(plugin_name: 'staff_notes')
+ values = PluginStoreRow.where(plugin_name: 'user_notes')
.where("value::json->0->>'created_at'>?", report.start_date)
.where("value::json->0->>'created_at'", report.end_date)
.pluck(:value)
values.each do |value|
- data = {}
- note = JSON.parse(value)[0]
- created_at = Time.parse(note['created_at'])
- user = User.find_by(id: note['user_id'])
- moderator = User.find_by(id: note['created_by'])
+ notes = JSON.parse(value)
+ notes.each do |note|
+ data = {}
+ created_at = Time.parse(note['created_at'])
+ user = User.find_by(id: note['user_id'])
+ moderator = User.find_by(id: note['created_by'])
- if user && moderator
- data[:created_at] = created_at
- data[:user_id] = user.id
- data[:username] = user.username_lower
- data[:user_avatar_template] = User.avatar_template(user.username_lower, user.uploaded_avatar_id)
- data[:moderator_id] = moderator.id
- data[:moderator_username] = moderator.username_lower
- data[:moderator_avatar_template] = User.avatar_template(moderator.username_lower, moderator.uploaded_avatar_id)
- data[:note] = note['raw']
- report.data << data
+ if user && moderator
+ data[:created_at] = created_at
+ data[:user_id] = user.id
+ data[:username] = user.username_lower
+ data[:user_avatar_template] = User.avatar_template(user.username_lower, user.uploaded_avatar_id)
+ data[:moderator_id] = moderator.id
+ data[:moderator_username] = moderator.username_lower
+ data[:moderator_avatar_template] = User.avatar_template(moderator.username_lower, moderator.uploaded_avatar_id)
+ data[:note] = note['raw']
+
+ report.data << data
+ end
end
end
end
diff --git a/spec/user_history_spec.rb b/spec/user_history_spec.rb
index 6fa3d1f..499f27c 100644
--- a/spec/user_history_spec.rb
+++ b/spec/user_history_spec.rb
@@ -15,7 +15,7 @@ describe UserHistory do
it "should create staff note for suspension" do
UserHistory.create!(action: UserHistory.actions[:suspend_user], target_user_id: user.id, acting_user_id: admin.id)
- expect(PluginStore.get('staff_notes', "notes:#{user.id}")).to be_present
+ expect(PluginStore.get('user_notes', "notes:#{user.id}")).to be_present
end
end
end
diff --git a/spec/user_warning_spec.rb b/spec/user_warning_spec.rb
index 95c0149..4d70051 100644
--- a/spec/user_warning_spec.rb
+++ b/spec/user_warning_spec.rb
@@ -16,7 +16,7 @@ describe UserWarning do
it "should create staff note for warning" do
UserWarning.create(topic_id: topic.id, user_id: user.id, created_by_id: admin.id)
- expect(PluginStore.get('staff_notes', "notes:#{user.id}")).to be_present
+ expect(PluginStore.get('user_notes', "notes:#{user.id}")).to be_present
end
end
end