feat: polish custom widgets and workshop
This commit is contained in:
98 files changed
+9097
-1624
No files matched your search
@@ -38,8 +38,10 @@ https://<workshop-host>/api/oauth2-redirect
|
||||
Self-hosted Homarr origins do not need to be registered with GitHub. Keep `PB_ALLOWED_ORIGINS=*` (the default) so localhost and arbitrary self-hosted domains can open the central PocketBase OAuth popup. Set a restricted origin list only if it includes every Homarr origin that should use Workshop sign-in.
|
||||
|
||||
Set `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` in the repository-root `.env`. Set
|
||||
`WORKSHOP_PUBLIC_ORIGIN=https://<workshop-host>` so new-comment emails link to the public submission page. Configure the
|
||||
sender and SMTP transport in PocketBase. Comment email failures are logged and never reject a saved comment.
|
||||
`WORKSHOP_PUBLIC_ORIGIN=https://<workshop-host>` so notification emails link to the public Workshop. Configure the sender
|
||||
and SMTP transport in PocketBase. PocketBase emails the submission author about new comments, emails every current
|
||||
Workshop administrator about a new report, and emails the author after an administrator deletes their submission. Mail
|
||||
failures are logged and never reject a comment, report, or deletion.
|
||||
|
||||
Run the disposable service integration test from the repository root:
|
||||
|
||||
@@ -55,9 +57,10 @@ The Workshop does not maintain a second Custom Widget schema. Its frontend valid
|
||||
The validated `$schema` is also stored as `widgetSchema` for listing compatibility badges; it must match the downloaded
|
||||
manifest before Homarr enables installation.
|
||||
PocketBase API rules enforce submission and comment ownership, one vote/report per user and submission, and
|
||||
administrator-only moderation. Each new submission receives one real author-owned upvote. Reports remain public and are
|
||||
dismissed by changing their status. PocketBase cascade deletion removes related votes, comments, and reports when a
|
||||
submission is deleted. Authors and administrators can mark a submission outdated without making it un-installable.
|
||||
administrator-only moderation. Each new submission receives one real author-owned upvote. Reports are private to
|
||||
administrators and are dismissed by changing their status. PocketBase cascade deletion removes related votes, comments,
|
||||
and reports when a submission is deleted. Authors and administrators can mark a submission outdated without making it
|
||||
un-installable.
|
||||
|
||||
## Production docs preview
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Workshop report</title>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; background: #f4f4f4; font-family: Helvetica, Arial, sans-serif">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background: #f4f4f4">
|
||||
<tr>
|
||||
<td align="center" style="padding: 50px 20px">
|
||||
<table
|
||||
role="presentation"
|
||||
width="600"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
style="width: 600px; max-width: 100%; background: #ffffff; border: 1px solid #dc2626"
|
||||
>
|
||||
<tr>
|
||||
<td style="background: #991b1b; padding: 28px 36px; color: #ffffff">
|
||||
<div style="font-size: 12px; font-weight: bold; letter-spacing: 1px; text-transform: uppercase">
|
||||
Moderation alert
|
||||
</div>
|
||||
<div style="margin-top: 8px; font-size: 22px; font-weight: bold">A Workshop submission was reported</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 36px; color: #18181b; font-size: 15px; line-height: 1.65">
|
||||
<p style="margin: 0 0 18px">
|
||||
<strong>{{reporterName}}</strong> reported <a href="{{submissionUrl}}">{{submissionTitle}}</a>.
|
||||
</p>
|
||||
<p style="margin: 0 0 8px; font-size: 12px; font-weight: bold; text-transform: uppercase; color: #991b1b">
|
||||
{{category}}
|
||||
</p>
|
||||
<blockquote
|
||||
style="margin: 0 0 26px; padding: 16px 18px; border-left: 3px solid #dc2626; background: #fef2f2"
|
||||
>
|
||||
{{explanation}}
|
||||
</blockquote>
|
||||
<a
|
||||
href="{{adminUrl}}"
|
||||
style="display: inline-block; padding: 12px 20px; background: #991b1b; color: #ffffff; font-weight: bold; text-decoration: none"
|
||||
>
|
||||
REVIEW REPORT
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,44 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Workshop submission removed</title>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; background: #f4f4f4; font-family: Helvetica, Arial, sans-serif">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background: #f4f4f4">
|
||||
<tr>
|
||||
<td align="center" style="padding: 50px 20px">
|
||||
<table
|
||||
role="presentation"
|
||||
width="600"
|
||||
cellpadding="0"
|
||||
cellspacing="0"
|
||||
style="width: 600px; max-width: 100%; background: #ffffff; border: 1px solid #27272a"
|
||||
>
|
||||
<tr>
|
||||
<td style="background: #18181b; padding: 28px 36px; color: #ffffff">
|
||||
<div style="font-size: 12px; font-weight: bold; letter-spacing: 1px; text-transform: uppercase">
|
||||
Homarr Workshop
|
||||
</div>
|
||||
<div style="margin-top: 8px; font-size: 22px; font-weight: bold">Your submission was removed</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 36px; color: #18181b; font-size: 15px; line-height: 1.65">
|
||||
<p style="margin: 0 0 18px">A Workshop administrator removed your submission:</p>
|
||||
<div style="margin: 0 0 24px; padding: 16px 18px; border-left: 3px solid #dc2626; background: #fef2f2">
|
||||
<strong>{{submissionTitle}}</strong>
|
||||
</div>
|
||||
<p style="margin: 0">
|
||||
The submission is no longer available in Workshop. Widgets or CSS already installed by users are not
|
||||
removed from their Homarr instances.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -22,6 +22,24 @@ const escapeHtml = (value) =>
|
||||
.replaceAll('"', """)
|
||||
.replaceAll("'", "'");
|
||||
|
||||
const emailTemplate = (filename) => {
|
||||
const hooksPath = $os.getenv("WORKSHOP_PB_HOOKS_DIR") || $filepath.dirname(__filepath);
|
||||
return $os.readFile($filepath.join(hooksPath, filename));
|
||||
};
|
||||
|
||||
const sendEmail = (app, recipientEmail, subject, text, html) => {
|
||||
const sender = app.settings().meta;
|
||||
app.newMailClient().send(
|
||||
new MailerMessage({
|
||||
from: { address: sender.senderAddress, name: sender.senderName },
|
||||
to: [{ address: recipientEmail }],
|
||||
subject,
|
||||
text,
|
||||
html,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
onRecordAfterCreateSuccess((event) => {
|
||||
try {
|
||||
const submission = event.app.findRecordById("submissions", event.record.get("submission"));
|
||||
@@ -39,25 +57,100 @@ onRecordAfterCreateSuccess((event) => {
|
||||
const submissionTitle = submission.getString("title");
|
||||
const rawExcerpt = event.record.getString("content").slice(0, 280);
|
||||
const submissionUrl = `${publicOrigin}/workshop/${submission.id}/`;
|
||||
const sender = event.app.settings().meta;
|
||||
const templatePath = $os.getenv("WORKSHOP_PB_HOOKS_DIR") || $filepath.dirname(__filepath);
|
||||
const template = $os
|
||||
.readFile($filepath.join(templatePath, "comment-email.html"))
|
||||
const template = emailTemplate("comment-email.html")
|
||||
.replaceAll("{{commenterName}}", escapeHtml(commenterName))
|
||||
.replaceAll("{{submissionTitle}}", escapeHtml(submissionTitle))
|
||||
.replaceAll("{{commentExcerpt}}", escapeHtml(rawExcerpt))
|
||||
.replaceAll("{{submissionUrl}}", escapeHtml(submissionUrl));
|
||||
|
||||
const message = new MailerMessage({
|
||||
from: { address: sender.senderAddress, name: sender.senderName },
|
||||
to: [{ address: recipientEmail }],
|
||||
subject: `${commenterName} commented on ${submissionTitle}`,
|
||||
text: `${commenterName} commented on “${submissionTitle}”:\n\n${rawExcerpt}\n\n${submissionUrl}`,
|
||||
html: template,
|
||||
});
|
||||
event.app.newMailClient().send(message);
|
||||
sendEmail(
|
||||
event.app,
|
||||
recipientEmail,
|
||||
`${commenterName} commented on ${submissionTitle}`,
|
||||
`${commenterName} commented on “${submissionTitle}”:\n\n${rawExcerpt}\n\n${submissionUrl}`,
|
||||
template,
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(`Workshop comment email failed for ${event.record.id}: ${error}`);
|
||||
}
|
||||
event.next();
|
||||
}, "comments");
|
||||
|
||||
onRecordAfterCreateSuccess((event) => {
|
||||
try {
|
||||
const submission = event.app.findRecordById("submissions", event.record.get("submission"));
|
||||
const reporter = event.app.findRecordById("users", event.record.get("reporter"));
|
||||
const publicOrigin = $os.getenv("WORKSHOP_PUBLIC_ORIGIN").replace(/\/$/, "");
|
||||
const admins = event.app
|
||||
.findAllRecords("users")
|
||||
.filter((user) => user.getBool("isAdmin") && Boolean(user.email()));
|
||||
|
||||
if (!publicOrigin || admins.length === 0) {
|
||||
event.next();
|
||||
return;
|
||||
}
|
||||
|
||||
const reporterName = reporter.getString("displayName") || "A community member";
|
||||
const submissionTitle = submission.getString("title");
|
||||
const category = event.record.getString("category");
|
||||
const explanation = event.record.getString("explanation");
|
||||
const adminUrl = `${publicOrigin}/workshop/admin`;
|
||||
const submissionUrl = `${publicOrigin}/workshop/${submission.id}/`;
|
||||
const template = emailTemplate("report-email.html")
|
||||
.replaceAll("{{reporterName}}", escapeHtml(reporterName))
|
||||
.replaceAll("{{submissionTitle}}", escapeHtml(submissionTitle))
|
||||
.replaceAll("{{category}}", escapeHtml(category))
|
||||
.replaceAll("{{explanation}}", escapeHtml(explanation))
|
||||
.replaceAll("{{adminUrl}}", escapeHtml(adminUrl))
|
||||
.replaceAll("{{submissionUrl}}", escapeHtml(submissionUrl));
|
||||
|
||||
for (const admin of admins) {
|
||||
try {
|
||||
sendEmail(
|
||||
event.app,
|
||||
admin.email(),
|
||||
`Workshop report: ${submissionTitle}`,
|
||||
`${reporterName} reported “${submissionTitle}” for ${category}.\n\n${explanation}\n\nReview: ${adminUrl}`,
|
||||
template,
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(`Workshop report email failed for admin ${admin.id}: ${error}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Workshop report email failed for ${event.record.id}: ${error}`);
|
||||
}
|
||||
event.next();
|
||||
}, "reports");
|
||||
|
||||
onRecordDeleteRequest((event) => {
|
||||
const submissionId = event.record.id;
|
||||
const submissionTitle = event.record.getString("title");
|
||||
const authorId = event.record.get("author");
|
||||
const actor = event.requestInfo().auth;
|
||||
const notifyAuthor = actor && actor.getBool("isAdmin") && actor.id !== authorId;
|
||||
|
||||
event.next();
|
||||
|
||||
if (!notifyAuthor) return;
|
||||
|
||||
try {
|
||||
const author = event.app.findRecordById("users", authorId);
|
||||
const recipientEmail = author.email();
|
||||
if (!recipientEmail) return;
|
||||
|
||||
const publicOrigin = $os.getenv("WORKSHOP_PUBLIC_ORIGIN").replace(/\/$/, "");
|
||||
const workshopUrl = publicOrigin ? `${publicOrigin}/workshop/` : "";
|
||||
const template = emailTemplate("submission-deleted-email.html").replaceAll(
|
||||
"{{submissionTitle}}",
|
||||
escapeHtml(submissionTitle),
|
||||
);
|
||||
const text = `A Workshop administrator removed your submission “${submissionTitle}”.${
|
||||
workshopUrl ? `\n\nReturn to Workshop: ${workshopUrl}` : ""
|
||||
}`;
|
||||
|
||||
sendEmail(event.app, recipientEmail, `Your Workshop submission was removed`, text, template);
|
||||
} catch (error) {
|
||||
console.log(`Workshop deletion email failed for ${submissionId}: ${error}`);
|
||||
}
|
||||
}, "submissions");
|
||||
@@ -181,7 +181,7 @@ migrate(
|
||||
viewRule: "",
|
||||
viewQuery: `
|
||||
SELECT s.id, s.type, s.title, s.description, s.widgetSchema, s.screenshots, s.author,
|
||||
u.displayName AS authorName, u.avatarUrl AS authorAvatarUrl,
|
||||
u.displayName AS authorName, u.avatar AS authorAvatar, u.avatarUrl AS authorAvatarUrl,
|
||||
u.githubUsername AS authorGithubUsername, u.githubProfileUrl AS authorGithubProfileUrl,
|
||||
s.revision, s.changelog, s.outdated, s.created, s.updated,
|
||||
COALESCE((SELECT COUNT(*) FROM votes v WHERE v.submission = s.id AND v.value = 1), 0) AS upvotes,
|
||||
|
||||
@@ -243,10 +243,10 @@ const report = await request("/api/collections/reports/records", {
|
||||
status: "open",
|
||||
}),
|
||||
});
|
||||
const ownReport = await request(`/api/collections/reports/records/${report.id}`, { headers: visitorSession.headers });
|
||||
if (ownReport.reporter !== visitor.id) throw new Error("Reporters must be able to view their own report");
|
||||
await expectStatus(`/api/collections/reports/records/${report.id}`, { headers: visitorSession.headers }, 404);
|
||||
await expectStatus("/api/collections/reports/records", { headers: visitorSession.headers }, 200);
|
||||
const publicReports = await request("/api/collections/reports/records", { headers: visitorSession.headers });
|
||||
if (publicReports.items.length !== 1) throw new Error("Report details must remain publicly visible");
|
||||
if (publicReports.items.length !== 0) throw new Error("Report details must remain private to Workshop administrators");
|
||||
await expectStatus(
|
||||
`/api/collections/reports/records/${report.id}`,
|
||||
{ method: "DELETE", headers: visitorSession.headers },
|
||||
|
||||
Reference in new issue
Block a user