activity: more presentable cards, fixes

fixed some missing data (being stored and being shown), improved layout,
also usernames are now injected by the route.
This commit is contained in:
Harvey Tindall 2023-10-20 22:16:40 +01:00
parent a73dfddd3f
commit 1032e4e747
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
9 changed files with 113 additions and 43 deletions

View File

@ -89,7 +89,7 @@ func activitySourceToString(v ActivitySource) string {
// @Produce json // @Produce json
// @Param GetActivitiesDTO body GetActivitiesDTO true "search parameters" // @Param GetActivitiesDTO body GetActivitiesDTO true "search parameters"
// @Success 200 {object} GetActivitiesRespDTO // @Success 200 {object} GetActivitiesRespDTO
// @Router /activity [get] // @Router /activity [post]
// @Security Bearer // @Security Bearer
// @tags Activity // @tags Activity
func (app *appContext) GetActivities(gc *gin.Context) { func (app *appContext) GetActivities(gc *gin.Context) {
@ -138,6 +138,16 @@ func (app *appContext) GetActivities(gc *gin.Context) {
Value: act.Value, Value: act.Value,
Time: act.Time.Unix(), Time: act.Time.Unix(),
} }
user, status, err := app.jf.UserByID(act.UserID, false)
if status == 200 && err == nil {
resp.Activities[i].Username = user.Name
}
if (act.SourceType == ActivityUser || act.SourceType == ActivityAdmin) && act.Source != "" {
user, status, err = app.jf.UserByID(act.Source, false)
if status == 200 && err == nil {
resp.Activities[i].SourceUsername = user.Name
}
}
} }
gc.JSON(200, resp) gc.JSON(200, resp)

View File

