mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 10:49:25 +00:00
feat: delete (#243)
* 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
This commit is contained in:
@@ -17,20 +17,22 @@ const (
|
||||
ProjectGrantKeyOrgID = "org_id"
|
||||
ProjectGrantKeyResourceOwner = "resource_owner"
|
||||
ProjectGrantKeyName = "project_name"
|
||||
ProjectGrantKeyRoleKeys = "granted_role_keys"
|
||||
)
|
||||
|
||||
type ProjectGrantView struct {
|
||||
GrantID string `json:"-" gorm:"column:grant_id;primary_key"`
|
||||
ProjectID string `json:"-" gorm:"column:project_id"`
|
||||
OrgID string `json:"-" gorm:"column:org_id"`
|
||||
Name string `json:"name" gorm:"column:project_name"`
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
State int32 `json:"-" gorm:"column:project_state"`
|
||||
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
|
||||
OrgName string `json:"-" gorm:"column:org_name"`
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
GrantedRoleKeys pq.StringArray `json:"-" gorm:"column:granted_role_keys"`
|
||||
GrantID string `json:"-" gorm:"column:grant_id;primary_key"`
|
||||
ProjectID string `json:"-" gorm:"column:project_id"`
|
||||
OrgID string `json:"-" gorm:"column:org_id"`
|
||||
Name string `json:"name" gorm:"column:project_name"`
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
State int32 `json:"-" gorm:"column:project_state"`
|
||||
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
|
||||
ResourceOwnerName string `json:"-" gorm:"column:resource_owner_name"`
|
||||
OrgName string `json:"-" gorm:"column:org_name"`
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
GrantedRoleKeys pq.StringArray `json:"-" gorm:"column:granted_role_keys"`
|
||||
}
|
||||
|
||||
type ProjectGrant struct {
|
||||
@@ -41,32 +43,35 @@ type ProjectGrant struct {
|
||||
|
||||
func ProjectGrantFromModel(project *model.ProjectGrantView) *ProjectGrantView {
|
||||
return &ProjectGrantView{
|
||||
ProjectID: project.ProjectID,
|
||||
OrgID: project.OrgID,
|
||||
Name: project.Name,
|
||||
ChangeDate: project.ChangeDate,
|
||||
CreationDate: project.CreationDate,
|
||||
State: int32(project.State),
|
||||
ResourceOwner: project.ResourceOwner,
|
||||
OrgName: project.OrgName,
|
||||
GrantID: project.GrantID,
|
||||
GrantedRoleKeys: project.GrantedRoleKeys,
|
||||
Sequence: project.Sequence,
|
||||
ProjectID: project.ProjectID,
|
||||
OrgID: project.OrgID,
|
||||
Name: project.Name,
|
||||
ChangeDate: project.ChangeDate,
|
||||
CreationDate: project.CreationDate,
|
||||
State: int32(project.State),
|
||||
ResourceOwner: project.ResourceOwner,
|
||||
ResourceOwnerName: project.ResourceOwnerName,
|
||||
OrgName: project.OrgName,
|
||||
GrantID: project.GrantID,
|
||||
GrantedRoleKeys: project.GrantedRoleKeys,
|
||||
Sequence: project.Sequence,
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantToModel(project *ProjectGrantView) *model.ProjectGrantView {
|
||||
return &model.ProjectGrantView{
|
||||
ProjectID: project.ProjectID,
|
||||
OrgID: project.OrgID,
|
||||
Name: project.Name,
|
||||
ChangeDate: project.ChangeDate,
|
||||
CreationDate: project.CreationDate,
|
||||
State: model.ProjectState(project.State),
|
||||
ResourceOwner: project.ResourceOwner,
|
||||
OrgName: project.OrgName,
|
||||
GrantID: project.GrantID,
|
||||
Sequence: project.Sequence,
|
||||
ProjectID: project.ProjectID,
|
||||
OrgID: project.OrgID,
|
||||
Name: project.Name,
|
||||
ChangeDate: project.ChangeDate,
|
||||
CreationDate: project.CreationDate,
|
||||
State: model.ProjectState(project.State),
|
||||
ResourceOwner: project.ResourceOwner,
|
||||
ResourceOwnerName: project.ResourceOwnerName,
|
||||
OrgName: project.OrgName,
|
||||
GrantID: project.GrantID,
|
||||
Sequence: project.Sequence,
|
||||
GrantedRoleKeys: project.GrantedRoleKeys,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +92,7 @@ func (p *ProjectGrantView) AppendEvent(event *models.Event) (err error) {
|
||||
p.CreationDate = event.CreationDate
|
||||
p.setRootData(event)
|
||||
err = p.setProjectGrantData(event)
|
||||
case es_model.ProjectGrantChanged:
|
||||
case es_model.ProjectGrantChanged, es_model.ProjectGrantCascadeChanged:
|
||||
err = p.setProjectGrantData(event)
|
||||
case es_model.ProjectGrantDeactivated:
|
||||
p.State = int32(model.PROJECTSTATE_INACTIVE)
|
||||
|
@@ -61,6 +61,8 @@ func (key ProjectGrantSearchKey) ToColumnName() string {
|
||||
return ProjectGrantKeyProjectID
|
||||
case proj_model.GRANTEDPROJECTSEARCHKEY_RESOURCE_OWNER:
|
||||
return ProjectGrantKeyResourceOwner
|
||||
case proj_model.GRANTEDPROJECTSEARCHKEY_ROLE_KEYS:
|
||||
return ProjectGrantKeyRoleKeys
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
@@ -39,6 +39,20 @@ func ProjectGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.Pr
|
||||
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})
|
||||
@@ -55,6 +69,6 @@ func PutProjectGrant(db *gorm.DB, table string, project *model.ProjectGrantView)
|
||||
}
|
||||
|
||||
func DeleteProjectGrant(db *gorm.DB, table, grantID string) error {
|
||||
delete := view.PrepareDeleteByKey(table, model.ProjectSearchKey(proj_model.PROJECTGRANTMEMBERSEARCHKEY_GRANT_ID), grantID)
|
||||
delete := view.PrepareDeleteByKey(table, model.ProjectSearchKey(proj_model.GRANTEDPROJECTSEARCHKEY_GRANTID), grantID)
|
||||
return delete(db)
|
||||
}
|
||||
|
Reference in New Issue
Block a user