mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: complete RBAC implementation lost during merge
Several RBAC features from feat/rbac-permissions were silently lost during the merge into main. This restores and completes them: - Add permissions and teamName to login/session API responses - Export Permission and Role types from shared package - Filter settings tabs by user permissions in frontend - Extend useAuth hook with role, permissions, and hasPermission - Restrict teams listing to admin only - Add admin override for API keys, files, and pipelines listing - Add ownership scoping to file access, download, and delete routes - Register userFileRoutes in integration test server - Mock auth import in unit permissions test to avoid SQLite lock
This commit is contained in:
@@ -11,7 +11,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
import { db, schema } from "../db/index.js";
|
||||
import { requirePermission } from "../permissions.js";
|
||||
import { requireAdmin, requireAuth } from "../plugins/auth.js";
|
||||
|
||||
function validateTeamName(name: unknown): string | null {
|
||||
if (typeof name !== "string") return "Team name is required";
|
||||
@@ -22,9 +22,9 @@ function validateTeamName(name: unknown): string | null {
|
||||
}
|
||||
|
||||
export async function teamsRoutes(app: FastifyInstance): Promise<void> {
|
||||
// GET /api/v1/teams — List all teams with member count
|
||||
// GET /api/v1/teams — List all teams with member count (admin only)
|
||||
app.get("/api/v1/teams", async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
const user = requirePermission("teams:manage")(request, reply);
|
||||
const user = requireAdmin(request, reply);
|
||||
if (!user) return;
|
||||
|
||||
const teams = db
|
||||
@@ -47,7 +47,7 @@ export async function teamsRoutes(app: FastifyInstance): Promise<void> {
|
||||
|
||||
// POST /api/v1/teams — Create team (admin only)
|
||||
app.post("/api/v1/teams", async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
const admin = requirePermission("teams:manage")(request, reply);
|
||||
const admin = requireAdmin(request, reply);
|
||||
if (!admin) return;
|
||||
|
||||
const body = request.body as { name?: string } | null;
|
||||
@@ -81,7 +81,7 @@ export async function teamsRoutes(app: FastifyInstance): Promise<void> {
|
||||
app.put(
|
||||
"/api/v1/teams/:id",
|
||||
async (request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply) => {
|
||||
const admin = requirePermission("teams:manage")(request, reply);
|
||||
const admin = requireAdmin(request, reply);
|
||||
if (!admin) return;
|
||||
|
||||
const { id } = request.params;
|
||||
@@ -122,7 +122,7 @@ export async function teamsRoutes(app: FastifyInstance): Promise<void> {
|
||||
app.delete(
|
||||
"/api/v1/teams/:id",
|
||||
async (request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply) => {
|
||||
const admin = requirePermission("teams:manage")(request, reply);
|
||||
const admin = requireAdmin(request, reply);
|
||||
if (!admin) return;
|
||||
|
||||
const { id } = request.params;
|
||||
|
||||
Reference in New Issue
Block a user