mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 06:07:33 +00:00
fix(sessions): add an expiration date filter to list sessions api (#10384)
# Which Problems Are Solved The deletion of expired sessions does not go through even though a success response is returned to the user. These expired and supposedly deleted (to the user) sessions are then returned when the `ListSessions` API is called. This PR fixes this issue by: 1. Allowing deletion of expired sessions 2. Providing an `expiration_date` filter in `ListSession` API to filter sessions by expiration date # How the Problems Are Solved 1. Remove expired session check during deletion 2. Add an `expiration_date` filter to the `ListSession` API # Additional Changes N/A # Additional Context - Closes #10045 --------- Co-authored-by: Marco A. <marco@zitadel.com>
This commit is contained in:

committed by
Stefan Benz

parent
a2938416d5
commit
f13380954f
@@ -109,6 +109,8 @@ func sessionQueryToQuery(ctx context.Context, sq *session.SearchQuery) (query.Se
|
||||
}
|
||||
}
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "GRPC-x8n23uh", "List.Query.Invalid")
|
||||
case *session.SearchQuery_ExpirationDateQuery:
|
||||
return expirationDateQueryToQuery(q.ExpirationDateQuery)
|
||||
default:
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "GRPC-Sfefs", "List.Query.Invalid")
|
||||
}
|
||||
@@ -123,6 +125,30 @@ func creationDateQueryToQuery(q *session.CreationDateQuery) (query.SearchQuery,
|
||||
return query.NewCreationDateQuery(q.GetCreationDate().AsTime(), comparison)
|
||||
}
|
||||
|
||||
func expirationDateQueryToQuery(q *session.ExpirationDateQuery) (query.SearchQuery, error) {
|
||||
comparison := timestampComparisons[q.GetMethod()]
|
||||
|
||||
// to obtain sessions with a set expiration date
|
||||
expirationDateQuery, err := query.NewExpirationDateQuery(q.GetExpirationDate().AsTime(), comparison)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch comparison {
|
||||
case query.TimestampEquals, query.TimestampLess, query.TimestampLessOrEquals:
|
||||
return expirationDateQuery, nil
|
||||
case query.TimestampGreater, query.TimestampGreaterOrEquals:
|
||||
// to obtain sessions without an expiration date
|
||||
expirationDateIsNullQuery, err := query.NewIsNullQuery(query.SessionColumnExpiration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return query.NewOrQuery(expirationDateQuery, expirationDateIsNullQuery)
|
||||
default:
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "GRPC-Dwigt", "List.Query.InvalidComparisonMethod")
|
||||
}
|
||||
}
|
||||
|
||||
func fieldNameToSessionColumn(field session.SessionFieldName) query.Column {
|
||||
switch field {
|
||||
case session.SessionFieldName_SESSION_FIELD_NAME_CREATION_DATE:
|
||||
|
Reference in New Issue
Block a user