c7ef709633
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>
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import ForeignKey, Integer, Text, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from fabledassistant.models import Base
|
|
from fabledassistant.models.base import CreatedAtMixin, TimestampMixin
|
|
|
|
|
|
class Group(Base, TimestampMixin):
|
|
__tablename__ = "groups"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
name: Mapped[str] = mapped_column(Text, nullable=False, unique=True)
|
|
description: Mapped[str | None] = mapped_column(Text)
|
|
created_by: Mapped[int | None] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="SET NULL")
|
|
)
|
|
|
|
memberships: Mapped[list["GroupMembership"]] = relationship(
|
|
"GroupMembership", back_populates="group", cascade="all, delete-orphan"
|
|
)
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"created_by": self.created_by,
|
|
"created_at": self.created_at.isoformat(),
|
|
"updated_at": self.updated_at.isoformat(),
|
|
}
|
|
|
|
|
|
class GroupMembership(Base, CreatedAtMixin):
|
|
__tablename__ = "group_memberships"
|
|
__table_args__ = (UniqueConstraint("group_id", "user_id", name="uq_gm_group_user"),)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
group_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("groups.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
role: Mapped[str] = mapped_column(Text, nullable=False, default="member")
|
|
|
|
group: Mapped["Group"] = relationship("Group", back_populates="memberships")
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"group_id": self.group_id,
|
|
"user_id": self.user_id,
|
|
"role": self.role,
|
|
"created_at": self.created_at.isoformat(),
|
|
}
|