(ctx context.Context, actingUserName string, targetUser database.User, status database.UserStatus)
| 1054 | } |
| 1055 | |
| 1056 | func (api *API) notifyUserStatusChanged(ctx context.Context, actingUserName string, targetUser database.User, status database.UserStatus) error { |
| 1057 | var labels map[string]string |
| 1058 | var data map[string]any |
| 1059 | var adminTemplateID, personalTemplateID uuid.UUID |
| 1060 | switch status { |
| 1061 | case database.UserStatusSuspended: |
| 1062 | labels = map[string]string{ |
| 1063 | "suspended_account_name": targetUser.Username, |
| 1064 | "suspended_account_user_name": targetUser.Name, |
| 1065 | "initiator": actingUserName, |
| 1066 | } |
| 1067 | data = map[string]any{ |
| 1068 | "user": map[string]any{"id": targetUser.ID, "name": targetUser.Name, "email": targetUser.Email}, |
| 1069 | } |
| 1070 | adminTemplateID = notifications.TemplateUserAccountSuspended |
| 1071 | personalTemplateID = notifications.TemplateYourAccountSuspended |
| 1072 | case database.UserStatusActive: |
| 1073 | labels = map[string]string{ |
| 1074 | "activated_account_name": targetUser.Username, |
| 1075 | "activated_account_user_name": targetUser.Name, |
| 1076 | "initiator": actingUserName, |
| 1077 | } |
| 1078 | data = map[string]any{ |
| 1079 | "user": map[string]any{"id": targetUser.ID, "name": targetUser.Name, "email": targetUser.Email}, |
| 1080 | } |
| 1081 | adminTemplateID = notifications.TemplateUserAccountActivated |
| 1082 | personalTemplateID = notifications.TemplateYourAccountActivated |
| 1083 | default: |
| 1084 | api.Logger.Error(ctx, "user status is not supported", slog.F("username", targetUser.Username), slog.F("user_status", string(status))) |
| 1085 | return xerrors.Errorf("unable to notify admins as the user's status is unsupported") |
| 1086 | } |
| 1087 | |
| 1088 | userAdmins, err := findUserAdmins(ctx, api.Database) |
| 1089 | if err != nil { |
| 1090 | api.Logger.Error(ctx, "unable to find user admins", slog.Error(err)) |
| 1091 | } |
| 1092 | |
| 1093 | // Send notifications to user admins and affected user |
| 1094 | for _, u := range userAdmins { |
| 1095 | // nolint:gocritic // Need notifier actor to enqueue notifications |
| 1096 | if _, err := api.NotificationsEnqueuer.EnqueueWithData(dbauthz.AsNotifier(ctx), u.ID, adminTemplateID, |
| 1097 | labels, data, "api-put-user-status", |
| 1098 | targetUser.ID, |
| 1099 | ); err != nil { |
| 1100 | api.Logger.Warn(ctx, "unable to notify about changed user's status", slog.F("affected_user", targetUser.Username), slog.Error(err)) |
| 1101 | } |
| 1102 | } |
| 1103 | // nolint:gocritic // Need notifier actor to enqueue notifications |
| 1104 | if _, err := api.NotificationsEnqueuer.EnqueueWithData(dbauthz.AsNotifier(ctx), targetUser.ID, personalTemplateID, |
| 1105 | labels, data, "api-put-user-status", |
| 1106 | targetUser.ID, |
| 1107 | ); err != nil { |
| 1108 | api.Logger.Warn(ctx, "unable to notify user about status change of their account", slog.F("affected_user", targetUser.Username), slog.Error(err)) |
| 1109 | } |
| 1110 | return nil |
| 1111 | } |
| 1112 | |
| 1113 | // @Summary Get user appearance settings |
no test coverage detected