Fix empty string in channels field in GetKeys route
This commit is contained in:
parent
686f89f75d
commit
90830fe384
@ -45,12 +45,12 @@ func (h APIHandler) ListUserKeys(g *gin.Context) ginresp.HTTPResponse {
|
|||||||
return *permResp
|
return *permResp
|
||||||
}
|
}
|
||||||
|
|
||||||
clients, err := h.database.ListKeyTokens(ctx, u.UserID)
|
toks, err := h.database.ListKeyTokens(ctx, u.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query keys", err)
|
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query keys", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res := langext.ArrMap(clients, func(v models.KeyToken) models.KeyTokenJSON { return v.JSON() })
|
res := langext.ArrMap(toks, func(v models.KeyToken) models.KeyTokenJSON { return v.JSON() })
|
||||||
|
|
||||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Keys: res}))
|
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Keys: res}))
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,12 @@ type KeyTokenDB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k KeyTokenDB) Model() KeyToken {
|
func (k KeyTokenDB) Model() KeyToken {
|
||||||
|
|
||||||
|
channels := make([]ChannelID, 0)
|
||||||
|
if strings.TrimSpace(k.Channels) != "" {
|
||||||
|
channels = langext.ArrMap(strings.Split(k.Channels, ";"), func(v string) ChannelID { return ChannelID(v) })
|
||||||
|
}
|
||||||
|
|
||||||
return KeyToken{
|
return KeyToken{
|
||||||
KeyTokenID: k.KeyTokenID,
|
KeyTokenID: k.KeyTokenID,
|
||||||
Name: k.Name,
|
Name: k.Name,
|
||||||
@ -136,7 +142,7 @@ func (k KeyTokenDB) Model() KeyToken {
|
|||||||
TimestampLastUsed: timeOptFromMilli(k.TimestampLastUsed),
|
TimestampLastUsed: timeOptFromMilli(k.TimestampLastUsed),
|
||||||
OwnerUserID: k.OwnerUserID,
|
OwnerUserID: k.OwnerUserID,
|
||||||
AllChannels: k.AllChannels,
|
AllChannels: k.AllChannels,
|
||||||
Channels: langext.ArrMap(strings.Split(k.Channels, ";"), func(v string) ChannelID { return ChannelID(v) }),
|
Channels: channels,
|
||||||
Token: k.Token,
|
Token: k.Token,
|
||||||
Permissions: ParseTokenPermissionList(k.Permissions),
|
Permissions: ParseTokenPermissionList(k.Permissions),
|
||||||
MessagesSent: k.MessagesSent,
|
MessagesSent: k.MessagesSent,
|
||||||
|
Loading…
Reference in New Issue
Block a user