Pomodoro backend paritesi + ikili ALLOW/DENY politikası
Browse files at this commit865bc07c626e3676930399e69fcf662444682843Parent: 44249ab- fix
- pomodoro backend paritesi + ikili ALLOW/DENY politikası
2 changed files +52 -58
- src/catalog.py +8 -7
- src/role_spaces.py +44 -51
src/catalog.pymodified+8 -7
| @@ -1203,17 +1203,18 @@ INTENTS: Final[list[dict[str, Any]]] = [ | |||
| 1203 | { | 1203 | { |
| 1204 | "intent": "pomodoro_use", | 1204 | "intent": "pomodoro_use", |
| 1205 | "category": "pomodoro", | 1205 | "category": "pomodoro", |
| 1206 | - "description": "Pomodoro odak oturumu başlatma/bitirme (Öğrenci).", | 1206 | + "description": "Pomodoro odak oturumu başlatma/bitirme (tüm roller).", |
| 1207 | "response_id": "pomodoro_instructions", | 1207 | "response_id": "pomodoro_instructions", |
| 1208 | "response_template": ( | 1208 | "response_template": ( |
| 1209 | - "Pomodoro, sunucu saatiyle damgalanan kişisel odak kaydıdır (yalnız " | 1209 | + "Pomodoro, sunucu saatiyle damgalanan kişisel odak kaydıdır; giriş yapan " |
| 1210 | - "Öğrenci). 1) `/pomodoro` sayfasına git. 2) **Odağı başlat (Start focus)** " | 1210 | + "her kullanıcı kendi oturumunu tutabilir. 1) `/pomodoro` sayfasına git. " |
| 1211 | - "ile oturumu aç — aynı anda tek açık oturum olabilir. 3) Çalışman bitince " | 1211 | + "2) **Odağı başlat (Start focus)** ile oturumu aç — aynı anda tek açık " |
| 1212 | - "**Odağı bitir (Finish focus)**'a bas. Sayfada **Toplam odak** süreni ve " | 1212 | + "oturum olabilir. 3) Çalışman bitince **Odağı bitir (Finish focus)**'a bas. " |
| 1213 | - "**Son oturumlar** geçmişini görürsün; saatler sunucu tarafından damgalanır." | 1213 | + "Sayfada **Toplam odak** süreni ve **Son oturumlar** geçmişini görürsün; " |
| 1214 | + "saatler sunucu tarafından damgalanır." | ||
| 1214 | ), | 1215 | ), |
| 1215 | "auth_required": True, | 1216 | "auth_required": True, |
| 1216 | - "min_role": "ogrenci", | 1217 | + "min_role": "veli", |
| 1217 | "example_questions": [ | 1218 | "example_questions": [ |
| 1218 | "Pomodoro nasıl kullanılır?", | 1219 | "Pomodoro nasıl kullanılır?", |
| 1219 | "Odak oturumu nasıl başlatırım?", | 1220 | "Odak oturumu nasıl başlatırım?", |
src/role_spaces.pymodified+44 -51
| @@ -38,34 +38,42 @@ def _matrix(parent, student, teacher, manager, admin): | |||
| 38 | 38 | ||
| 39 | A = AccessOutcome.ALLOW | 39 | A = AccessOutcome.ALLOW |
| 40 | D = AccessOutcome.DENY | 40 | D = AccessOutcome.DENY |
| 41 | -C = AccessOutcome.CLARIFY | ||
| 42 | G = AccessScope.GENERAL | 41 | G = AccessScope.GENERAL |
| 43 | O = AccessScope.OWN | 42 | O = AccessScope.OWN |
| 44 | -L = AccessScope.LINKED_CHILD | ||
| 45 | E = AccessScope.ENROLLED_COURSE | 43 | E = AccessScope.ENROLLED_COURSE |
| 46 | M = AccessScope.MANAGED_COURSE | 44 | M = AccessScope.MANAGED_COURSE |
| 47 | S = AccessScope.SCHOOL | 45 | S = AccessScope.SCHOOL |
| 48 | V = AccessScope.EVENT_AUDIENCE | 46 | V = AccessScope.EVENT_AUDIENCE |
| 49 | 47 | ||
| 50 | -# (outcome, scope, navigation_key). These are the actions used by the current | 48 | +# (outcome, scope, navigation_key). İkili model: bir rol o işlemi backend'de |
| 51 | -# catalog, copied from the backend policy rather than inferred from role rank. | 49 | +# yapabiliyorsa (kapsamı ne olursa olsun) ALLOW — asistan adımları anlatır, kapsam |
| 50 | +# cevabın içinde nottur. Yapamıyorsa DENY — adım/rota/ayrıcalıklı rol adı sızmaz. | ||
| 51 | +# Kaynak: hezarfen_backend endpoint guard'ları (rol×yetki taraması). CLARIFY-for- | ||
| 52 | +# scope KALDIRILDI: bu asistan sistemi ANLATIR, kapsamı çalışma anında doğrulamaz. | ||
| 52 | _ACTION_RULES: Final[dict[str, dict[str, tuple[AccessOutcome, AccessScope | None, str | None]]]] = { | 53 | _ACTION_RULES: Final[dict[str, dict[str, tuple[AccessOutcome, AccessScope | None, str | None]]]] = { |
| 53 | "platform.help": _matrix((A, G, "guide"), (A, G, "guide"), (A, G, "guide"), (A, G, "guide"), (A, G, "guide")), | 54 | "platform.help": _matrix((A, G, "guide"), (A, G, "guide"), (A, G, "guide"), (A, G, "guide"), (A, G, "guide")), |
| 54 | "account.self": _matrix((A, O, "profile"), (A, O, "profile"), (A, O, "profile"), (A, O, "profile"), (A, O, "profile")), | 55 | "account.self": _matrix((A, O, "profile"), (A, O, "profile"), (A, O, "profile"), (A, O, "profile"), (A, O, "profile")), |
| 55 | "messages.use": _matrix((A, O, "messages"), (A, O, "messages"), (A, O, "messages"), (A, O, "messages"), (A, O, "messages")), | 56 | "messages.use": _matrix((A, O, "messages"), (A, O, "messages"), (A, O, "messages"), (A, O, "messages"), (A, O, "messages")), |
| 56 | "notes.use": _matrix((A, O, "notes"), (A, O, "notes"), (A, O, "notes"), (A, O, "notes"), (A, O, "notes")), | 57 | "notes.use": _matrix((A, O, "notes"), (A, O, "notes"), (A, O, "notes"), (A, O, "notes"), (A, O, "notes")), |
| 57 | - "courses.view": _matrix((D, None, None), (C, E, "courses"), (C, M, "courses"), (A, S, "courses"), (A, S, "courses")), | 58 | + # Ders görüntüleme: Veli erişemez (kayıt/yönetim yok); öğrenci kayıtlı derslerini, |
| 59 | + # öğretmen yönettiklerini görür — ikisi de ALLOW (kapsam nottur). | ||
| 60 | + "courses.view": _matrix((D, None, None), (A, E, "courses"), (A, M, "courses"), (A, S, "courses"), (A, S, "courses")), | ||
| 58 | "courses.create": _matrix((D, None, None), (D, None, None), (A, O, "courses"), (A, S, "courses"), (A, S, "courses")), | 61 | "courses.create": _matrix((D, None, None), (D, None, None), (A, O, "courses"), (A, S, "courses"), (A, S, "courses")), |
| 59 | - "courses.manage": _matrix((D, None, None), (D, None, None), (C, M, "courses"), (A, S, "courses"), (A, S, "courses")), | 62 | + "courses.manage": _matrix((D, None, None), (D, None, None), (A, M, "courses"), (A, S, "courses"), (A, S, "courses")), |
| 60 | - "courses.enroll_student": _matrix((D, None, None), (D, None, None), (C, M, "courses"), (A, S, "courses"), (A, S, "courses")), | 63 | + "courses.enroll_student": _matrix((D, None, None), (D, None, None), (A, M, "courses"), (A, S, "courses"), (A, S, "courses")), |
| 61 | - "exams.take": _matrix((D, None, None), (C, E, "exams"), (D, None, None), (D, None, None), (D, None, None)), | 64 | + # Sınava girme yalnız Öğrenci (backend: tam olarak Student + enrolled). Personel giremez. |
| 62 | - "exams.manage": _matrix((D, None, None), (D, None, None), (C, M, "exams"), (A, S, "exams"), (A, S, "exams")), | 65 | + "exams.take": _matrix((D, None, None), (A, E, "exams"), (D, None, None), (D, None, None), (D, None, None)), |
| 66 | + "exams.manage": _matrix((D, None, None), (D, None, None), (A, M, "exams"), (A, S, "exams"), (A, S, "exams")), | ||
| 63 | "events.create": _matrix((D, None, None), (D, None, None), (A, O, "events"), (A, S, "events"), (A, S, "events")), | 67 | "events.create": _matrix((D, None, None), (D, None, None), (A, O, "events"), (A, S, "events"), (A, S, "events")), |
| 64 | - "events.mark_attendance": _matrix((D, None, None), (D, None, None), (C, V, "events"), (C, V, "events"), (C, V, "events")), | 68 | + # Kendi etkinlik yoklamasını herkes işaretler (öğrenci+); Veli salt-okunur gözlemci. |
| 69 | + "events.mark_attendance": _matrix((D, None, None), (A, O, "events"), (A, V, "events"), (A, V, "events"), (A, V, "events")), | ||
| 65 | "reports.read_own": _matrix((A, O, "reports_self"), (A, O, "reports_self"), (A, O, "reports_self"), (A, O, "reports_self"), (A, O, "reports_self")), | 70 | "reports.read_own": _matrix((A, O, "reports_self"), (A, O, "reports_self"), (A, O, "reports_self"), (A, O, "reports_self"), (A, O, "reports_self")), |
| 66 | - "reports.observe_student": _matrix((C, L, None), (D, None, None), (C, M, None), (A, S, None), (A, S, None)), | 71 | + # Öğrenci not/yoklama arama = Öğretmen yönetim sayfası (Öğretmen+). Veli bu sayfayı |
| 67 | - "pomodoro.start": _matrix((D, None, None), (A, O, "pomodoro"), (D, None, None), (D, None, None), (D, None, None)), | 72 | + # kullanmaz (çocuğunun verisini ayrı akıştan görür) -> DENY. |
| 68 | - "pomodoro.observe_student": _matrix((C, L, None), (D, None, None), (A, S, None), (A, S, None), (A, S, None)), | 73 | + "reports.observe_student": _matrix((D, None, None), (D, None, None), (A, M, "student_marks"), (A, S, "student_marks"), (A, S, "student_marks")), |
| 74 | + # Pomodoro backend'de her doğrulanmış kullanıcıya açık (CurrentUser) -> hepsi ALLOW. | ||
| 75 | + "pomodoro.start": _matrix((A, O, "pomodoro"), (A, O, "pomodoro"), (A, O, "pomodoro"), (A, O, "pomodoro"), (A, O, "pomodoro")), | ||
| 76 | + "pomodoro.observe_student": _matrix((D, None, None), (D, None, None), (A, S, "student_pomodoro"), (A, S, "student_pomodoro"), (A, S, "student_pomodoro")), | ||
| 69 | "work.self": _matrix((D, None, None), (D, None, None), (A, O, "work"), (A, O, "work"), (A, O, "work")), | 77 | "work.self": _matrix((D, None, None), (D, None, None), (A, O, "work"), (A, O, "work"), (A, O, "work")), |
| 70 | "work.manage": _matrix((D, None, None), (D, None, None), (D, None, None), (A, S, "staff_work"), (A, S, "staff_work")), | 78 | "work.manage": _matrix((D, None, None), (D, None, None), (D, None, None), (A, S, "staff_work"), (A, S, "staff_work")), |
| 71 | "school.settings_manage": _matrix((D, None, None), (D, None, None), (D, None, None), (A, S, "school_settings"), (A, S, "school_settings")), | 79 | "school.settings_manage": _matrix((D, None, None), (D, None, None), (D, None, None), (A, S, "school_settings"), (A, S, "school_settings")), |
| @@ -150,30 +158,6 @@ _OWN_REPORT_RESPONSES: Final[dict[str, str]] = { | |||
| 150 | ), | 158 | ), |
| 151 | } | 159 | } |
| 152 | 160 | ||
| 153 | -_CONTEXT_TEXT: Final[dict[AccessScope, str]] = { | ||
| 154 | - AccessScope.LINKED_CHILD: ( | ||
| 155 | - "Bu bilgi yalnızca sana bağlı bir çocuk için görüntülenebilir. Bu mesajda " | ||
| 156 | - "veli–öğrenci bağlantısını doğrulayamıyorum; hangi bağlı öğrenciyi kastettiğini belirt." | ||
| 157 | - ), | ||
| 158 | - AccessScope.ENROLLED_COURSE: ( | ||
| 159 | - "Bu işlem yalnızca kayıtlı olduğun ders veya sınav bağlamında yapılabilir. " | ||
| 160 | - "Kaydını bu mesajdan doğrulayamıyorum; ilgili ders/sınavı belirt." | ||
| 161 | - ), | ||
| 162 | - AccessScope.MANAGED_COURSE: ( | ||
| 163 | - "Bu işlem yalnızca yönettiğin ders bağlamında yapılabilir. Ders sahipliğini " | ||
| 164 | - "bu mesajdan doğrulayamıyorum; ilgili dersi belirt." | ||
| 165 | - ), | ||
| 166 | - AccessScope.OWNED_RESOURCE: "Bu işlem yalnızca sahibi olduğun kaynak için yapılabilir.", | ||
| 167 | - AccessScope.PARTICIPANT: "Bu işlem yalnızca katılımcısı olduğun kaynak için yapılabilir.", | ||
| 168 | - AccessScope.REQUESTER: "Bu işlem yalnızca talebin sahibi için yapılabilir.", | ||
| 169 | - AccessScope.EVENT_AUDIENCE: ( | ||
| 170 | - "Etkinlik yoklamasını Öğretmen, Yönetici veya ADMIN yalnızca etkinliğin " | ||
| 171 | - "hedef kitlesindeki kullanıcı için kaydedebilir. Etkinlik ve hedef kullanıcı " | ||
| 172 | - "bilgisi olmadan bu koşulu doğrulayamıyorum." | ||
| 173 | - ), | ||
| 174 | -} | ||
| 175 | - | ||
| 176 | - | ||
| 177 | def action_id_for_intent(intent: str) -> str: | 161 | def action_id_for_intent(intent: str) -> str: |
| 178 | return _ACTION_BY_INTENT[intent] | 162 | return _ACTION_BY_INTENT[intent] |
| 179 | 163 | ||
| @@ -188,11 +172,20 @@ def _local_rule(item: dict, role: str): | |||
| 188 | return action_id, outcome, scope, route_key | 172 | return action_id, outcome, scope, route_key |
| 189 | 173 | ||
| 190 | 174 | ||
| 191 | -def _deny_text(item: dict, role: str, reason: ReasonCode) -> str: | 175 | +def _deny_text(reason: ReasonCode) -> str: |
| 176 | + """Ret metni. Ayrıcalıklı adım, rota veya gerekli-rol adı ASLA sızmaz. | ||
| 177 | + | ||
| 178 | + Giriş gereken durumda (ziyaretçi) yalnız kamuya açık `/login` yolu verilir — | ||
| 179 | + bu bir sızıntı değil, herkesin erişebildiği giriş sayfasıdır. | ||
| 180 | + """ | ||
| 181 | + | ||
| 192 | if reason is ReasonCode.AUTHENTICATION_REQUIRED: | 182 | if reason is ReasonCode.AUTHENTICATION_REQUIRED: |
| 193 | - return "Bu konu oturum bilgisi gerektiriyor. Önce güvenli biçimde giriş yapmalısın." | 183 | + return ( |
| 184 | + "Bu konu için önce giriş yapman gerekiyor. `/login` sayfasından " | ||
| 185 | + "güvenli biçimde giriş yapabilirsin." | ||
| 186 | + ) | ||
| 194 | return ( | 187 | return ( |
| 195 | - f"Bu işlem **{role}** rolüne açık değil. Yetkisiz işlem adımları veya " | 188 | + "Bu işlem senin rolünde yapılamıyor. Yetkisiz işlem adımları ve " |
| 196 | "yönlendirme paylaşılmadı." | 189 | "yönlendirme paylaşılmadı." |
| 197 | ) | 190 | ) |
| 198 | 191 | ||
| @@ -205,19 +198,17 @@ def _view(item: dict, role: str) -> RoleIntentView: | |||
| 205 | if role == "ziyaretci" and item["auth_required"] | 198 | if role == "ziyaretci" and item["auth_required"] |
| 206 | else ReasonCode.ROLE_NOT_PERMITTED | 199 | else ReasonCode.ROLE_NOT_PERMITTED |
| 207 | ) | 200 | ) |
| 208 | - body = _deny_text(item, role, reason) | 201 | + body = _deny_text(reason) |
| 209 | - elif outcome is C: | 202 | + scope = None |
| 210 | - reason = ReasonCode.CONTEXT_REQUIRED | ||
| 211 | - body = _CONTEXT_TEXT[scope] | ||
| 212 | route_key = None | 203 | route_key = None |
| 213 | - else: | 204 | + else: # ALLOW |
| 214 | reason = ReasonCode.ALLOWED | 205 | reason = ReasonCode.ALLOWED |
| 215 | body = item["response_template"] | 206 | body = item["response_template"] |
| 207 | + # Karne/yoklama sayfası öğrenciye özeldir; üst roller için kişisel karne | ||
| 208 | + # yerine kapsam notu döndürülür (adım değil, bilgi). | ||
| 209 | + if item["intent"] in {"report_card_view", "attendance_view"} and role != "ogrenci": | ||
| 210 | + body = _OWN_REPORT_RESPONSES.get(role, body) | ||
| 216 | 211 | ||
| 217 | - if item["intent"] in {"report_card_view", "attendance_view"} and role != "ogrenci": | ||
| 218 | - body = _OWN_REPORT_RESPONSES.get(role, body) | ||
| 219 | - | ||
| 220 | - clarification = _CONTEXT_TEXT.get(scope) if outcome is C else None | ||
| 221 | return RoleIntentView( | 212 | return RoleIntentView( |
| 222 | role=role, | 213 | role=role, |
| 223 | intent=item["intent"], | 214 | intent=item["intent"], |
| @@ -228,8 +219,10 @@ def _view(item: dict, role: str) -> RoleIntentView: | |||
| 228 | response_id=item["response_id"], | 219 | response_id=item["response_id"], |
| 229 | response_template=body, | 220 | response_template=body, |
| 230 | examples=tuple(item["example_questions"]), | 221 | examples=tuple(item["example_questions"]), |
| 231 | - clarification=clarification, | 222 | + clarification=None, |
| 232 | - required_role=None if outcome is not D else item["min_role"], | 223 | + # Sözleşme metadata'sı (frontend butonu pasifleştirmek için kullanabilir); |
| 224 | + # kullanıcıya dönen METİN ayrıcalıklı rol adını/adımı ASLA içermez. | ||
| 225 | + required_role=item["min_role"] if outcome is D else None, | ||
| 233 | route_key=route_key if outcome is A else None, | 226 | route_key=route_key if outcome is A else None, |
| 234 | route_label=None, | 227 | route_label=None, |
| 235 | ) | 228 | ) |