Quellcode durchsuchen

changed gorm query

Stefan McShane vor 3 Jahren
Ursprung
Commit
95cc7a6850

+ 0 - 6
api/server/authz/policy/policy.go

@@ -1,8 +1,6 @@
 package policy
 
 import (
-	"fmt"
-
 	"github.com/porter-dev/porter/api/types"
 )
 
@@ -28,21 +26,17 @@ func HasScopeAccess(
 			continue
 		}
 
-		fmt.Println("STEFAN1", matchDocs)
 		for matchScope, matchDoc := range matchDocs {
 			// for the matching scope, make sure it matches the allowed resources if the
 			// resource list is explicitly set
 			if len(matchDoc.Resources) > 0 && reqScopes[matchScope].Verb != types.APIVerbList {
 				if !isResourceAllowed(matchDoc, reqScopes[matchScope].Resource) {
-					fmt.Println("STEFANR", matchScope, *matchDoc, reqScopes[matchScope].Resource)
 					isValid = false
 				}
 			}
 
 			// for the matching scope, make sure it matches the allowed verbs
 			if !isVerbAllowed(matchDoc, reqScopes[matchScope].Verb) {
-				fmt.Println("STEFANP", *matchDoc, matchScope, reqScopes[matchScope].Verb)
-
 				isValid = false
 			}
 		}

+ 1 - 1
api/server/handlers/api_contract/list.go

@@ -49,7 +49,7 @@ func (c *APIContractRevisionListHandler) ServeHTTP(w http.ResponseWriter, r *htt
 
 	revisions, err := c.Config().Repo.APIContractRevisioner().List(ctx, proj.ID, uint(clusterID))
 	if err != nil {
-		e := fmt.Errorf("error creating new api contract revision: %w", err)
+		e := fmt.Errorf("error listing api contract revision: %w", err)
 		c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
 		return
 	}

+ 2 - 0
api/server/router/project.go

@@ -1274,6 +1274,7 @@ func getProjectRoutes(
 			Scopes: []types.PermissionScope{
 				types.UserScope,
 				types.ProjectScope,
+				types.APIContractRevisionScope,
 			},
 		},
 	)
@@ -1302,6 +1303,7 @@ func getProjectRoutes(
 			Scopes: []types.PermissionScope{
 				types.UserScope,
 				types.ProjectScope,
+				types.APIContractRevisionScope,
 			},
 		},
 	)

+ 1 - 1
internal/repository/api_contract.go

@@ -11,7 +11,7 @@ import (
 type APIContractRevisioner interface {
 	Insert(ctx context.Context, conf models.APIContractRevision) (models.APIContractRevision, error)
 	// List returns a slice of APIContractRevision, sorted by created_at descending
-	List(ctx context.Context, projectID uint, clusterID uint) ([]models.APIContractRevision, error)
+	List(ctx context.Context, projectID uint, clusterID uint) ([]*models.APIContractRevision, error)
 	Get(ctx context.Context, revisionID uuid.UUID) (models.APIContractRevision, error)
 	Delete(ctx context.Context, projectID uint, clusterID uint, revisionID uuid.UUID) error
 }

+ 4 - 4
internal/repository/gorm/api_contract.go

@@ -34,17 +34,17 @@ func (cr APIContractRepository) Insert(ctx context.Context, conf models.APIContr
 
 // List returns a list of api contract revisions sorted by created date for a given projectID.
 // If clusterID is not specified (set to 0), this will return all revisions for a given project
-func (cr APIContractRepository) List(ctx context.Context, projectID uint, clusterID uint) ([]models.APIContractRevision, error) {
-	var confs []models.APIContractRevision
+func (cr APIContractRepository) List(ctx context.Context, projectID uint, clusterID uint) ([]*models.APIContractRevision, error) {
+	var confs []*models.APIContractRevision
 
 	if clusterID == 0 {
-		tx := cr.db.Preload("api_contract_revisions").Where("project_id = ?", projectID, clusterID).Order("created_at").Find(&confs)
+		tx := cr.db.Where("project_id = ?", projectID).Find(&confs)
 		if tx.Error != nil {
 			return nil, tx.Error
 		}
 		return confs, nil
 	}
-	tx := cr.db.Preload("api_contract_revisions").Where("project_id = ? and cluster_id = ?", projectID, clusterID).Order("created_at").Find(&confs)
+	tx := cr.db.Where("project_id = ? and cluster_id = ?", projectID, clusterID).Find(&confs)
 	if tx.Error != nil {
 		return nil, tx.Error
 	}

+ 2 - 2
internal/repository/test/api_contract.go

@@ -23,8 +23,8 @@ func (cr APIContractRepository) Insert(ctx context.Context, conf models.APIContr
 }
 
 // List returns a list of api contract revisions sorted by created date for a given project and cluster
-func (cr APIContractRepository) List(ctx context.Context, projectID uint, clusterID uint) ([]models.APIContractRevision, error) {
-	var confs []models.APIContractRevision
+func (cr APIContractRepository) List(ctx context.Context, projectID uint, clusterID uint) ([]*models.APIContractRevision, error) {
+	var confs []*models.APIContractRevision
 	return confs, errors.New("not implemented")
 }