Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' 'unsafe-eval' 'wasm-unsafe-eval' http://localhost:* https://localhost:* __DEV_LAN_ORIGIN__; style-src 'self' 'unsafe-inline'; worker-src 'self' blob:; connect-src 'self' blob: tauri: tauri://localhost http://tauri.localhost http://localhost:5174 http://127.0.0.1:5174 http://ipc.localhost https://api.synco.one ws://api.synco.one wss://api.synco.one ws://api.synco.one:9001 wss://api.synco.one:9001 https://auth.silvercore.fr https://livekit.silvercore.fr wss://livekit.silvercore.fr http://localhost:* https://localhost:* ws://localhost:* wss://localhost:* __DEV_LAN_ORIGIN__ https://huggingface.co https://*.huggingface.co https://cdn.jsdelivr.net https://raw.githubusercontent.com https://cas-bridge.xethub.hf.co https://*.cdn.hf.co; img-src 'self' data: blob: https://ui-avatars.com https://avatars.githubusercontent.com http://localhost:* https://localhost:* __DEV_LAN_ORIGIN__ https://api.synco.one; frame-src 'self' blob: http://localhost:* https://localhost:* __DEV_LAN_ORIGIN__ https://api.synco.one https://auth.silvercore.fr;">
<title>Synco.</title>
<meta name="description" content="Synco, la plateforme de collaboration sécurisée : messagerie chiffrée, salons, appels vocaux et vidéo pour votre équipe." />

<!-- Open Graph -->
<meta property="og:type" content="website" />
<meta property="og:site_name" content="Synco" />
<meta property="og:title" content="Synco." />
<meta property="og:description" content="La plateforme de collaboration sécurisée : messagerie chiffrée, salons, appels vocaux et vidéo pour votre équipe." />
<meta property="og:url" content="https://app.synco.one" />
<meta property="og:locale" content="fr_FR" />
<meta property="og:image" content="https://app.synco.one/banner.png" />
<meta property="og:image:width" content="279" />
<meta property="og:image:height" content="90" />

<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Synco." />
<meta name="twitter:description" content="La plateforme de collaboration sécurisée : messagerie chiffrée, salons, appels vocaux et vidéo pour votre équipe." />
<meta name="twitter:image" content="https://app.synco.one/banner.png" />

</head>

Expand Down
39 changes: 5 additions & 34 deletions src/composables/useAgenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Composable pour la gestion de l'Agenda
// ============================================

