Multi-user sharing, groups, and in-app notifications

Backend:
- Alembic migration 0025: groups, group_memberships, project_shares,
  note_shares, notifications tables
- models: Group, GroupMembership, ProjectShare, NoteShare, Notification
- services/access.py: permission resolution (viewer/editor/admin/owner)
- services/groups.py + routes/groups.py: full group CRUD + membership
- services/sharing.py + routes/shares.py: project/note sharing API
- services/notifications.py: in-app notification create/list/mark-read
- routes/in_app_notifications.py: GET/POST notification endpoints
- routes/users.py: user search endpoint
- services/projects.py + services/notes.py: *_for_user variants
- routes updated to use *_for_user on get/list; adds permission field
- app.py: register all new blueprints

Frontend:
- api/client.ts: ShareEntry, GroupEntry, NotificationEntry types + helpers
- stores/notifications.ts: Pinia store with polling
- NotificationBell.vue: bell icon + badge + dropdown toggle + 60s poll
- NotificationsPanel.vue: unread notification list with mark-all-read
- ShareDialog.vue: teleport modal for sharing projects/notes with users/groups
- SharedWithMeView.vue: /shared route listing shared projects and notes
- AppHeader: NotificationBell, Shared nav link
- ProjectView, NoteViewerView, TaskViewerView: Share button + ShareDialog
- SettingsView: Groups admin tab with create/delete groups + member mgmt
- router: /shared route

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 15:37:00 -04:00
parent 878b149f4d
commit c7ef709633
31 changed files with 3147 additions and 16 deletions
+5
View File
@@ -6,6 +6,7 @@ import { useShortcuts } from "@/composables/useShortcuts";
import { useAuthStore } from "@/stores/auth";
import { useChatStore } from "@/stores/chat";
import AppLogo from "@/components/AppLogo.vue";
import NotificationBell from "@/components/NotificationBell.vue";
const { theme, toggleTheme } = useTheme();
const { toggleShortcuts } = useShortcuts();
@@ -76,6 +77,7 @@ router.afterEach(() => {
<router-link to="/tasks" class="nav-link">Tasks</router-link>
<router-link to="/chat" :class="['nav-link', { 'router-link-active': isChatActive }]">Chat</router-link>
<router-link to="/graph" class="nav-link">Graph</router-link>
<router-link to="/shared" class="nav-link">Shared</router-link>
</div>
<!-- Right: status + utilities + gear + user -->
@@ -85,6 +87,8 @@ router.afterEach(() => {
<span class="status-text">{{ statusShortLabel }}</span>
</span>
<NotificationBell />
<button class="btn-icon" @click="toggleShortcuts" title="Keyboard shortcuts (?)">?</button>
<button class="btn-icon" @click="toggleTheme" :title="`Switch to ${theme === 'dark' ? 'light' : 'dark'} mode`">
@@ -121,6 +125,7 @@ router.afterEach(() => {
<router-link to="/tasks" class="nav-link">Tasks</router-link>
<router-link to="/chat" :class="['nav-link', { 'router-link-active': isChatActive }]">Chat</router-link>
<router-link to="/graph" class="nav-link">Graph</router-link>
<router-link to="/shared" class="nav-link">Shared</router-link>
<div class="mobile-divider"></div>
<router-link to="/settings" class="nav-link">Settings</router-link>
<div class="mobile-divider"></div>
@@ -0,0 +1,100 @@
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { useNotificationsStore } from '@/stores/notifications'
import NotificationsPanel from './NotificationsPanel.vue'
const store = useNotificationsStore()
const open = ref(false)
const wrapRef = ref<HTMLElement | null>(null)
let pollInterval: ReturnType<typeof setInterval> | null = null
function toggle() {
open.value = !open.value
if (open.value) store.fetchAll()
}
function close() {
open.value = false
}
function onDocClick(e: MouseEvent) {
if (open.value && wrapRef.value && !wrapRef.value.contains(e.target as Node)) {
close()
}
}
onMounted(() => {
store.fetchCount()
pollInterval = setInterval(() => store.fetchCount(), 60_000)
document.addEventListener('click', onDocClick, true)
})
onUnmounted(() => {
if (pollInterval) clearInterval(pollInterval)
document.removeEventListener('click', onDocClick, true)
})
</script>
<template>
<div class="bell-wrap" ref="wrapRef">
<button
class="btn-bell"
:class="{ active: open }"
@click="toggle"
aria-label="Notifications"
:title="`${store.count} unread notification${store.count !== 1 ? 's' : ''}`"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/>
<path d="M13.73 21a2 2 0 0 1-3.46 0"/>
</svg>
<span v-if="store.count > 0" class="bell-badge" aria-live="polite">{{ store.count > 99 ? '99+' : store.count }}</span>
</button>
<NotificationsPanel v-if="open" @close="close" />
</div>
</template>
<style scoped>
.bell-wrap {
position: relative;
}
.btn-bell {
background: none;
border: 1px solid var(--color-border);
border-radius: var(--radius-sm);
padding: 0.25rem 0.45rem;
cursor: pointer;
color: var(--color-text-muted);
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.btn-bell:hover,
.btn-bell.active {
background: var(--color-bg-card);
color: var(--color-text);
border-color: var(--color-primary);
}
.bell-badge {
position: absolute;
top: -5px;
right: -5px;
background: var(--color-danger, #ef4444);
color: #fff;
font-size: 0.6rem;
font-weight: 700;
min-width: 16px;
height: 16px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
padding: 0 3px;
line-height: 1;
pointer-events: none;
}
</style>
@@ -0,0 +1,156 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useNotificationsStore } from '@/stores/notifications'
import { relativeTime } from '@/composables/useRelativeTime'
const emit = defineEmits<{ close: [] }>()
const store = useNotificationsStore()
const router = useRouter()
const typeIcon: Record<string, string> = {
project_shared: '📁',
note_shared: '📝',
group_added: '👥',
}
async function handleClick(notif: { id: number; payload: Record<string, unknown> }) {
await store.markRead(notif.id)
const url = notif.payload.url as string | undefined
if (url) {
emit('close')
router.push(url)
}
}
onMounted(() => store.fetchAll())
</script>
<template>
<div class="notif-panel" role="dialog" aria-label="Notifications">
<header class="notif-panel-header">
<span class="notif-panel-title">Notifications</span>
<button
v-if="store.count > 0"
class="btn-mark-all"
@click="store.markAll()"
>Mark all read</button>
</header>
<ul class="notif-list" v-if="store.items.length">
<li
v-for="n in store.items"
:key="n.id"
class="notif-item"
@click="handleClick(n)"
>
<span class="notif-icon">{{ typeIcon[n.type] ?? '🔔' }}</span>
<div class="notif-body">
<p class="notif-msg">
<strong v-if="n.payload.invited_by">{{ n.payload.invited_by }}</strong>
{{ n.type === 'project_shared'
? ` shared "${n.payload.project_title}" with you as ${n.payload.permission}`
: n.type === 'note_shared'
? ` shared "${n.payload.note_title}" with you as ${n.payload.permission}`
: ` added you to "${n.payload.group_name}" as ${n.payload.role}` }}
</p>
<span class="notif-time">{{ relativeTime(n.created_at) }}</span>
</div>
<button class="btn-notif-close" @click.stop="store.markRead(n.id)" aria-label="Dismiss"></button>
</li>
</ul>
<div v-else class="notif-empty">No unread notifications</div>
</div>
</template>
<style scoped>
.notif-panel {
position: absolute;
top: calc(100% + 8px);
right: 0;
width: 340px;
max-height: 400px;
overflow-y: auto;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
z-index: 500;
}
.notif-panel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--color-border);
position: sticky;
top: 0;
background: var(--color-surface);
}
.notif-panel-title {
font-weight: 700;
font-size: 0.9rem;
}
.btn-mark-all {
background: none;
border: none;
color: var(--color-primary);
font-size: 0.78rem;
cursor: pointer;
padding: 0;
}
.btn-mark-all:hover { text-decoration: underline; }
.notif-list {
list-style: none;
padding: 0;
margin: 0;
}
.notif-item {
display: flex;
align-items: flex-start;
gap: 0.6rem;
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--color-border);
cursor: pointer;
transition: background 0.1s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--color-hover); }
.notif-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 0.1rem; }
.notif-body { flex: 1; min-width: 0; }
.notif-msg {
margin: 0 0 0.2rem;
font-size: 0.85rem;
color: var(--color-text);
line-height: 1.4;
word-break: break-word;
}
.notif-time { font-size: 0.75rem; color: var(--color-muted); }
.btn-notif-close {
background: none;
border: none;
color: var(--color-muted);
cursor: pointer;
font-size: 0.8rem;
padding: 0.1rem 0.25rem;
flex-shrink: 0;
transition: color 0.1s;
}
.btn-notif-close:hover { color: var(--color-text); }
.notif-empty {
padding: 1.5rem;
text-align: center;
color: var(--color-muted);
font-size: 0.88rem;
font-style: italic;
}
</style>
+417
View File
@@ -0,0 +1,417 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import {
searchUsers,
listGroups,
listProjectShares,
createProjectShare,
updateProjectShare,
deleteProjectShare,
listNoteShares,
createNoteShare,
updateNoteShare,
deleteNoteShare,
type ShareEntry,
type GroupEntry,
type UserSearchResult,
} from '@/api/client'
const props = defineProps<{
resourceType: 'project' | 'note'
resourceId: number
resourceTitle: string
}>()
const emit = defineEmits<{ close: [] }>()
const addMode = ref<'user' | 'group'>('user')
const userQuery = ref('')
const userResults = ref<UserSearchResult[]>([])
const selectedUser = ref<UserSearchResult | null>(null)
const selectedGroupId = ref<number | ''>('')
const newPermission = ref('viewer')
const groups = ref<GroupEntry[]>([])
const shares = ref<ShareEntry[]>([])
const saving = ref(false)
let searchTimer: ReturnType<typeof setTimeout> | null = null
function debounceSearch() {
if (searchTimer) clearTimeout(searchTimer)
searchTimer = setTimeout(async () => {
if (userQuery.value.length < 2) { userResults.value = []; return }
userResults.value = await searchUsers(userQuery.value)
}, 300)
}
function selectUser(u: UserSearchResult) {
selectedUser.value = u
userQuery.value = u.username
userResults.value = []
}
async function loadShares() {
if (props.resourceType === 'project') {
shares.value = await listProjectShares(props.resourceId)
} else {
shares.value = await listNoteShares(props.resourceId)
}
}
async function addShare() {
if (saving.value) return
saving.value = true
try {
const body: { user_id?: number; group_id?: number; permission: string } = {
permission: newPermission.value,
}
if (addMode.value === 'user' && selectedUser.value) {
body.user_id = selectedUser.value.id
} else if (addMode.value === 'group' && selectedGroupId.value) {
body.group_id = selectedGroupId.value as number
} else {
return
}
if (props.resourceType === 'project') {
await createProjectShare(props.resourceId, body)
} else {
await createNoteShare(props.resourceId, body)
}
selectedUser.value = null
userQuery.value = ''
selectedGroupId.value = ''
newPermission.value = 'viewer'
await loadShares()
} finally {
saving.value = false
}
}
async function changePermission(share: ShareEntry, permission: string) {
if (props.resourceType === 'project') {
await updateProjectShare(props.resourceId, share.id, permission)
} else {
await updateNoteShare(props.resourceId, share.id, permission)
}
await loadShares()
}
async function removeShare(share: ShareEntry) {
if (props.resourceType === 'project') {
await deleteProjectShare(props.resourceId, share.id)
} else {
await deleteNoteShare(props.resourceId, share.id)
}
await loadShares()
}
onMounted(async () => {
groups.value = await listGroups()
await loadShares()
})
</script>
<template>
<Teleport to="body">
<div class="share-overlay" @click.self="emit('close')">
<div class="share-dialog" role="dialog" :aria-label="`Share ${resourceTitle}`">
<header class="share-header">
<h2 class="share-title">Share "{{ resourceTitle }}"</h2>
<button class="btn-close" @click="emit('close')" aria-label="Close"></button>
</header>
<!-- Add share form -->
<div class="share-add">
<div class="share-tabs">
<button :class="['share-tab', { active: addMode === 'user' }]" @click="addMode = 'user'">User</button>
<button :class="['share-tab', { active: addMode === 'group' }]" @click="addMode = 'group'">Group</button>
</div>
<div v-if="addMode === 'user'" class="share-target-form">
<div class="user-search-wrap">
<input
v-model="userQuery"
class="share-input"
placeholder="Search by username or email…"
@input="debounceSearch"
autocomplete="off"
/>
<ul v-if="userResults.length" class="user-results">
<li v-for="u in userResults" :key="u.id" @click="selectUser(u)" class="user-result-item">
<span class="user-result-name">{{ u.username }}</span>
<span class="user-result-email">{{ u.email }}</span>
</li>
</ul>
</div>
<template v-if="selectedUser">
<select v-model="newPermission" class="perm-select">
<option value="viewer">Viewer</option>
<option value="editor">Editor</option>
<option value="admin">Admin</option>
</select>
<button class="btn-add-share" @click="addShare" :disabled="saving">Add</button>
</template>
</div>
<div v-else class="share-target-form">
<select v-model="selectedGroupId" class="share-input">
<option value="" disabled>Select a group</option>
<option v-for="g in groups" :key="g.id" :value="g.id">{{ g.name }} ({{ g.member_count }} members)</option>
</select>
<select v-model="newPermission" class="perm-select">
<option value="viewer">Viewer</option>
<option value="editor">Editor</option>
<option value="admin">Admin</option>
</select>
<button class="btn-add-share" @click="addShare" :disabled="saving || !selectedGroupId">Add</button>
</div>
</div>
<!-- Current shares -->
<div class="shares-list-wrap">
<p class="shares-label">Current access</p>
<ul class="shares-list">
<li v-for="share in shares" :key="share.id" class="share-row">
<span class="share-target-icon">{{ share.shared_with_user_id ? '👤' : '👥' }}</span>
<span class="share-target-name">
{{ share.shared_with_user_id ? share.username : share.group_name }}
</span>
<select
class="perm-select-inline"
:value="share.permission"
@change="changePermission(share, ($event.target as HTMLSelectElement).value)"
>
<option value="viewer">Viewer</option>
<option value="editor">Editor</option>
<option value="admin">Admin</option>
</select>
<button class="btn-remove-share" @click="removeShare(share)" aria-label="Remove"></button>
</li>
<li v-if="!shares.length" class="shares-empty">Not shared with anyone yet</li>
</ul>
</div>
</div>
</div>
</Teleport>
</template>
<style scoped>
.share-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.share-dialog {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
width: 480px;
max-width: 95vw;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
.share-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1.25rem 1.5rem;
border-bottom: 1px solid var(--color-border);
}
.share-title {
font-family: 'Fraunces', Georgia, serif;
font-size: 1.1rem;
font-weight: 700;
margin: 0;
color: var(--color-text);
}
.btn-close {
background: none;
border: none;
color: var(--color-muted);
cursor: pointer;
font-size: 1.1rem;
padding: 0.25rem;
line-height: 1;
border-radius: 4px;
transition: color 0.15s;
}
.btn-close:hover { color: var(--color-text); }
.share-add {
padding: 1rem 1.5rem;
border-bottom: 1px solid var(--color-border);
}
.share-tabs {
display: flex;
gap: 0.25rem;
margin-bottom: 0.75rem;
}
.share-tab {
background: none;
border: 1px solid var(--color-border);
border-radius: 6px;
padding: 0.3rem 0.8rem;
font-size: 0.82rem;
cursor: pointer;
color: var(--color-muted);
transition: all 0.15s;
}
.share-tab.active {
background: var(--color-primary);
border-color: var(--color-primary);
color: #fff;
}
.share-target-form {
display: flex;
gap: 0.5rem;
align-items: flex-start;
flex-wrap: wrap;
}
.user-search-wrap {
flex: 1;
position: relative;
}
.share-input {
width: 100%;
padding: 0.45rem 0.7rem;
border: 1px solid var(--color-border);
border-radius: 6px;
background: var(--color-surface);
color: var(--color-text);
font-size: 0.9rem;
outline: none;
transition: border-color 0.15s;
}
.share-input:focus { border-color: var(--color-primary); }
.user-results {
position: absolute;
top: 100%;
left: 0;
right: 0;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 6px;
margin-top: 2px;
list-style: none;
padding: 0.25rem 0;
z-index: 10;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
max-height: 180px;
overflow-y: auto;
}
.user-result-item {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 0.8rem;
cursor: pointer;
transition: background 0.1s;
}
.user-result-item:hover { background: var(--color-hover); }
.user-result-name { font-weight: 600; font-size: 0.88rem; }
.user-result-email { color: var(--color-muted); font-size: 0.8rem; }
.perm-select {
padding: 0.45rem 0.5rem;
border: 1px solid var(--color-border);
border-radius: 6px;
background: var(--color-surface);
color: var(--color-text);
font-size: 0.85rem;
cursor: pointer;
}
.btn-add-share {
padding: 0.45rem 1rem;
background: linear-gradient(135deg, #6366f1, #4f46e5);
color: #fff;
border: none;
border-radius: 6px;
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
transition: opacity 0.15s;
white-space: nowrap;
}
.btn-add-share:disabled { opacity: 0.5; cursor: not-allowed; }
.shares-list-wrap {
padding: 1rem 1.5rem 1.5rem;
}
.shares-label {
font-size: 0.78rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--color-muted);
margin: 0 0 0.5rem;
}
.shares-list {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 0.35rem;
}
.share-row {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 0.75rem;
border-radius: 8px;
background: var(--color-hover);
}
.share-target-icon { font-size: 1rem; flex-shrink: 0; }
.share-target-name { flex: 1; font-size: 0.88rem; font-weight: 500; }
.perm-select-inline {
padding: 0.25rem 0.4rem;
border: 1px solid var(--color-border);
border-radius: 4px;
background: var(--color-surface);
color: var(--color-text);
font-size: 0.8rem;
cursor: pointer;
}
.btn-remove-share {
background: none;
border: none;
color: var(--color-muted);
cursor: pointer;
font-size: 0.9rem;
padding: 0.15rem 0.3rem;
border-radius: 4px;
transition: color 0.15s;
flex-shrink: 0;
}
.btn-remove-share:hover { color: var(--color-danger, #ef4444); }
.shares-empty {
color: var(--color-muted);
font-size: 0.85rem;
font-style: italic;
text-align: center;
padding: 0.75rem;
}
</style>