mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
710652ef24
* feat: project role remove * feat: search queries * feat: search queries * feat: cascade remove/change project role * fix: comment in project grant * fix: remove projecr grant * fix: only search usergrants of my org * fix: delete usergrants * fix: delete usergrants * fix: check if role exists on project grant * feat: bulk add project role * fix: tests * fix: update user grants on project update * fix: return roles * feat: add resourceowner name on project grants * fix: migration number * fix: tests * fix: generate protos * fix: some unnecessary code
75 lines
3.2 KiB
Go
75 lines
3.2 KiB
Go
package view
|
|
|
|
import (
|
|
global_model "github.com/caos/zitadel/internal/model"
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
"github.com/caos/zitadel/internal/project/repository/view/model"
|
|
"github.com/caos/zitadel/internal/view"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
func ProjectGrantByProjectAndOrg(db *gorm.DB, table, projectID, orgID string) (*model.ProjectGrantView, error) {
|
|
project := new(model.ProjectGrantView)
|
|
|
|
projectIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS}
|
|
orgIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_ORGID, Value: orgID, Method: global_model.SEARCHMETHOD_EQUALS}
|
|
query := view.PrepareGetByQuery(table, projectIDQuery, orgIDQuery)
|
|
err := query(db, project)
|
|
return project, err
|
|
}
|
|
|
|
func ProjectGrantByID(db *gorm.DB, table, grantID string) (*model.ProjectGrantView, error) {
|
|
project := new(model.ProjectGrantView)
|
|
grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_GRANTID, Value: grantID, Method: global_model.SEARCHMETHOD_EQUALS}
|
|
query := view.PrepareGetByQuery(table, grantIDQuery)
|
|
err := query(db, project)
|
|
return project, err
|
|
}
|
|
|
|
func ProjectGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectGrantView, error) {
|
|
projects := make([]*model.ProjectGrantView, 0)
|
|
queries := []*proj_model.ProjectGrantViewSearchQuery{
|
|
&proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS},
|
|
}
|
|
query := view.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries})
|
|
_, err := query(db, &projects)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return projects, nil
|
|
}
|
|
|
|
func ProjectGrantsByProjectIDAndRoleKey(db *gorm.DB, table, projectID, roleKey string) ([]*model.ProjectGrantView, error) {
|
|
projects := make([]*model.ProjectGrantView, 0)
|
|
queries := []*proj_model.ProjectGrantViewSearchQuery{
|
|
&proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_PROJECTID, Value: projectID, Method: global_model.SEARCHMETHOD_EQUALS},
|
|
&proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GRANTEDPROJECTSEARCHKEY_ROLE_KEYS, Value: roleKey, Method: global_model.SEARCHMETHOD_LIST_CONTAINS},
|
|
}
|
|
query := view.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries})
|
|
_, err := query(db, &projects)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return projects, nil
|
|
}
|
|
|
|
func SearchProjectGrants(db *gorm.DB, table string, req *proj_model.ProjectGrantViewSearchRequest) ([]*model.ProjectGrantView, int, error) {
|
|
projects := make([]*model.ProjectGrantView, 0)
|
|
query := view.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
|
count, err := query(db, &projects)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return projects, count, nil
|
|
}
|
|
|
|
func PutProjectGrant(db *gorm.DB, table string, project *model.ProjectGrantView) error {
|
|
save := view.PrepareSave(table)
|
|
return save(db, project)
|
|
}
|
|
|
|
func DeleteProjectGrant(db *gorm.DB, table, grantID string) error {
|
|
delete := view.PrepareDeleteByKey(table, model.ProjectSearchKey(proj_model.GRANTEDPROJECTSEARCHKEY_GRANTID), grantID)
|
|
return delete(db)
|
|
}
|