Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Validate Prisma schema
run: pnpm exec prisma validate

- name: Run lint
run: pnpm lint

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Add the fields required by Better Auth's admin plugin.
ALTER TABLE "User"
ADD COLUMN "banned" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "banReason" TEXT,
ADD COLUMN "banExpires" TIMESTAMP(3);

ALTER TABLE "Session"
ADD COLUMN "impersonatedBy" TEXT;
1 change: 1 addition & 0 deletions prisma/schema/session.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ model Session {
expiresAt DateTime
ipAddress String?
userAgent String?
impersonatedBy String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

createdAt DateTime @default(now())
Expand Down
3 changes: 3 additions & 0 deletions prisma/schema/user.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ model User {
emailVerified Boolean @default(false)
image String?
role UserRole?
banned Boolean @default(false)
banReason String?
banExpires DateTime?
pushSubscription String?
accounts Account[]
sessions Session[]
Expand Down
127 changes: 0 additions & 127 deletions src/app/api/impersonate/route.ts

This file was deleted.

67 changes: 0 additions & 67 deletions src/app/api/impersonate/status/route.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/app/api/users/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export async function GET(request: NextRequest) {
name: true,
email: true,
role: true,
banned: true,
banReason: true,
banExpires: true,
createdAt: true,
updatedAt: true,
},
Expand Down
53 changes: 53 additions & 0 deletions src/app/users/BanUserDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { render, screen } from '@/test/test-utils';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import { BanUserDialog } from './BanUserDialog';

describe('BanUserDialog', () => {
const defaultProps = {
isOpen: true,
onOpenChange: vi.fn(),
userToBan: { name: 'Test User' },
onConfirm: vi.fn().mockResolvedValue(undefined),
isLoading: false,
};

it('renders shadcn inputs and user details', () => {
render(<BanUserDialog {...defaultProps} />);

expect(
screen.getByRole('heading', { name: 'Ban User' })
).toBeInTheDocument();
expect(screen.getByLabelText('Reason')).toBeInTheDocument();
expect(screen.getByLabelText('Ban ends')).toHaveAttribute(
'type',
'datetime-local'
);
});

it('requires a reason', async () => {
const user = userEvent.setup();
render(<BanUserDialog {...defaultProps} />);

await user.click(screen.getByRole('button', { name: 'Ban User' }));

expect(defaultProps.onConfirm).not.toHaveBeenCalled();
expect(screen.getByRole('alert')).toHaveTextContent(
'A reason is required.'
);
});

it('submits the reason and end time', async () => {
const user = userEvent.setup();
render(<BanUserDialog {...defaultProps} />);

await user.type(screen.getByLabelText('Reason'), 'Abuse of service');
await user.type(screen.getByLabelText('Ban ends'), '2030-01-01T12:00');
await user.click(screen.getByRole('button', { name: 'Ban User' }));

expect(defaultProps.onConfirm).toHaveBeenCalledWith({
banReason: 'Abuse of service',
banExpiresAt: '2030-01-01T12:00',
});
});
});
Loading
Loading