1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

activity: log account link/unlinks

This commit is contained in:
Harvey Tindall 2023-10-19 21:13:00 +01:00
parent b620c0d9ae
commit 9d1c7bba6f
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 126 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/lithammer/shortuuid/v3"
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
) )
@ -677,7 +678,18 @@ func (app *appContext) DiscordConnect(gc *gin.Context) {
respondBool(500, false, gc) respondBool(500, false, gc)
return return
} }
app.storage.SetDiscordKey(req.JellyfinID, user) app.storage.SetDiscordKey(req.JellyfinID, user)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactLinked,
UserID: req.JellyfinID,
SourceType: ActivityAdmin,
Source: gc.GetString("jfId"),
Value: "discord",
Time: time.Now(),
})
linkExistingOmbiDiscordTelegram(app) linkExistingOmbiDiscordTelegram(app)
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -697,6 +709,16 @@ func (app *appContext) UnlinkDiscord(gc *gin.Context) {
return return
} */ } */
app.storage.DeleteDiscordKey(req.ID) app.storage.DeleteDiscordKey(req.ID)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactUnlinked,
UserID: req.ID,
SourceType: ActivityAdmin,
Source: gc.GetString("jfId"),
Value: "discord",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -715,6 +737,16 @@ func (app *appContext) UnlinkTelegram(gc *gin.Context) {
return return
} */ } */
app.storage.DeleteTelegramKey(req.ID) app.storage.DeleteTelegramKey(req.ID)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactUnlinked,
UserID: req.ID,
SourceType: ActivityAdmin,
Source: gc.GetString("jfId"),
Value: "telegram",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -733,5 +765,15 @@ func (app *appContext) UnlinkMatrix(gc *gin.Context) {
return return
} */ } */
app.storage.DeleteMatrixKey(req.ID) app.storage.DeleteMatrixKey(req.ID)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactUnlinked,
UserID: req.ID,
SourceType: ActivityAdmin,
Source: gc.GetString("jfId"),
Value: "matrix",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }

View File

