Skip to content

Commit c8ed125

Browse files
committed
Relax the validity check of the token actor
1 parent f51747a commit c8ed125

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

crates/data-model/src/users.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ impl User {
3030
pub fn is_valid(&self) -> bool {
3131
self.locked_at.is_none() && self.deactivated_at.is_none()
3232
}
33+
34+
/// Returns `true` if the user is a valid actor, for example
35+
/// of a personal session.
36+
///
37+
/// Currently: this is `true` unless the user is deactivated.
38+
///
39+
/// This is a weaker form of validity: `is_valid` always implies
40+
/// `is_valid_actor`, but some users (currently: locked users)
41+
/// can be valid actors for personal sessions but aren't valid
42+
/// except through administrative access.
43+
#[must_use]
44+
pub fn is_valid_actor(&self) -> bool {
45+
self.deactivated_at.is_none()
46+
}
3347
}
3448

3549
impl User {

crates/handlers/src/admin/call_context.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,20 @@ where
264264
None
265265
};
266266

267-
// If there is a user for this session, check that it is not locked
268-
if let Some(user) = &user
269-
&& !user.is_valid()
270-
{
271-
return Err(Rejection::UserLocked);
267+
if let CallerSession::PersonalSession(_) = &session {
268+
// For personal sessions: check that the actor is valid enough
269+
// to be an actor.
270+
// unwrap: personal sessions always have an actor user
271+
if !user.as_ref().unwrap().is_valid_actor() {
272+
return Err(Rejection::UserLocked);
273+
}
274+
} else {
275+
// If there is a user for this session, check that it is not locked
276+
if let Some(user) = &user
277+
&& !user.is_valid()
278+
{
279+
return Err(Rejection::UserLocked);
280+
}
272281
}
273282

274283
// For now, we only check that the session has the admin scope

0 commit comments

Comments
 (0)