feat: ability for moderators to send mod mail

This commit is contained in:
ThatOneCalculator 2023-05-10 14:06:45 -07:00
parent 10e6e3ae14
commit a11abdde60
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
4 changed files with 88 additions and 0 deletions

View File

@ -1080,6 +1080,7 @@ noteId: "Post ID"
signupsDisabled: "Signups on this server are currently disabled, but you can always sign up at another server! If you have an invitation code for this server, please enter it below."
findOtherInstance: "Find another server"
apps: "Apps"
sendModMail: "Send Moderation Notice"
_sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing\

View File

@ -53,6 +53,7 @@ import * as ep___admin_resetPassword from "./endpoints/admin/reset-password.js";
import * as ep___admin_resolveAbuseUserReport from "./endpoints/admin/resolve-abuse-user-report.js";
import * as ep___admin_search_indexAll from "./endpoints/admin/search/index-all.js";
import * as ep___admin_sendEmail from "./endpoints/admin/send-email.js";
import * as ep___admin_sendModMail from "./endpoints/admin/send-mod-mail.js";
import * as ep___admin_serverInfo from "./endpoints/admin/server-info.js";
import * as ep___admin_showModerationLogs from "./endpoints/admin/show-moderation-logs.js";
import * as ep___admin_showUser from "./endpoints/admin/show-user.js";
@ -403,6 +404,7 @@ const eps = [
["admin/resolve-abuse-user-report", ep___admin_resolveAbuseUserReport],
["admin/search/index-all", ep___admin_search_indexAll],
["admin/send-email", ep___admin_sendEmail],
["admin/send-mod-mail", ep___admin_sendModMail],
["admin/server-info", ep___admin_serverInfo],
["admin/show-moderation-logs", ep___admin_showModerationLogs],
["admin/show-user", ep___admin_showUser],

View File

@ -0,0 +1,68 @@
import * as sanitizeHtml from "sanitize-html";
import define from "../../define.js";
import { Users, UserProfiles } from "@/models/index.js";
import { ApiError } from "../../error.js";
import { sendEmail } from "@/services/send-email.js";
import { createNotification } from "@/services/create-notification.js";
export const meta = {
tags: ["users"],
requireCredential: true,
requireModerator: true,
description: "Send a mod mail.",
errors: {
noSuchUser: {
message: "No such user.",
code: "NO_SUCH_USER",
id: "1acefcb5-0959-43fd-9685-b48305736cb5",
},
noEmail: {
message: "No email for user.",
code: "NO_EMAIL",
id: "ac9d2d22-ef73-11ed-a05b-0242ac120003",
},
},
} as const;
export const paramDef = {
type: "object",
properties: {
userId: { type: "string", format: "misskey:id" },
comment: { type: "string", minLength: 1, maxLength: 2048 },
},
required: ["userId", "comment"],
} as const;
export default define(meta, paramDef, async (ps) => {
const [user, profile] = await Promise.all([
Users.findOneBy({ id: ps.userId }),
UserProfiles.findOneBy({ userId: ps.userId }),
]);
if (user == null || profile == null) {
throw new ApiError(meta.errors.noSuchUser);
}
createNotification(user.id, "app", {
customBody: ps.comment,
customHeader: "Moderation Notice",
customIcon: "/static-assets/badges/info.png",
});
setImmediate(async () => {
const email = profile.email;
if (email == null) {
throw new ApiError(meta.errors.noEmail);
}
sendEmail(
email,
"Moderation notice",
sanitizeHtml(ps.comment),
sanitizeHtml(ps.comment),
);
});
});

View File

@ -218,6 +218,12 @@
>{{ i18n.ts.deleteAccount }}</FormButton
>
</div>
<MkButton
v-if="user.host == null && iAmModerator"
inline
@click="sendModMail"
>{{ i18n.ts.sendModMail }}</MkButton
>
<FormTextarea
v-model="moderationNote"
manual-save
@ -486,6 +492,17 @@ async function toggleModerator(v) {
await refreshUser();
}
async function sendModMail() {
const { canceled, result } = await os.inputParagraph({
title: "Mod mail",
});
if (canceled) return;
await os.apiWithDialog("admin/send-mod-mail", {
userId: user.id,
text: result,
});
};
async function deleteAllFiles() {
const confirm = await os.confirm({
type: "warning",