@ -208,6 +208,16 @@ func (app *appContext) confirmMyAction(gc *gin.Context, key string) {
} }
emailStore.Addr = claims["email"].(string) emailStore.Addr = claims["email"].(string)
app.storage.SetEmailsKey(id, emailStore) app.storage.SetEmailsKey(id, emailStore)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactLinked,
UserID: gc.GetString("jfId"),
SourceType: ActivityUser,
Source: gc.GetString("jfId"),
Value: "email",
Time: time.Now(),
})
if app.config.Section("ombi").Key("enabled").MustBool(false) { if app.config.Section("ombi").Key("enabled").MustBool(false) {
ombiUser, code, err := app.getOmbiUser(id) ombiUser, code, err := app.getOmbiUser(id)
if code == 200 && err == nil { if code == 200 && err == nil {
@ -360,6 +370,16 @@ func (app *appContext) MyDiscordVerifiedInvite(gc *gin.Context) {
dcUser.Contact = existingUser.Contact dcUser.Contact = existingUser.Contact
} }
app.storage.SetDiscordKey(gc.GetString("jfId"), dcUser) app.storage.SetDiscordKey(gc.GetString("jfId"), dcUser)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactLinked,
UserID: gc.GetString("jfId"),
SourceType: ActivityUser,
Source: gc.GetString("jfId"),
Value: "discord",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -398,6 +418,16 @@ func (app *appContext) MyTelegramVerifiedInvite(gc *gin.Context) {
tgUser.Contact = existingUser.Contact tgUser.Contact = existingUser.Contact
} }
app.storage.SetTelegramKey(gc.GetString("jfId"), tgUser) app.storage.SetTelegramKey(gc.GetString("jfId"), tgUser)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactLinked,
UserID: gc.GetString("jfId"),
SourceType: ActivityUser,
Source: gc.GetString("jfId"),
Value: "telegram",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -469,6 +499,16 @@ func (app *appContext) MatrixCheckMyPIN(gc *gin.Context) {
} }
app.storage.SetMatrixKey(gc.GetString("jfId"), mxUser) app.storage.SetMatrixKey(gc.GetString("jfId"), mxUser)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactLinked,
UserID: gc.GetString("jfId"),
SourceType: ActivityUser,
Source: gc.GetString("jfId"),
Value: "matrix",
Time: time.Now(),
})
delete(app.matrix.tokens, pin) delete(app.matrix.tokens, pin)
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -481,6 +521,16 @@ func (app *appContext) MatrixCheckMyPIN(gc *gin.Context) {
// @Tags User Page // @Tags User Page
func (app *appContext) UnlinkMyDiscord(gc *gin.Context) { func (app *appContext) UnlinkMyDiscord(gc *gin.Context) {
app.storage.DeleteDiscordKey(gc.GetString("jfId")) app.storage.DeleteDiscordKey(gc.GetString("jfId"))
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactUnlinked,
UserID: gc.GetString("jfId"),
SourceType: ActivityUser,
Source: gc.GetString("jfId"),
Value: "discord",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -492,6 +542,16 @@ func (app *appContext) UnlinkMyDiscord(gc *gin.Context) {
// @Tags User Page // @Tags User Page
func (app *appContext) UnlinkMyTelegram(gc *gin.Context) { func (app *appContext) UnlinkMyTelegram(gc *gin.Context) {
app.storage.DeleteTelegramKey(gc.GetString("jfId")) app.storage.DeleteTelegramKey(gc.GetString("jfId"))
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactUnlinked,
UserID: gc.GetString("jfId"),
SourceType: ActivityUser,
Source: gc.GetString("jfId"),
Value: "telegram",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }
@ -503,6 +563,16 @@ func (app *appContext) UnlinkMyTelegram(gc *gin.Context) {
// @Tags User Page // @Tags User Page
func (app *appContext) UnlinkMyMatrix(gc *gin.Context) { func (app *appContext) UnlinkMyMatrix(gc *gin.Context) {
app.storage.DeleteMatrixKey(gc.GetString("jfId")) app.storage.DeleteMatrixKey(gc.GetString("jfId"))
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactUnlinked,
UserID: gc.GetString("jfId"),
SourceType: ActivityUser,
Source: gc.GetString("jfId"),
Value: "matrix",
Time: time.Now(),
})
respondBool(200, true, gc) respondBool(200, true, gc)
} }

View File

@ -381,6 +381,7 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc
if app.storage.deprecatedDiscord == nil { if app.storage.deprecatedDiscord == nil {
app.storage.deprecatedDiscord = discordStore{} app.storage.deprecatedDiscord = discordStore{}
} }
// Note we don't log an activity here, since it's part of creating a user.
app.storage.SetDiscordKey(user.ID, discordUser) app.storage.SetDiscordKey(user.ID, discordUser)
delete(app.discord.verifiedTokens, req.DiscordPIN) delete(app.discord.verifiedTokens, req.DiscordPIN)
} }
@ -1149,6 +1150,16 @@ func (app *appContext) ModifyEmails(gc *gin.Context) {
emailStore.Addr = address emailStore.Addr = address
app.storage.SetEmailsKey(id, emailStore) app.storage.SetEmailsKey(id, emailStore)
app.storage.SetActivityKey(shortuuid.New(), Activity{
Type: ActivityContactLinked,
UserID: id,
SourceType: ActivityAdmin,
Source: gc.GetString("jfId"),
Value: "email",
Time: time.Now(),
})
if ombiEnabled { if ombiEnabled {
ombiUser, code, err := app.getOmbiUser(id) ombiUser, code, err := app.getOmbiUser(id)
if code == 200 && err == nil { if code == 200 && err == nil {

View File

@ -28,7 +28,8 @@ const (
ActivityDeletion ActivityDeletion
ActivityDisabled ActivityDisabled
ActivityEnabled ActivityEnabled
ActivityLinked ActivityContactLinked
ActivityContactUnlinked
ActivityChangePassword ActivityChangePassword
ActivityResetPassword ActivityResetPassword
ActivityCreateInvite ActivityCreateInvite
@ -50,6 +51,7 @@ type Activity struct {
SourceType ActivitySource SourceType ActivitySource
Source string Source string
InviteCode string // Only set for ActivityCreation InviteCode string // Only set for ActivityCreation
Value string // Used for ActivityContactLinked, "email/discord/telegram/matrix"
Time time.Time Time time.Time
} }