diff --git a/.env b/.env index a090bf7b..c58a6e2b 100644 --- a/.env +++ b/.env @@ -45,11 +45,4 @@ NEXT_PUBLIC_IFRAME_AI_ASSISTANT_URL=https://alma.slm-lab.net ROCKET_CHAT_TOKEN=w91TYgkH-Z67Oz72usYdkW5TZLLRwnre7qyAhp7aHJB ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb -LEANTIME_API_URL=https://agilite.slm-lab.net - -DATABASE_URL="postgresql://alma:Sict33711###@cube.governance-labs.com:5432/rivacube?schema=public" - -DB_USER=alma -DB_PASSWORD=Sict33711### -DB_NAME=rivacube -DB_HOST=cube.governance-labs.com \ No newline at end of file +LEANTIME_API_URL=https://agilite.slm-lab.net \ No newline at end of file diff --git a/app/api/emails/route.ts b/app/api/emails/route.ts index 89f71254..5d86b2f3 100644 --- a/app/api/emails/route.ts +++ b/app/api/emails/route.ts @@ -7,7 +7,6 @@ export async function GET(req: NextRequest) { const session = await getServerSession(authOptions); if (!session?.user?.email) { - console.error('No session or email found'); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } @@ -20,152 +19,35 @@ export async function GET(req: NextRequest) { ); } - // Get the Keycloak token from the session - const keycloakToken = session.accessToken; - if (!keycloakToken) { - console.error('Missing Keycloak token in session'); - return NextResponse.json( - { error: 'Authentication token is missing' }, - { status: 401 } - ); - } - - // First, try the unified inbox endpoint for unread messages - const unifiedResponse = await fetch( - `${nextcloudUrl}/index.php/apps/mail/api/messages?filter=is:unread`, - { - headers: { - 'Authorization': `Bearer ${keycloakToken}`, - 'Accept': 'application/json', - 'OCS-APIRequest': 'true', - 'X-Requested-With': 'XMLHttpRequest' - } - } - ); - - // Log the response status and headers for debugging - console.log('Unified inbox response status:', unifiedResponse.status); - console.log('Unified inbox response headers:', Object.fromEntries(unifiedResponse.headers.entries())); - - if (unifiedResponse.ok) { - const unifiedData = await unifiedResponse.json(); - console.log('Unified inbox data:', unifiedData); - const messages = unifiedData.data || []; - - const unreadEmails = messages.map((msg: any) => ({ - id: msg.id, - subject: msg.subject, - sender: { - name: msg.from[0].label || msg.from[0].email, - email: msg.from[0].email - }, - date: msg.date, - isUnread: true - })); - - return NextResponse.json({ - emails: unreadEmails, - mailUrl: `${nextcloudUrl}/apps/mail/box/unified` - }); - } - - // If unified inbox fails, fall back to the account-based approach - const accountsResponse = await fetch( - `${nextcloudUrl}/index.php/apps/mail/api/accounts`, - { - headers: { - 'Authorization': `Bearer ${keycloakToken}`, - 'Accept': 'application/json', - 'OCS-APIRequest': 'true', - 'X-Requested-With': 'XMLHttpRequest' - } - } - ); - - // Log the response status and headers for debugging - console.log('Accounts response status:', accountsResponse.status); - console.log('Accounts response headers:', Object.fromEntries(accountsResponse.headers.entries())); - - if (!accountsResponse.ok) { - const errorText = await accountsResponse.text(); - console.error('Failed to fetch mail accounts. Response:', errorText); + // Test Nextcloud connectivity + const testResponse = await fetch(`${nextcloudUrl}/status.php`); + if (!testResponse.ok) { + console.error('Nextcloud is not accessible:', await testResponse.text()); return NextResponse.json( { - error: "L'application Mail n'est pas disponible sur Nextcloud. Veuillez contacter votre administrateur.", + error: "Nextcloud n'est pas accessible. Veuillez contacter votre administrateur.", emails: [] }, - { status: 404 } + { status: 503 } ); } - const accountsData = await accountsResponse.json(); - console.log('Accounts data:', accountsData); - const accounts = accountsData.data || []; - - const unreadEmails = []; - for (const account of accounts) { - // Get mailboxes for the account - const mailboxesResponse = await fetch( - `${nextcloudUrl}/index.php/apps/mail/api/accounts/${account.id}/mailboxes`, - { - headers: { - 'Authorization': `Bearer ${keycloakToken}`, - 'Accept': 'application/json', - 'OCS-APIRequest': 'true', - 'X-Requested-With': 'XMLHttpRequest' - } - } - ); - - if (!mailboxesResponse.ok) { - console.error(`Failed to fetch mailboxes for account ${account.id}`); - continue; - } - - const mailboxesData = await mailboxesResponse.json(); - const mailboxes = mailboxesData.data || []; - - // Get unread messages from each mailbox - for (const mailbox of mailboxes) { - const messagesResponse = await fetch( - `${nextcloudUrl}/index.php/apps/mail/api/accounts/${account.id}/mailboxes/${mailbox.id}/messages?filter=is:unread`, - { - headers: { - 'Authorization': `Bearer ${keycloakToken}`, - 'Accept': 'application/json', - 'OCS-APIRequest': 'true', - 'X-Requested-With': 'XMLHttpRequest' - } - } - ); - - if (!messagesResponse.ok) { - console.error(`Failed to fetch messages for mailbox ${mailbox.id}`); - continue; - } - - const messagesData = await messagesResponse.json(); - const messages = messagesData.data || []; - - unreadEmails.push(...messages.map((msg: any) => ({ - id: msg.id, - subject: msg.subject, - sender: { - name: msg.from[0].label || msg.from[0].email, - email: msg.from[0].email - }, - date: msg.date, - isUnread: true - }))); - } - } - + // For now, return a test response return NextResponse.json({ - emails: unreadEmails, + emails: [{ + id: 'test-1', + subject: 'Test Email', + sender: { + name: 'System', + email: 'system@example.com' + }, + date: new Date().toISOString(), + isUnread: true + }], mailUrl: `${nextcloudUrl}/apps/mail/box/unified` }); } catch (error) { - console.error('Error getting emails:', error); + console.error('Error:', error); return NextResponse.json( { error: "Une erreur est survenue. Veuillez contacter votre administrateur.", diff --git a/app/api/news/route.ts b/app/api/news/route.ts deleted file mode 100644 index 43188657..00000000 --- a/app/api/news/route.ts +++ /dev/null @@ -1,137 +0,0 @@ -import { NextResponse } from 'next/server'; -import { Pool } from 'pg'; - -// Function to clean database host URL -function cleanDatabaseHost(host: string | undefined): string { - if (!host) { - throw new Error('Database host is not defined'); - } - // Remove any protocol and trailing slashes - return host.replace(/^https?:\/\//, '').replace(/\/$/, ''); -} - -// Create connection configuration -const dbConfig = { - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - host: cleanDatabaseHost(process.env.DB_HOST), - database: process.env.DB_NAME, - port: 5432, // Default PostgreSQL port - ssl: { - rejectUnauthorized: false - } -}; - -// Create a new pool using the configuration -const pool = new Pool(dbConfig); - -// Mock data for development -const MOCK_NEWS = [ - { - id: 1, - title: "New Project Management Features Released", - url: "#", - date: "2024-03-20", - source: "Internal", - description: "New features added to improve project management workflow", - category: "Update", - sentiment: { score: null, label: null }, - symbols: null, - symbol: null - }, - { - id: 2, - title: "Team Meeting Schedule Changes", - url: "#", - date: "2024-03-19", - source: "Internal", - description: "Updates to the team meeting schedule", - category: "Announcement", - sentiment: { score: null, label: null }, - symbols: null, - symbol: null - }, - { - id: 3, - title: "Upcoming Training Sessions", - url: "#", - date: "2024-03-18", - source: "Internal", - description: "Schedule for upcoming training sessions", - category: "Training", - sentiment: { score: null, label: null }, - symbols: null, - symbol: null - } -]; - -export async function GET() { - try { - console.log('Attempting database connection with config:', { - user: dbConfig.user, - host: dbConfig.host, - database: dbConfig.database, - // Excluding password for security - }); - - // Connect to the database - const client = await pool.connect(); - console.log('Successfully connected to database'); - - try { - console.log('Executing news query...'); - // Query the news table for the latest 10 news items - const result = await client.query(` - SELECT - id, - title, - url, - date, - source, - description, - category, - sentiment_score, - sentiment, - symbols, - symbol - FROM news - ORDER BY date DESC - LIMIT 10 - `); - - console.log(`Found ${result.rows.length} news items`); - - // Format the response - const news = result.rows.map(row => ({ - id: row.id, - title: row.title, - url: row.url, - date: row.date, - source: row.source, - description: row.description, - category: row.category, - sentiment: { - score: row.sentiment_score, - label: row.sentiment - }, - symbols: row.symbols, - symbol: row.symbol - })); - - return NextResponse.json({ news }); - } finally { - // Release the client back to the pool - client.release(); - console.log('Database client released'); - } - } catch (error) { - console.error('Database error:', error); - return NextResponse.json( - { - error: 'Failed to fetch news', - details: error instanceof Error ? error.message : String(error) - }, - { status: 500 } - ); - } -} \ No newline at end of file diff --git a/components/calendar.tsx b/components/calendar.tsx index 7c5d7b5f..197f50c5 100644 --- a/components/calendar.tsx +++ b/components/calendar.tsx @@ -90,7 +90,7 @@ export function Calendar() { return ( - Calendar + Agenda - -