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}} - pencil - {{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 @@ -
  • {{show-staff-notes show="showStaffNotes" count=staffNotesCount}}
  • diff --git a/assets/javascripts/discourse-staff-notes/connectors/admin-user-controls-after/add-staff-notes-button.js.es6 b/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.js.es6 similarity index 60% rename from assets/javascripts/discourse-staff-notes/connectors/admin-user-controls-after/add-staff-notes-button.js.es6 rename to assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.js.es6 index c7bce70..dd79869 100644 --- a/assets/javascripts/discourse-staff-notes/connectors/admin-user-controls-after/add-staff-notes-button.js.es6 +++ b/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.js.es6 @@ -1,4 +1,4 @@ -import connector from "discourse/plugins/discourse-user-notes/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile"; +import connector from "discourse/plugins/discourse-user-notes/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile"; // Same as other connector export default connector; diff --git a/assets/javascripts/discourse-staff-notes/connectors/flagged-post-controls/show-staff-notes-on-flags.js.es6 b/assets/javascripts/discourse-user-notes/connectors/flagged-post-controls/show-user-notes-on-flags.js.es6 similarity index 58% rename from assets/javascripts/discourse-staff-notes/connectors/flagged-post-controls/show-staff-notes-on-flags.js.es6 rename to assets/javascripts/discourse-user-notes/connectors/flagged-post-controls/show-user-notes-on-flags.js.es6 index 125534f..980c6cc 100644 --- a/assets/javascripts/discourse-staff-notes/connectors/flagged-post-controls/show-staff-notes-on-flags.js.es6 +++ b/assets/javascripts/discourse-user-notes/connectors/flagged-post-controls/show-user-notes-on-flags.js.es6 @@ -1,4 +1,4 @@ -import { showStaffNotes } from "discourse/plugins/discourse-user-notes/discourse-staff-notes/lib/staff-notes"; +import { showUserNotes } from "discourse/plugins/discourse-user-notes/discourse-user-notes/lib/user-notes"; import { getOwner } from "discourse-common/lib/get-owner"; export default { @@ -9,17 +9,17 @@ export default { setupComponent(args, component) { let model = args.flaggedPost.get("user"); component.set( - "staffNotesCount", - model.get("custom_fields.staff_notes_count") || 0 + "userNotesCount", + model.get("custom_fields.user_notes_count") || 0 ); }, actions: { - showStaffNotes() { + showUserNotes() { const store = getOwner(this).lookup("store:main"); const user = this.get("args.flaggedPost.user"); - showStaffNotes(store, user.get("id"), count => - this.set("staffNotesCount", count) + showUserNotes(store, user.get("id"), count => + this.set("userNotesCount", count) ); } } diff --git a/assets/javascripts/discourse-staff-notes/connectors/user-card-post-names/show-staff-notes-on-card.js.es6 b/assets/javascripts/discourse-user-notes/connectors/user-card-post-names/show-user-notes-on-card.js.es6 similarity index 57% rename from assets/javascripts/discourse-staff-notes/connectors/user-card-post-names/show-staff-notes-on-card.js.es6 rename to assets/javascripts/discourse-user-notes/connectors/user-card-post-names/show-user-notes-on-card.js.es6 index 1356bc2..ebcdbaf 100644 --- a/assets/javascripts/discourse-staff-notes/connectors/user-card-post-names/show-staff-notes-on-card.js.es6 +++ b/assets/javascripts/discourse-user-notes/connectors/user-card-post-names/show-user-notes-on-card.js.es6 @@ -1,4 +1,4 @@ -import { showStaffNotes } from "discourse/plugins/discourse-user-notes/discourse-staff-notes/lib/staff-notes"; +import { showUserNotes } from "discourse/plugins/discourse-user-notes/discourse-user-notes/lib/user-notes"; import { getOwner } from "discourse-common/lib/get-owner"; import { emojiUrlFor } from "discourse/lib/text"; @@ -11,24 +11,28 @@ export default { setupComponent(args, component) { const { user } = args; const count = - user.get("staff_notes_count") || - user.get("custom_fields.staff_notes_count") || + user.get("user_notes_count") || + user.get("custom_fields.user_notes_count") || 0; - component.set("staffNotesCount", count); + component.set("userNotesCount", count); component.set("emojiEnabled", component.siteSettings.enable_emoji); component.set("emojiUrl", emojiUrlFor("pencil")); component.set("user", user); - component.set("staffNotesTitle", I18n.t("staff_notes.show", { count })); + component.set("userNotesTitle", I18n.t("user_notes.show", { count })); }, actions: { - showStaffNotes() { + showUserNotes() { this.parentView.parentView._close(); const store = getOwner(this).lookup("store:main"); const user = this.get("args.user"); - showStaffNotes(store, user.get("id"), count => - this.set("staffNotesCount", count) - ); + showUserNotes(store, user.get("id"), count => { + if (this.isDestroying || this.isDestroyed) { + return; + } + + this.set("userNotesCount", count); + }); } } }; diff --git a/assets/javascripts/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 b/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 similarity index 58% rename from assets/javascripts/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 rename to assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 index 27e4a9c..f094aac 100644 --- a/assets/javascripts/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 +++ b/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 @@ -1,4 +1,4 @@ -import { showStaffNotes } from "discourse/plugins/discourse-user-notes/discourse-staff-notes/lib/staff-notes"; +import { showUserNotes } from "discourse/plugins/discourse-user-notes/discourse-user-notes/lib/user-notes"; import { getOwner } from "discourse-common/lib/get-owner"; export default { @@ -10,19 +10,19 @@ export default { setupComponent(args, component) { const { model } = args; component.set( - "staffNotesCount", - model.get("staff_notes_count") || - model.get("custom_fields.staff_notes_count") || + "userNotesCount", + model.get("user_notes_count") || + model.get("custom_fields.user_notes_count") || 0 ); }, actions: { - showStaffNotes() { + showUserNotes() { const store = getOwner(this).lookup("store:main"); const user = this.get("args.model"); - showStaffNotes(store, user.get("id"), count => - this.set("staffNotesCount", count) + showUserNotes(store, user.get("id"), count => + this.set("userNotesCount", count) ); } } diff --git a/assets/javascripts/discourse-staff-notes/lib/staff-notes.js.es6 b/assets/javascripts/discourse-user-notes/lib/user-notes.js.es6 similarity index 66% rename from assets/javascripts/discourse-staff-notes/lib/staff-notes.js.es6 rename to assets/javascripts/discourse-user-notes/lib/user-notes.js.es6 index 59d75c5..f9e2358 100644 --- a/assets/javascripts/discourse-staff-notes/lib/staff-notes.js.es6 +++ b/assets/javascripts/discourse-user-notes/lib/user-notes.js.es6 @@ -1,14 +1,14 @@ import showModal from "discourse/lib/show-modal"; import loadScript from "discourse/lib/load-script"; -export function showStaffNotes(store, userId, callback, opts) { +export function showUserNotes(store, userId, callback, opts) { opts = opts || {}; return loadScript("defer/html-sanitizer-bundle").then(() => { - return store.find("staff-note", { user_id: userId }).then(model => { - const controller = showModal("staff-notes", { + return store.find("user-note", { user_id: userId }).then(model => { + const controller = showModal("user-notes", { model, - title: "staff_notes.title", + title: "user_notes.title", addModalBodyView: true }); controller.reset(); diff --git a/assets/javascripts/discourse-user-notes/templates/connectors/admin-user-controls-after/add-user-notes-button.hbs b/assets/javascripts/discourse-user-notes/templates/connectors/admin-user-controls-after/add-user-notes-button.hbs new file mode 100644 index 0000000..a0e3cb4 --- /dev/null +++ b/assets/javascripts/discourse-user-notes/templates/connectors/admin-user-controls-after/add-user-notes-button.hbs @@ -0,0 +1 @@ +{{show-user-notes show="showUserNotes" count=userNotesCount}} diff --git a/assets/javascripts/discourse-user-notes/templates/connectors/flagged-post-controls/show-user-notes-on-flags.hbs b/assets/javascripts/discourse-user-notes/templates/connectors/flagged-post-controls/show-user-notes-on-flags.hbs new file mode 100644 index 0000000..dae2eee --- /dev/null +++ b/assets/javascripts/discourse-user-notes/templates/connectors/flagged-post-controls/show-user-notes-on-flags.hbs @@ -0,0 +1,3 @@ +{{#if userNotesCount}} + {{show-user-notes show="showUserNotes" count=userNotesCount}} +{{/if}} diff --git a/assets/javascripts/discourse-user-notes/templates/connectors/user-card-post-names/show-user-notes-on-card.hbs b/assets/javascripts/discourse-user-notes/templates/connectors/user-card-post-names/show-user-notes-on-card.hbs new file mode 100644 index 0000000..d7fb5e4 --- /dev/null +++ b/assets/javascripts/discourse-user-notes/templates/connectors/user-card-post-names/show-user-notes-on-card.hbs @@ -0,0 +1,9 @@ +{{#if userNotesCount}} + + {{#if emojiEnabled}} + pencil + {{else}} + {{d-icon "sticky-note"}} + {{/if}} + +{{/if}} diff --git a/assets/javascripts/discourse-user-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs b/assets/javascripts/discourse-user-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs new file mode 100644 index 0000000..e059a9e --- /dev/null +++ b/assets/javascripts/discourse-user-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs @@ -0,0 +1 @@ +
  • {{show-user-notes show="showUserNotes" count=userNotesCount}}
  • diff --git a/assets/javascripts/discourse/adapters/staff-note.js.es6 b/assets/javascripts/discourse/adapters/user-note.js.es6 similarity index 100% rename from assets/javascripts/discourse/adapters/staff-note.js.es6 rename to assets/javascripts/discourse/adapters/user-note.js.es6 diff --git a/assets/javascripts/discourse/components/show-staff-notes.js.es6 b/assets/javascripts/discourse/components/show-user-notes.js.es6 similarity index 100% rename from assets/javascripts/discourse/components/show-staff-notes.js.es6 rename to assets/javascripts/discourse/components/show-user-notes.js.es6 diff --git a/assets/javascripts/discourse/controllers/staff-notes.js.es6 b/assets/javascripts/discourse/controllers/user-notes.js.es6 similarity index 94% rename from assets/javascripts/discourse/controllers/staff-notes.js.es6 rename to assets/javascripts/discourse/controllers/user-notes.js.es6 index 5706271..ea687e2 100644 --- a/assets/javascripts/discourse/controllers/staff-notes.js.es6 +++ b/assets/javascripts/discourse/controllers/user-notes.js.es6 @@ -28,7 +28,7 @@ export default Ember.Controller.extend({ actions: { attachNote() { - const note = this.store.createRecord("staff-note"); + const note = this.store.createRecord("user-note"); const userId = parseInt(this.get("userId")); this.set("saving", true); @@ -53,7 +53,7 @@ export default Ember.Controller.extend({ removeNote(note) { bootbox.confirm( - I18n.t("staff_notes.delete_confirm"), + I18n.t("user_notes.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), result => { diff --git a/assets/javascripts/discourse/initializers/enable-staff-notes.js.es6 b/assets/javascripts/discourse/initializers/enable-user-notes.js.es6 similarity index 64% rename from assets/javascripts/discourse/initializers/enable-staff-notes.js.es6 rename to assets/javascripts/discourse/initializers/enable-user-notes.js.es6 index 846f75b..2daebcb 100644 --- a/assets/javascripts/discourse/initializers/enable-staff-notes.js.es6 +++ b/assets/javascripts/discourse/initializers/enable-user-notes.js.es6 @@ -1,9 +1,9 @@ import { withPluginApi } from "discourse/lib/plugin-api"; import { iconNode } from "discourse-common/lib/icon-library"; -import { showStaffNotes } from "discourse/plugins/discourse-user-notes/discourse-staff-notes/lib/staff-notes"; +import { showUserNotes } from "discourse/plugins/discourse-user-notes/discourse-user-notes/lib/user-notes"; export default { - name: "enable-staff-notes", + name: "enable-user-notes", initialize(container) { const siteSettings = container.lookup("site-settings:main"); const currentUser = container.lookup("current-user:main"); @@ -17,12 +17,12 @@ export default { const store = container.lookup("store:main"); withPluginApi("0.8.15", api => { - function widgetShowStaffNotes() { - showStaffNotes( + function widgetshowUserNotes() { + showUserNotes( store, this.attrs.user_id, count => { - this.sendWidgetAction("refreshStaffNotes", count); + this.sendWidgetAction("refreshUserNotes", count); }, { postId: this.attrs.id @@ -30,29 +30,29 @@ export default { ); } - api.attachWidgetAction("post", "refreshStaffNotes", function(count) { + api.attachWidgetAction("post", "refreshUserNotes", function(count) { const cfs = this.model.get("user_custom_fields") || {}; - cfs.staff_notes_count = count; + cfs.user_notes_count = count; this.model.set("user_custom_fields", cfs); }); api.modifyClass("controller:user", { - staffNotesCount: null, + userNotesCount: null, _modelChanged: function() { this.set( - "staffNotesCount", - this.get("model.custom_fields.staff_notes_count") || 0 + "userNotesCount", + this.get("model.custom_fields.user_notes_count") || 0 ); } .observes("model") .on("init"), actions: { - showStaffNotes() { + showUserNotes() { const user = this.get("model"); - showStaffNotes(store, user.get("id"), count => - this.set("staffNotesCount", count) + showUserNotes(store, user.get("id"), count => + this.set("userNotesCount", count) ); } } @@ -66,8 +66,8 @@ export default { } const cfs = dec.attrs.userCustomFields || {}; - if (cfs.staff_notes_count > 0) { - return dec.attach("staff-notes-icon"); + if (cfs.user_notes_count > 0) { + return dec.attach("user-notes-icon"); } }); @@ -77,24 +77,24 @@ export default { } const cfs = dec.attrs.userCustomFields || {}; - if (cfs.staff_notes_count > 0) { - return dec.attach("staff-notes-icon"); + if (cfs.user_notes_count > 0) { + return dec.attach("user-notes-icon"); } }); api.decorateWidget("post-admin-menu:after", dec => { return dec.attach("post-admin-menu-button", { icon: "pencil", - label: "staff_notes.attach", - action: "showStaffNotes" + label: "user_notes.attach", + action: "showUserNotes" }); }); - api.attachWidgetAction("post", "showStaffNotes", widgetShowStaffNotes); + api.attachWidgetAction("post", "showUserNotes", widgetshowUserNotes); - api.createWidget("staff-notes-icon", { - tagName: "span.staff-notes-icon", - click: widgetShowStaffNotes, + api.createWidget("user-notes-icon", { + tagName: "span.user-notes-icon", + click: widgetshowUserNotes, html() { if (siteSettings.enable_emoji) { diff --git a/assets/javascripts/discourse/templates/components/show-staff-notes.hbs b/assets/javascripts/discourse/templates/components/show-user-notes.hbs similarity index 59% rename from assets/javascripts/discourse/templates/components/show-staff-notes.hbs rename to assets/javascripts/discourse/templates/components/show-user-notes.hbs index 21b122e..8c2c2ff 100644 --- a/assets/javascripts/discourse/templates/components/show-staff-notes.hbs +++ b/assets/javascripts/discourse/templates/components/show-user-notes.hbs @@ -1,8 +1,8 @@ {{d-icon "pencil-alt"}} {{#if showCount}} - {{i18n 'staff_notes.show' count=count}} + {{i18n 'user_notes.show' count=count}} {{else}} - {{i18n 'staff_notes.title'}} + {{i18n 'user_notes.title'}} {{/if}} diff --git a/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs b/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-user-notes-report-table.hbs similarity index 76% rename from assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs rename to assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-user-notes-report-table.hbs index 62438d1..5752686 100644 --- a/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs +++ b/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-user-notes-report-table.hbs @@ -1,6 +1,6 @@ {{#if siteSettings.user_notes_enabled}} {{admin-report - dataSourceName="staff_notes" + dataSourceName="user_notes" startDate=lastWeek endDate=endDate}} {{/if}} diff --git a/assets/javascripts/discourse/templates/modal/staff-notes.hbs b/assets/javascripts/discourse/templates/modal/user-notes.hbs similarity index 78% rename from assets/javascripts/discourse/templates/modal/staff-notes.hbs rename to assets/javascripts/discourse/templates/modal/user-notes.hbs index 233c644..9c36c41 100644 --- a/assets/javascripts/discourse/templates/modal/staff-notes.hbs +++ b/assets/javascripts/discourse/templates/modal/user-notes.hbs @@ -1,9 +1,9 @@ -{{#d-modal-body class="staff-notes-modal"}} +{{#d-modal-body class="user-notes-modal"}} {{textarea value=newNote}} - {{d-button action="attachNote" label="staff_notes.attach" class="btn-primary" disabled=attachDisabled}} + {{d-button action="attachNote" label="user_notes.attach" class="btn-primary" disabled=attachDisabled}} {{#each model as |n|}} -
    +
    {{#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'