~edwargix/git.sr.ht

1f4f2d16bebeec118d28bb8189b2d846f3f49cce — Drew DeVault 3 years ago 04dac14
API: Implement mutation { deleteACL }
3 files changed, 30 insertions(+), 20 deletions(-)

M api/graph/api/generated.go
M api/graph/schema.graphqls
M api/graph/schema.resolvers.go
M api/graph/api/generated.go => api/graph/api/generated.go +8 -17
@@ 110,7 110,7 @@ type ComplexityRoot struct {

	Mutation struct {
		CreateRepository func(childComplexity int, name string, visibility model.Visibility, description *string) int
		DeleteACL        func(childComplexity int, repoID int, entity string) int
		DeleteACL        func(childComplexity int, id int) int
		DeleteArtifact   func(childComplexity int, id int) int
		DeleteRepository func(childComplexity int, id int) int
		UpdateACL        func(childComplexity int, repoID int, mode model.AccessMode, entity string) int


@@ 245,7 245,7 @@ type MutationResolver interface {
	UpdateRepository(ctx context.Context, id int, input map[string]interface{}) (*model.Repository, error)
	DeleteRepository(ctx context.Context, id int) (*model.Repository, error)
	UpdateACL(ctx context.Context, repoID int, mode model.AccessMode, entity string) (*model.ACL, error)
	DeleteACL(ctx context.Context, repoID int, entity string) (*model.ACL, error)
	DeleteACL(ctx context.Context, id int) (*model.ACL, error)
	UploadArtifact(ctx context.Context, repoID int, revspec string, file graphql.Upload) (*model.Artifact, error)
	DeleteArtifact(ctx context.Context, id int) (*model.Artifact, error)
}


@@ 540,7 540,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
			return 0, false
		}

		return e.complexity.Mutation.DeleteACL(childComplexity, args["repoId"].(int), args["entity"].(string)), true
		return e.complexity.Mutation.DeleteACL(childComplexity, args["id"].(int)), true

	case "Mutation.deleteArtifact":
		if e.complexity.Mutation.DeleteArtifact == nil {


@@ 1599,7 1599,7 @@ type Mutation {
  updateACL(repoId: Int!, mode: AccessMode!, entity: ID!): ACL! @access(scope: ACLS, kind: RW)

  # Deletes an entry from the access control list
  deleteACL(repoId: Int!, entity: ID!): ACL! @access(scope: ACLS, kind: RW)
  deleteACL(id: Int!): ACL! @access(scope: ACLS, kind: RW)

  # Uploads an artifact. revspec must match a specific git tag, and the
  # filename must be unique among artifacts for this repository.


@@ 1692,23 1692,14 @@ func (ec *executionContext) field_Mutation_deleteACL_args(ctx context.Context, r
	var err error
	args := map[string]interface{}{}
	var arg0 int
	if tmp, ok := rawArgs["repoId"]; ok {
		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("repoId"))
	if tmp, ok := rawArgs["id"]; ok {
		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id"))
		arg0, err = ec.unmarshalNInt2int(ctx, tmp)
		if err != nil {
			return nil, err
		}
	}
	args["repoId"] = arg0
	var arg1 string
	if tmp, ok := rawArgs["entity"]; ok {
		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("entity"))
		arg1, err = ec.unmarshalNID2string(ctx, tmp)
		if err != nil {
			return nil, err
		}
	}
	args["entity"] = arg1
	args["id"] = arg0
	return args, nil
}



@@ 3597,7 3588,7 @@ func (ec *executionContext) _Mutation_deleteACL(ctx context.Context, field graph
	resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
		directive0 := func(rctx context.Context) (interface{}, error) {
			ctx = rctx // use context from middleware stack in children
			return ec.resolvers.Mutation().DeleteACL(rctx, args["repoId"].(int), args["entity"].(string))
			return ec.resolvers.Mutation().DeleteACL(rctx, args["id"].(int))
		}
		directive1 := func(ctx context.Context) (interface{}, error) {
			scope, err := ec.unmarshalNAccessScope2gitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐAccessScope(ctx, "ACLS")

M api/graph/schema.graphqls => api/graph/schema.graphqls +1 -1
@@ 352,7 352,7 @@ type Mutation {
  updateACL(repoId: Int!, mode: AccessMode!, entity: ID!): ACL! @access(scope: ACLS, kind: RW)

  # Deletes an entry from the access control list
  deleteACL(repoId: Int!, entity: ID!): ACL! @access(scope: ACLS, kind: RW)
  deleteACL(id: Int!): ACL! @access(scope: ACLS, kind: RW)

  # Uploads an artifact. revspec must match a specific git tag, and the
  # filename must be unique among artifacts for this repository.

M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +21 -2
@@ 361,8 361,27 @@ func (r *mutationResolver) UpdateACL(ctx context.Context, repoID int, mode model
	return &acl, nil
}

func (r *mutationResolver) DeleteACL(ctx context.Context, repoID int, entity string) (*model.ACL, error) {
	panic(fmt.Errorf("deleteACL: not implemented"))
func (r *mutationResolver) DeleteACL(ctx context.Context, id int) (*model.ACL, error) {
	var acl model.ACL
	if err := database.WithTx(ctx, nil, func(tx *sql.Tx) error {
		row := tx.QueryRowContext(ctx, `
			DELETE FROM access
			USING repository repo
			WHERE repo_id = repo.id AND repo.owner_id = $1 AND access.id = $2
			RETURNING access.id, access.created, mode, repo_id, user_id;
		`, auth.ForContext(ctx).UserID, id)
		if err := row.Scan(&acl.ID, &acl.Created, &acl.RawAccessMode,
			&acl.RepoID, &acl.UserID); err != nil {
			if err == sql.ErrNoRows {
				return fmt.Errorf("No such repository or ACL entry found")
			}
			return err
		}
		return nil
	}); err != nil {
		return nil, err
	}
	return &acl, nil
}

func (r *mutationResolver) UploadArtifact(ctx context.Context, repoID int, revspec string, file graphql.Upload) (*model.Artifact, error) {