mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 06:07:33 +00:00
feat: handle instanceID in projections (#3442)
* feat: handle instanceID in projections * rename functions * fix key lock * fix import
This commit is contained in:
@@ -11,9 +11,12 @@ import (
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
func TokenByID(db *gorm.DB, table, tokenID string) (*usr_model.TokenView, error) {
|
||||
func TokenByID(db *gorm.DB, table, tokenID, instanceID string) (*usr_model.TokenView, error) {
|
||||
token := new(usr_model.TokenView)
|
||||
query := repository.PrepareGetByKey(table, usr_model.TokenSearchKey(model.TokenSearchKeyTokenID), tokenID)
|
||||
query := repository.PrepareGetByQuery(table,
|
||||
&usr_model.TokenSearchQuery{Key: model.TokenSearchKeyTokenID, Method: domain.SearchMethodEquals, Value: tokenID},
|
||||
&usr_model.TokenSearchQuery{Key: model.TokenSearchKeyInstanceID, Method: domain.SearchMethodEquals, Value: instanceID},
|
||||
)
|
||||
err := query(db, token)
|
||||
if errors.IsNotFound(err) {
|
||||
return nil, errors.ThrowNotFound(nil, "VIEW-6ub3p", "Errors.Token.NotFound")
|
||||
@@ -21,15 +24,20 @@ func TokenByID(db *gorm.DB, table, tokenID string) (*usr_model.TokenView, error)
|
||||
return token, err
|
||||
}
|
||||
|
||||
func TokensByUserID(db *gorm.DB, table, userID string) ([]*usr_model.TokenView, error) {
|
||||
func TokensByUserID(db *gorm.DB, table, userID, instanceID string) ([]*usr_model.TokenView, error) {
|
||||
tokens := make([]*usr_model.TokenView, 0)
|
||||
userIDQuery := &model.TokenSearchQuery{
|
||||
Key: model.TokenSearchKeyUserID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: userID,
|
||||
}
|
||||
instanceIDQuery := &model.TokenSearchQuery{
|
||||
Key: model.TokenSearchKeyInstanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: instanceID,
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, usr_model.TokenSearchRequest{
|
||||
Queries: []*model.TokenSearchQuery{userIDQuery},
|
||||
Queries: []*model.TokenSearchQuery{userIDQuery, instanceIDQuery},
|
||||
})
|
||||
_, err := query(db, &tokens)
|
||||
return tokens, err
|
||||
@@ -49,30 +57,43 @@ func PutTokens(db *gorm.DB, table string, tokens ...*usr_model.TokenView) error
|
||||
return save(db, t...)
|
||||
}
|
||||
|
||||
func DeleteToken(db *gorm.DB, table, tokenID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, usr_model.TokenSearchKey(model.TokenSearchKeyTokenID), tokenID)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteSessionTokens(db *gorm.DB, table, agentID, userID string) error {
|
||||
func DeleteToken(db *gorm.DB, table, tokenID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{Key: usr_model.TokenSearchKey(model.TokenSearchKeyUserAgentID), Value: agentID},
|
||||
repository.Key{Key: usr_model.TokenSearchKey(model.TokenSearchKeyUserID), Value: userID},
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyTokenID), tokenID},
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyInstanceID), instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteUserTokens(db *gorm.DB, table, userID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, usr_model.TokenSearchKey(model.TokenSearchKeyUserID), userID)
|
||||
func DeleteSessionTokens(db *gorm.DB, table, agentID, userID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{Key: usr_model.TokenSearchKey(model.TokenSearchKeyUserAgentID), Value: agentID},
|
||||
repository.Key{Key: usr_model.TokenSearchKey(model.TokenSearchKeyUserID), Value: userID},
|
||||
repository.Key{Key: usr_model.TokenSearchKey(model.TokenSearchKeyInstanceID), Value: instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteTokensFromRefreshToken(db *gorm.DB, table, refreshTokenID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, usr_model.TokenSearchKey(model.TokenSearchKeyRefreshTokenID), refreshTokenID)
|
||||
func DeleteUserTokens(db *gorm.DB, table, userID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyUserID), userID},
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyInstanceID), instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteApplicationTokens(db *gorm.DB, table string, appIDs []string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, usr_model.TokenSearchKey(model.TokenSearchKeyApplicationID), pq.StringArray(appIDs))
|
||||
func DeleteTokensFromRefreshToken(db *gorm.DB, table, refreshTokenID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyRefreshTokenID), refreshTokenID},
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyInstanceID), instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteApplicationTokens(db *gorm.DB, table, instanceID string, appIDs []string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyApplicationID), pq.StringArray(appIDs)},
|
||||
repository.Key{usr_model.TokenSearchKey(model.TokenSearchKeyInstanceID), instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
Reference in New Issue
Block a user