mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
79 lines
2.7 KiB
Go
79 lines
2.7 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
"github.com/hanzoteam/server/server/public/shared/i18n"
|
|
"github.com/hanzoteam/server/server/public/shared/mlog"
|
|
"github.com/hanzoteam/server/server/public/shared/request"
|
|
)
|
|
|
|
// NotifyExpiredAccessTokensDeleted DMs the owner of each expired personal
|
|
// access token that the cleanup_expired_access_tokens job is about to delete.
|
|
//
|
|
// This is the at-expiry safety net that complements the pre-expiry warning
|
|
// cascade (pat_expiry_notify): it fires from the cleanup job at the moment a
|
|
// token is removed, so an owner whose fire-and-forget integration silently
|
|
// swallowed the rejection error still learns their token stopped working.
|
|
//
|
|
// It is best-effort. It is invoked before the tokens are deleted so the
|
|
// token→owner mapping is still available, and every failure is logged and
|
|
// swallowed so it never blocks the cleanup. Bot-owned tokens and tokens owned
|
|
// by deactivated users are skipped, matching pat_expiry_notify — GetExpiredBefore
|
|
// returns those too because the cleanup job must still delete them.
|
|
func (a *App) NotifyExpiredAccessTokensDeleted(rctx request.CTX, tokens []*model.UserAccessToken) {
|
|
if len(tokens) == 0 {
|
|
return
|
|
}
|
|
|
|
systemBot, appErr := a.GetSystemBot(rctx)
|
|
if appErr != nil {
|
|
rctx.Logger().Error("Failed to get system bot to notify expired personal access token owners", mlog.Err(appErr))
|
|
return
|
|
}
|
|
|
|
for _, token := range tokens {
|
|
user, appErr := a.GetUser(token.UserId)
|
|
if appErr != nil {
|
|
rctx.Logger().Warn("Failed to get user for expired personal access token notification",
|
|
mlog.String("user_id", token.UserId),
|
|
mlog.Err(appErr),
|
|
)
|
|
continue
|
|
}
|
|
|
|
// Skip bot accounts and deactivated users, matching pat_expiry_notify.
|
|
if user.IsBot || user.DeleteAt != 0 {
|
|
continue
|
|
}
|
|
|
|
channel, appErr := a.GetOrCreateDirectChannel(rctx, token.UserId, systemBot.UserId)
|
|
if appErr != nil {
|
|
rctx.Logger().Warn("Failed to get direct channel for expired personal access token notification",
|
|
mlog.String("user_id", token.UserId),
|
|
mlog.Err(appErr),
|
|
)
|
|
continue
|
|
}
|
|
|
|
T := i18n.GetUserTranslations(user.Locale)
|
|
post := &model.Post{
|
|
ChannelId: channel.Id,
|
|
Message: T("app.user_access_token.expired_deleted_notification", model.StringInterface{
|
|
"Description": token.Description,
|
|
}),
|
|
Type: model.PostTypeDefault,
|
|
UserId: systemBot.UserId,
|
|
}
|
|
|
|
if _, _, appErr := a.CreatePost(rctx, post, channel, model.CreatePostFlags{SetOnline: true}); appErr != nil {
|
|
rctx.Logger().Warn("Failed to send expired personal access token notification",
|
|
mlog.String("user_id", token.UserId),
|
|
mlog.Err(appErr),
|
|
)
|
|
}
|
|
}
|
|
}
|