Преглед на файлове

use existing format for accept-invite route

Anukul Sangwan преди 4 години
родител
ревизия
ee5ca0d0a0

+ 5 - 10
api/server/handlers/invite/accept.go

@@ -9,32 +9,27 @@ import (
 	"github.com/go-chi/chi"
 
 	"github.com/porter-dev/porter/api/server/handlers"
-	"github.com/porter-dev/porter/api/server/shared"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/config"
+	"github.com/porter-dev/porter/api/server/shared/requestutils"
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/internal/models"
 )
 
 type InviteAcceptHandler struct {
-	handlers.PorterHandlerReader
+	handlers.PorterHandler
 }
 
 func NewInviteAcceptHandler(
 	config *config.Config,
-	decoderValidator shared.RequestDecoderValidator,
 ) *InviteAcceptHandler {
 	return &InviteAcceptHandler{
-		PorterHandlerReader: handlers.NewDefaultPorterHandler(config, decoderValidator, nil),
+		PorterHandler: handlers.NewDefaultPorterHandler(config, nil, nil),
 	}
 }
 
 func (c *InviteAcceptHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	request := &types.AcceptInviteRequest{}
-
-	if ok := c.DecodeAndValidate(w, r, request); !ok {
-		return
-	}
+	token, _ := requestutils.GetURLParamString(r, types.URLParamInviteToken)
 
 	session, err := c.Config().Store.Get(r, c.Config().ServerConf.CookieName)
 
@@ -58,7 +53,7 @@ func (c *InviteAcceptHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 		return
 	}
 
-	invite, err := c.Repo().Invite().ReadInviteByToken(request.Token)
+	invite, err := c.Repo().Invite().ReadInviteByToken(token)
 
 	if err != nil || invite.ProjectID != uint(projectID) {
 		vals := url.Values{}

+ 1 - 1
api/server/handlers/invite/create.go

@@ -60,7 +60,7 @@ func (c *InviteCreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 	if err := c.Config().UserNotifier.SendProjectInviteEmail(
 		&notifier.SendProjectInviteEmailOpts{
 			InviteeEmail:      request.Email,
-			URL:               fmt.Sprintf("%s/api/projects/%d/invites/accept?token=%s", c.Config().ServerConf.ServerURL, project.ID, invite.Token),
+			URL:               fmt.Sprintf("%s/api/projects/%d/invites/%s", c.Config().ServerConf.ServerURL, project.ID, invite.Token),
 			Project:           project.Name,
 			ProjectOwnerEmail: user.Email,
 		},

+ 0 - 30
api/server/handlers/invite/get.go

@@ -1,30 +0,0 @@
-package invite
-
-import (
-	"net/http"
-
-	"github.com/porter-dev/porter/api/server/handlers"
-	"github.com/porter-dev/porter/api/server/shared"
-	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/types"
-	"github.com/porter-dev/porter/internal/models"
-)
-
-type InviteGetHandler struct {
-	handlers.PorterHandlerWriter
-}
-
-func NewInviteGetHandler(
-	config *config.Config,
-	writer shared.ResultWriter,
-) *InviteGetHandler {
-	return &InviteGetHandler{
-		PorterHandlerWriter: handlers.NewDefaultPorterHandler(config, nil, writer),
-	}
-}
-
-func (c *InviteGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	invite, _ := r.Context().Value(types.InviteScope).(*models.Invite)
-
-	c.WriteResult(w, r, invite.ToInviteType())
-}

+ 3 - 34
api/server/router/invite.go

@@ -52,34 +52,6 @@ func getInviteRoutes(
 
 	routes := make([]*Route, 0)
 
-	// GET /api/projects/{project_id}/invites/{invite_id} -> invite.NewInviteGetHandler
-	getEndpoint := factory.NewAPIEndpoint(
-		&types.APIRequestMetadata{
-			Verb:   types.APIVerbGet,
-			Method: types.HTTPVerbGet,
-			Path: &types.Path{
-				Parent:       basePath,
-				RelativePath: relPath,
-			},
-			Scopes: []types.PermissionScope{
-				types.UserScope,
-				types.ProjectScope,
-				types.InviteScope,
-			},
-		},
-	)
-
-	getHandler := invite.NewInviteGetHandler(
-		config,
-		factory.GetResultWriter(),
-	)
-
-	routes = append(routes, &Route{
-		Endpoint: getEndpoint,
-		Handler:  getHandler,
-		Router:   r,
-	})
-
 	// GET /api/projects/{project_id}/invites -> invite.NewInvitesListHandler
 	listEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{
@@ -135,23 +107,20 @@ func getInviteRoutes(
 		Router:   r,
 	})
 
-	// GET /api/projects/{project_id}/invites/accept -> invite.NewInviteAcceptHandler
+	// GET /api/projects/{project_id}/invites/{token} -> invite.NewInviteAcceptHandler
 	acceptEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{
 			Verb:   types.APIVerbGet,
 			Method: types.HTTPVerbGet,
 			Path: &types.Path{
 				Parent:       basePath,
-				RelativePath: "/invites/accept",
+				RelativePath: "/invites/{token}",
 			},
 			Scopes: []types.PermissionScope{},
 		},
 	)
 
-	acceptHandler := invite.NewInviteAcceptHandler(
-		config,
-		factory.GetDecoderValidator(),
-	)
+	acceptHandler := invite.NewInviteAcceptHandler(config)
 
 	routes = append(routes, &Route{
 		Endpoint: acceptEndpoint,

+ 4 - 4
api/types/invite.go

@@ -1,5 +1,9 @@
 package types
 
+const (
+	URLParamInviteToken = "token"
+)
+
 type Invite struct {
 	ID       uint   `json:"id"`
 	Token    string `json:"token"`
@@ -25,7 +29,3 @@ type ListInvitesResponse []*Invite
 type UpdateInviteRoleRequest struct {
 	Kind string `json:"kind,required"`
 }
-
-type AcceptInviteRequest struct {
-	Token string `schema:"token,required"`
-}

+ 1 - 1
dashboard/src/main/home/project-settings/InviteList.tsx

@@ -310,7 +310,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
     const buildInviteLink = (token: string) => `
       ${isHTTPS ? "https://" : ""}${window.location.host}/api/projects/${
       currentProject.id
-    }/invites/accept?token=${token}
+    }/invites/${token}
     `;
 
     const mappedInviteList = inviteList.map(

+ 1 - 1
docs/developing/backend-refactor-status.md

@@ -76,7 +76,7 @@
 | <li>- [x] `POST /api/projects/{project_id}/invites`                                                                         | AS          |                 |             | yes              |
 | <li>- [x] `POST /api/projects/{project_id}/invites/{invite_id}`                                                             | AS          |                 |             | yes              |
 | <li>- [x] `DELETE /api/projects/{project_id}/invites/{invite_id}`                                                           | AS          |                 |             | yes              |
-| <li>- [x] `GET /api/projects/{project_id}/invites/{token}`                                                                  | AS          | yes             |             | yes              |
+| <li>- [x] `GET /api/projects/{project_id}/invites/{token}`                                                                  | AS          |                 |             | yes              |
 | <li>- [x] `GET /api/projects/{project_id}/k8s/configmap`                                                                    | AS          | yes             |             | yes              |
 | <li>- [x] `POST /api/projects/{project_id}/k8s/configmap/create`                                                            | AS          | yes             |             | yes              |
 | <li>- [x] `DELETE /api/projects/{project_id}/k8s/configmap/delete`                                                          | AS          | yes             |             | yes              |