feat(project): PC tray notifier for mentions and assignments

Windows tray app (desktop/notifier, C# .NET Framework 4.8 WinForms,
single exe, no installer/admin) that shows the same big alert popup as
the web even when the browser is in the background: layered topmost
window that does not steal focus, blinking border, open/close actions,
sound, autostart toggle, DPAPI-encrypted token.

Server side (project_db migration 023):
- notifier_links / notifier_tokens (SHA-256 hashes only)
- device link flow: link/start -> browser approve at /project/notifier
  -> link/poll issues token once
- Bearer API for alerts/read/logout reusing _alerts_payload; token
  re-checks current user record and project permission each call
- /project/notifier page (approve, connected PCs, revoke, download)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 10:21:58 +09:00
parent 8f46d6c13a
commit 06af036f86
24 changed files with 2093 additions and 3 deletions
@@ -7,7 +7,7 @@
my_open_total 진행 중인 내 업무 개수 (내 업무 배지)
nav_projects 프로젝트 목록(평면)
current_pid 지금 보고 있는 프로젝트 id (내 업무/수신함 화면이면 0)
side_active 'inbox' | 'mytasks' | 'trash' | 'goals' | '' — 개인 메뉴 활성 표시
side_active 'inbox' | 'mytasks' | 'notifier' | 'trash' | 'goals' | '' — 개인 메뉴 활성 표시
goal_years "목표" 아래 연도 목록(router._goal_years_nav — 올해는 항상 포함)
goal_year_active 목표 화면에서 보고 있는 연도
is_admin 프로젝트 생성/수정/삭제 권한
@@ -44,6 +44,11 @@
<span class="pj-side-navbadge pj-side-navbadge-open" id="pj-myopen-badge"
{% if not my_open_total %}hidden{% endif %}>{{ my_open_total }}</span>
</a>
{# PC 알림 — 트레이 프로그램(desktop/notifier) 내려받기·연결 승인·연결된 PC 해제(023) #}
<a class="pj-side-navlink {% if side_active == 'notifier' %}is-active{% endif %}" href="/project/notifier">
<span class="material-symbols-outlined pj-side-navic">desktop_windows</span>
<span class="pj-side-navtext">PC 알림</span>
</a>
{# 휴지통 — 관리자만 보이고(화면·복구 API 도 관리자 전용), 지운 업무를 3개월 보관. #}
{% if is_admin %}
<a class="pj-side-navlink {% if side_active == 'trash' %}is-active{% endif %}" href="/project/trash">
@@ -0,0 +1,112 @@
{% extends "erp_base.html" %}
{% block head_extra %}
<link rel="stylesheet" href="/static/project.css?v=20261008a" />
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
{% endblock %}
{% block topbar_after_logout %}{% include "project/_help_btn.html" %}{% endblock %}
{% block content %}
{# PC 알림 프로그램(023) — 트레이 프로그램(desktop/notifier) 내려받기, 연결 승인(?code=), 연결된 PC 해제.
토큰은 프로그램이 받아 PC 에 암호화 저장(Windows DPAPI). 이 화면은 토큰 원문을 보지 않는다. #}
<div class="pj-wrap pj-inbox-view pj-notifier-view">
<div class="pj-layout">
{% with current_pid = 0, side_active = "notifier" %}{% include "project/_side.html" %}{% endwith %}
<section class="pj-main">
<div class="pj-section-head"><h2>PC 알림 프로그램</h2></div>
<div class="pj-view pj-inbox-pane pj-notifier-pane">
{% if not notifier_enabled %}
<div class="pj-empty">PC 알림 연결이 아직 준비되지 않았습니다(DB 마이그레이션 023 필요).</div>
{% else %}
{% if code %}
<div class="pj-notifier-card is-link" id="pj-notifier-link" data-code="{{ code }}">
{% if link and not link.approved_at %}
<h3>이 PC 를 내 알림에 연결할까요?</h3>
<p>PC 이름 <b>{{ link.device_name or '-' }}</b> · 연결 코드 <b class="pj-notifier-code">{{ link.code }}</b></p>
<p class="pj-notifier-note">알림 프로그램 창에 보이는 코드와 같을 때만 연결하세요. 연결하면 그 PC 에
<b>{{ user.name or user.email }}</b> 님의 태그·작업 배정 알림이 뜹니다.</p>
<button type="button" class="pj-btn pj-btn-primary" id="pj-notifier-approve">연결</button>
{% elif link %}
<h3>이미 연결을 승인했습니다</h3>
<p class="pj-notifier-note">알림 프로그램이 곧 연결을 마칩니다. 이 창은 닫아도 됩니다.</p>
{% else %}
<h3>연결 코드가 없거나 만료되었습니다</h3>
<p class="pj-notifier-note">연결 코드는 10분 동안만 쓸 수 있습니다. 알림 프로그램에서 [연결]을 다시 누르세요.</p>
{% endif %}
</div>
{% endif %}
<div class="pj-notifier-card">
<h3>설치</h3>
<ol class="pj-notifier-steps">
<li>{% if download_ready %}<a class="pj-btn pj-btn-primary pj-btn-sm" href="/project/notifier/download">DBXNotifier.exe 내려받기</a>
{% else %}관리자에게 <b>DBXNotifier.exe</b> 파일을 받으세요.{% endif %}
설치 없이 파일 하나로 실행됩니다(Windows 10·11).</li>
<li>실행하면 화면 오른쪽 아래 트레이에 종 아이콘이 생기고 연결 창이 열립니다. [브라우저에서 연결]을 누르세요.</li>
<li>열린 이 화면에서 코드를 확인하고 [연결]을 누르면 끝입니다. 트레이 아이콘 메뉴에서 [Windows 시작 시 실행]을 켜 두세요.</li>
</ol>
<p class="pj-notifier-note">나를 태그하거나 작업이 배정되면 다른 프로그램을 쓰고 있어도 화면 아래 가운데에 큰 알림 창이 뜹니다.
[열기]를 누르면 브라우저에서 그 작업이 열립니다.</p>
</div>
<div class="pj-notifier-card">
<h3>연결된 PC</h3>
{% if devices %}
<table class="pj-table pj-notifier-table">
<thead><tr><th>PC 이름</th><th>연결한 때</th><th>마지막 확인</th><th></th></tr></thead>
<tbody>
{% for d in devices %}
<tr>
<td>{{ d.device_name or '-' }}</td>
<td>{{ (d.created_at or '')[:16] | replace('T', ' ') }}</td>
<td>{{ (d.last_seen_at or '-')[:16] | replace('T', ' ') }}</td>
<td class="pj-trash-act"><button type="button" class="pj-btn pj-btn-sm pj-notifier-revoke"
data-id="{{ d.id }}" data-name="{{ d.device_name }}">연결 해제</button></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="pj-notifier-note">연결된 PC 가 없습니다.</p>
{% endif %}
</div>
{% endif %}
</div>
</section>
</div>
</div>
{% include "project/_side_modals.html" %}
{% include "project/_member_tasks_modal.html" %}
<script>
(function () {
async function post(url, body) {
const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body || {}) });
const data = await res.json().catch(function () { return {}; });
if (!res.ok) throw new Error(data.detail || ("HTTP " + res.status));
return data;
}
const approve = document.getElementById("pj-notifier-approve");
if (approve) approve.addEventListener("click", async function () {
approve.disabled = true;
try {
await post("/project/api/notifier/link/approve", { code: document.getElementById("pj-notifier-link").dataset.code });
location.replace("/project/notifier?code=" + encodeURIComponent(document.getElementById("pj-notifier-link").dataset.code));
} catch (e) { approve.disabled = false; alert("연결 실패: " + e.message); }
});
document.querySelectorAll(".pj-notifier-revoke").forEach(function (b) {
b.addEventListener("click", async function () {
if (!confirm((b.dataset.name || "이 PC") + " 의 알림 연결을 해제할까요?")) return;
b.disabled = true;
try { await post("/project/api/notifier/devices/" + b.dataset.id + "/revoke"); location.reload(); }
catch (e) { b.disabled = false; alert("해제 실패: " + e.message); }
});
});
})();
</script>
<script src="/static/project.js?v=20261007m" defer></script>
{% endblock %}