Deprecate admin advisor (#26045)
* Deprecate admin advisor * Webapp portion * More webapp deprecation * More cleanup * Linting * emoved metric ack dialog from annoucenemet bar * Cleanued up uninsed i18n strings * Updated test * fixed types * Updating server test * Updated i18n * Updated cypress test: * Updated cypress test: --------- Co-authored-by: harshil Sharma <harshilsharma63@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dc8fc773dc
Коммит
e9b9d4ff60
@@ -27,14 +27,12 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
@@ -230,14 +228,6 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
|
||||
return "", appErr
|
||||
}
|
||||
|
||||
if strings.HasPrefix(upstreamURL, "/warn_metrics/") {
|
||||
appErr = a.doLocalWarnMetricsRequest(c, upstreamURL, upstreamRequest)
|
||||
if appErr != nil {
|
||||
return "", appErr
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
requestJSON, err := json.Marshal(upstreamRequest)
|
||||
if err != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
@@ -446,92 +436,6 @@ func (ch *Channels) doPluginRequest(c request.CTX, method, rawURL string, values
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (a *App) doLocalWarnMetricsRequest(c request.CTX, rawURL string, upstreamRequest *model.PostActionIntegrationRequest) *model.AppError {
|
||||
_, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
return model.NewAppError("doLocalWarnMetricsRequest", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
warnMetricId := filepath.Base(rawURL)
|
||||
if warnMetricId == "" {
|
||||
return model.NewAppError("doLocalWarnMetricsRequest", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
license := a.Srv().License()
|
||||
if license != nil {
|
||||
c.Logger().Debug("License is present, skip this call")
|
||||
return nil
|
||||
}
|
||||
|
||||
user, appErr := a.GetUser(c.Session().UserId)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
botPost := &model.Post{
|
||||
UserId: upstreamRequest.Context["bot_user_id"].(string),
|
||||
ChannelId: upstreamRequest.ChannelId,
|
||||
HasReactions: true,
|
||||
}
|
||||
|
||||
isE0Edition := (model.BuildEnterpriseReady == "true") // license == nil was already validated upstream
|
||||
_, warnMetricDisplayTexts := a.getWarnMetricStatusAndDisplayTextsForId(c, warnMetricId, i18n.T, isE0Edition)
|
||||
botPost.Message = ":white_check_mark: " + warnMetricDisplayTexts.BotSuccessMessage
|
||||
|
||||
if isE0Edition {
|
||||
if appErr = a.RequestLicenseAndAckWarnMetric(c, warnMetricId, true); appErr != nil {
|
||||
botPost.Message = ":warning: " + i18n.T("api.server.warn_metric.bot_response.start_trial_failure.message")
|
||||
}
|
||||
} else {
|
||||
forceAck := upstreamRequest.Context["force_ack"].(bool)
|
||||
if appErr = a.NotifyAndSetWarnMetricAck(c, warnMetricId, user, forceAck, true); appErr != nil {
|
||||
if forceAck {
|
||||
return appErr
|
||||
}
|
||||
mailtoLinkText := a.buildWarnMetricMailtoLink(c, warnMetricId, user)
|
||||
botPost.Message = ":warning: " + i18n.T("api.server.warn_metric.bot_response.notification_failure.message")
|
||||
actions := []*model.PostAction{}
|
||||
actions = append(actions,
|
||||
&model.PostAction{
|
||||
Id: "emailUs",
|
||||
Name: i18n.T("api.server.warn_metric.email_us"),
|
||||
Type: model.PostActionTypeButton,
|
||||
Options: []*model.PostActionOptions{
|
||||
{
|
||||
Text: "WarnMetricMailtoUrl",
|
||||
Value: mailtoLinkText,
|
||||
},
|
||||
{
|
||||
Text: "TrackEventId",
|
||||
Value: warnMetricId,
|
||||
},
|
||||
},
|
||||
Integration: &model.PostActionIntegration{
|
||||
Context: model.StringInterface{
|
||||
"bot_user_id": botPost.UserId,
|
||||
"force_ack": true,
|
||||
},
|
||||
URL: fmt.Sprintf("/warn_metrics/ack/%s", model.SystemWarnMetricNumberOfActiveUsers500),
|
||||
},
|
||||
},
|
||||
)
|
||||
attachments := []*model.SlackAttachment{{
|
||||
AuthorName: "",
|
||||
Title: "",
|
||||
Actions: actions,
|
||||
Text: i18n.T("api.server.warn_metric.bot_response.notification_failure.body"),
|
||||
}}
|
||||
model.ParseSlackAttachment(botPost, attachments)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := a.CreatePostAsUser(c, botPost, c.Session().Id, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type MailToLinkContent struct {
|
||||
MetricId string `json:"metric_id"`
|
||||
MailRecipient string `json:"mail_recipient"`
|
||||
@@ -545,43 +449,6 @@ func (mlc *MailToLinkContent) ToJSON() string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (a *App) buildWarnMetricMailtoLink(rctx request.CTX, warnMetricId string, user *model.User) string {
|
||||
T := i18n.GetUserTranslations(user.Locale)
|
||||
_, warnMetricDisplayTexts := a.getWarnMetricStatusAndDisplayTextsForId(rctx, warnMetricId, T, false)
|
||||
|
||||
mailBody := warnMetricDisplayTexts.EmailBody
|
||||
mailBody += T("api.server.warn_metric.bot_response.mailto_contact_header", map[string]any{"Contact": user.GetFullName()})
|
||||
mailBody += "\r\n"
|
||||
mailBody += T("api.server.warn_metric.bot_response.mailto_email_header", map[string]any{"Email": user.Email})
|
||||
mailBody += "\r\n"
|
||||
|
||||
registeredUsersCount, err := a.Srv().Store().User().Count(model.UserCountOptions{})
|
||||
if err != nil {
|
||||
rctx.Logger().Warn("Error retrieving the number of registered users", mlog.Err(err))
|
||||
} else {
|
||||
mailBody += i18n.T("api.server.warn_metric.bot_response.mailto_registered_users_header", map[string]any{"NoRegisteredUsers": registeredUsersCount})
|
||||
mailBody += "\r\n"
|
||||
}
|
||||
|
||||
mailBody += T("api.server.warn_metric.bot_response.mailto_site_url_header", map[string]any{"SiteUrl": a.GetSiteURL()})
|
||||
mailBody += "\r\n"
|
||||
|
||||
mailBody += T("api.server.warn_metric.bot_response.mailto_diagnostic_id_header", map[string]any{"DiagnosticId": a.TelemetryId()})
|
||||
mailBody += "\r\n"
|
||||
|
||||
mailBody += T("api.server.warn_metric.bot_response.mailto_footer")
|
||||
|
||||
mailToLinkContent := &MailToLinkContent{
|
||||
MetricId: warnMetricId,
|
||||
MailRecipient: model.MmSupportAdvisorAddress,
|
||||
MailCC: user.Email,
|
||||
MailSubject: T("api.server.warn_metric.bot_response.mailto_subject"),
|
||||
MailBody: mailBody,
|
||||
}
|
||||
|
||||
return mailToLinkContent.ToJSON()
|
||||
}
|
||||
|
||||
func (a *App) DoLocalRequest(c request.CTX, rawURL string, body []byte) (*http.Response, *model.AppError) {
|
||||
return a.doPluginRequest(c, "POST", rawURL, nil, body)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user