diff --git a/crates/graphql/src/model/browser_sessions.rs b/crates/graphql/src/model/browser_sessions.rs index eecbda75..e07249c7 100644 --- a/crates/graphql/src/model/browser_sessions.rs +++ b/crates/graphql/src/model/browser_sessions.rs @@ -73,6 +73,20 @@ impl BrowserSession { pub async fn created_at(&self) -> DateTime { self.0.created_at } + + /// When the session was finished. + pub async fn finished_at(&self) -> Option> { + self.0.finished_at + } + + /// The state of the session. + pub async fn state(&self) -> BrowserSessionState { + if self.0.finished_at.is_some() { + BrowserSessionState::Finished + } else { + BrowserSessionState::Active + } + } } /// An authentication records when a user enter their credential in a browser diff --git a/crates/graphql/src/model/compat_sessions.rs b/crates/graphql/src/model/compat_sessions.rs index 91cacdcd..441efd67 100644 --- a/crates/graphql/src/model/compat_sessions.rs +++ b/crates/graphql/src/model/compat_sessions.rs @@ -89,6 +89,14 @@ impl CompatSession { pub async fn sso_login(&self) -> Option { self.1.as_ref().map(|l| CompatSsoLogin(l.clone())) } + + /// The state of the session. + pub async fn state(&self) -> CompatSessionState { + match &self.0.state { + mas_data_model::CompatSessionState::Valid => CompatSessionState::Active, + mas_data_model::CompatSessionState::Finished { .. } => CompatSessionState::Finished, + } + } } /// A compat SSO login represents a login done through the legacy Matrix login diff --git a/crates/graphql/src/model/oauth.rs b/crates/graphql/src/model/oauth.rs index d385c2a3..3653172d 100644 --- a/crates/graphql/src/model/oauth.rs +++ b/crates/graphql/src/model/oauth.rs @@ -78,6 +78,14 @@ impl OAuth2Session { } } + /// The state of the session. + pub async fn state(&self) -> OAuth2SessionState { + match &self.0.state { + SessionState::Valid => OAuth2SessionState::Active, + SessionState::Finished { .. } => OAuth2SessionState::Finished, + } + } + /// The browser session which started this OAuth 2.0 session. pub async fn browser_session( &self, diff --git a/frontend/schema.graphql b/frontend/schema.graphql index e171bcd5..5570861e 100644 --- a/frontend/schema.graphql +++ b/frontend/schema.graphql @@ -87,6 +87,14 @@ type BrowserSession implements Node & CreationEvent { When the object was created. """ createdAt: DateTime! + """ + When the session was finished. + """ + finishedAt: DateTime + """ + The state of the session. + """ + state: BrowserSessionState! } type BrowserSessionConnection { @@ -165,6 +173,10 @@ type CompatSession implements Node & CreationEvent { The associated SSO login, if any. """ ssoLogin: CompatSsoLogin + """ + The state of the session. + """ + state: CompatSessionState! } type CompatSessionConnection { @@ -557,6 +569,10 @@ type Oauth2Session implements Node & CreationEvent { """ finishedAt: DateTime """ + The state of the session. + """ + state: Oauth2SessionState! + """ The browser session which started this OAuth 2.0 session. """ browserSession: BrowserSession! diff --git a/frontend/src/gql/graphql.ts b/frontend/src/gql/graphql.ts index 35b0c817..645a1cc6 100644 --- a/frontend/src/gql/graphql.ts +++ b/frontend/src/gql/graphql.ts @@ -90,10 +90,14 @@ export type BrowserSession = CreationEvent & __typename?: "BrowserSession"; /** When the object was created. */ createdAt: Scalars["DateTime"]["output"]; + /** When the session was finished. */ + finishedAt?: Maybe; /** ID of the object. */ id: Scalars["ID"]["output"]; /** The most recent authentication of this session. */ lastAuthentication?: Maybe; + /** The state of the session. */ + state: BrowserSessionState; /** The user logged in this session. */ user: User; }; @@ -144,6 +148,8 @@ export type CompatSession = CreationEvent & id: Scalars["ID"]["output"]; /** The associated SSO login, if any. */ ssoLogin?: Maybe; + /** The state of the session. */ + state: CompatSessionState; /** The user authorized for this session. */ user: User; }; @@ -432,6 +438,8 @@ export type Oauth2Session = CreationEvent & id: Scalars["ID"]["output"]; /** Scope granted for this session. */ scope: Scalars["String"]["output"]; + /** The state of the session. */ + state: Oauth2SessionState; /** User authorized for this session. */ user: User; }; diff --git a/frontend/src/gql/schema.ts b/frontend/src/gql/schema.ts index 4688f0de..5aa3a07b 100644 --- a/frontend/src/gql/schema.ts +++ b/frontend/src/gql/schema.ts @@ -121,6 +121,14 @@ export default { }, args: [], }, + { + name: "finishedAt", + type: { + kind: "SCALAR", + name: "Any", + }, + args: [], + }, { name: "id", type: { @@ -141,6 +149,17 @@ export default { }, args: [], }, + { + name: "state", + type: { + kind: "NON_NULL", + ofType: { + kind: "SCALAR", + name: "Any", + }, + }, + args: [], + }, { name: "user", type: { @@ -315,6 +334,17 @@ export default { }, args: [], }, + { + name: "state", + type: { + kind: "NON_NULL", + ofType: { + kind: "SCALAR", + name: "Any", + }, + }, + args: [], + }, { name: "user", type: { @@ -1219,6 +1249,17 @@ export default { }, args: [], }, + { + name: "state", + type: { + kind: "NON_NULL", + ofType: { + kind: "SCALAR", + name: "Any", + }, + }, + args: [], + }, { name: "user", type: {