Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
050010d
1
Parent(s): 1f006fc
feat: admin improvements - merged tabs, plan column, admin bypass, role labels
Browse files
backend/app/api/admin.py
CHANGED
|
@@ -237,6 +237,8 @@ class AdminUserResponse(BaseModel):
|
|
| 237 |
# Tenant info
|
| 238 |
tenant_name: Optional[str] = None
|
| 239 |
tenant_id: Optional[UUID] = None
|
|
|
|
|
|
|
| 240 |
# Partner info (if they are a partner)
|
| 241 |
partner_status: Optional[str] = None
|
| 242 |
referral_code: Optional[str] = None
|
|
@@ -278,6 +280,8 @@ async def list_all_users(
|
|
| 278 |
created_at=user.created_at,
|
| 279 |
tenant_name=tenant.name if tenant else "No Tenant",
|
| 280 |
tenant_id=tenant.id if tenant else None,
|
|
|
|
|
|
|
| 281 |
partner_status=partner.status if partner else None,
|
| 282 |
referral_code=partner.referral_code if partner else None
|
| 283 |
))
|
|
|
|
| 237 |
# Tenant info
|
| 238 |
tenant_name: Optional[str] = None
|
| 239 |
tenant_id: Optional[UUID] = None
|
| 240 |
+
subscription_plan: Optional[str] = None
|
| 241 |
+
subscription_status: Optional[str] = None
|
| 242 |
# Partner info (if they are a partner)
|
| 243 |
partner_status: Optional[str] = None
|
| 244 |
referral_code: Optional[str] = None
|
|
|
|
| 280 |
created_at=user.created_at,
|
| 281 |
tenant_name=tenant.name if tenant else "No Tenant",
|
| 282 |
tenant_id=tenant.id if tenant else None,
|
| 283 |
+
subscription_plan=tenant.subscription_plan if tenant else None,
|
| 284 |
+
subscription_status=tenant.subscription_status if tenant else None,
|
| 285 |
partner_status=partner.status if partner else None,
|
| 286 |
referral_code=partner.referral_code if partner else None
|
| 287 |
))
|
backend/app/services/subscription_manager.py
CHANGED
|
@@ -39,11 +39,15 @@ class SubscriptionManager:
|
|
| 39 |
"enterprise": None # Безлимит
|
| 40 |
}
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
@classmethod
|
| 43 |
async def check_can_create_conversation(
|
| 44 |
cls,
|
| 45 |
tenant: Tenant,
|
| 46 |
-
session: AsyncSession
|
|
|
|
| 47 |
) -> Tuple[bool, Optional[str]]:
|
| 48 |
"""
|
| 49 |
Проверить может ли tenant создать новый диалог.
|
|
@@ -52,6 +56,10 @@ class SubscriptionManager:
|
|
| 52 |
(can_create: bool, reason: Optional[str])
|
| 53 |
"""
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# 1. Проверка истечения подписки
|
| 56 |
if tenant.subscription_end:
|
| 57 |
if datetime.utcnow() > tenant.subscription_end:
|
|
@@ -77,7 +85,7 @@ class SubscriptionManager:
|
|
| 77 |
plan = tenant.subscription_plan.lower()
|
| 78 |
limit = cls.PLAN_LIMITS.get(plan)
|
| 79 |
|
| 80 |
-
if limit is not None: # Если есть лимит (не
|
| 81 |
if tenant.leads_this_month >= limit:
|
| 82 |
return False, f"Достигнут лимит диалогов ({limit}) для плана {plan.upper()}. Улучшите план для продолжения."
|
| 83 |
|
|
|
|
| 39 |
"enterprise": None # Безлимит
|
| 40 |
}
|
| 41 |
|
| 42 |
+
# Admin email that bypasses all limits
|
| 43 |
+
ADMIN_EMAIL = "axeroni.s2@gmail.com"
|
| 44 |
+
|
| 45 |
@classmethod
|
| 46 |
async def check_can_create_conversation(
|
| 47 |
cls,
|
| 48 |
tenant: Tenant,
|
| 49 |
+
session: AsyncSession,
|
| 50 |
+
user_email: Optional[str] = None
|
| 51 |
) -> Tuple[bool, Optional[str]]:
|
| 52 |
"""
|
| 53 |
Проверить может ли tenant создать новый диалог.
|
|
|
|
| 56 |
(can_create: bool, reason: Optional[str])
|
| 57 |
"""
|
| 58 |
|
| 59 |
+
# ADMIN BYPASS - admin gets unlimited access
|
| 60 |
+
if user_email and user_email.lower() == cls.ADMIN_EMAIL.lower():
|
| 61 |
+
return True, None
|
| 62 |
+
|
| 63 |
# 1. Проверка истечения подписки
|
| 64 |
if tenant.subscription_end:
|
| 65 |
if datetime.utcnow() > tenant.subscription_end:
|
|
|
|
| 85 |
plan = tenant.subscription_plan.lower()
|
| 86 |
limit = cls.PLAN_LIMITS.get(plan)
|
| 87 |
|
| 88 |
+
if limit is not None: # Если есть лимит (не enterprise)
|
| 89 |
if tenant.leads_this_month >= limit:
|
| 90 |
return False, f"Достигнут лимит диалогов ({limit}) для плана {plan.upper()}. Улучшите план для продолжения."
|
| 91 |
|
frontend/app/admin/page.tsx
CHANGED
|
@@ -9,9 +9,7 @@ import { Shield, ShieldAlert, LayoutDashboard, Users, UserCog, Megaphone, Settin
|
|
| 9 |
import AnalyticsTab from '@/components/admin/AnalyticsTab'
|
| 10 |
import UsersTab from '@/components/admin/UsersTab'
|
| 11 |
import PartnersTab from '@/components/admin/PartnersTab'
|
| 12 |
-
import TenantsTab from '@/components/admin/TenantsTab'
|
| 13 |
import AnnouncementsTab from '@/components/admin/AnnouncementsTab'
|
| 14 |
-
import LandingTab from '@/components/admin/LandingTab'
|
| 15 |
|
| 16 |
export default function AdminPanelPage() {
|
| 17 |
const { user } = useAuth()
|
|
@@ -40,11 +38,9 @@ export default function AdminPanelPage() {
|
|
| 40 |
|
| 41 |
const tabs = [
|
| 42 |
{ id: 'analytics', label: 'Аналитика', icon: BarChart3 },
|
| 43 |
-
{ id: 'tenants', label: 'Клиенты', icon: LayoutDashboard },
|
| 44 |
{ id: 'users', label: 'Пользователи', icon: Users },
|
| 45 |
{ id: 'partners', label: 'Партнеры', icon: UserCog },
|
| 46 |
{ id: 'announcements', label: 'Объявления', icon: Megaphone },
|
| 47 |
-
{ id: 'landing', label: 'Лендинг', icon: Settings },
|
| 48 |
]
|
| 49 |
|
| 50 |
return (
|
|
@@ -84,11 +80,9 @@ export default function AdminPanelPage() {
|
|
| 84 |
|
| 85 |
<div className="max-w-[1400px] mx-auto px-6 py-8">
|
| 86 |
{activeTab === 'analytics' && <AnalyticsTab />}
|
| 87 |
-
{activeTab === 'tenants' && <TenantsTab />}
|
| 88 |
{activeTab === 'users' && <UsersTab />}
|
| 89 |
{activeTab === 'partners' && <PartnersTab />}
|
| 90 |
{activeTab === 'announcements' && <AnnouncementsTab />}
|
| 91 |
-
{activeTab === 'landing' && <LandingTab />}
|
| 92 |
</div>
|
| 93 |
</div>
|
| 94 |
)
|
|
|
|
| 9 |
import AnalyticsTab from '@/components/admin/AnalyticsTab'
|
| 10 |
import UsersTab from '@/components/admin/UsersTab'
|
| 11 |
import PartnersTab from '@/components/admin/PartnersTab'
|
|
|
|
| 12 |
import AnnouncementsTab from '@/components/admin/AnnouncementsTab'
|
|
|
|
| 13 |
|
| 14 |
export default function AdminPanelPage() {
|
| 15 |
const { user } = useAuth()
|
|
|
|
| 38 |
|
| 39 |
const tabs = [
|
| 40 |
{ id: 'analytics', label: 'Аналитика', icon: BarChart3 },
|
|
|
|
| 41 |
{ id: 'users', label: 'Пользователи', icon: Users },
|
| 42 |
{ id: 'partners', label: 'Партнеры', icon: UserCog },
|
| 43 |
{ id: 'announcements', label: 'Объявления', icon: Megaphone },
|
|
|
|
| 44 |
]
|
| 45 |
|
| 46 |
return (
|
|
|
|
| 80 |
|
| 81 |
<div className="max-w-[1400px] mx-auto px-6 py-8">
|
| 82 |
{activeTab === 'analytics' && <AnalyticsTab />}
|
|
|
|
| 83 |
{activeTab === 'users' && <UsersTab />}
|
| 84 |
{activeTab === 'partners' && <PartnersTab />}
|
| 85 |
{activeTab === 'announcements' && <AnnouncementsTab />}
|
|
|
|
| 86 |
</div>
|
| 87 |
</div>
|
| 88 |
)
|
frontend/components/admin/UsersTab.tsx
CHANGED
|
@@ -14,6 +14,9 @@ interface User {
|
|
| 14 |
role: string
|
| 15 |
created_at: string
|
| 16 |
tenant_name: string
|
|
|
|
|
|
|
|
|
|
| 17 |
partner_status: string | null
|
| 18 |
referral_code: string | null
|
| 19 |
}
|
|
@@ -112,8 +115,9 @@ export default function UsersTab() {
|
|
| 112 |
<thead>
|
| 113 |
<tr className="border-b border-white/10">
|
| 114 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">ID</th>
|
| 115 |
-
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">
|
| 116 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Email</th>
|
|
|
|
| 117 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Роль</th>
|
| 118 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Статус</th>
|
| 119 |
<th className="px-6 py-4 text-right text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Действия</th>
|
|
@@ -126,28 +130,44 @@ export default function UsersTab() {
|
|
| 126 |
{index + 1}
|
| 127 |
</td>
|
| 128 |
<td className="px-6 py-4">
|
| 129 |
-
<div className="flex
|
| 130 |
-
{/* Avatar/Initial */}
|
| 131 |
-
{/* <div className="w-8 h-8 rounded-full bg-slate-800 flex items-center justify-center text-xs font-bold text-slate-400 border border-white/10">
|
| 132 |
-
{user.full_name?.[0] || user.email?.[0]?.toUpperCase()}
|
| 133 |
-
</div> */}
|
| 134 |
<span className="text-sm font-medium text-slate-300 group-hover:text-white transition-colors">
|
| 135 |
-
{user.
|
| 136 |
</span>
|
|
|
|
|
|
|
|
|
|
| 137 |
</div>
|
| 138 |
</td>
|
| 139 |
<td className="px-6 py-4 text-sm text-slate-400 group-hover:text-slate-300 transition-colors">
|
| 140 |
{user.email}
|
| 141 |
</td>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
<td className="px-6 py-4 text-sm text-slate-400">
|
| 143 |
-
{user.role === 'admin'
|
| 144 |
</td>
|
| 145 |
<td className="px-6 py-4">
|
| 146 |
<div className={`inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium border ${user.is_active
|
| 147 |
-
|
| 148 |
-
|
| 149 |
}`}>
|
| 150 |
-
{user.is_active ? '
|
| 151 |
</div>
|
| 152 |
</td>
|
| 153 |
<td className="px-6 py-4 text-right">
|
|
|
|
| 14 |
role: string
|
| 15 |
created_at: string
|
| 16 |
tenant_name: string
|
| 17 |
+
tenant_id?: string
|
| 18 |
+
subscription_plan?: string
|
| 19 |
+
subscription_status?: string
|
| 20 |
partner_status: string | null
|
| 21 |
referral_code: string | null
|
| 22 |
}
|
|
|
|
| 115 |
<thead>
|
| 116 |
<tr className="border-b border-white/10">
|
| 117 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">ID</th>
|
| 118 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Компания</th>
|
| 119 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Email</th>
|
| 120 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Тариф</th>
|
| 121 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Роль</th>
|
| 122 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Статус</th>
|
| 123 |
<th className="px-6 py-4 text-right text-xs font-bold text-slate-400 uppercase tracking-wider bg-white/5">Действия</th>
|
|
|
|
| 130 |
{index + 1}
|
| 131 |
</td>
|
| 132 |
<td className="px-6 py-4">
|
| 133 |
+
<div className="flex flex-col">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
<span className="text-sm font-medium text-slate-300 group-hover:text-white transition-colors">
|
| 135 |
+
{user.tenant_name || '—'}
|
| 136 |
</span>
|
| 137 |
+
{user.full_name && (
|
| 138 |
+
<span className="text-xs text-slate-500">{user.full_name}</span>
|
| 139 |
+
)}
|
| 140 |
</div>
|
| 141 |
</td>
|
| 142 |
<td className="px-6 py-4 text-sm text-slate-400 group-hover:text-slate-300 transition-colors">
|
| 143 |
{user.email}
|
| 144 |
</td>
|
| 145 |
+
<td className="px-6 py-4">
|
| 146 |
+
{(() => {
|
| 147 |
+
const plan = user.subscription_plan?.toLowerCase() || 'trial'
|
| 148 |
+
const planConfig: Record<string, { bg: string, text: string, label: string }> = {
|
| 149 |
+
trial: { bg: 'bg-slate-500/10', text: 'text-slate-400', label: 'Trial' },
|
| 150 |
+
start: { bg: 'bg-blue-500/10', text: 'text-blue-400', label: 'Start' },
|
| 151 |
+
growth: { bg: 'bg-purple-500/10', text: 'text-purple-400', label: 'Growth' },
|
| 152 |
+
enterprise: { bg: 'bg-amber-500/10', text: 'text-amber-400', label: 'Enterprise' },
|
| 153 |
+
}
|
| 154 |
+
const config = planConfig[plan] || planConfig.trial
|
| 155 |
+
return (
|
| 156 |
+
<span className={`inline-flex px-2.5 py-1 rounded-full text-xs font-bold border border-white/10 ${config.bg} ${config.text}`}>
|
| 157 |
+
{config.label}
|
| 158 |
+
</span>
|
| 159 |
+
)
|
| 160 |
+
})()}
|
| 161 |
+
</td>
|
| 162 |
<td className="px-6 py-4 text-sm text-slate-400">
|
| 163 |
+
{user.is_superuser || user.role === 'admin' ? 'Админ' : user.role === 'OWNER' ? 'Владелец' : 'Менеджер'}
|
| 164 |
</td>
|
| 165 |
<td className="px-6 py-4">
|
| 166 |
<div className={`inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium border ${user.is_active
|
| 167 |
+
? 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20'
|
| 168 |
+
: 'bg-red-500/10 text-red-400 border-red-500/20'
|
| 169 |
}`}>
|
| 170 |
+
{user.is_active ? 'Активен' : 'Заблокирован'}
|
| 171 |
</div>
|
| 172 |
</td>
|
| 173 |
<td className="px-6 py-4 text-right">
|