BlueGit

ict rusty-teams

Merge pull request #53: fix(chat): show no access when the roster ACL denies the thread

metis Daniel Däschle · pushed by metis

Authored 2026-11-16 · 2 weeks ago

Hash
3852683f372b498be98f261a94d7e48ce825482a
5 files changed +108 −0
crates/app-state/src/outbox.rs +3 −0
@@ -351,6 +351,9 @@ mod tests {
351 351 )))
352 352 };
353 353 assert!(is_permanent(&api(403)));
354 assert!(is_permanent(&teams_core::Error::Graph(
355 graph::Error::NotAMember
356 )));
354 357 assert!(is_permanent(&api(400)));
355 358 assert!(!is_permanent(&api(429)));
356 359 assert!(!is_permanent(&api(503)));
@@ -351,6 +351,9 @@ mod tests {
351 )))
351 )))
352 };
352 };
353 assert!(is_permanent(&api(403)));
353 assert!(is_permanent(&api(403)));
354 assert!(is_permanent(&teams_core::Error::Graph(
355 graph::Error::NotAMember
356 )));
354 assert!(is_permanent(&api(400)));
357 assert!(is_permanent(&api(400)));
355 assert!(!is_permanent(&api(429)));
358 assert!(!is_permanent(&api(429)));
356 assert!(!is_permanent(&api(503)));
359 assert!(!is_permanent(&api(503)));
crates/app/src/views/conversation.rs +29 −0
@@ -2230,6 +2230,7 @@ impl ConversationView {
2230 2230 }
2231 2231 self.mark_fetched_new(newest_cached, started_at, cx)
2232 2232 }
2233 Ok(Err(error)) if Self::denies_access(&error) => self.fail_access(generation, cx),
2233 2234 Ok(Err(error)) => self.fail_sync(generation, short_error(&error), cx),
2234 2235 Err(error) => self.fail_sync(generation, short_error(&error), cx),
2235 2236 }
@@ -2263,6 +2264,24 @@ impl ConversationView {
2263 2264 self.notice = Some(format!("Could not refresh: {error}"));
2264 2265 }
2265 2266
2267 fn denies_access(error: &teams_core::Error) -> bool {
2268 matches!(error, teams_core::Error::Graph(graph::Error::NotAMember))
2269 }
2270
2271 fn fail_access(&mut self, generation: u64, _cx: &mut Context<Self>) {
2272 let conversation_id = self
2273 .current
2274 .as_ref()
2275 .map(|current| current.selection.conversation_id().to_owned())
2276 .unwrap_or_default();
2277 log::info!("chat access denied: {conversation_id} HTTP 403 AclCheckFailed");
2278 if let Some(sync) = self.sync_of(generation) {
2279 sync.failed = true;
2280 sync.receipts = false;
2281 }
2282 self.notice = Some("No access to this chat".to_owned());
2283 }
2284
2266 2285 fn mark_fetched_new(
2267 2286 &mut self,
2268 2287 newest_cached: Option<DateTime<Utc>>,
@@ -4892,4 +4911,14 @@ mod tests {
4892 4911 );
4893 4912 assert_eq!(typing_bottom_offset(Some(timeline), None), 8.);
4894 4913 }
4914
4915 #[test]
4916 fn no_access_is_a_roster_denial_and_other_errors_still_refresh() {
4917 assert!(ConversationView::denies_access(&teams_core::Error::Graph(
4918 graph::Error::NotAMember
4919 )));
4920 assert!(!ConversationView::denies_access(
4921 &teams_core::Error::Unsupported("refresh")
4922 ));
4923 }
4895 4924 }
@@ -2230,6 +2230,7 @@ impl ConversationView {
2230 }
2230 }
2231 self.mark_fetched_new(newest_cached, started_at, cx)
2231 self.mark_fetched_new(newest_cached, started_at, cx)
2232 }
2232 }
2233 Ok(Err(error)) if Self::denies_access(&error) => self.fail_access(generation, cx),
2233 Ok(Err(error)) => self.fail_sync(generation, short_error(&error), cx),
2234 Ok(Err(error)) => self.fail_sync(generation, short_error(&error), cx),
2234 Err(error) => self.fail_sync(generation, short_error(&error), cx),
2235 Err(error) => self.fail_sync(generation, short_error(&error), cx),
2235 }
2236 }
@@ -2263,6 +2264,24 @@ impl ConversationView {
2263 self.notice = Some(format!("Could not refresh: {error}"));
2264 self.notice = Some(format!("Could not refresh: {error}"));
2264 }
2265 }
2265
2266
2267 fn denies_access(error: &teams_core::Error) -> bool {
2268 matches!(error, teams_core::Error::Graph(graph::Error::NotAMember))
2269 }
2270
2271 fn fail_access(&mut self, generation: u64, _cx: &mut Context<Self>) {
2272 let conversation_id = self
2273 .current
2274 .as_ref()
2275 .map(|current| current.selection.conversation_id().to_owned())
2276 .unwrap_or_default();
2277 log::info!("chat access denied: {conversation_id} HTTP 403 AclCheckFailed");
2278 if let Some(sync) = self.sync_of(generation) {
2279 sync.failed = true;
2280 sync.receipts = false;
2281 }
2282 self.notice = Some("No access to this chat".to_owned());
2283 }
2284
2266 fn mark_fetched_new(
2285 fn mark_fetched_new(
2267 &mut self,
2286 &mut self,
2268 newest_cached: Option<DateTime<Utc>>,
2287 newest_cached: Option<DateTime<Utc>>,
@@ -4892,4 +4911,14 @@ mod tests {
4892 );
4911 );
4893 assert_eq!(typing_bottom_offset(Some(timeline), None), 8.);
4912 assert_eq!(typing_bottom_offset(Some(timeline), None), 8.);
4894 }
4913 }
4914
4915 #[test]
4916 fn no_access_is_a_roster_denial_and_other_errors_still_refresh() {
4917 assert!(ConversationView::denies_access(&teams_core::Error::Graph(
4918 graph::Error::NotAMember
4919 )));
4920 assert!(!ConversationView::denies_access(
4921 &teams_core::Error::Unsupported("refresh")
4922 ));
4923 }
4895}
4924}
crates/chatsvc/src/error.rs +3 −0
@@ -16,6 +16,9 @@ pub enum Error {
16 16 VersionConflict,
17 17 #[error("GIFs are disabled by the organization")]
18 18 GifsDisabled,
19 /// HTTP 403, error code 209, sub-code `AclCheckFailed`: this account is not on the thread roster.
20 #[error("no access to this chat")]
21 AccessDenied,
19 22 #[error("invalid event payload: {0}")]
20 23 Decode(String),
21 24 }
@@ -16,6 +16,9 @@ pub enum Error {
16 VersionConflict,
16 VersionConflict,
17 #[error("GIFs are disabled by the organization")]
17 #[error("GIFs are disabled by the organization")]
18 GifsDisabled,
18 GifsDisabled,
19 /// HTTP 403, error code 209, sub-code `AclCheckFailed`: this account is not on the thread roster.
20 #[error("no access to this chat")]
21 AccessDenied,
19 #[error("invalid event payload: {0}")]
22 #[error("invalid event payload: {0}")]
20 Decode(String),
23 Decode(String),
21}
24}
crates/chatsvc/src/messages.rs +61 −0
@@ -371,6 +371,8 @@ fn typing_body(active: bool) -> Value {
371 371 pub(crate) fn ensure_success(answer: &ApiResponse) -> Result<()> {
372 372 if answer.is_success() {
373 373 Ok(())
374 } else if answer.status == 403 && acl_check_failed(&answer.body) {
375 Err(Error::AccessDenied)
374 376 } else {
375 377 Err(Error::Session(session::Error::api(
376 378 answer.status,
@@ -379,3 +381,62 @@ pub(crate) fn ensure_success(answer: &ApiResponse) -> Result<()> {
379 381 )))
380 382 }
381 383 }
384
385 /// `errorCode` 209 whose `message` is a JSON string with `subCode` `AclCheckFailed`.
386 pub(crate) fn acl_check_failed(body: &Value) -> bool {
387 if body.get("errorCode").and_then(Value::as_i64) != Some(209) {
388 return false;
389 }
390 let Some(message) = body.get("message").and_then(Value::as_str) else {
391 return false;
392 };
393 serde_json::from_str::<Value>(message)
394 .ok()
395 .and_then(|inner| {
396 inner
397 .get("subCode")
398 .and_then(Value::as_str)
399 .map(|code| code == "AclCheckFailed")
400 })
401 .unwrap_or(false)
402 }
403
404 #[cfg(test)]
405 mod acl_check_tests {
406 use serde_json::json;
407 use session::ApiResponse;
408
409 use super::{Error, acl_check_failed, ensure_success};
410
411 fn denied() -> serde_json::Value {
412 json!({
413 "errorCode": 209,
414 "message": "{\"subCode\":\"AclCheckFailed\",\"details\":\"The initiator 8:orgid:abc\"}"
415 })
416 }
417
418 #[test]
419 fn acl_check_failed_on_a_roster_denial() {
420 assert!(acl_check_failed(&denied()));
421 assert!(!acl_check_failed(
422 &json!({"errorCode": 209, "message": "{\"subCode\":\"Other\"}"})
423 ));
424 assert!(!acl_check_failed(&json!({"errorCode": 403})));
425 }
426
427 #[test]
428 fn ensure_success_maps_the_denial_and_keeps_other_403s() {
429 let denied = ApiResponse {
430 status: 403,
431 body: denied(),
432 retry_after: None,
433 };
434 assert!(matches!(ensure_success(&denied), Err(Error::AccessDenied)));
435 let other = ApiResponse {
436 status: 403,
437 body: json!({"error": "nope"}),
438 retry_after: None,
439 };
440 assert!(matches!(ensure_success(&other), Err(Error::Session(_))));
441 }
442 }
@@ -371,6 +371,8 @@ fn typing_body(active: bool) -> Value {
371pub(crate) fn ensure_success(answer: &ApiResponse) -> Result<()> {
371pub(crate) fn ensure_success(answer: &ApiResponse) -> Result<()> {
372 if answer.is_success() {
372 if answer.is_success() {
373 Ok(())
373 Ok(())
374 } else if answer.status == 403 && acl_check_failed(&answer.body) {
375 Err(Error::AccessDenied)
374 } else {
376 } else {
375 Err(Error::Session(session::Error::api(
377 Err(Error::Session(session::Error::api(
376 answer.status,
378 answer.status,
@@ -379,3 +381,62 @@ pub(crate) fn ensure_success(answer: &ApiResponse) -> Result<()> {
379 )))
381 )))
380 }
382 }
381}
383}
384
385/// `errorCode` 209 whose `message` is a JSON string with `subCode` `AclCheckFailed`.
386pub(crate) fn acl_check_failed(body: &Value) -> bool {
387 if body.get("errorCode").and_then(Value::as_i64) != Some(209) {
388 return false;
389 }
390 let Some(message) = body.get("message").and_then(Value::as_str) else {
391 return false;
392 };
393 serde_json::from_str::<Value>(message)
394 .ok()
395 .and_then(|inner| {
396 inner
397 .get("subCode")
398 .and_then(Value::as_str)
399 .map(|code| code == "AclCheckFailed")
400 })
401 .unwrap_or(false)
402}
403
404#[cfg(test)]
405mod acl_check_tests {
406 use serde_json::json;
407 use session::ApiResponse;
408
409 use super::{Error, acl_check_failed, ensure_success};
410
411 fn denied() -> serde_json::Value {
412 json!({
413 "errorCode": 209,
414 "message": "{\"subCode\":\"AclCheckFailed\",\"details\":\"The initiator 8:orgid:abc\"}"
415 })
416 }
417
418 #[test]
419 fn acl_check_failed_on_a_roster_denial() {
420 assert!(acl_check_failed(&denied()));
421 assert!(!acl_check_failed(
422 &json!({"errorCode": 209, "message": "{\"subCode\":\"Other\"}"})
423 ));
424 assert!(!acl_check_failed(&json!({"errorCode": 403})));
425 }
426
427 #[test]
428 fn ensure_success_maps_the_denial_and_keeps_other_403s() {
429 let denied = ApiResponse {
430 status: 403,
431 body: denied(),
432 retry_after: None,
433 };
434 assert!(matches!(ensure_success(&denied), Err(Error::AccessDenied)));
435 let other = ApiResponse {
436 status: 403,
437 body: json!({"error": "nope"}),
438 retry_after: None,
439 };
440 assert!(matches!(ensure_success(&other), Err(Error::Session(_))));
441 }
442}
crates/core/src/error.rs +12 −0
@@ -28,7 +28,19 @@ impl From<chatsvc::Error> for Error {
28 28 match error {
29 29 chatsvc::Error::Session(inner) => Error::Graph(graph::Error::Session(inner)),
30 30 chatsvc::Error::GifsDisabled => Error::GifsDisabled,
31 chatsvc::Error::AccessDenied => Error::Graph(graph::Error::NotAMember),
31 32 other => Error::Folders(other.to_string()),
32 33 }
33 34 }
34 35 }
36
37 #[cfg(test)]
38 mod tests {
39 use super::*;
40
41 #[test]
42 fn access_denied_is_not_a_member() {
43 let error = Error::from(chatsvc::Error::AccessDenied);
44 assert!(matches!(error, Error::Graph(graph::Error::NotAMember)));
45 }
46 }
@@ -28,7 +28,19 @@ impl From<chatsvc::Error> for Error {
28 match error {
28 match error {
29 chatsvc::Error::Session(inner) => Error::Graph(graph::Error::Session(inner)),
29 chatsvc::Error::Session(inner) => Error::Graph(graph::Error::Session(inner)),
30 chatsvc::Error::GifsDisabled => Error::GifsDisabled,
30 chatsvc::Error::GifsDisabled => Error::GifsDisabled,
31 chatsvc::Error::AccessDenied => Error::Graph(graph::Error::NotAMember),
31 other => Error::Folders(other.to_string()),
32 other => Error::Folders(other.to_string()),
32 }
33 }
33 }
34 }
34}
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn access_denied_is_not_a_member() {
43 let error = Error::from(chatsvc::Error::AccessDenied);
44 assert!(matches!(error, Error::Graph(graph::Error::NotAMember)));
45 }
46}