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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ cd frontend && npx playwright test e2e/questions.spec.ts

`frontend/e2e/git.spec.ts` covers git integration on the same stack, with the same requirements as the workflow test (the Go toolchain and `git` on the PATH). It starts a fake GitHub Enterprise API on the host (`frontend/e2e/helpers/fakeGit.ts`, on a free port), which the stack reaches as `http://host.docker.internal:<port>` (the compose file maps that name for the backend and worker). An admin adds the connection in Admin → Git with a token and a webhook secret, and **Test** shows the fake login. Project GIT requires a human code review, and its repository is linked to the connection. The fake agent runs GIT-1 to Finish, which reports pull request #1: the task shows "PR open · checks pending" and waits. The fake host then marks it merged, and a signed webhook makes MegooColab look: the task finishes by itself. A forged or unsigned delivery gets 401. GIT-3's pull request #2 is closed without a merge: the workflow escalates `pr_closed`, and **Accept** finishes it.

`frontend/e2e/notifications.spec.ts` covers notifications on the same stack (it also builds the runner and the fake agent). The admin assigns NOT-1 to an invited member, whose bell shows 1, and the notification opens the task. A mention made with the comment picker reaches her; an outsider mentioned by hand gets nothing. The admin's agent submits NOT-2's design, and the owner is told it awaits approval. Turning off in-app assignments silences the next one. A new notification chimes in her open tab, and no longer once she turns the sound off.
`frontend/e2e/notifications.spec.ts` covers notifications on the same stack (it also builds the runner and the fake agent). The admin assigns NOT-1 to an invited member, whose bell shows 1, and the notification opens the task. A mention made with the comment picker reaches her; an outsider mentioned by hand gets nothing. The admin's agent submits NOT-2's design, and the owner is told it awaits approval. Turning off in-app assignments silences the next one. A new notification chimes in her open tab, and no longer once she turns the sound off. While anything is unread, her tab title starts with the count and the favicon carries a bell, also after a page change, and reading everything in one tab clears both in her other tab.

Both create their own users, teams and projects (GIT and NOT), so they need a fresh stack. To run them:

Expand Down
10 changes: 8 additions & 2 deletions backend/app/notifications/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from app.audit import service as audit
from app.auth.deps import AuthedUser
from app.core.db import DbSession
from app.core.events import Event, publish
from app.notifications.models import DEFAULT_PREFS, Kind, Notification, NotificationPref
from app.notifications.schemas import NotificationOut, NotificationPrefIO, UnreadCount

Expand Down Expand Up @@ -48,14 +49,19 @@ async def mark_read(notification_id: uuid.UUID, user: AuthedUser, db: DbSession)
raise HTTPException(status.HTTP_404_NOT_FOUND, "notification_not_found")
if n.read_at is None:
n.read_at = datetime.now(UTC)
# the person's other tabs and devices refresh their count
await publish(db, Event(type="notification.read", user_id=user.id))
await db.commit()
return Response(status_code=status.HTTP_204_NO_CONTENT)


@router.post("/api/notifications/read-all", status_code=status.HTTP_204_NO_CONTENT)
async def mark_all_read(user: AuthedUser, db: DbSession) -> Response:
await db.execute(update(Notification).where(Notification.user_id == user.id, Notification.read_at.is_(None))
.values(read_at=datetime.now(UTC)))
done = await db.execute(update(Notification).where(Notification.user_id == user.id,
Notification.read_at.is_(None))
.values(read_at=datetime.now(UTC)))
if done.rowcount: # the person's other tabs and devices refresh their count
await publish(db, Event(type="notification.read", user_id=user.id))
await db.commit()
return Response(status_code=status.HTTP_204_NO_CONTENT)

Expand Down
32 changes: 32 additions & 0 deletions backend/tests/notifications/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from app.core.email import OutboxMailer
from app.jobs.models import Job
from app.notifications import jobs as notify_jobs
from app.notifications import router as notify_router
from app.notifications import service
from app.notifications.models import Kind, Notification
from app.org.models import ORG_SETTINGS_ID, OrgSettings
Expand Down Expand Up @@ -201,6 +202,37 @@ async def test_list_read_and_unread_count(client_factory, db):
assert task


async def test_mark_read_tells_other_tabs(client_factory, db, monkeypatch):
"""Reading in one tab tells the person's other tabs and devices, so their bell (and tab badge) follows."""
_manager, bea, _m, b, _task = await _world(client_factory, db)
async with SessionLocal() as s:
for i in range(2):
s.add(Notification(user_id=bea.id, kind="assigned", title=f"r{i}", body="", link="/x"))
await s.commit()
first, second = [n for n in await _rows(bea.id) if n.title in ("r0", "r1")]
seen = []
real = notify_router.publish

async def capture(session, event):
seen.append((event.type, event.user_id))
await real(session, event)

monkeypatch.setattr(notify_router, "publish", capture)
other = client_factory()
await login(other, await make_user(db))
assert (await other.post(f"/api/notifications/{first.id}/read")).status_code == 404
assert seen == [] # someone else's notification: nothing read, nothing sent
assert (await b.post(f"/api/notifications/{first.id}/read")).status_code == 204
assert seen == [("notification.read", bea.id)]
assert (await b.post(f"/api/notifications/{first.id}/read")).status_code == 204
assert len(seen) == 1 # already read: no event
assert (await b.post("/api/notifications/read-all")).status_code == 204
assert seen == [("notification.read", bea.id)] * 2 # second (and any other unread) became read
assert (await b.post("/api/notifications/read-all")).status_code == 204
assert len(seen) == 2 # nothing unread: no event
assert second


async def test_live_event_per_user(client_factory, db, monkeypatch):
_manager, bea, _m, _b, task = await _world(client_factory, db)
seen = []
Expand Down
4 changes: 3 additions & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ to you or your agent, a mention (`@` in a comment), your agent going offline mid
questions that need a person. Each person chooses, per kind, in-app, email and push under **avatar → Notifications**
(`/settings/notifications`). Email needs SMTP (section 7); its links use `PUBLIC_URL`. While MegooColab is open in a
browser, a short chime also plays when a new notification arrives (after the first click in the tab, as browsers
require); each person turns it off for that browser in the **Sound** card on the same page.
require); each person turns it off for that browser in the **Sound** card on the same page. While anything is unread,
the browser tab shows it too: the title starts with the count, such as `(3) Projects · MegooColab`, and the icon
carries a small red bell.

### Push notifications

Expand Down
Loading
Loading