refactor(scripts): remove admin role checks from plugin API endpoints
- Eliminated admin role checks from the create, install, and delete plugin API endpoints to simplify access control. - Updated the ScriptsPage component to remove unnecessary user role checks, streamlining the installation process for all users. - Improved UI by consolidating the zip installation button, enhancing user experience during plugin management.
This commit is contained in:
@@ -466,7 +466,6 @@ export default function scriptsPluginFactory(registry) {
|
|||||||
|
|
||||||
fastify.post(
|
fastify.post(
|
||||||
"/plugins/create",
|
"/plugins/create",
|
||||||
{ onRequest: [fastify.requireAdmin] },
|
|
||||||
async (req, reply) => {
|
async (req, reply) => {
|
||||||
const body = /** @type {{ id?: string, content?: string, description?: string }} */ (
|
const body = /** @type {{ id?: string, content?: string, description?: string }} */ (
|
||||||
req.body ?? {}
|
req.body ?? {}
|
||||||
@@ -498,7 +497,6 @@ export default function scriptsPluginFactory(registry) {
|
|||||||
|
|
||||||
fastify.post(
|
fastify.post(
|
||||||
"/plugins/install",
|
"/plugins/install",
|
||||||
{ onRequest: [fastify.requireAdmin] },
|
|
||||||
async (req, reply) => {
|
async (req, reply) => {
|
||||||
const body = /** @type {{
|
const body = /** @type {{
|
||||||
source?: string,
|
source?: string,
|
||||||
@@ -573,7 +571,6 @@ export default function scriptsPluginFactory(registry) {
|
|||||||
|
|
||||||
fastify.delete(
|
fastify.delete(
|
||||||
"/plugins/:id",
|
"/plugins/:id",
|
||||||
{ onRequest: [fastify.requireAdmin] },
|
|
||||||
async (req, reply) => {
|
async (req, reply) => {
|
||||||
const { id } = /** @type {{ id: string }} */ (req.params);
|
const { id } = /** @type {{ id: string }} */ (req.params);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
useDuplicatePlugin,
|
useDuplicatePlugin,
|
||||||
useForkScript,
|
useForkScript,
|
||||||
useInstallPlugin,
|
useInstallPlugin,
|
||||||
useMe,
|
|
||||||
useScripts,
|
useScripts,
|
||||||
} from "../api/hooks.js";
|
} from "../api/hooks.js";
|
||||||
import { ConfirmDialog } from "../components/ConfirmDialog.jsx";
|
import { ConfirmDialog } from "../components/ConfirmDialog.jsx";
|
||||||
@@ -46,8 +45,6 @@ export function ScriptsPage() {
|
|||||||
const fork = useForkScript();
|
const fork = useForkScript();
|
||||||
const duplicate = useDuplicatePlugin();
|
const duplicate = useDuplicatePlugin();
|
||||||
const install = useInstallPlugin();
|
const install = useInstallPlugin();
|
||||||
const me = useMe();
|
|
||||||
const isAdmin = me.data?.user?.role === "admin";
|
|
||||||
const { notify } = useNotifications();
|
const { notify } = useNotifications();
|
||||||
const [pendingZip, setPendingZip] = useState(null);
|
const [pendingZip, setPendingZip] = useState(null);
|
||||||
const [zipEncoding, setZipEncoding] = useState(false);
|
const [zipEncoding, setZipEncoding] = useState(false);
|
||||||
@@ -144,23 +141,21 @@ export function ScriptsPage() {
|
|||||||
>
|
>
|
||||||
Install example
|
Install example
|
||||||
</button>
|
</button>
|
||||||
{isAdmin ? (
|
<label className={`btn btn-outline btn-sm ${zipBusy ? "btn-disabled" : ""}`}>
|
||||||
<label className={`btn btn-outline btn-sm ${zipBusy ? "btn-disabled" : ""}`}>
|
{zipBusy ? (
|
||||||
{zipBusy ? (
|
<span className="loading loading-spinner loading-xs" />
|
||||||
<span className="loading loading-spinner loading-xs" />
|
) : (
|
||||||
) : (
|
<LuUpload className="size-4" />
|
||||||
<LuUpload className="size-4" />
|
)}
|
||||||
)}
|
Install from zip
|
||||||
Install from zip
|
<input
|
||||||
<input
|
type="file"
|
||||||
type="file"
|
accept=".zip,application/zip"
|
||||||
accept=".zip,application/zip"
|
className="hidden"
|
||||||
className="hidden"
|
disabled={zipBusy}
|
||||||
disabled={zipBusy}
|
onChange={onPickZip}
|
||||||
onChange={onPickZip}
|
/>
|
||||||
/>
|
</label>
|
||||||
</label>
|
|
||||||
) : null}
|
|
||||||
<Link to="/scripts/new" className="btn btn-primary btn-sm">
|
<Link to="/scripts/new" className="btn btn-primary btn-sm">
|
||||||
<LuPlus className="size-4" />
|
<LuPlus className="size-4" />
|
||||||
Add plugin
|
Add plugin
|
||||||
|
|||||||
Reference in New Issue
Block a user