2020-05-20 12:28:08 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2021-03-01 07:48:50 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2020-07-06 11:18:10 +00:00
|
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
2020-05-20 12:28:08 +00:00
|
|
|
usr_model "github.com/caos/zitadel/internal/user/model"
|
|
|
|
"github.com/caos/zitadel/internal/user/repository/view/model"
|
2020-06-25 06:01:13 +00:00
|
|
|
"github.com/caos/zitadel/internal/view/repository"
|
2020-05-20 12:28:08 +00:00
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NotifyUserByID(db *gorm.DB, table, userID string) (*model.NotifyUser, error) {
|
|
|
|
user := new(model.NotifyUser)
|
2020-07-07 17:31:51 +00:00
|
|
|
query := repository.PrepareGetByKey(table, model.NotifyUserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID)
|
2020-05-20 12:28:08 +00:00
|
|
|
err := query(db, user)
|
2020-07-06 11:18:10 +00:00
|
|
|
if caos_errs.IsNotFound(err) {
|
|
|
|
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Gad31", "Errors.User.NotFound")
|
|
|
|
}
|
2020-05-20 12:28:08 +00:00
|
|
|
return user, err
|
|
|
|
}
|
|
|
|
|
2020-07-07 17:31:51 +00:00
|
|
|
func NotifyUsersByOrgID(db *gorm.DB, table, orgID string) ([]*model.NotifyUser, error) {
|
|
|
|
users := make([]*model.NotifyUser, 0)
|
|
|
|
orgIDQuery := &usr_model.NotifyUserSearchQuery{
|
|
|
|
Key: usr_model.NotifyUserSearchKeyResourceOwner,
|
2021-03-01 07:48:50 +00:00
|
|
|
Method: domain.SearchMethodEquals,
|
2020-07-07 17:31:51 +00:00
|
|
|
Value: orgID,
|
|
|
|
}
|
|
|
|
query := repository.PrepareSearchQuery(table, model.NotifyUserSearchRequest{
|
|
|
|
Queries: []*usr_model.NotifyUserSearchQuery{orgIDQuery},
|
|
|
|
})
|
|
|
|
_, err := query(db, &users)
|
|
|
|
return users, err
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:28:08 +00:00
|
|
|
func PutNotifyUser(db *gorm.DB, table string, project *model.NotifyUser) error {
|
2020-06-25 06:01:13 +00:00
|
|
|
save := repository.PrepareSave(table)
|
2020-05-20 12:28:08 +00:00
|
|
|
return save(db, project)
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteNotifyUser(db *gorm.DB, table, userID string) error {
|
2020-06-25 06:01:13 +00:00
|
|
|
delete := repository.PrepareDeleteByKey(table, model.UserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID)
|
2020-05-20 12:28:08 +00:00
|
|
|
return delete(db)
|
|
|
|
}
|