[MM-28694] Add MM User information in the CWS request headers (#15824)

* Include user data in the cloud endpoints

Those headers will include the user ID and Email so we can use them
in CWS

* Removed AppError from enterprise/cloud

We're removing the AppError from all the places that don't belong
to the app or api4 packages.

* Remove unused i18n strings

* Move it to the server init of enterprise

Also moved the initialization of the enterprise part in the server after the store is initialized

* Initialize after the store is set in NewServer

The ideal way to do it should be to move the initEnterprise call after
the store is set but that would lead to undesired side-effects so we
initialize the cloud part alone.

Signed-off-by: Mario de Frutos <mario@defrutos.org>
Этот коммит содержится в:
Mario de Frutos Dieguez
2021-03-05 09:23:39 +01:00
коммит произвёл GitHub
родитель 633d82f0ac
Коммит 5203fc8608
8 изменённых файлов: 190 добавлений и 166 удалений

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

@@ -84,9 +84,14 @@ func (a *App) CheckAndSendUserLimitWarningEmails() *model.AppError {
return nil
}
subscription, subErr := a.Cloud().GetSubscription()
if subErr != nil {
return subErr
subscription, err := a.Cloud().GetSubscription(a.Session().UserId)
if err != nil {
return model.NewAppError(
"app.CheckAndSendUserLimitWarningEmails",
"api.cloud.get_subscription.error",
nil,
err.Error(),
http.StatusInternalServerError)
}
if subscription != nil && subscription.IsPaidTier == "true" {
@@ -101,21 +106,40 @@ func (a *App) CheckAndSendUserLimitWarningEmails() *model.AppError {
if remainingUsers > 0 {
return nil
}
sysAdmins, err := a.getSysAdminsEmailRecipients()
if err != nil {
return err
sysAdmins, appErr := a.getSysAdminsEmailRecipients()
if appErr != nil {
return model.NewAppError(
"app.CheckAndSendUserLimitWarningEmails",
"api.cloud.get_admins_emails.error",
nil,
appErr.Error(),
http.StatusInternalServerError)
}
// -1 means they are 1 user over the limit - we only want to send the email for the 11th user
if remainingUsers == -1 {
// Over limit by 1 user
for admin := range sysAdmins {
a.Srv().EmailService.SendOverUserLimitWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL)
_, appErr := a.Srv().EmailService.SendOverUserLimitWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL)
if appErr != nil {
a.Log().Error(
"Error sending user limit warning email to admin",
mlog.String("username", sysAdmins[admin].Username),
mlog.Err(err),
)
}
}
} else if remainingUsers == 0 {
// At limit
for admin := range sysAdmins {
a.Srv().EmailService.SendAtUserLimitWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL)
_, appErr := a.Srv().EmailService.SendAtUserLimitWarningEmail(sysAdmins[admin].Email, sysAdmins[admin].Locale, *a.Config().ServiceSettings.SiteURL)
if appErr != nil {
a.Log().Error(
"Error sending user limit warning email to admin",
mlog.String("username", sysAdmins[admin].Username),
mlog.Err(err),
)
}
}
}
return nil

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

@@ -150,9 +150,9 @@ func RegisterMessageExportInterface(f func(*Server) einterfaces.MessageExportInt
messageExportInterface = f
}
var cloudInterface func(*App) einterfaces.CloudInterface
var cloudInterface func(*Server) einterfaces.CloudInterface
func RegisterCloudInterface(f func(*App) einterfaces.CloudInterface) {
func RegisterCloudInterface(f func(*Server) einterfaces.CloudInterface) {
cloudInterface = f
}
@@ -217,7 +217,4 @@ func (a *App) initEnterprise() {
}
})
}
if cloudInterface != nil {
a.srv.Cloud = cloudInterface(a)
}
}

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

@@ -416,6 +416,14 @@ func NewServer(options ...Option) (*Server, error) {
})
// This enterprise init should happen after the store is set
// but we don't want to move the s.initEnterprise() call because
// we had side-effects with that in the past and needs further
// investigation
if cloudInterface != nil {
s.Cloud = cloudInterface(s)
}
s.telemetryService = telemetry.New(s, s.Store, s.SearchEngine, s.Log)
emailService, err := NewEmailService(s)