mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-13 13:42:29 +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,7 +11,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/user/repository/view/model"
|
||||
)
|
||||
|
||||
func ExternalIDPByExternalUserIDAndIDPConfigID(db *gorm.DB, table, externalUserID, idpConfigID string) (*model.ExternalIDPView, error) {
|
||||
func ExternalIDPByExternalUserIDAndIDPConfigID(db *gorm.DB, table, externalUserID, idpConfigID, instanceID string) (*model.ExternalIDPView, error) {
|
||||
user := new(model.ExternalIDPView)
|
||||
userIDQuery := &model.ExternalIDPSearchQuery{
|
||||
Key: usr_model.ExternalIDPSearchKeyExternalUserID,
|
||||
@@ -23,7 +23,12 @@ func ExternalIDPByExternalUserIDAndIDPConfigID(db *gorm.DB, table, externalUserI
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: idpConfigID,
|
||||
}
|
||||
query := repository.PrepareGetByQuery(table, userIDQuery, idpConfigIDQuery)
|
||||
instanceIDQuery := &model.ExternalIDPSearchQuery{
|
||||
Key: usr_model.ExternalIDPSearchKeyInstanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: instanceID,
|
||||
}
|
||||
query := repository.PrepareGetByQuery(table, userIDQuery, idpConfigIDQuery, instanceIDQuery)
|
||||
err := query(db, user)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Mso9f", "Errors.ExternalIDP.NotFound")
|
||||
@@ -31,7 +36,7 @@ func ExternalIDPByExternalUserIDAndIDPConfigID(db *gorm.DB, table, externalUserI
|
||||
return user, err
|
||||
}
|
||||
|
||||
func ExternalIDPByExternalUserIDAndIDPConfigIDAndResourceOwner(db *gorm.DB, table, externalUserID, idpConfigID, resourceOwner string) (*model.ExternalIDPView, error) {
|
||||
func ExternalIDPByExternalUserIDAndIDPConfigIDAndResourceOwner(db *gorm.DB, table, externalUserID, idpConfigID, resourceOwner, instanceID string) (*model.ExternalIDPView, error) {
|
||||
user := new(model.ExternalIDPView)
|
||||
userIDQuery := &model.ExternalIDPSearchQuery{
|
||||
Key: usr_model.ExternalIDPSearchKeyExternalUserID,
|
||||
@@ -48,7 +53,12 @@ func ExternalIDPByExternalUserIDAndIDPConfigIDAndResourceOwner(db *gorm.DB, tabl
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: resourceOwner,
|
||||
}
|
||||
query := repository.PrepareGetByQuery(table, userIDQuery, idpConfigIDQuery, resourceOwnerQuery)
|
||||
instanceIDQuery := &model.ExternalIDPSearchQuery{
|
||||
Key: usr_model.ExternalIDPSearchKeyInstanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: instanceID,
|
||||
}
|
||||
query := repository.PrepareGetByQuery(table, userIDQuery, idpConfigIDQuery, resourceOwnerQuery, instanceIDQuery)
|
||||
err := query(db, user)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Sf8sd", "Errors.ExternalIDP.NotFound")
|
||||
@@ -56,15 +66,20 @@ func ExternalIDPByExternalUserIDAndIDPConfigIDAndResourceOwner(db *gorm.DB, tabl
|
||||
return user, err
|
||||
}
|
||||
|
||||
func ExternalIDPsByIDPConfigID(db *gorm.DB, table, idpConfigID string) ([]*model.ExternalIDPView, error) {
|
||||
func ExternalIDPsByIDPConfigID(db *gorm.DB, table, idpConfigID, instanceID string) ([]*model.ExternalIDPView, error) {
|
||||
externalIDPs := make([]*model.ExternalIDPView, 0)
|
||||
orgIDQuery := &usr_model.ExternalIDPSearchQuery{
|
||||
Key: usr_model.ExternalIDPSearchKeyIdpConfigID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: idpConfigID,
|
||||
}
|
||||
instanceIDQuery := &usr_model.ExternalIDPSearchQuery{
|
||||
Key: usr_model.ExternalIDPSearchKeyInstanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: instanceID,
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.ExternalIDPSearchRequest{
|
||||
Queries: []*usr_model.ExternalIDPSearchQuery{orgIDQuery},
|
||||
Queries: []*usr_model.ExternalIDPSearchQuery{orgIDQuery, instanceIDQuery},
|
||||
})
|
||||
_, err := query(db, &externalIDPs)
|
||||
return externalIDPs, err
|
||||
@@ -84,15 +99,19 @@ func PutExternalIDP(db *gorm.DB, table string, idp *model.ExternalIDPView) error
|
||||
return save(db, idp)
|
||||
}
|
||||
|
||||
func DeleteExternalIDP(db *gorm.DB, table, externalUserID, idpConfigID string) error {
|
||||
func DeleteExternalIDP(db *gorm.DB, table, externalUserID, idpConfigID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{Key: model.ExternalIDPSearchKey(usr_model.ExternalIDPSearchKeyExternalUserID), Value: externalUserID},
|
||||
repository.Key{Key: model.ExternalIDPSearchKey(usr_model.ExternalIDPSearchKeyIdpConfigID), Value: idpConfigID},
|
||||
repository.Key{Key: model.ExternalIDPSearchKey(usr_model.ExternalIDPSearchKeyInstanceID), Value: instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteExternalIDPsByUserID(db *gorm.DB, table, userID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, model.ExternalIDPSearchKey(usr_model.ExternalIDPSearchKeyUserID), userID)
|
||||
func DeleteExternalIDPsByUserID(db *gorm.DB, table, userID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{model.ExternalIDPSearchKey(usr_model.ExternalIDPSearchKeyUserID), userID},
|
||||
repository.Key{model.ExternalIDPSearchKey(usr_model.ExternalIDPSearchKeyInstanceID), instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user