mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
57 lines
2.0 KiB
Go
57 lines
2.0 KiB
Go
package view
|
|
|
|
import (
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
|
usr_model "github.com/zitadel/zitadel/internal/user/model"
|
|
"github.com/zitadel/zitadel/internal/user/repository/view/model"
|
|
"github.com/zitadel/zitadel/internal/view/repository"
|
|
)
|
|
|
|
func NotifyUserByID(db *gorm.DB, table, userID, instanceID string) (*model.NotifyUser, error) {
|
|
user := new(model.NotifyUser)
|
|
query := repository.PrepareGetByQuery(table,
|
|
model.NotifyUserSearchQuery{Key: usr_model.NotifyUserSearchKeyUserID, Method: domain.SearchMethodEquals, Value: userID},
|
|
model.NotifyUserSearchQuery{Key: usr_model.NotifyUserSearchKeyInstanceID, Method: domain.SearchMethodEquals, Value: instanceID},
|
|
)
|
|
err := query(db, user)
|
|
if caos_errs.IsNotFound(err) {
|
|
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Gad31", "Errors.User.NotFound")
|
|
}
|
|
return user, err
|
|
}
|
|
|
|
func NotifyUsersByOrgID(db *gorm.DB, table, orgID, instanceID string) ([]*model.NotifyUser, error) {
|
|
users := make([]*model.NotifyUser, 0)
|
|
orgIDQuery := &usr_model.NotifyUserSearchQuery{
|
|
Key: usr_model.NotifyUserSearchKeyResourceOwner,
|
|
Method: domain.SearchMethodEquals,
|
|
Value: orgID,
|
|
}
|
|
instanceIDQuery := &usr_model.NotifyUserSearchQuery{
|
|
Key: usr_model.NotifyUserSearchKeyInstanceID,
|
|
Method: domain.SearchMethodEquals,
|
|
Value: instanceID,
|
|
}
|
|
query := repository.PrepareSearchQuery(table, model.NotifyUserSearchRequest{
|
|
Queries: []*usr_model.NotifyUserSearchQuery{orgIDQuery, instanceIDQuery},
|
|
})
|
|
_, err := query(db, &users)
|
|
return users, err
|
|
}
|
|
|
|
func PutNotifyUser(db *gorm.DB, table string, project *model.NotifyUser) error {
|
|
save := repository.PrepareSave(table)
|
|
return save(db, project)
|
|
}
|
|
|
|
func DeleteNotifyUser(db *gorm.DB, table, userID, instanceID string) error {
|
|
delete := repository.PrepareDeleteByKeys(table,
|
|
repository.Key{model.UserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID},
|
|
repository.Key{model.UserSearchKey(usr_model.NotifyUserSearchKeyInstanceID), instanceID},
|
|
)
|
|
return delete(db)
|
|
}
|