Skip to content

Commit f9eca5a

Browse files
committed
feat: add additional fields to first time setup trial flow
1 parent f9f94b5 commit f9eca5a

File tree

21 files changed

+1336
-33
lines changed

21 files changed

+1336
-33
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ provisionersdk/proto/*.go linguist-generated=true
1212
*.tfstate.dot linguist-generated=true
1313
*.tfplan.dot linguist-generated=true
1414
site/src/api/typesGenerated.ts linguist-generated=true
15+
site/src/pages/SetupPage/countries.tsx linguist-generated=true

.github/workflows/typos.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ darcula = "darcula"
1414
Hashi = "Hashi"
1515
trialer = "trialer"
1616
encrypter = "encrypter"
17-
hel = "hel" # as in helsinki
17+
hel = "hel" # as in helsinki
1818

1919
[files]
2020
extend-exclude = [
@@ -31,4 +31,5 @@ extend-exclude = [
3131
"**/*.test.tsx",
3232
"**/pnpm-lock.yaml",
3333
"tailnet/testdata/**",
34+
"site/src/pages/SetupPage/countries.tsx",
3435
]

coderd/apidoc/docs.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type Options struct {
123123
TracerProvider trace.TracerProvider
124124
ExternalAuthConfigs []*externalauth.Config
125125
RealIPConfig *httpmw.RealIPConfig
126-
TrialGenerator func(ctx context.Context, email string) error
126+
TrialGenerator func(ctx context.Context, body codersdk.LicensorTrialRequest) error
127127
// TLSCertificates is used to mesh DERP servers securely.
128128
TLSCertificates []tls.Certificate
129129
TailnetCoordinator tailnet.Coordinator

coderd/coderdtest/coderdtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type Options struct {
107107
Auditor audit.Auditor
108108
TLSCertificates []tls.Certificate
109109
ExternalAuthConfigs []*externalauth.Config
110-
TrialGenerator func(context.Context, string) error
110+
TrialGenerator func(ctx context.Context, body codersdk.LicensorTrialRequest) error
111111
TemplateScheduleStore schedule.TemplateScheduleStore
112112
Coordinator tailnet.Coordinator
113113

coderd/externalauth/externalauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.ExternalAut
325325
// return a better error.
326326
switch resp.StatusCode {
327327
case http.StatusTooManyRequests:
328-
return nil, fmt.Errorf("rate limit hit, unable to authorize device. please try again later")
328+
return nil, xerrors.New("rate limit hit, unable to authorize device. please try again later")
329329
default:
330330
return nil, err
331331
}

coderd/httpapi/websocket.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"context"
55
"time"
66

7-
"cdr.dev/slog"
87
"nhooyr.io/websocket"
8+
9+
"cdr.dev/slog"
910
)
1011

1112
// Heartbeat loops to ping a WebSocket to keep it alive.

coderd/promoauth/github.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package promoauth
22

33
import (
4-
"fmt"
54
"net/http"
65
"strconv"
76
"time"
7+
8+
"golang.org/x/xerrors"
89
)
910

1011
type rateLimits struct {
@@ -81,7 +82,7 @@ func (p *headerParser) string(key string) string {
8182

8283
v := p.header.Get(key)
8384
if v == "" {
84-
p.errors[key] = fmt.Errorf("missing header %q", key)
85+
p.errors[key] = xerrors.Errorf("missing header %q", key)
8586
}
8687
return v
8788
}

coderd/users.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,16 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) {
152152
}
153153

154154
if createUser.Trial && api.TrialGenerator != nil {
155-
err = api.TrialGenerator(ctx, createUser.Email)
155+
err = api.TrialGenerator(ctx, codersdk.LicensorTrialRequest{
156+
Email: createUser.Email,
157+
FirstName: createUser.TrialInfo.FirstName,
158+
LastName: createUser.TrialInfo.LastName,
159+
PhoneNumber: createUser.TrialInfo.PhoneNumber,
160+
JobTitle: createUser.TrialInfo.JobTitle,
161+
CompanyName: createUser.TrialInfo.CompanyName,
162+
Country: createUser.TrialInfo.CompanyName,
163+
Developers: createUser.TrialInfo.Developers,
164+
})
156165
if err != nil {
157166
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
158167
Message: "Failed to generate trial",

coderd/users_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestFirstUser(t *testing.T) {
7676
t.Parallel()
7777
called := make(chan struct{})
7878
client := coderdtest.New(t, &coderdtest.Options{
79-
TrialGenerator: func(ctx context.Context, s string) error {
79+
TrialGenerator: func(context.Context, codersdk.LicensorTrialRequest) error {
8080
close(called)
8181
return nil
8282
},

codersdk/users.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,38 @@ type GetUsersResponse struct {
6363
Count int `json:"count"`
6464
}
6565

66+
// @typescript-ignore LicensorTrialRequest
67+
type LicensorTrialRequest struct {
68+
DeploymentID string `json:"deployment_id"`
69+
Email string `json:"email"`
70+
Source string `json:"source"`
71+
72+
// Personal details.
73+
FirstName string `json:"first_name"`
74+
LastName string `json:"last_name"`
75+
PhoneNumber string `json:"phone_number"`
76+
JobTitle string `json:"job_title"`
77+
CompanyName string `json:"company_name"`
78+
Country string `json:"country"`
79+
Developers string `json:"developers"`
80+
}
81+
6682
type CreateFirstUserRequest struct {
67-
Email string `json:"email" validate:"required,email"`
68-
Username string `json:"username" validate:"required,username"`
69-
Password string `json:"password" validate:"required"`
70-
Trial bool `json:"trial"`
83+
Email string `json:"email" validate:"required,email"`
84+
Username string `json:"username" validate:"required,username"`
85+
Password string `json:"password" validate:"required"`
86+
Trial bool `json:"trial"`
87+
TrialInfo CreateFirstUserTrialInfo `json:"trial_info"`
88+
}
89+
90+
type CreateFirstUserTrialInfo struct {
91+
FirstName string `json:"first_name"`
92+
LastName string `json:"last_name"`
93+
PhoneNumber string `json:"phone_number"`
94+
JobTitle string `json:"job_title"`
95+
CompanyName string `json:"company_name"`
96+
Country string `json:"country"`
97+
Developers string `json:"developers"`
7198
}
7299

73100
// CreateFirstUserResponse contains IDs for newly created user info.

docs/api/schemas.md

Lines changed: 42 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/users.md

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/trialer/trialer.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@ import (
1414

1515
"github.com/coder/coder/v2/coderd/database"
1616
"github.com/coder/coder/v2/coderd/database/dbtime"
17+
"github.com/coder/coder/v2/codersdk"
1718
"github.com/coder/coder/v2/enterprise/coderd/license"
1819
)
1920

20-
type request struct {
21-
DeploymentID string `json:"deployment_id"`
22-
Email string `json:"email"`
23-
}
24-
2521
// New creates a handler that can issue trial licenses!
26-
func New(db database.Store, url string, keys map[string]ed25519.PublicKey) func(ctx context.Context, email string) error {
27-
return func(ctx context.Context, email string) error {
22+
func New(db database.Store, url string, keys map[string]ed25519.PublicKey) func(ctx context.Context, body codersdk.LicensorTrialRequest) error {
23+
return func(ctx context.Context, body codersdk.LicensorTrialRequest) error {
2824
deploymentID, err := db.GetDeploymentID(ctx)
2925
if err != nil {
3026
return xerrors.Errorf("get deployment id: %w", err)
3127
}
32-
data, err := json.Marshal(request{
33-
DeploymentID: deploymentID,
34-
Email: email,
35-
})
28+
body.DeploymentID = deploymentID
29+
data, err := json.Marshal(body)
3630
if err != nil {
3731
return xerrors.Errorf("marshal: %w", err)
3832
}

enterprise/trialer/trialer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/stretchr/testify/require"
1010

1111
"github.com/coder/coder/v2/coderd/database/dbmem"
12+
"github.com/coder/coder/v2/codersdk"
1213
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
1314
"github.com/coder/coder/v2/enterprise/trialer"
1415
)
@@ -26,7 +27,7 @@ func TestTrialer(t *testing.T) {
2627
db := dbmem.New()
2728

2829
gen := trialer.New(db, srv.URL, coderdenttest.Keys)
29-
err := gen(context.Background(), "kyle@coder.com")
30+
err := gen(context.Background(), codersdk.LicensorTrialRequest{Email: "kyle+colin@coder.com"})
3031
require.NoError(t, err)
3132
licenses, err := db.GetLicenses(context.Background())
3233
require.NoError(t, err)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ require (
206206

207207
require go.uber.org/mock v0.4.0
208208

209-
require github.com/benbjohnson/clock v1.3.5 // indirect
209+
require github.com/benbjohnson/clock v1.3.5
210210

211211
require (
212212
cloud.google.com/go/compute v1.23.3 // indirect

0 commit comments

Comments
 (0)