[MM-51233] Updates for Trial Requests (#22620)

* Add new trial form to enrich trial requests with more customer info

* Update snapshots

* One more addition

* Fixes from PR feedback

* Fix types, i18n, update e2e tests

* Fix linter

* Fix i18n?

* Fix blank translation

* update snapshot

* Update snapshot properly

* Remove inapplicable test

* Fix business email validation only happening once

* UX Feedback

* Fix linter

* Fix linter again, not working locally

* FIX LINTER

* Move isvalid check until after some fields are set

* Fix for overlapping modals

* Fix linter

* UX feedback

* UX Feedback

* Fix typo in error modal

* [MM-51551] Add new Trial Form to Playbooks trial requests (#22650)

* Playbooks start trial entrypoints opens new trial form modal

* Fix style

---------

Co-authored-by: Mattermost Build <build@mattermost.com>

* [MM-51347] Trial form error modal for embargoed and air gapped entities (#22656)

* Playbooks start trial entrypoints opens new trial form modal

* Add support for air gapped environments when making trial requests

* Add specific handling for embargoed entities

* undo some code

* Fix linter

* Fix types

* Fix style

* Updates because TE has to upgrade to E0 before it can activate a trial

---------

Co-authored-by: Mattermost Build <build@mattermost.com>

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Nick Misasi
2023-03-30 14:57:07 -04:00
коммит произвёл GitHub
родитель e09d5690a7
Коммит 957f999266
51 изменённых файлов: 2575 добавлений и 970 удалений

Просмотреть файл

@@ -7812,7 +7812,23 @@ func (c *Client4) GetChannelMemberCountsByGroup(channelID string, includeTimezon
return ch, BuildResponse(r), nil
}
func (c *Client4) RequestTrialLicenseWithExtraFields(trialRequest *TrialLicenseRequest) (*Response, error) {
b, err := json.Marshal(trialRequest)
if err != nil {
return nil, NewAppError("RequestTrialLicense", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
r, err := c.DoAPIPost("/trial-license", string(b))
if err != nil {
return BuildResponse(r), err
}
defer closeBody(r)
return BuildResponse(r), nil
}
// RequestTrialLicense will request a trial license and install it in the server
// DEPRECATED - USE RequestTrialLicenseWithExtraFields (this method remains for backwards compatibility)
func (c *Client4) RequestTrialLicense(users int) (*Response, error) {
b, err := json.Marshal(map[string]any{"users": users, "terms_accepted": true})
if err != nil {

Просмотреть файл

@@ -84,6 +84,48 @@ type TrialLicenseRequest struct {
Users int `json:"users"`
TermsAccepted bool `json:"terms_accepted"`
ReceiveEmailsAccepted bool `json:"receive_emails_accepted"`
ContactName string `json:"contact_name"`
ContactEmail string `json:"contact_email"`
CompanyName string `json:"company_name"`
CompanyCountry string `json:"company_country"`
CompanySize string `json:"company_size"`
}
// If any of the below fields are set, this is not a legacy request, and all fields should be validated
func (tlr *TrialLicenseRequest) IsLegacy() bool {
return tlr.CompanyCountry == "" && tlr.CompanyName == "" && tlr.CompanySize == "" && tlr.ContactName == ""
}
func (tlr *TrialLicenseRequest) IsValid() bool {
if !tlr.TermsAccepted {
return false
}
if tlr.Email == "" {
return false
}
if tlr.Users <= 0 {
return false
}
if tlr.CompanyCountry == "" {
return false
}
if tlr.CompanyName == "" {
return false
}
if tlr.CompanySize == "" {
return false
}
if tlr.ContactName == "" {
return false
}
return true
}
type Features struct {

Просмотреть файл

@@ -200,6 +200,100 @@ func TestLicenseRecordPreSave(t *testing.T) {
assert.NotZero(t, lr.CreateAt)
}
func TestIsLegacyTrialRequest(t *testing.T) {
legacyTr := &TrialLicenseRequest{
Email: "test@mattermost.com",
TermsAccepted: true,
SiteURL: "https://mattermost.com",
SiteName: "Mattermost",
Users: 100,
}
t.Run("legacy trial request", func(t *testing.T) {
assert.True(t, legacyTr.IsLegacy())
})
t.Run("legacy trial request with any non-legacy field set is not a legacy request", func(t *testing.T) {
legacyTr.CompanyCountry = "US"
assert.False(t, legacyTr.IsLegacy())
legacyTr.CompanyCountry = ""
legacyTr.CompanyName = "test company"
assert.False(t, legacyTr.IsLegacy())
legacyTr.CompanyName = ""
legacyTr.CompanySize = "50-100"
assert.False(t, legacyTr.IsLegacy())
legacyTr.CompanySize = ""
legacyTr.ContactName = "test user"
assert.False(t, legacyTr.IsLegacy())
legacyTr.ContactName = ""
assert.True(t, legacyTr.IsLegacy())
})
}
func TestTrialLicenseRequestIsValid(t *testing.T) {
validTlr := &TrialLicenseRequest{
Email: "test@test.com",
Users: 100,
CompanyCountry: "US",
CompanyName: "Test Company",
CompanySize: "50-100",
ContactName: "Test User",
TermsAccepted: true,
}
resetBaseRequest := func() {
validTlr = &TrialLicenseRequest{
Email: "test@test.com",
Users: 100,
CompanyCountry: "US",
CompanyName: "Test Company",
CompanySize: "50-100",
ContactName: "Test User",
TermsAccepted: true,
}
}
t.Run("valid request", func(t *testing.T) {
resetBaseRequest()
assert.Equal(t, true, validTlr.IsValid())
})
t.Run("no terms", func(t *testing.T) {
resetBaseRequest()
validTlr.TermsAccepted = false
assert.Equal(t, false, validTlr.IsValid())
})
t.Run("no email", func(t *testing.T) {
resetBaseRequest()
validTlr.Email = ""
assert.Equal(t, false, validTlr.IsValid())
})
t.Run("no CompanyCountry", func(t *testing.T) {
resetBaseRequest()
validTlr.CompanyCountry = ""
assert.Equal(t, false, validTlr.IsValid())
})
t.Run("no CompanyName", func(t *testing.T) {
resetBaseRequest()
validTlr.CompanyName = ""
assert.Equal(t, false, validTlr.IsValid())
})
t.Run("no CompanySize", func(t *testing.T) {
resetBaseRequest()
validTlr.CompanySize = ""
assert.Equal(t, false, validTlr.IsValid())
})
t.Run("Bad User Count", func(t *testing.T) {
resetBaseRequest()
validTlr.Users = 0
assert.Equal(t, false, validTlr.IsValid())
})
}
func TestLicense_IsTrialLicense(t *testing.T) {
t.Run("detect trial license directly from the flag", func(t *testing.T) {
license := &License{