DEV: Rename files, functions and DB entries plus two small fixes
1. Shows the full list of notes for a user in the admin report (instead of just the first note). 2. Fixes a UI-only warning when adding or removing a note from the user card.
This commit is contained in:
parent
65f01e6867
commit
03366e344b
|
@ -1 +0,0 @@
|
||||||
{{show-staff-notes show="showStaffNotes" count=staffNotesCount}}
|
|
|
@ -1,3 +0,0 @@
|
||||||
{{#if staffNotesCount}}
|
|
||||||
{{show-staff-notes show="showStaffNotes" count=staffNotesCount}}
|
|
||||||
{{/if}}
|
|
|
@ -1,9 +0,0 @@
|
||||||
{{#if staffNotesCount}}
|
|
||||||
<a href {{action "showStaffNotes"}} title="{{staffNotesTitle}}">
|
|
||||||
{{#if emojiEnabled}}
|
|
||||||
<img src={{emojiUrl}} title={{staffNotesTitle}} alt="pencil" class="emoji">
|
|
||||||
{{else}}
|
|
||||||
{{d-icon "sticky-note"}}
|
|
||||||
{{/if}}
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
|
@ -1 +0,0 @@
|
||||||
<li>{{show-staff-notes show="showStaffNotes" count=staffNotesCount}}</li>
|
|
|
@ -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
|
// Same as other connector
|
||||||
export default connector;
|
export default connector;
|
|
@ -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 { getOwner } from "discourse-common/lib/get-owner";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -9,17 +9,17 @@ export default {
|
||||||
setupComponent(args, component) {
|
setupComponent(args, component) {
|
||||||
let model = args.flaggedPost.get("user");
|
let model = args.flaggedPost.get("user");
|
||||||
component.set(
|
component.set(
|
||||||
"staffNotesCount",
|
"userNotesCount",
|
||||||
model.get("custom_fields.staff_notes_count") || 0
|
model.get("custom_fields.user_notes_count") || 0
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
showStaffNotes() {
|
showUserNotes() {
|
||||||
const store = getOwner(this).lookup("store:main");
|
const store = getOwner(this).lookup("store:main");
|
||||||
const user = this.get("args.flaggedPost.user");
|
const user = this.get("args.flaggedPost.user");
|
||||||
showStaffNotes(store, user.get("id"), count =>
|
showUserNotes(store, user.get("id"), count =>
|
||||||
this.set("staffNotesCount", count)
|
this.set("userNotesCount", count)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 { getOwner } from "discourse-common/lib/get-owner";
|
||||||
import { emojiUrlFor } from "discourse/lib/text";
|
import { emojiUrlFor } from "discourse/lib/text";
|
||||||
|
|
||||||
|
@ -11,24 +11,28 @@ export default {
|
||||||
setupComponent(args, component) {
|
setupComponent(args, component) {
|
||||||
const { user } = args;
|
const { user } = args;
|
||||||
const count =
|
const count =
|
||||||
user.get("staff_notes_count") ||
|
user.get("user_notes_count") ||
|
||||||
user.get("custom_fields.staff_notes_count") ||
|
user.get("custom_fields.user_notes_count") ||
|
||||||
0;
|
0;
|
||||||
component.set("staffNotesCount", count);
|
component.set("userNotesCount", count);
|
||||||
component.set("emojiEnabled", component.siteSettings.enable_emoji);
|
component.set("emojiEnabled", component.siteSettings.enable_emoji);
|
||||||
component.set("emojiUrl", emojiUrlFor("pencil"));
|
component.set("emojiUrl", emojiUrlFor("pencil"));
|
||||||
component.set("user", user);
|
component.set("user", user);
|
||||||
component.set("staffNotesTitle", I18n.t("staff_notes.show", { count }));
|
component.set("userNotesTitle", I18n.t("user_notes.show", { count }));
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
showStaffNotes() {
|
showUserNotes() {
|
||||||
this.parentView.parentView._close();
|
this.parentView.parentView._close();
|
||||||
const store = getOwner(this).lookup("store:main");
|
const store = getOwner(this).lookup("store:main");
|
||||||
const user = this.get("args.user");
|
const user = this.get("args.user");
|
||||||
showStaffNotes(store, user.get("id"), count =>
|
showUserNotes(store, user.get("id"), count => {
|
||||||
this.set("staffNotesCount", count)
|
if (this.isDestroying || this.isDestroyed) {
|
||||||
);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.set("userNotesCount", count);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -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 { getOwner } from "discourse-common/lib/get-owner";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -10,19 +10,19 @@ export default {
|
||||||
setupComponent(args, component) {
|
setupComponent(args, component) {
|
||||||
const { model } = args;
|
const { model } = args;
|
||||||
component.set(
|
component.set(
|
||||||
"staffNotesCount",
|
"userNotesCount",
|
||||||
model.get("staff_notes_count") ||
|
model.get("user_notes_count") ||
|
||||||
model.get("custom_fields.staff_notes_count") ||
|
model.get("custom_fields.user_notes_count") ||
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
showStaffNotes() {
|
showUserNotes() {
|
||||||
const store = getOwner(this).lookup("store:main");
|
const store = getOwner(this).lookup("store:main");
|
||||||
const user = this.get("args.model");
|
const user = this.get("args.model");
|
||||||
showStaffNotes(store, user.get("id"), count =>
|
showUserNotes(store, user.get("id"), count =>
|
||||||
this.set("staffNotesCount", count)
|
this.set("userNotesCount", count)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
import loadScript from "discourse/lib/load-script";
|
import loadScript from "discourse/lib/load-script";
|
||||||
|
|
||||||
export function showStaffNotes(store, userId, callback, opts) {
|
export function showUserNotes(store, userId, callback, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
return loadScript("defer/html-sanitizer-bundle").then(() => {
|
return loadScript("defer/html-sanitizer-bundle").then(() => {
|
||||||
return store.find("staff-note", { user_id: userId }).then(model => {
|
return store.find("user-note", { user_id: userId }).then(model => {
|
||||||
const controller = showModal("staff-notes", {
|
const controller = showModal("user-notes", {
|
||||||
model,
|
model,
|
||||||
title: "staff_notes.title",
|
title: "user_notes.title",
|
||||||
addModalBodyView: true
|
addModalBodyView: true
|
||||||
});
|
});
|
||||||
controller.reset();
|
controller.reset();
|
|
@ -0,0 +1 @@
|
||||||
|
{{show-user-notes show="showUserNotes" count=userNotesCount}}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{{#if userNotesCount}}
|
||||||
|
{{show-user-notes show="showUserNotes" count=userNotesCount}}
|
||||||
|
{{/if}}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{{#if userNotesCount}}
|
||||||
|
<a href {{action "showUserNotes"}} title="{{userNotesTitle}}">
|
||||||
|
{{#if emojiEnabled}}
|
||||||
|
<img src={{emojiUrl}} title={{userNotesTitle}} alt="pencil" class="emoji">
|
||||||
|
{{else}}
|
||||||
|
{{d-icon "sticky-note"}}
|
||||||
|
{{/if}}
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
|
@ -0,0 +1 @@
|
||||||
|
<li>{{show-user-notes show="showUserNotes" count=userNotesCount}}</li>
|
|
@ -28,7 +28,7 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
attachNote() {
|
attachNote() {
|
||||||
const note = this.store.createRecord("staff-note");
|
const note = this.store.createRecord("user-note");
|
||||||
const userId = parseInt(this.get("userId"));
|
const userId = parseInt(this.get("userId"));
|
||||||
|
|
||||||
this.set("saving", true);
|
this.set("saving", true);
|
||||||
|
@ -53,7 +53,7 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
removeNote(note) {
|
removeNote(note) {
|
||||||
bootbox.confirm(
|
bootbox.confirm(
|
||||||
I18n.t("staff_notes.delete_confirm"),
|
I18n.t("user_notes.delete_confirm"),
|
||||||
I18n.t("no_value"),
|
I18n.t("no_value"),
|
||||||
I18n.t("yes_value"),
|
I18n.t("yes_value"),
|
||||||
result => {
|
result => {
|
|
@ -1,9 +1,9 @@
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import { iconNode } from "discourse-common/lib/icon-library";
|
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 {
|
export default {
|
||||||
name: "enable-staff-notes",
|
name: "enable-user-notes",
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
const siteSettings = container.lookup("site-settings:main");
|
const siteSettings = container.lookup("site-settings:main");
|
||||||
const currentUser = container.lookup("current-user:main");
|
const currentUser = container.lookup("current-user:main");
|
||||||
|
@ -17,12 +17,12 @@ export default {
|
||||||
|
|
||||||
const store = container.lookup("store:main");
|
const store = container.lookup("store:main");
|
||||||
withPluginApi("0.8.15", api => {
|
withPluginApi("0.8.15", api => {
|
||||||
function widgetShowStaffNotes() {
|
function widgetshowUserNotes() {
|
||||||
showStaffNotes(
|
showUserNotes(
|
||||||
store,
|
store,
|
||||||
this.attrs.user_id,
|
this.attrs.user_id,
|
||||||
count => {
|
count => {
|
||||||
this.sendWidgetAction("refreshStaffNotes", count);
|
this.sendWidgetAction("refreshUserNotes", count);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
postId: this.attrs.id
|
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") || {};
|
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);
|
this.model.set("user_custom_fields", cfs);
|
||||||
});
|
});
|
||||||
|
|
||||||
api.modifyClass("controller:user", {
|
api.modifyClass("controller:user", {
|
||||||
staffNotesCount: null,
|
userNotesCount: null,
|
||||||
|
|
||||||
_modelChanged: function() {
|
_modelChanged: function() {
|
||||||
this.set(
|
this.set(
|
||||||
"staffNotesCount",
|
"userNotesCount",
|
||||||
this.get("model.custom_fields.staff_notes_count") || 0
|
this.get("model.custom_fields.user_notes_count") || 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
.observes("model")
|
.observes("model")
|
||||||
.on("init"),
|
.on("init"),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
showStaffNotes() {
|
showUserNotes() {
|
||||||
const user = this.get("model");
|
const user = this.get("model");
|
||||||
showStaffNotes(store, user.get("id"), count =>
|
showUserNotes(store, user.get("id"), count =>
|
||||||
this.set("staffNotesCount", count)
|
this.set("userNotesCount", count)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
const cfs = dec.attrs.userCustomFields || {};
|
const cfs = dec.attrs.userCustomFields || {};
|
||||||
if (cfs.staff_notes_count > 0) {
|
if (cfs.user_notes_count > 0) {
|
||||||
return dec.attach("staff-notes-icon");
|
return dec.attach("user-notes-icon");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -77,24 +77,24 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
const cfs = dec.attrs.userCustomFields || {};
|
const cfs = dec.attrs.userCustomFields || {};
|
||||||
if (cfs.staff_notes_count > 0) {
|
if (cfs.user_notes_count > 0) {
|
||||||
return dec.attach("staff-notes-icon");
|
return dec.attach("user-notes-icon");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
api.decorateWidget("post-admin-menu:after", dec => {
|
api.decorateWidget("post-admin-menu:after", dec => {
|
||||||
return dec.attach("post-admin-menu-button", {
|
return dec.attach("post-admin-menu-button", {
|
||||||
icon: "pencil",
|
icon: "pencil",
|
||||||
label: "staff_notes.attach",
|
label: "user_notes.attach",
|
||||||
action: "showStaffNotes"
|
action: "showUserNotes"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
api.attachWidgetAction("post", "showStaffNotes", widgetShowStaffNotes);
|
api.attachWidgetAction("post", "showUserNotes", widgetshowUserNotes);
|
||||||
|
|
||||||
api.createWidget("staff-notes-icon", {
|
api.createWidget("user-notes-icon", {
|
||||||
tagName: "span.staff-notes-icon",
|
tagName: "span.user-notes-icon",
|
||||||
click: widgetShowStaffNotes,
|
click: widgetshowUserNotes,
|
||||||
|
|
||||||
html() {
|
html() {
|
||||||
if (siteSettings.enable_emoji) {
|
if (siteSettings.enable_emoji) {
|
|
@ -1,8 +1,8 @@
|
||||||
<a {{action "show"}} href class="btn">
|
<a {{action "show"}} href class="btn">
|
||||||
{{d-icon "pencil-alt"}}
|
{{d-icon "pencil-alt"}}
|
||||||
{{#if showCount}}
|
{{#if showCount}}
|
||||||
{{i18n 'staff_notes.show' count=count}}
|
{{i18n 'user_notes.show' count=count}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{i18n 'staff_notes.title'}}
|
{{i18n 'user_notes.title'}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</a>
|
</a>
|
|
@ -1,6 +1,6 @@
|
||||||
{{#if siteSettings.user_notes_enabled}}
|
{{#if siteSettings.user_notes_enabled}}
|
||||||
{{admin-report
|
{{admin-report
|
||||||
dataSourceName="staff_notes"
|
dataSourceName="user_notes"
|
||||||
startDate=lastWeek
|
startDate=lastWeek
|
||||||
endDate=endDate}}
|
endDate=endDate}}
|
||||||
{{/if}}
|
{{/if}}
|
|
@ -1,9 +1,9 @@
|
||||||
{{#d-modal-body class="staff-notes-modal"}}
|
{{#d-modal-body class="user-notes-modal"}}
|
||||||
{{textarea value=newNote}}
|
{{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|}}
|
{{#each model as |n|}}
|
||||||
<div class='staff-note'>
|
<div class='user-note'>
|
||||||
<div class='posted-by'>
|
<div class='posted-by'>
|
||||||
{{#user-link user=n.created_by}}
|
{{#user-link user=n.created_by}}
|
||||||
{{avatar n.created_by imageSize="small"}}
|
{{avatar n.created_by imageSize="small"}}
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
{{d-button action=(action "removeNote" n)
|
{{d-button action=(action "removeNote" n)
|
||||||
icon="far-trash-alt"
|
icon="far-trash-alt"
|
||||||
class="btn-small btn-danger"
|
class="btn-small btn-danger"
|
||||||
title="staff_notes.remove"}}
|
title="user_notes.remove"}}
|
||||||
</span>
|
</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
{{#if n.post_id}}
|
{{#if n.post_id}}
|
||||||
<a class="btn btn-small" href={{n.post_url}}>
|
<a class="btn btn-small" href={{n.post_url}}>
|
||||||
{{i18n "staff_notes.show_post"}}
|
{{i18n "user_notes.show_post"}}
|
||||||
</a>
|
</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
|
@ -1,10 +1,10 @@
|
||||||
#discourse-modal {
|
#discourse-modal {
|
||||||
.modal-body.staff-notes-modal {
|
.modal-body.user-notes-modal {
|
||||||
max-height: 80vh !important;
|
max-height: 80vh !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-body.staff-notes-modal {
|
.modal-body.user-notes-modal {
|
||||||
-webkit-box-sizing: border-box;
|
-webkit-box-sizing: border-box;
|
||||||
-moz-box-sizing: border-box;
|
-moz-box-sizing: border-box;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.staff-note {
|
.user-note {
|
||||||
border-top: 1px solid $primary-low;
|
border-top: 1px solid $primary-low;
|
||||||
padding-top: 1em;
|
padding-top: 1em;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.staff-notes-icon {
|
.user-notes-icon {
|
||||||
.mobile-view & {
|
.mobile-view & {
|
||||||
order: 2;
|
order: 2;
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin-report.staff-notes {
|
.admin-report.user-notes {
|
||||||
grid-column: span 12;
|
grid-column: span 12;
|
||||||
|
|
||||||
.admin-report-table {
|
.admin-report-table {
|
|
@ -1,6 +1,6 @@
|
||||||
en:
|
en:
|
||||||
js:
|
js:
|
||||||
staff_notes:
|
user_notes:
|
||||||
title: "User Notes"
|
title: "User Notes"
|
||||||
attach: "Add User Note"
|
attach: "Add User Note"
|
||||||
remove: "Remove User Note"
|
remove: "Remove User Note"
|
||||||
|
|
|
@ -3,13 +3,13 @@ en:
|
||||||
user_notes_enabled: "Allow staff users to attach notes to users"
|
user_notes_enabled: "Allow staff users to attach notes to users"
|
||||||
user_notes_moderators_delete: "Allow moderators to delete user notes"
|
user_notes_moderators_delete: "Allow moderators to delete user notes"
|
||||||
|
|
||||||
staff_notes:
|
user_notes:
|
||||||
official_warning: "Received an official warning from @%{username} -- %{warning_link}"
|
official_warning: "Received an official warning from @%{username} -- %{warning_link}"
|
||||||
user_suspended: "@%{username} suspended this account until %{suspended_till}. Reason: %{reason}"
|
user_suspended: "@%{username} suspended this account until %{suspended_till}. Reason: %{reason}"
|
||||||
user_silenced: "@%{username} silenced this account until %{silenced_till}. Reason: %{reason}"
|
user_silenced: "@%{username} silenced this account until %{silenced_till}. Reason: %{reason}"
|
||||||
|
|
||||||
reports:
|
reports:
|
||||||
staff_notes:
|
user_notes:
|
||||||
title: "User notes"
|
title: "User notes"
|
||||||
description: "List most recent user notes."
|
description: "List most recent user notes."
|
||||||
labels:
|
labels:
|
||||||
|
|
|
@ -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
|
95
plugin.rb
95
plugin.rb
|
@ -4,24 +4,24 @@
|
||||||
# about: Gives the ability for staff members to attach notes to users
|
# about: Gives the ability for staff members to attach notes to users
|
||||||
# version: 0.0.2
|
# version: 0.0.2
|
||||||
# authors: Robin Ward
|
# 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
|
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)
|
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
|
after_initialize do
|
||||||
|
|
||||||
require_dependency 'user'
|
require_dependency 'user'
|
||||||
|
|
||||||
module ::DiscourseStaffNotes
|
module ::DiscourseUserNotes
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
engine_name "discourse_staff_notes"
|
engine_name "discourse_user_notes"
|
||||||
isolate_namespace DiscourseStaffNotes
|
isolate_namespace DiscourseUserNotes
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.key_for(user_id)
|
def self.key_for(user_id)
|
||||||
|
@ -29,7 +29,7 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.notes_for(user_id)
|
def self.notes_for(user_id)
|
||||||
PluginStore.get('staff_notes', key_for(user_id)) || []
|
PluginStore.get('user_notes', key_for(user_id)) || []
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_note(user, raw, created_by, opts = nil)
|
def self.add_note(user, raw, created_by, opts = nil)
|
||||||
|
@ -45,9 +45,9 @@ after_initialize do
|
||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
notes << record
|
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
|
user.save_custom_fields
|
||||||
|
|
||||||
record
|
record
|
||||||
|
@ -58,18 +58,18 @@ after_initialize do
|
||||||
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("user_notes", key_for(user.id), notes)
|
||||||
else
|
else
|
||||||
::PluginStore.remove("staff_notes", key_for(user.id))
|
::PluginStore.remove("user_notes", key_for(user.id))
|
||||||
end
|
end
|
||||||
user.custom_fields[STAFF_NOTE_COUNT_FIELD] = notes.size
|
user.custom_fields[COUNT_FIELD] = notes.size
|
||||||
user.save_custom_fields
|
user.save_custom_fields
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency 'application_serializer'
|
require_dependency 'application_serializer'
|
||||||
class ::StaffNoteSerializer < ApplicationSerializer
|
class ::UserNoteSerializer < ApplicationSerializer
|
||||||
attributes(
|
attributes(
|
||||||
:id,
|
:id,
|
||||||
:user_id,
|
:user_id,
|
||||||
|
@ -103,7 +103,7 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_delete
|
def can_delete
|
||||||
scope.can_delete_staff_notes?
|
scope.can_delete_user_notes?
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_id
|
def post_id
|
||||||
|
@ -131,7 +131,7 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency 'application_controller'
|
require_dependency 'application_controller'
|
||||||
class DiscourseStaffNotes::StaffNotesController < ::ApplicationController
|
class DiscourseUserNotes::UserNotesController < ::ApplicationController
|
||||||
before_action :ensure_logged_in
|
before_action :ensure_logged_in
|
||||||
before_action :ensure_staff
|
before_action :ensure_staff
|
||||||
|
|
||||||
|
@ -139,38 +139,38 @@ 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?
|
||||||
|
|
||||||
notes = ::DiscourseStaffNotes.notes_for(params[:user_id])
|
notes = ::DiscourseUserNotes.notes_for(params[:user_id])
|
||||||
render json: {
|
render json: {
|
||||||
extras: { username: user.username },
|
extras: { username: user.username },
|
||||||
staff_notes: create_json(notes.reverse)
|
user_notes: create_json(notes.reverse)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
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?
|
raise Discourse::NotFound if user.blank?
|
||||||
extras = {}
|
extras = {}
|
||||||
if post_id = params[:staff_note][:post_id]
|
if post_id = params[:user_note][:post_id]
|
||||||
extras[:post_id] = post_id
|
extras[:post_id] = post_id
|
||||||
end
|
end
|
||||||
|
|
||||||
staff_note = ::DiscourseStaffNotes.add_note(
|
user_note = ::DiscourseUserNotes.add_note(
|
||||||
user,
|
user,
|
||||||
params[:staff_note][:raw],
|
params[:user_note][:raw],
|
||||||
current_user.id,
|
current_user.id,
|
||||||
extras
|
extras
|
||||||
)
|
)
|
||||||
|
|
||||||
render json: create_json(staff_note)
|
render json: create_json(user_note)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
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?
|
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
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -196,36 +196,36 @@ after_initialize do
|
||||||
obj[:post] = Post.with_deleted.where(id: obj[:post_id]).first
|
obj[:post] = Post.with_deleted.where(id: obj[:post_id]).first
|
||||||
end
|
end
|
||||||
|
|
||||||
serialize_data(obj, ::StaffNoteSerializer)
|
serialize_data(obj, ::UserNoteSerializer)
|
||||||
end
|
end
|
||||||
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?
|
(SiteSetting.user_notes_moderators_delete? && user.staff?) || user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_serializer(:admin_detailed_user, :staff_notes_count, false) do
|
add_to_serializer(:admin_detailed_user, :user_notes_count, false) do
|
||||||
object.custom_fields && object.custom_fields['staff_notes_count'].to_i
|
object.custom_fields && object.custom_fields['user_notes_count'].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
DiscourseStaffNotes::Engine.routes.draw do
|
DiscourseUserNotes::Engine.routes.draw do
|
||||||
get '/' => 'staff_notes#index'
|
get '/' => 'user_notes#index'
|
||||||
post '/' => 'staff_notes#create'
|
post '/' => 'user_notes#create'
|
||||||
delete '/:id' => 'staff_notes#destroy'
|
delete '/:id' => 'user_notes#destroy'
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
mount ::DiscourseStaffNotes::Engine, at: "/staff_notes"
|
mount ::DiscourseUserNotes::Engine, at: "/user_notes"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_model_callback(UserWarning, :after_commit, on: :create) do
|
add_model_callback(UserWarning, :after_commit, on: :create) do
|
||||||
user = User.find_by_id(self.user_id)
|
user = User.find_by_id(self.user_id)
|
||||||
created_by_user = User.find_by_id(self.created_by_id)
|
created_by_user = User.find_by_id(self.created_by_id)
|
||||||
warning_topic = Topic.find_by_id(self.topic_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})")
|
raw_note = I18n.t("user_notes.official_warning", username: created_by_user.username, warning_link: "[#{warning_topic.title}](#{warning_topic.url})")
|
||||||
::DiscourseStaffNotes.add_note(
|
::DiscourseUserNotes.add_note(
|
||||||
user,
|
user,
|
||||||
raw_note,
|
raw_note,
|
||||||
Discourse::SYSTEM_USER_ID,
|
Discourse::SYSTEM_USER_ID,
|
||||||
|
@ -237,8 +237,8 @@ after_initialize do
|
||||||
return unless self.action == UserHistory.actions[:suspend_user]
|
return unless self.action == UserHistory.actions[:suspend_user]
|
||||||
target_user = User.find_by_id(self.target_user_id)
|
target_user = User.find_by_id(self.target_user_id)
|
||||||
created_by_user = User.find_by_id(self.acting_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)
|
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)
|
||||||
::DiscourseStaffNotes.add_note(
|
::DiscourseUserNotes.add_note(
|
||||||
target_user,
|
target_user,
|
||||||
raw_note,
|
raw_note,
|
||||||
Discourse::SYSTEM_USER_ID,
|
Discourse::SYSTEM_USER_ID,
|
||||||
|
@ -249,7 +249,7 @@ after_initialize do
|
||||||
|
|
||||||
on(:user_silenced) do |details|
|
on(:user_silenced) do |details|
|
||||||
raw_note = I18n.t(
|
raw_note = I18n.t(
|
||||||
"staff_notes.user_silenced",
|
"user_notes.user_silenced",
|
||||||
username: details[:silenced_by]&.username || '',
|
username: details[:silenced_by]&.username || '',
|
||||||
silenced_till: I18n.l(details[:silenced_till], format: :date_only),
|
silenced_till: I18n.l(details[:silenced_till], format: :date_only),
|
||||||
reason: details[:reason]
|
reason: details[:reason]
|
||||||
|
@ -259,7 +259,7 @@ after_initialize do
|
||||||
note_args = { post_id: post.id, topic_id: post.topic_id }
|
note_args = { post_id: post.id, topic_id: post.topic_id }
|
||||||
end
|
end
|
||||||
|
|
||||||
::DiscourseStaffNotes.add_note(
|
::DiscourseUserNotes.add_note(
|
||||||
details[:user],
|
details[:user],
|
||||||
raw_note,
|
raw_note,
|
||||||
Discourse::SYSTEM_USER_ID,
|
Discourse::SYSTEM_USER_ID,
|
||||||
|
@ -268,7 +268,7 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
if respond_to? :add_report
|
if respond_to? :add_report
|
||||||
add_report('staff_notes') do |report|
|
add_report('user_notes') do |report|
|
||||||
report.modes = [:table]
|
report.modes = [:table]
|
||||||
|
|
||||||
report.data = []
|
report.data = []
|
||||||
|
@ -281,7 +281,7 @@ after_initialize do
|
||||||
id: :user_id,
|
id: :user_id,
|
||||||
avatar: :user_avatar_template,
|
avatar: :user_avatar_template,
|
||||||
},
|
},
|
||||||
title: I18n.t("reports.staff_notes.labels.user")
|
title: I18n.t("reports.user_notes.labels.user")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: :user,
|
type: :user,
|
||||||
|
@ -290,21 +290,22 @@ after_initialize do
|
||||||
id: :moderator_id,
|
id: :moderator_id,
|
||||||
avatar: :moderator_avatar_template,
|
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 = []
|
||||||
|
|
||||||
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.start_date)
|
||||||
.where("value::json->0->>'created_at'<?", report.end_date)
|
.where("value::json->0->>'created_at'<?", report.end_date)
|
||||||
.pluck(:value)
|
.pluck(:value)
|
||||||
|
|
||||||
values.each do |value|
|
values.each do |value|
|
||||||
|
notes = JSON.parse(value)
|
||||||
|
notes.each do |note|
|
||||||
data = {}
|
data = {}
|
||||||
note = JSON.parse(value)[0]
|
|
||||||
created_at = Time.parse(note['created_at'])
|
created_at = Time.parse(note['created_at'])
|
||||||
user = User.find_by(id: note['user_id'])
|
user = User.find_by(id: note['user_id'])
|
||||||
moderator = User.find_by(id: note['created_by'])
|
moderator = User.find_by(id: note['created_by'])
|
||||||
|
@ -318,9 +319,11 @@ after_initialize do
|
||||||
data[:moderator_username] = moderator.username_lower
|
data[:moderator_username] = moderator.username_lower
|
||||||
data[:moderator_avatar_template] = User.avatar_template(moderator.username_lower, moderator.uploaded_avatar_id)
|
data[:moderator_avatar_template] = User.avatar_template(moderator.username_lower, moderator.uploaded_avatar_id)
|
||||||
data[:note] = note['raw']
|
data[:note] = note['raw']
|
||||||
|
|
||||||
report.data << data
|
report.data << data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe UserHistory do
|
||||||
it "should create staff note for suspension" 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)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe UserWarning do
|
||||||
it "should create staff note for warning" do
|
it "should create staff note for warning" do
|
||||||
UserWarning.create(topic_id: topic.id, user_id: user.id, created_by_id: admin.id)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue