mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
75f1c4c576
* feat: add search user memberships * feat: add search user memberships * feat: read user member ship * feat: add usergrant search key * feat: uesrmemberships based on permissions * feat: merge master * fix: correct permissions * fix: update display name on change profile * fix: merge request converations * fix: err handling * Update internal/user/model/user_membership_view.go Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Silvan <silvan.reusser@gmail.com>
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package view
|
|
|
|
import (
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
org_model "github.com/caos/zitadel/internal/org/model"
|
|
"github.com/caos/zitadel/internal/org/repository/view/model"
|
|
"github.com/caos/zitadel/internal/view/repository"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
func OrgByID(db *gorm.DB, table, orgID string) (*model.OrgView, error) {
|
|
org := new(model.OrgView)
|
|
query := repository.PrepareGetByKey(table, model.OrgSearchKey(org_model.OrgSearchKeyOrgID), orgID)
|
|
err := query(db, org)
|
|
if caos_errs.IsNotFound(err) {
|
|
return nil, caos_errs.ThrowNotFound(nil, "VIEW-GEwea", "Errors.Org.NotFound")
|
|
}
|
|
return org, err
|
|
}
|
|
|
|
func SearchOrgs(db *gorm.DB, table string, req *org_model.OrgSearchRequest) ([]*model.OrgView, uint64, error) {
|
|
orgs := make([]*model.OrgView, 0)
|
|
query := repository.PrepareSearchQuery(table, model.OrgSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
|
count, err := query(db, &orgs)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return orgs, count, nil
|
|
}
|
|
|
|
func PutOrg(db *gorm.DB, table string, org *model.OrgView) error {
|
|
save := repository.PrepareSave(table)
|
|
return save(db, org)
|
|
}
|
|
|
|
func DeleteOrg(db *gorm.DB, table, orgID string) error {
|
|
delete := repository.PrepareDeleteByKey(table, model.OrgSearchKey(org_model.OrgSearchKeyOrgID), orgID)
|
|
return delete(db)
|
|
}
|