@ -90,6 +90,7 @@ func (app *appContext) checkInvites() {
Type: ActivityDeleteInvite, Type: ActivityDeleteInvite,
SourceType: ActivityDaemon, SourceType: ActivityDaemon,
InviteCode: data.Code, InviteCode: data.Code,
Value: data.Label,
Time: time.Now(), Time: time.Now(),
}) })
} }
@ -141,6 +142,7 @@ func (app *appContext) checkInvite(code string, used bool, username string) bool
Type: ActivityDeleteInvite, Type: ActivityDeleteInvite,
SourceType: ActivityDaemon, SourceType: ActivityDaemon,
InviteCode: code, InviteCode: code,
Value: inv.Label,
Time: time.Now(), Time: time.Now(),
}) })
} else if used { } else if used {
@ -153,6 +155,7 @@ func (app *appContext) checkInvite(code string, used bool, username string) bool
Type: ActivityDeleteInvite, Type: ActivityDeleteInvite,
SourceType: ActivityDaemon, SourceType: ActivityDaemon,
InviteCode: code, InviteCode: code,
Value: inv.Label,
Time: time.Now(), Time: time.Now(),
}) })
} else if newInv.RemainingUses != 0 { } else if newInv.RemainingUses != 0 {
@ -460,8 +463,7 @@ func (app *appContext) DeleteInvite(gc *gin.Context) {
var req deleteInviteDTO var req deleteInviteDTO
gc.BindJSON(&req) gc.BindJSON(&req)
app.debug.Printf("%s: Deletion requested", req.Code) app.debug.Printf("%s: Deletion requested", req.Code)
var ok bool inv, ok := app.storage.GetInvitesKey(req.Code)
_, ok = app.storage.GetInvitesKey(req.Code)
if ok { if ok {
app.storage.DeleteInvitesKey(req.Code) app.storage.DeleteInvitesKey(req.Code)
@ -470,6 +472,8 @@ func (app *appContext) DeleteInvite(gc *gin.Context) {
Type: ActivityDeleteInvite, Type: ActivityDeleteInvite,
SourceType: ActivityAdmin, SourceType: ActivityAdmin,
Source: gc.GetString("jfId"), Source: gc.GetString("jfId"),
InviteCode: req.Code,
Value: inv.Label,
Time: time.Now(), Time: time.Now(),
}) })

View File

@ -778,7 +778,7 @@
<span class="button ~neutral @low settings-section-button justify-between mb-2" id="setting-about"><span class="flex">{{ .strings.aboutProgram }} <i class="ri-information-line ml-2"></i></span></span> <span class="button ~neutral @low settings-section-button justify-between mb-2" id="setting-about"><span class="flex">{{ .strings.aboutProgram }} <i class="ri-information-line ml-2"></i></span></span>
<span class="button ~neutral @low settings-section-button justify-between mb-2" id="setting-profiles"><span class="flex">{{ .strings.userProfiles }} <i class="ri-user-line ml-2"></i></span></span> <span class="button ~neutral @low settings-section-button justify-between mb-2" id="setting-profiles"><span class="flex">{{ .strings.userProfiles }} <i class="ri-user-line ml-2"></i></span></span>
</div> </div>
<div class="card ~neutral @low col overflow" id="activity-card-list"> <div class="card ~neutral @low col" id="activity-card-list">
<div class="card ~urge @low"> <div class="card ~urge @low">
<div class="flex justify-between mb-2"> <div class="flex justify-between mb-2">
<span class="heading text-2xl activity-title">Account Created: <a href="/fixme" class="activity-url">"hrfee"</a></span> <span class="heading text-2xl activity-title">Account Created: <a href="/fixme" class="activity-url">"hrfee"</a></span>

View File

@ -134,8 +134,8 @@
"builtBy": "Built By", "builtBy": "Built By",
"loginNotAdmin": "Not an Admin?", "loginNotAdmin": "Not an Admin?",
"referrer": "Referrer", "referrer": "Referrer",
"accountLinked": "{user}: {contactMethod} linked", "accountLinked": "{contactMethod} linked: {user}",
"accountUnlinked": "{user}: {contactMethod} removed", "accountUnlinked": "{contactMethod} removed: {user}",
"accountResetPassword": "{user} reset their password", "accountResetPassword": "{user} reset their password",
"accountChangedPassword": "{user} changed their password", "accountChangedPassword": "{user} changed their password",
"accountCreated": "Account created: {user}", "accountCreated": "Account created: {user}",
@ -146,7 +146,8 @@
"userDeleted": "User was deleted.", "userDeleted": "User was deleted.",
"userDisabled": "User was disabled", "userDisabled": "User was disabled",
"inviteCreated": "Invite created: {invite}", "inviteCreated": "Invite created: {invite}",
"inviteDeleted": "Invite deleted: {invite}" "inviteDeleted": "Invite deleted: {invite}",
"inviteExpired": "Invite expired: {invite}"
}, },
"notifications": { "notifications": {
"changedEmailAddress": "Changed email address of {n}.", "changedEmailAddress": "Changed email address of {n}.",

View File

@ -432,14 +432,16 @@ type EnableDisableReferralDTO struct {
} }
type ActivityDTO struct { type ActivityDTO struct {
ID string `json:"id"` ID string `json:"id"`
Type string `json:"type"` Type string `json:"type"`
UserID string `json:"user_id"` UserID string `json:"user_id"`
SourceType string `json:"source_type"` Username string `json:"username"`
Source string `json:"source"` SourceType string `json:"source_type"`
InviteCode string `json:"invite_code"` Source string `json:"source"`
Value string `json:"value"` SourceUsername string `json:"source_username"`
Time int64 `json:"time"` InviteCode string `json:"invite_code"`
Value string `json:"value"`
Time int64 `json:"time"`
} }
type GetActivitiesDTO struct { type GetActivitiesDTO struct {

View File

@ -232,7 +232,7 @@ func (app *appContext) loadRoutes(router *gin.Engine) {
api.DELETE(p+"/profiles/referral/:profile", app.DisableReferralForProfile) api.DELETE(p+"/profiles/referral/:profile", app.DisableReferralForProfile)
} }
api.GET(p+"/activity", app.GetActivities) api.POST(p+"/activity", app.GetActivities)
if userPageEnabled { if userPageEnabled {
user.GET("/details", app.MyDetails) user.GET("/details", app.MyDetails)

View File

@ -52,7 +52,7 @@ type Activity struct {
UserID string // ID of target user. For account creation, this will be the newly created account UserID string // ID of target user. For account creation, this will be the newly created account
SourceType ActivitySource SourceType ActivitySource
Source string Source string
InviteCode string // Only set for ActivityCreation InviteCode string // Set for ActivityCreation, create/deleteInvite
Value string // Used for ActivityContactLinked, "email/discord/telegram/matrix", and Create/DeleteInvite, where it's the label. Value string // Used for ActivityContactLinked, "email/discord/telegram/matrix", and Create/DeleteInvite, where it's the label.
Time time.Time Time time.Time
} }

View File

@ -1,4 +1,4 @@
import { _get, toDateString } from "../modules/common.js"; import { _post, toDateString } from "../modules/common.js";
export interface activity { export interface activity {
id: string; id: string;
@ -9,6 +9,8 @@ export interface activity {
invite_code: string; invite_code: string;
value: string; value: string;
time: number; time: number;
username: string;
source_username: string;
} }
var activityTypeMoods = { var activityTypeMoods = {
@ -37,25 +39,50 @@ export class Activity { // FIXME: Add "implements"
private _expiryTypeBadge: HTMLElement; private _expiryTypeBadge: HTMLElement;
private _act: activity; private _act: activity;
_genUserLink = (): string => {
return `<a class="font-medium hover:underline" href="/accounts/user/${this._act.user_id}">${this._act.username || this._act.user_id.substring(0, 5)}</a>`;
}
_genSrcUserLink = (): string => {
return `<a class="font-medium hover:underline" href="/accounts/user/${this._act.source}">${this._act.source_username || this._act.source.substring(0, 5)}</a>`;
}
private _renderInvText = (): string => { return `<span class="font-medium font-mono">${this.value || this.invite_code || "???"}</span>`; }
private _genInvLink = (): string => {
return `<a class="hover:underline" href="/accounts/invites/${this.invite_code}">${this._renderInvText()}</a>`;
}
get type(): string { return this._act.type; } get type(): string { return this._act.type; }
set type(v: string) { set type(v: string) {
this._act.type = v; this._act.type = v;
let mood = activityTypeMoods[v]; // 1 = positive, 0 = neutral, -1 = negative let mood = activityTypeMoods[v]; // 1 = positive, 0 = neutral, -1 = negative
this._card.classList.remove("~warning");
this._card.classList.remove("~neutral");
this._card.classList.remove("~urge");
for (let i = 0; i < moodColours.length; i++) { if (mood == -1) {
this._card.classList.add("~warning");
} else if (mood == 0) {
this._card.classList.add("~neutral");
} else if (mood == 1) {
this._card.classList.add("~urge");
}
/* for (let i = 0; i < moodColours.length; i++) {
if (i-1 == mood) this._card.classList.add(moodColours[i]); if (i-1 == mood) this._card.classList.add(moodColours[i]);
else this._card.classList.remove(moodColours[i]); else this._card.classList.remove(moodColours[i]);
} } */
if (this.type == "changePassword" || this.type == "resetPassword") { if (this.type == "changePassword" || this.type == "resetPassword") {
let innerHTML = ``; let innerHTML = ``;
if (this.type == "changePassword") innerHTML = window.lang.strings("accountChangedPassword"); if (this.type == "changePassword") innerHTML = window.lang.strings("accountChangedPassword");
else innerHTML = window.lang.strings("accountResetPassword"); else innerHTML = window.lang.strings("accountResetPassword");
innerHTML = innerHTML.replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`); innerHTML = innerHTML.replace("{user}", this._genUserLink());
this._title.innerHTML = innerHTML; this._title.innerHTML = innerHTML;
} else if (this.type == "contactLinked" || this.type == "contactUnlinked") { } else if (this.type == "contactLinked" || this.type == "contactUnlinked") {
let platform = this._act.type; let platform = this.value;
if (platform == "email") { if (platform == "email") {
platform = window.lang.strings("emailAddress"); platform = window.lang.strings("emailAddress");
} else { } else {
@ -64,40 +91,46 @@ export class Activity { // FIXME: Add "implements"
let innerHTML = ``; let innerHTML = ``;
if (this.type == "contactLinked") innerHTML = window.lang.strings("accountLinked"); if (this.type == "contactLinked") innerHTML = window.lang.strings("accountLinked");
else innerHTML = window.lang.strings("accountUnlinked"); else innerHTML = window.lang.strings("accountUnlinked");
innerHTML = innerHTML.replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`).replace("{contactMethod}", platform); innerHTML = innerHTML.replace("{user}", this._genUserLink()).replace("{contactMethod}", platform);
this._title.innerHTML = innerHTML; this._title.innerHTML = innerHTML;
} else if (this.type == "creation") { } else if (this.type == "creation") {
this._title.innerHTML = window.lang.strings("accountCreated").replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`); this._title.innerHTML = window.lang.strings("accountCreated").replace("{user}", this._genUserLink());
if (this.source_type == "user") { if (this.source_type == "user") {
this._referrer.innerHTML = `<span class="supra mr-2">${window.lang.strings("referrer")}</span><a href="/accounts/${this._source}">FIXME</a>`; this._referrer.innerHTML = `<span class="supra mr-2">${window.lang.strings("referrer")}</span>${this._genSrcUserLink()}`;
} else { } else {
this._referrer.textContent = ``; this._referrer.textContent = ``;
} }
} else if (this.type == "deletion") { } else if (this.type == "deletion") {
if (this.source_type == "daemon") { if (this.source_type == "daemon") {
this._title.innerHTML = window.lang.strings("accountExpired").replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`); this._title.innerHTML = window.lang.strings("accountExpired").replace("{user}", this._genUserLink());
this._expiryTypeBadge.classList.add("~critical"); this._expiryTypeBadge.classList.add("~critical");
this._expiryTypeBadge.classList.remove("~warning"); this._expiryTypeBadge.classList.remove("~info");
this._expiryTypeBadge.textContent = window.lang.strings("deleted"); this._expiryTypeBadge.textContent = window.lang.strings("deleted");
} else { } else {
this._title.innerHTML = window.lang.strings("accountDeleted").replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`); this._title.innerHTML = window.lang.strings("accountDeleted").replace("{user}", this._genUserLink());
} }
} else if (this.type == "enabled") { } else if (this.type == "enabled") {
this._title.innerHTML = window.lang.strings("accountReEnabled").replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`); this._title.innerHTML = window.lang.strings("accountReEnabled").replace("{user}", this._genUserLink());
} else if (this.type == "disabled") { } else if (this.type == "disabled") {
if (this.source_type == "daemon") { if (this.source_type == "daemon") {
this._title.innerHTML = window.lang.strings("accountExpired").replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`); this._title.innerHTML = window.lang.strings("accountExpired").replace("{user}", this._genUserLink());
this._expiryTypeBadge.classList.add("~warning"); this._expiryTypeBadge.classList.add("~info");
this._expiryTypeBadge.classList.remove("~critical"); this._expiryTypeBadge.classList.remove("~critical");
this._expiryTypeBadge.textContent = window.lang.strings("disabled"); this._expiryTypeBadge.textContent = window.lang.strings("disabled");
} else { } else {
this._title.innerHTML = window.lang.strings("accountDisabled").replace("{user}", `<a href="/accounts/user/${this._act.user_id}">FIXME</a>`); this._title.innerHTML = window.lang.strings("accountDisabled").replace("{user}", this._genUserLink());
} }
} else if (this.type == "createInvite") { } else if (this.type == "createInvite") {
this._title.innerHTML = window.lang.strings("inviteCreated").replace("{invite}", `<a href="/accounts/user/${this.invite_code}">${this.value || this.invite_code}</a>`); this._title.innerHTML = window.lang.strings("inviteCreated").replace("{invite}", this._genInvLink());
} else if (this.type == "deleteInvite") { } else if (this.type == "deleteInvite") {
let innerHTML = ``;
if (this.source_type == "daemon") {
innerHTML = window.lang.strings("inviteExpired");
} else {
innerHTML = window.lang.strings("inviteDeleted");
}
this._title.innerHTML = window.lang.strings("inviteDeleted").replace("{invite}", this.value || this.invite_code); this._title.innerHTML = innerHTML.replace("{invite}", this._renderInvText());
} }
/*} else if (this.source_type == "admin") { /*} else if (this.source_type == "admin") {
@ -130,14 +163,22 @@ export class Activity { // FIXME: Add "implements"
this._act.value = v; this._act.value = v;
} }
get source(): string { return this._act.source; }
set source(v: string) {
this._act.source = v;
}
constructor(act: activity) { constructor(act: activity) {
this._card = document.createElement("div"); this._card = document.createElement("div");
this._card.classList.add("card", "@low"); this._card.classList.add("card", "@low", "my-2");
this._card.innerHTML = ` this._card.innerHTML = `
<div class="flex justify-between mb-2"> <div class="flex flex-col md:flex-row justify-between mb-2">
<span class="heading text-2xl activity-title"></span><span class="activity-expiry-type badge"></span> <span class="heading truncate flex-initial md:text-2xl text-xl activity-title"></span>
<span class="text-sm font-medium activity-time" aria-label="${window.lang.strings("date")}"></span> <div class="flex flex-col flex-none ml-0 md:ml-2">
<span class="font-medium md:text-sm text-xs activity-time" aria-label="${window.lang.strings("date")}"></span>
<span class="activity-expiry-type badge self-start md:self-end mt-1"></span>
</div>
</div> </div>
<div class="flex justify-between"> <div class="flex justify-between">
<div> <div>
@ -156,6 +197,10 @@ export class Activity { // FIXME: Add "implements"
this._referrer = this._card.querySelector(".activity-referrer"); this._referrer = this._card.querySelector(".activity-referrer");
this._expiryTypeBadge = this._card.querySelector(".activity-expiry-type"); this._expiryTypeBadge = this._card.querySelector(".activity-expiry-type");
document.addEventListener("timefmt-change", () => {
this.time = this.time;
});
this.update(act); this.update(act);
} }
@ -164,6 +209,8 @@ export class Activity { // FIXME: Add "implements"
this._act = act; this._act = act;
this.source_type = act.source_type; this.source_type = act.source_type;
this.invite_code = act.invite_code; this.invite_code = act.invite_code;
this.time = act.time;
this.source = act.source;
this.value = act.value; this.value = act.value;
this.type = act.type; this.type = act.type;
} }
@ -179,7 +226,13 @@ export class activityList {
private _activityList: HTMLElement; private _activityList: HTMLElement;
reload = () => { reload = () => {
_get("/activity", null, (req: XMLHttpRequest) => { let send = {
"type": [],
"limit": 30,
"page": 0,
"ascending": false
}
_post("/activity", send, (req: XMLHttpRequest) => {
if (req.readyState != 4) return; if (req.readyState != 4) return;
if (req.status != 200) { if (req.status != 200) {
window.notifications.customError("loadActivitiesError", window.lang.notif("errorLoadActivities")); window.notifications.customError("loadActivitiesError", window.lang.notif("errorLoadActivities"));
@ -193,7 +246,7 @@ export class activityList {
const activity = new Activity(act); const activity = new Activity(act);
this._activityList.appendChild(activity.asElement()); this._activityList.appendChild(activity.asElement());
} }
}); }, true);
} }
constructor() { constructor() {

View File

@ -61,10 +61,10 @@ func (app *appContext) checkUsers() {
return return
} }
mode := "disable" mode := "disable"
termPlural := "Disabling" term := "Disabling"
if app.config.Section("user_expiry").Key("behaviour").MustString("disable_user") == "delete_user" { if app.config.Section("user_expiry").Key("behaviour").MustString("disable_user") == "delete_user" {
mode = "delete" mode = "delete"
termPlural = "Deleting" term = "Deleting"
} }
contact := false contact := false
if messagesEnabled && app.config.Section("user_expiry").Key("send_email").MustBool(true) { if messagesEnabled && app.config.Section("user_expiry").Key("send_email").MustBool(true) {
@ -95,7 +95,7 @@ func (app *appContext) checkUsers() {
app.storage.DeleteUserExpiryKey(expiry.JellyfinID) app.storage.DeleteUserExpiryKey(expiry.JellyfinID)
continue continue
} }
app.info.Printf("%s expired user \"%s\"", termPlural, user.Name) app.info.Printf("%s expired user \"%s\"", term, user.Name)
// Record activity // Record activity
activity := Activity{ activity := Activity{