import { ref, computed } from 'vue';
import { ref } from 'vue';
import sfetch from '@/assets/utils/sfetch';
import { useToast } from './useToast';
import { user } from '@/assets/var';
import type {
CalendarEvent,
CalendarEventWithDetails,
Expand Down Expand Up @@ -39,12 +38,6 @@ const myReminders = ref<ReminderWithEvent[]>([]);
const loading = ref<boolean>(false);
const error = ref<string | null>(null);

// Agenda affiché : soi-même par défaut, ou un membre dirigé (cascade Équipes).
// `null` = "moi" (résolu dynamiquement via `user`, jamais figé au chargement du module).
const viewingUserId = ref<string | null>(null);

const isViewingSelf = computed(() => !viewingUserId.value || viewingUserId.value === user.value?.id);

// ============================================
// Fonctions utilitaires internes
// ============================================
Expand All @@ -58,17 +51,16 @@ function buildOccurrencePath(eventId: string, occurrenceStartAt: string): string
// ============================================

/**
* Récupère les occurrences dans une plage de dates, pour soi ou (via le
* cascade Équipes) pour un membre dirigé.
* Récupère mes propres occurrences dans une plage de dates. Pour les
* calendriers partagés par des collègues, voir useCalendarAccess.ts::
* fetchSharedOccurrences (state séparé, ne touche jamais `occurrences` ici).
*/
async function fetchRange(orgId: string, from: string, to: string, userId?: string): Promise<OccurrenceInstance[] | null> {
async function fetchRange(orgId: string, from: string, to: string): Promise<OccurrenceInstance[] | null> {
loading.value = true;
error.value = null;

try {
const targetUserId = userId ?? viewingUserId.value ?? undefined;
const params = new URLSearchParams({ from, to });
if (targetUserId) params.set('userId', targetUserId);

const res = await sfetch(`/api/orgs/${orgId}/agenda/events?${params.toString()}`);

Expand Down Expand Up @@ -498,20 +490,6 @@ async function listMyReminders(orgId: string): Promise<ReminderWithEvent[] | nul
}
}

// ============================================
// Fonctions utilitaires — sélecteur "voir comme"
// ============================================

/** Bascule l'agenda affiché sur celui d'un membre dirigé */
function setViewingUser(userId: string): void {
viewingUserId.value = userId;
}

/** Revient à son propre agenda */
function resetViewingUser(): void {
viewingUserId.value = null;
}

/**
* Réinitialise le state
*/
Expand All @@ -520,7 +498,6 @@ function resetState(): void {
currentEvent.value = null;
myReminders.value = [];
error.value = null;
viewingUserId.value = null;
}

// ============================================
Expand All @@ -535,8 +512,6 @@ export function useAgenda() {
myReminders,
loading,
error,
viewingUserId,
isViewingSelf,

// Fonctions API — Événements
fetchRange,
Expand All @@ -557,10 +532,6 @@ export function useAgenda() {
removeReminder,
listMyReminders,

// Sélecteur "voir comme"
setViewingUser,
resetViewingUser,

// Utilitaires
resetState
};
Expand Down
30 changes: 30 additions & 0 deletions src/composables/useAgendaViewMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Vue affichée dans l'Agenda (mois / semaine / jour), persistée via les
// attributs Keycloak — même mécanisme que showUsersBar (useUsersBar.ts).
// Tant que l'utilisateur n'a jamais choisi explicitement, aucune valeur
// n'est écrite et la vue par défaut dépend du device courant (semaine sur
// desktop, jour sur mobile) ; dès qu'un choix est fait, il est mémorisé et
// prime sur ce défaut, quel que soit l'appareil utilisé ensuite.

import { computed } from 'vue';
import useSettingsItem from './useSettingsItem';
import { isLittleScreen } from '@/assets/var';

export type AgendaViewMode = 'month' | 'week' | 'day';

const { Item: viewModeSetting } = useSettingsItem('agendaViewMode', undefined);

export const useAgendaViewMode = () => {
const viewMode = computed<AgendaViewMode>({
get: () => {
if (viewModeSetting.value === 'month' || viewModeSetting.value === 'week' || viewModeSetting.value === 'day') {
return viewModeSetting.value;
}
return isLittleScreen.value ? 'day' : 'week';
},
set: (val: AgendaViewMode) => {
viewModeSetting.value = val;
}
});

return { viewMode };
};
236 changes: 236 additions & 0 deletions src/composables/useCalendarAccess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
// ============================================
// Composable pour le partage d'agenda entre collègues
// (CalendarAccessGrant — demande/invitation, lecture seule ou modification)
// ============================================

import { ref, computed } from 'vue';
import sfetch from '@/assets/utils/sfetch';
import { useToast } from './useToast';
import type {
CalendarAccessGrantAsOwner,
CalendarAccessGrantAsGrantee,
CalendarAccessLevel,
ListMyGrantsResponse,
GrantResponse,
ApiErrorResponse,
MergedOccurrence
} from '@/types/agenda';

// Palette de couleurs par défaut proposées pour un nouveau calendrier partagé
// (réutilisée dans l'ordre, cycliquement, si l'utilisateur n'en choisit pas).
const DEFAULT_COLORS = ['#6366f1', '#ec4899', '#f59e0b', '#10b981', '#06b6d4', '#8b5cf6', '#ef4444'];

const asOwner = ref<CalendarAccessGrantAsOwner[]>([]);
const asGrantee = ref<CalendarAccessGrantAsGrantee[]>([]);
const sharedOccurrences = ref<MergedOccurrence[]>([]);
const loading = ref(false);

// Demandes reçues sur MON agenda (quelqu'un demande à me lire/modifier) —
// c'est moi qui décide.
const incomingRequests = computed(() => asOwner.value.filter(g => g.status === 'PENDING' && g.initiatedBy === 'REQUESTER'));
// Invitations reçues à consulter/modifier l'agenda d'un tiers — c'est moi qui décide.
const incomingInvites = computed(() => asGrantee.value.filter(g => g.status === 'PENDING' && g.initiatedBy === 'OWNER'));
// Mes propres demandes/invitations envoyées, en attente de réponse de l'autre partie.
const outgoingRequests = computed(() => asGrantee.value.filter(g => g.status === 'PENDING' && g.initiatedBy === 'REQUESTER'));
const outgoingInvites = computed(() => asOwner.value.filter(g => g.status === 'PENDING' && g.initiatedBy === 'OWNER'));
const acceptedSharedCalendars = computed(() => asGrantee.value.filter(g => g.status === 'ACCEPTED'));

function hiddenKey(orgId: string): string {
return `agenda-hidden-calendars:${orgId}`;
}

function getHiddenIds(orgId: string): Set<string> {
try {
const raw = localStorage.getItem(hiddenKey(orgId));
return new Set(raw ? JSON.parse(raw) : []);
} catch {
return new Set();
}
}

function isVisible(orgId: string, grantId: string): boolean {
return !getHiddenIds(orgId).has(grantId);
}

function toggleVisibility(orgId: string, grantId: string): void {
const hidden = getHiddenIds(orgId);
if (hidden.has(grantId)) hidden.delete(grantId);
else hidden.add(grantId);
localStorage.setItem(hiddenKey(orgId), JSON.stringify([...hidden]));
}

function colorFor(grant: CalendarAccessGrantAsGrantee, index: number): string {
return grant.color || DEFAULT_COLORS[index % DEFAULT_COLORS.length] || DEFAULT_COLORS[0]!;
}

async function fetchGrants(orgId: string): Promise<void> {
loading.value = true;
try {
const res = await sfetch(`/api/orgs/${orgId}/agenda/access`);
if (!res.ok) {
const err: ApiErrorResponse = await res.json();
throw new Error(err.error || "Erreur lors du chargement des accès à l'agenda");
}
const data: ListMyGrantsResponse = await res.json();
asOwner.value = data.asOwner;
asGrantee.value = data.asGrantee;
} catch (err: any) {
useToast().show(err.message || 'Erreur inconnue', 'error');
} finally {
loading.value = false;
}
}

async function requestAccess(orgId: string, ownerId: string, level: CalendarAccessLevel): Promise<boolean> {
try {
const res = await sfetch(`/api/orgs/${orgId}/agenda/access/request`, {
method: 'POST',
body: JSON.stringify({ ownerId, level })
});
if (!res.ok) {
const err: ApiErrorResponse = await res.json();
throw new Error(err.error || "Erreur lors de la demande d'accès");
}
useToast().show('Demande envoyée', 'success');
await fetchGrants(orgId);
return true;
} catch (err: any) {
useToast().show(err.message || 'Erreur inconnue', 'error');
return false;
}
}

async function inviteAccess(orgId: string, granteeId: string, level: CalendarAccessLevel): Promise<boolean> {
try {
const res = await sfetch(`/api/orgs/${orgId}/agenda/access/invite`, {
method: 'POST',
body: JSON.stringify({ granteeId, level })
});
if (!res.ok) {
const err: ApiErrorResponse = await res.json();
throw new Error(err.error || "Erreur lors de l'invitation");
}
useToast().show('Invitation envoyée', 'success');
await fetchGrants(orgId);
return true;
} catch (err: any) {
useToast().show(err.message || 'Erreur inconnue', 'error');
return false;
}
}

async function respondToGrant(orgId: string, grantId: string, action: 'ACCEPT' | 'DECLINE', level?: CalendarAccessLevel): Promise<boolean> {
try {
const res = await sfetch(`/api/orgs/${orgId}/agenda/access/${grantId}/respond`, {
method: 'PATCH',
body: JSON.stringify({ action, level })
});
if (!res.ok) {
const err: ApiErrorResponse = await res.json();
throw new Error(err.error || 'Erreur lors de la réponse');
}
const data: GrantResponse = await res.json();
useToast().show(action === 'ACCEPT' ? 'Accès accordé' : 'Demande refusée', 'success');
await fetchGrants(orgId);
return data.grant.status === 'ACCEPTED';
} catch (err: any) {
useToast().show(err.message || 'Erreur inconnue', 'error');
return false;
}
}

async function revokeGrant(orgId: string, grantId: string): Promise<boolean> {
// Capturé avant l'appel : une fois révoqué, le grant peut disparaître des
// listes rechargées par fetchGrants, on ne pourrait plus retrouver son
// ownerId pour purger sharedOccurrences.
const ownerId = asGrantee.value.find(g => g.id === grantId)?.ownerId;
try {
const res = await sfetch(`/api/orgs/${orgId}/agenda/access/${grantId}`, { method: 'DELETE' });
if (!res.ok) {
const err: ApiErrorResponse = await res.json();
throw new Error(err.error || "Erreur lors du retrait de l'accès");
}
useToast().show('Accès retiré', 'success');
await fetchGrants(orgId);
if (ownerId) sharedOccurrences.value = sharedOccurrences.value.filter(o => o.sourceOwnerId !== ownerId);
return true;
} catch (err: any) {
useToast().show(err.message || 'Erreur inconnue', 'error');
return false;
}
}

async function setColor(orgId: string, grantId: string, color: string): Promise<boolean> {
try {
const res = await sfetch(`/api/orgs/${orgId}/agenda/access/${grantId}/color`, {
method: 'PATCH',
body: JSON.stringify({ color })
});
if (!res.ok) return false;
await fetchGrants(orgId);
return true;
} catch {
return false;
}
}

// Récupère et fusionne les occurrences de tous les calendriers partagés
// actuellement visibles (accès accepté + non masqué), taguées par calendrier
// source pour l'affichage superposé. N'affecte jamais l'agenda "moi" (voir
// useAgenda.ts::fetchRange, séparé).
async function fetchSharedOccurrences(orgId: string, from: string, to: string): Promise<void> {
const visible = acceptedSharedCalendars.value.filter(g => isVisible(orgId, g.id));
if (visible.length === 0) {
sharedOccurrences.value = [];
return;
}

const results = await Promise.all(visible.map(async (grant, index) => {
try {
const params = new URLSearchParams({ from, to, userId: grant.ownerId });
const res = await sfetch(`/api/orgs/${orgId}/agenda/events?${params.toString()}`);
if (!res.ok) return [];
const data = await res.json();
const color = colorFor(grant, index);
return (data.occurrences || []).map((o: any) => ({ ...o, sourceOwnerId: grant.ownerId, sourceColor: color }));
} catch {
return [];
}
}));

sharedOccurrences.value = results.flat();
}

function resetState(): void {
asOwner.value = [];
asGrantee.value = [];
sharedOccurrences.value = [];
}

export function useCalendarAccess() {
return {
asOwner,
asGrantee,
sharedOccurrences,
loading,
incomingRequests,
incomingInvites,
outgoingRequests,
outgoingInvites,
acceptedSharedCalendars,

fetchGrants,
requestAccess,
inviteAccess,
respondToGrant,
revokeGrant,
setColor,
fetchSharedOccurrences,

isVisible,
toggleVisibility,
colorFor,

resetState
};
}
Loading
Loading