Browse Source

Address code review feedback - fix hooks and random usage

Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com>
copilot-swe-agent[bot] 3 months ago
parent
commit
1a6a53d92e

+ 3 - 1
backend/app/services/email_service.py

@@ -30,6 +30,8 @@ def generate_secure_password(length: int = 16) -> str:
     Returns:
     Returns:
         A secure random password containing uppercase, lowercase, digits, and special characters
         A secure random password containing uppercase, lowercase, digits, and special characters
     """
     """
+    import random
+    
     # Define character sets
     # Define character sets
     lowercase = string.ascii_lowercase
     lowercase = string.ascii_lowercase
     uppercase = string.ascii_uppercase
     uppercase = string.ascii_uppercase
@@ -49,7 +51,7 @@ def generate_secure_password(length: int = 16) -> str:
     password_chars.extend(secrets.choice(all_chars) for _ in range(length - 4))
     password_chars.extend(secrets.choice(all_chars) for _ in range(length - 4))
     
     
     # Shuffle to avoid predictable patterns
     # Shuffle to avoid predictable patterns
-    secrets.SystemRandom().shuffle(password_chars)
+    random.shuffle(password_chars)
     
     
     return "".join(password_chars)
     return "".join(password_chars)
 
 

+ 3 - 2
frontend/src/components/EmailSettings.tsx

@@ -7,6 +7,7 @@ import type { SMTPSettings, TestSMTPRequest } from '../api/client';
 import { Card, CardContent, CardHeader } from './Card';
 import { Card, CardContent, CardHeader } from './Card';
 import { Button } from './Button';
 import { Button } from './Button';
 import { useToast } from '../contexts/ToastContext';
 import { useToast } from '../contexts/ToastContext';
+import { useEffect } from 'react';
 
 
 export function EmailSettings() {
 export function EmailSettings() {
   const { t } = useTranslation();
   const { t } = useTranslation();
@@ -37,14 +38,14 @@ export function EmailSettings() {
   });
   });
 
 
   // Load existing settings when fetched
   // Load existing settings when fetched
-  useState(() => {
+  useEffect(() => {
     if (existingSettings) {
     if (existingSettings) {
       setSMTPSettings({
       setSMTPSettings({
         ...existingSettings,
         ...existingSettings,
         smtp_password: '', // Never show password
         smtp_password: '', // Never show password
       });
       });
     }
     }
-  });
+  }, [existingSettings]);
 
 
   // Save SMTP settings
   // Save SMTP settings
   const saveMutation = useMutation({
   const saveMutation = useMutation({

+ 2 - 1
frontend/src/pages/UsersPage.tsx

@@ -124,7 +124,8 @@ export function UsersPage() {
   });
   });
 
 
   const handleCreate = () => {
   const handleCreate = () => {
-    const advancedAuthEnabled = advancedAuthStatus?.advanced_auth_enabled;
+    // Use the status from the query hook
+    const advancedAuthEnabled = advancedAuthStatus?.advanced_auth_enabled || false;
     
     
     if (!formData.username) {
     if (!formData.username) {
       showToast(t('users.toast.fillRequired'), 'error');
       showToast(t('users.toast.fillRequired'), 'error');