diff --git a/backend/src/db.ts b/backend/src/db.ts index d5b7770..2c0ae71 100644 --- a/backend/src/db.ts +++ b/backend/src/db.ts @@ -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 } diff --git a/backend/src/routes/chats.ts b/backend/src/routes/chats.ts index b031eb0..0ff978d 100644 --- a/backend/src/routes/chats.ts +++ b/backend/src/routes/chats.ts @@ -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' }); } diff --git a/frontend/src/components/ChatHeader.tsx b/frontend/src/components/ChatHeader.tsx index ff5bd62..6c7f1d6 100644 --- a/frontend/src/components/ChatHeader.tsx +++ b/frontend/src/components/ChatHeader.tsx @@ -42,7 +42,7 @@ export default function ChatHeader({ chat, onBack, onRefresh, onShowInfo }: Prop subtitle = `${chat.memberCount} участников`; } - const isOwnerOrAdmin = chat.myRole === 'owner' || chat.myRole === 'admin' || user?.isAdmin; + const isOwnerOrAdmin = chat.myRole === 'owner' || chat.myRole === 'admin'; async function handleLeave() { if (!confirm('Выйти из чата?')) return; diff --git a/frontend/src/components/ChatInfoPanel.tsx b/frontend/src/components/ChatInfoPanel.tsx index cf2a7ca..b2e37b3 100644 --- a/frontend/src/components/ChatInfoPanel.tsx +++ b/frontend/src/components/ChatInfoPanel.tsx @@ -23,7 +23,7 @@ export default function ChatInfoPanel({ chat, onClose, onRefresh }: Props) { const [uploadingAvatar, setUploadingAvatar] = useState(false); const fileRef = useRef(null); - const isOwnerOrAdmin = chat.myRole === 'owner' || chat.myRole === 'admin' || me?.isAdmin; + const isOwnerOrAdmin = chat.myRole === 'owner' || chat.myRole === 'admin'; useEffect(() => { if (addMode) { diff --git a/frontend/src/pages/MainLayout.tsx b/frontend/src/pages/MainLayout.tsx index 9583a79..65ea454 100644 --- a/frontend/src/pages/MainLayout.tsx +++ b/frontend/src/pages/MainLayout.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import { Search, Edit, Settings, Shield, Wifi, WifiOff, MessageCircle } from 'lucide-react'; +import { Search, Edit, Settings, Wifi, WifiOff, MessageCircle } from 'lucide-react'; import { useStore } from '../store'; import { wsClient } from '../api/ws'; import api from '../api/client'; @@ -9,7 +9,6 @@ import MessageList from '../components/MessageList'; import ChatHeader from '../components/ChatHeader'; import ChatInfoPanel from '../components/ChatInfoPanel'; import NewChatModal from '../components/NewChatModal'; -import AdminPanel from '../components/admin/AdminPanel'; import ProfileModal from '../components/ProfileModal'; import { usePushNotifications } from '../hooks/usePushNotifications'; import { Chat } from '../types'; @@ -19,7 +18,6 @@ export default function MainLayout() { const [search, setSearch] = useState(''); const [searchUsers, setSearchUsers] = useState([]); const [showNew, setShowNew] = useState(false); - const [showAdmin, setShowAdmin] = useState(false); const [showInfo, setShowInfo] = useState(false); const [showProfile, setShowProfile] = useState(false); const [mobileChatOpen, setMobileChatOpen] = useState(false); @@ -132,7 +130,7 @@ export default function MainLayout() { if (!activeChat) return false; if (activeChat.type === 'private') return true; if (activeChat.type === 'group') return activeChat.canSendMessages !== false; - if (activeChat.type === 'channel') return activeChat.myRole === 'owner' || activeChat.myRole === 'admin' || !!user?.isAdmin; + if (activeChat.type === 'channel') return activeChat.myRole === 'owner' || activeChat.myRole === 'admin'; return false; })(); @@ -155,12 +153,6 @@ export default function MainLayout() {
- {user?.isAdmin && ( - - )}
);