gateway: update CreateProject api

remove currentuserid since we can get it directly in the action
This commit is contained in:
Simone Gotti 2019-05-09 15:34:58 +02:00
parent e1d0318c9b
commit a43be4a6be
2 changed files with 4 additions and 13 deletions

View File

@ -49,7 +49,6 @@ func (h *ActionHandler) GetProject(ctx context.Context, projectRef string) (*csa
}
type CreateProjectRequest struct {
CurrentUserID string
Name string
ParentRef string
Visibility types.Visibility
@ -59,9 +58,11 @@ type CreateProjectRequest struct {
}
func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectRequest) (*csapi.Project, error) {
user, resp, err := h.configstoreClient.GetUser(ctx, req.CurrentUserID)
curUserID := h.CurrentUserID(ctx)
user, resp, err := h.configstoreClient.GetUser(ctx, curUserID)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", req.CurrentUserID))
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", curUserID))
}
parentRef := req.ParentRef
if parentRef == "" {

View File

@ -19,7 +19,6 @@ import (
"net/http"
"net/url"
"github.com/pkg/errors"
csapi "github.com/sorintlab/agola/internal/services/configstore/api"
"github.com/sorintlab/agola/internal/services/gateway/action"
"github.com/sorintlab/agola/internal/services/types"
@ -58,21 +57,12 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return
}
userIDVal := ctx.Value("userid")
if userIDVal == nil {
httpError(w, util.NewErrBadRequest(errors.Errorf("user not authenticated")))
return
}
userID := userIDVal.(string)
h.log.Infof("userID: %q", userID)
areq := &action.CreateProjectRequest{
Name: req.Name,
ParentRef: req.ParentRef,
Visibility: req.Visibility,
RepoPath: req.RepoPath,
RemoteSourceName: req.RemoteSourceName,
CurrentUserID: userID,
SkipSSHHostKeyCheck: req.SkipSSHHostKeyCheck,
}