fix: Remove project (#538)

* Remove project added

* Gemeriert

* corrections

* corrections

* Delete*sByProjectID added

* Correct typos
This commit is contained in:
Michael Waeger
2020-08-05 18:32:25 +02:00
committed by GitHub
parent ade09724a4
commit 41fa434439
39 changed files with 12243 additions and 21919 deletions

View File

@@ -19,6 +19,19 @@ func ApplicationByID(db *gorm.DB, table, appID string) (*model.ApplicationView,
return app, err
}
func ApplicationsByProjectID(db *gorm.DB, table, projectID string) ([]*model.ApplicationView, error) {
applications := make([]*model.ApplicationView, 0)
queries := []*proj_model.ApplicationSearchQuery{
&proj_model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
}
query := repository.PrepareSearchQuery(table, model.ApplicationSearchRequest{Queries: queries})
_, err := query(db, &applications)
if err != nil {
return nil, err
}
return applications, nil
}
func ApplicationByOIDCClientID(db *gorm.DB, table, clientID string) (*model.ApplicationView, error) {
app := new(model.ApplicationView)
clientIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyOIDCClientID, Value: clientID, Method: global_model.SearchMethodEquals}
@@ -58,3 +71,8 @@ func DeleteApplication(db *gorm.DB, table, appID string) error {
delete := repository.PrepareDeleteByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID)
return delete(db)
}
func DeleteApplicationsByProjectID(db *gorm.DB, table, projectID string) error {
delete := repository.PrepareDeleteByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyProjectID), projectID)
return delete(db)
}

View File

@@ -2,18 +2,20 @@ package model
import (
"encoding/json"
"time"
"github.com/caos/logging"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/models"
"github.com/caos/zitadel/internal/project/model"
es_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
"github.com/lib/pq"
"time"
)
const (
ProjectGrantMemberKeyUserID = "user_id"
ProjectGrantMemberKeyGrantID = "grant_id"
ProjectGrantMemberKeyProjectID = "project_id"
ProjectGrantMemberKeyUserName = "user_name"
ProjectGrantMemberKeyEmail = "email"
ProjectGrantMemberKeyFirstName = "first_name"

View File

@@ -63,6 +63,8 @@ func (key ProjectGrantMemberSearchKey) ToColumnName() string {
return ProjectGrantMemberKeyUserID
case proj_model.ProjectGrantMemberSearchKeyGrantID:
return ProjectGrantMemberKeyGrantID
case proj_model.ProjectGrantMemberSearchKeyProjectID:
return ProjectGrantMemberKeyProjectID
default:
return ""
}

View File

@@ -22,6 +22,19 @@ func ProjectGrantMemberByIDs(db *gorm.DB, table, grantID, userID string) (*model
return role, err
}
func ProjectGrantMembersByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectGrantMemberView, error) {
members := make([]*model.ProjectGrantMemberView, 0)
queries := []*proj_model.ProjectGrantMemberSearchQuery{
&proj_model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
}
query := repository.PrepareSearchQuery(table, model.ProjectGrantMemberSearchRequest{Queries: queries})
_, err := query(db, &members)
if err != nil {
return nil, err
}
return members, nil
}
func SearchProjectGrantMembers(db *gorm.DB, table string, req *proj_model.ProjectGrantMemberSearchRequest) ([]*model.ProjectGrantMemberView, uint64, error) {
roles := make([]*model.ProjectGrantMemberView, 0)
query := repository.PrepareSearchQuery(table, model.ProjectGrantMemberSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
@@ -58,3 +71,8 @@ func DeleteProjectGrantMember(db *gorm.DB, table, grantID, userID string) error
delete := repository.PrepareDeleteByObject(table, role)
return delete(db)
}
func DeleteProjectGrantMembersByProjectID(db *gorm.DB, table, projectID string) error {
delete := repository.PrepareDeleteByKey(table, model.ProjectGrantMemberSearchKey(proj_model.ProjectGrantMemberSearchKeyProjectID), projectID)
return delete(db)
}

View File

@@ -72,3 +72,8 @@ func DeleteProjectGrant(db *gorm.DB, table, grantID string) error {
delete := repository.PrepareDeleteByKey(table, model.ProjectGrantSearchKey(proj_model.GrantedProjectSearchKeyGrantID), grantID)
return delete(db)
}
func DeleteProjectGrantsByProjectID(db *gorm.DB, table, projectID string) error {
delete := repository.PrepareDeleteByKey(table, model.ProjectGrantSearchKey(proj_model.GrantedProjectSearchKeyProjectID), projectID)
return delete(db)
}

View File

@@ -22,6 +22,19 @@ func ProjectMemberByIDs(db *gorm.DB, table, projectID, userID string) (*model.Pr
return role, err
}
func ProjectMembersByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectMemberView, error) {
members := make([]*model.ProjectMemberView, 0)
queries := []*proj_model.ProjectMemberSearchQuery{
&proj_model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
}
query := repository.PrepareSearchQuery(table, model.ProjectMemberSearchRequest{Queries: queries})
_, err := query(db, &members)
if err != nil {
return nil, err
}
return members, nil
}
func SearchProjectMembers(db *gorm.DB, table string, req *proj_model.ProjectMemberSearchRequest) ([]*model.ProjectMemberView, uint64, error) {
roles := make([]*model.ProjectMemberView, 0)
query := repository.PrepareSearchQuery(table, model.ProjectMemberSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
@@ -57,3 +70,8 @@ func DeleteProjectMember(db *gorm.DB, table, projectID, userID string) error {
delete := repository.PrepareDeleteByObject(table, role)
return delete(db)
}
func DeleteProjectMembersByProjectID(db *gorm.DB, table, projectID string) error {
delete := repository.PrepareDeleteByKey(table, model.ProjectMemberSearchKey(proj_model.ProjectMemberSearchKeyProjectID), projectID)
return delete(db)
}

View File

@@ -23,6 +23,19 @@ func ProjectRoleByIDs(db *gorm.DB, table, projectID, orgID, key string) (*model.
return role, err
}
func ProjectRolesByProjectID(db *gorm.DB, table, projectID string) ([]*model.ProjectRoleView, error) {
roles := make([]*model.ProjectRoleView, 0)
queries := []*proj_model.ProjectRoleSearchQuery{
&proj_model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
}
query := repository.PrepareSearchQuery(table, model.ProjectRoleSearchRequest{Queries: queries})
_, err := query(db, &roles)
if err != nil {
return nil, err
}
return roles, nil
}
func ResourceOwnerProjectRolesByKey(db *gorm.DB, table, projectID, resourceOwner, key string) ([]*model.ProjectRoleView, error) {
roles := make([]*model.ProjectRoleView, 0)
queries := []*proj_model.ProjectRoleSearchQuery{
@@ -75,3 +88,9 @@ func DeleteProjectRole(db *gorm.DB, table, projectID, orgID, key string) error {
delete := repository.PrepareDeleteByObject(table, role)
return delete(db)
}
func DeleteProjectRolesByProjectID(db *gorm.DB, table, projectID string) error {
delete := repository.PrepareDeleteByKey(table, model.ProjectRoleSearchKey(proj_model.ProjectRoleSearchKeyProjectID), projectID)
return delete(db)
}