[MM-51236] - Add opt-in checkbox in self-hosted account creation page (#22709)
* [MM-51236] - Add opt-in checkbox in self-hosted account creation page * add server impl * fix lint and translations * add tests * improvents * fix model * fix mocks * feedback impl * update text color * handle error * fix tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bbadbfde45
Коммит
ed36e8bd64
@@ -36,6 +36,8 @@ func (api *API) InitHostedCustomer() {
|
||||
api.BaseRoutes.HostedCustomer.Handle("/invoices", api.APISessionRequired(selfHostedInvoices)).Methods("GET")
|
||||
// GET /api/v4/hosted_customer/invoices/{invoice_id:in_[A-Za-z0-9]+}/pdf
|
||||
api.BaseRoutes.HostedCustomer.Handle("/invoices/{invoice_id:in_[A-Za-z0-9]+}/pdf", api.APISessionRequired(selfHostedInvoicePDF)).Methods("GET")
|
||||
|
||||
api.BaseRoutes.HostedCustomer.Handle("/subscribe-newsletter", api.APIHandler(handleSubscribeToNewsletter)).Methods(http.MethodPost)
|
||||
}
|
||||
|
||||
func ensureSelfHostedAdmin(c *Context, where string) {
|
||||
@@ -293,3 +295,33 @@ func selfHostedInvoicePDF(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
r,
|
||||
)
|
||||
}
|
||||
|
||||
func handleSubscribeToNewsletter(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
const where = "Api4.handleSubscribeToNewsletter"
|
||||
ensured := ensureCloudInterface(c, where)
|
||||
if !ensured {
|
||||
return
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError(where, "api.cloud.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
req := new(model.SubscribeNewsletterRequest)
|
||||
err = json.Unmarshal(bodyBytes, req)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError(where, "api.cloud.request_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
req.ServerID = c.App.Srv().TelemetryId()
|
||||
|
||||
if err := c.App.Cloud().SubscribeToNewsletter("", req); err != nil {
|
||||
c.Err = model.NewAppError(where, "api.server.cws.subscribe_to_newsletter.app_error", nil, "CWS Server failed to subscribe to newsletter.", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
@@ -47,4 +47,5 @@ type CloudInterface interface {
|
||||
CheckCWSConnection(userId string) error
|
||||
|
||||
SelfServeDeleteWorkspace(userID string, deletionRequest *model.WorkspaceDeletionRequest) error
|
||||
SubscribeToNewsletter(userID string, req *model.SubscribeNewsletterRequest) error
|
||||
}
|
||||
|
||||
@@ -540,6 +540,20 @@ func (_m *CloudInterface) SelfServeDeleteWorkspace(userID string, deletionReques
|
||||
return r0
|
||||
}
|
||||
|
||||
// SubscribeToNewsletter provides a mock function with given fields: userID, req
|
||||
func (_m *CloudInterface) SubscribeToNewsletter(userID string, req *model.SubscribeNewsletterRequest) error {
|
||||
ret := _m.Called(userID, req)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, *model.SubscribeNewsletterRequest) error); ok {
|
||||
r0 = rf(userID, req)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// UpdateCloudCustomer provides a mock function with given fields: userID, customerInfo
|
||||
func (_m *CloudInterface) UpdateCloudCustomer(userID string, customerInfo *model.CloudCustomerInfo) (*model.CloudCustomer, error) {
|
||||
ret := _m.Called(userID, customerInfo)
|
||||
|
||||
@@ -2591,6 +2591,10 @@
|
||||
"id": "api.server.cws.needs_enterprise_edition",
|
||||
"translation": "Service only available in Mattermost Enterprise edition"
|
||||
},
|
||||
{
|
||||
"id": "api.server.cws.subscribe_to_newsletter.app_error",
|
||||
"translation": "CWS Server failed to subscribe to newsletter."
|
||||
},
|
||||
{
|
||||
"id": "api.server.hosted_signup_unavailable.error",
|
||||
"translation": "Portal unavailable for self-hosted signup."
|
||||
|
||||
Ссылка в новой задаче
Block a user