[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
Этот коммит содержится в:
Allan Guwatudde
2023-04-04 13:57:32 +03:00
коммит произвёл GitHub
родитель bbadbfde45
Коммит ed36e8bd64
15 изменённых файлов: 304 добавлений и 6 удалений

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

@@ -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)
}