mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 11:27:33 +00:00
feat(auth): My user changes (#318)
* fix: project by id loads project from view and from eventstore * fix: correct search key for role * feat(auth): my user changes * fix: improve error handling in change converters * fix: log-id
This commit is contained in:
@@ -14,7 +14,7 @@ type ProjectCache struct {
|
||||
|
||||
func StartCache(conf *config.CacheConfig) (*ProjectCache, error) {
|
||||
projectCache, err := conf.Config.NewCache()
|
||||
logging.Log("EVENT-vDneN").OnError(err).Panic("unable to create project cache")
|
||||
logging.Log("EVENT-CsHdo").OnError(err).Panic("unable to create project cache")
|
||||
|
||||
return &ProjectCache{projectCache: projectCache}, nil
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func StartCache(conf *config.CacheConfig) (*ProjectCache, error) {
|
||||
func (c *ProjectCache) getProject(ID string) (project *model.Project) {
|
||||
project = &model.Project{ObjectRoot: models.ObjectRoot{AggregateID: ID}}
|
||||
if err := c.projectCache.Get(ID, project); err != nil {
|
||||
logging.Log("EVENT-4eTZh").WithError(err).Debug("error in getting cache")
|
||||
logging.Log("EVENT-tMydV").WithError(err).Debug("error in getting cache")
|
||||
}
|
||||
return project
|
||||
}
|
||||
@@ -30,6 +30,6 @@ func (c *ProjectCache) getProject(ID string) (project *model.Project) {
|
||||
func (c *ProjectCache) cacheProject(project *model.Project) {
|
||||
err := c.projectCache.Set(project.AggregateID, project)
|
||||
if err != nil {
|
||||
logging.Log("EVENT-ThnBb").WithError(err).Debug("error in setting project cache")
|
||||
logging.Log("EVENT-3wKzj").WithError(err).Debug("error in setting project cache")
|
||||
}
|
||||
}
|
||||
|
@@ -9,58 +9,51 @@ import (
|
||||
)
|
||||
|
||||
func ProjectGrantByProjectAndOrg(db *gorm.DB, table, projectID, orgID string) (*model.ProjectGrantView, error) {
|
||||
project := new(model.ProjectGrantView)
|
||||
projectGrant := new(model.ProjectGrantView)
|
||||
|
||||
projectIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}
|
||||
orgIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyOrgID, Value: orgID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, projectIDQuery, orgIDQuery)
|
||||
err := query(db, project)
|
||||
return project, err
|
||||
err := query(db, projectGrant)
|
||||
return projectGrant, err
|
||||
}
|
||||
|
||||
func ProjectGrantByID(db *gorm.DB, table, grantID string) (*model.ProjectGrantView, error) {
|
||||
project := new(model.ProjectGrantView)
|
||||
projectGrant := new(model.ProjectGrantView)
|
||||
grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, grantIDQuery)
|
||||
err := query(db, project)
|
||||
return project, err
|
||||
err := query(db, projectGrant)
|
||||
return projectGrant, err
|
||||
}
|
||||
|
||||
func ProjectGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectGrantView, error) {
|
||||
projects := make([]*model.ProjectGrantView, 0)
|
||||
projectGrants := make([]*model.ProjectGrantView, 0)
|
||||
queries := []*proj_model.ProjectGrantViewSearchQuery{
|
||||
&proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
|
||||
{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries})
|
||||
_, err := query(db, &projects)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return projects, nil
|
||||
_, err := query(db, &projectGrants)
|
||||
return projectGrants, err
|
||||
}
|
||||
|
||||
func ProjectGrantsByProjectIDAndRoleKey(db *gorm.DB, table, projectID, roleKey string) ([]*model.ProjectGrantView, error) {
|
||||
projects := make([]*model.ProjectGrantView, 0)
|
||||
projectGrants := make([]*model.ProjectGrantView, 0)
|
||||
queries := []*proj_model.ProjectGrantViewSearchQuery{
|
||||
&proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
|
||||
&proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyRoleKeys, Value: roleKey, Method: global_model.SearchMethodListContains},
|
||||
{Key: proj_model.GrantedProjectSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
|
||||
{Key: proj_model.GrantedProjectSearchKeyRoleKeys, Value: roleKey, Method: global_model.SearchMethodListContains},
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.ProjectGrantSearchRequest{Queries: queries})
|
||||
_, err := query(db, &projects)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return projects, nil
|
||||
_, err := query(db, &projectGrants)
|
||||
|
||||
return projectGrants, err
|
||||
}
|
||||
|
||||
func SearchProjectGrants(db *gorm.DB, table string, req *proj_model.ProjectGrantViewSearchRequest) ([]*model.ProjectGrantView, int, error) {
|
||||
projects := make([]*model.ProjectGrantView, 0)
|
||||
projectGrants := make([]*model.ProjectGrantView, 0)
|
||||
query := repository.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
|
||||
count, err := query(db, &projectGrants)
|
||||
|
||||
return projectGrants, count, err
|
||||
}
|
||||
|
||||
func PutProjectGrant(db *gorm.DB, table string, project *model.ProjectGrantView) error {
|
||||
|
Reference in New Issue
Block a user