feat: remove global admin, open registration, clear DB seed
- All users are equal — no is_admin superuser - Removed AdminPanel, Shield button from sidebar - isOwnerOrAdmin checks only by chat role (owner/admin) - Removed auto-seed of admin user on startup - DB already cleared on server Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Pool } from 'pg';
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
export const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
||||
|
||||
@@ -94,14 +93,5 @@ export async function initDB() {
|
||||
ALTER TABLE chat_members ADD COLUMN IF NOT EXISTS is_pinned BOOLEAN DEFAULT FALSE;
|
||||
`);
|
||||
|
||||
// Seed admin if no users
|
||||
const { rows } = await pool.query('SELECT COUNT(*) FROM users');
|
||||
if (parseInt(rows[0].count) === 0) {
|
||||
const hash = await bcrypt.hash('admin123', 10);
|
||||
await pool.query(
|
||||
`INSERT INTO users (username, display_name, password_hash, is_admin) VALUES ($1,$2,$3,TRUE)`,
|
||||
['admin', 'Администратор', hash]
|
||||
);
|
||||
console.log('Created admin user: admin / admin123');
|
||||
}
|
||||
// No auto-seed — users register themselves
|
||||
}
|
||||
|
||||
@@ -339,13 +339,13 @@ export default async function chatRoutes(app: FastifyInstance) {
|
||||
|
||||
// Delete chat (owner only)
|
||||
app.delete('/:id', async (req, reply) => {
|
||||
const { id: userId, isAdmin } = req.user as { id: string; isAdmin: boolean };
|
||||
const { id: userId } = req.user as { id: string };
|
||||
const { id } = req.params as { id: string };
|
||||
|
||||
const { rows: [member] } = await pool.query(
|
||||
'SELECT role FROM chat_members WHERE chat_id = $1 AND user_id = $2', [id, userId]
|
||||
);
|
||||
if (!member || (member.role !== 'owner' && !isAdmin)) {
|
||||
if (!member || member.role !== 'owner') {
|
||||
return reply.status(403).send({ error: 'No permission' });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user