From ef2c97a5ec589f12c1a607cc2c41d07865902b4f Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Fri, 11 Jun 2021 17:20:41 -0400 Subject: [PATCH] MM-34434: Trial license flag (#17359) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MM-34434: Added 'is_trial' boolean to all trial license requests and to the License struct. * MM-34434: Generalized the concept of a license request. * MM-34434: Verifies JSON field of license instance is set. * MM-34434: Added missing client param. * MM-34434: Added some tests of the request trial API endpoint. * MM-34434: Removed comment. * fix broken test (#17348) * Add missing wrapped errors (#17339) * Improve document extraction and including a document extraction command (#17183) * Add extract documents content command * Adding the extraction command and making the pure go pdf library as secondary option * Improving the memory usage and docextractor interface * Enable content extraction by default in all the instances * Tiny improvement on archive indexing * Adding App interface generation and the opentracing layer * Fixing linter errors * Addressing PR review comments * Addressing PR review comments * Update en.json (#17356) Automatic Merge * adding new feature flag (#17308) Co-authored-by: Benjamin Cooke Co-authored-by: Mattermod * Bump no_output_timeout to 2 hours (#17358) * log invalid username (#17345) Automatic Merge * MM-34434: Added missing client param. MM-34434: Added some tests of the request trial API endpoint. MM-34434: Removed comment. * MM-34434: Switched to a hard-coded true value. * MM-34434: Reverts test change. * MM-34434: Removes unnecessary field. * MM-34434: Tests that is_trial is hard-coded by TrialLicenseRequest. * MM-34434: Removed accidental commit. * MM-34434: Removes unnecessary is_trial key from JSON payload. * MM-34434: Reverts to old pointer receiver variable name. * MM-34434: Removes test. Co-authored-by: Hossein Co-authored-by: Ben Schumacher Co-authored-by: Jesús Espino Co-authored-by: Amy Blais Co-authored-by: Ben Cooke Co-authored-by: Benjamin Cooke Co-authored-by: Mattermod Co-authored-by: Agniva De Sarker Co-authored-by: Max Erenberg --- api4/license_test.go | 29 +++++++++++++++++++++++++++++ model/client4.go | 2 +- model/license.go | 1 + model/license_test.go | 2 ++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api4/license_test.go b/api4/license_test.go index bec61798cb..a3955b065d 100644 --- a/api4/license_test.go +++ b/api4/license_test.go @@ -111,3 +111,32 @@ func TestRemoveLicenseFile(t *testing.T) { require.True(t, ok) }) } + +func TestRequestTrialLicense(t *testing.T) { + th := Setup(t) + defer th.TearDown() + + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065/" }) + + t.Run("permission denied", func(t *testing.T) { + ok, resp := th.Client.RequestTrialLicense(1000) + CheckForbiddenStatus(t, resp) + require.False(t, ok) + }) + + t.Run("blank site url", func(t *testing.T) { + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "" }) + defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065/" }) + ok, resp := th.SystemAdminClient.RequestTrialLicense(1000) + CheckBadRequestStatus(t, resp) + require.Equal(t, "api.license.request_trial_license.no-site-url.app_error", resp.Error.Id) + require.False(t, ok) + }) + + t.Run("trial license user count less than current users", func(t *testing.T) { + ok, resp := th.SystemAdminClient.RequestTrialLicense(1) + CheckBadRequestStatus(t, resp) + require.Equal(t, "api.license.add_license.unique_users.app_error", resp.Error.Id) + require.False(t, ok) + }) +} diff --git a/model/client4.go b/model/client4.go index 75738d1394..77cb654dbc 100644 --- a/model/client4.go +++ b/model/client4.go @@ -5805,7 +5805,7 @@ func (c *Client4) GetChannelMemberCountsByGroup(channelID string, includeTimezon // RequestTrialLicense will request a trial license and install it in the server func (c *Client4) RequestTrialLicense(users int) (bool, *Response) { - b, _ := json.Marshal(map[string]int{"users": users}) + b, _ := json.Marshal(map[string]interface{}{"users": users, "terms_accepted": true}) r, err := c.DoApiPost("/trial-license", string(b)) if err != nil { return false, BuildErrorResponse(r, err) diff --git a/model/license.go b/model/license.go index e180a356d2..6823b5ffdd 100644 --- a/model/license.go +++ b/model/license.go @@ -31,6 +31,7 @@ type License struct { Features *Features `json:"features"` SkuName string `json:"sku_name"` SkuShortName string `json:"sku_short_name"` + IsTrial bool `json:"is_trial"` } type Customer struct { diff --git a/model/license_test.go b/model/license_test.go index c85b500e58..c3d893d325 100644 --- a/model/license_test.go +++ b/model/license_test.go @@ -158,6 +158,7 @@ func TestLicenseToFromJson(t *testing.T) { Company: NewId(), }, Features: &f, + IsTrial: true, } j := l.ToJson() @@ -169,6 +170,7 @@ func TestLicenseToFromJson(t *testing.T) { CheckInt64(t, l1.IssuedAt, l.IssuedAt) CheckInt64(t, l1.StartsAt, l.StartsAt) CheckInt64(t, l1.ExpiresAt, l.ExpiresAt) + CheckBool(t, l1.IsTrial, l.IsTrial) CheckString(t, l1.Customer.Id, l.Customer.Id) CheckString(t, l1.Customer.Name, l.Customer.Name)