invites: add "User Label" 1/2

Adds a "User Label" invite field, which is a label applied to users
created with it. This commit contains everything apart from the code to
apply it on account creation.
This commit is contained in:
Harvey Tindall 2023-09-08 14:29:25 +01:00
parent 4ea2dfdfb7
commit 7c76b58ab8
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
7 changed files with 57 additions and 17 deletions

View File

@ -161,6 +161,9 @@ func (app *appContext) GenerateInvite(gc *gin.Context) {
if req.Label != "" {
invite.Label = req.Label
}
if req.UserLabel != "" {
invite.UserLabel = req.UserLabel
}
invite.Created = currentTime
if req.MultipleUses {
if req.NoLimit {
@ -261,6 +264,7 @@ func (app *appContext) GetInvites(gc *gin.Context) {
Profile: inv.Profile,
NoLimit: inv.NoLimit,
Label: inv.Label,
UserLabel: inv.UserLabel,
}
if len(inv.UsedBy) != 0 {
invite.UsedBy = map[string]int64{}

View File

@ -589,6 +589,11 @@
<label class="label supra" for="create-label"> {{ .strings.label }}</label>
<input type="text" id="create-label" class="input ~neutral @low mb-2 mt-4">
</div>
<div class="col">
<label class="label supra" for="create-user-label"> {{ .strings.userLabel }}</label>
<p class="support">{{ .strings.userLabelDescription }}</p>
<input type="text" id="create-user-label" class="input ~neutral @low mb-2 mt-4">
</div>
</div>
<div class="card ~neutral @low col">
<label class="label supra" for="create-uses">{{ .strings.inviteNumberOfUses }}</label>

View File

@ -41,6 +41,8 @@
"profile": "Profile",
"unknown": "Unknown",
"label": "Label",
"userLabel": "User Label",
"userLabelDescription": "Label to apply to users created with this invite.",
"logs": "Logs",
"announce": "Announce",
"templates": "Templates",
@ -223,4 +225,4 @@
"plural": "Extended expiry for {n} users."
}
}
}
}

View File

@ -48,21 +48,22 @@ type enableDisableUserDTO struct {
}
type generateInviteDTO struct {
Months int `json:"months" example:"0"` // Number of months
Days int `json:"days" example:"1"` // Number of days
Hours int `json:"hours" example:"2"` // Number of hours
Minutes int `json:"minutes" example:"3"` // Number of minutes
UserExpiry bool `json:"user-expiry"` // Whether or not user expiry is enabled
UserMonths int `json:"user-months,omitempty" example:"1"` // Number of months till user expiry
UserDays int `json:"user-days,omitempty" example:"1"` // Number of days till user expiry
UserHours int `json:"user-hours,omitempty" example:"2"` // Number of hours till user expiry
UserMinutes int `json:"user-minutes,omitempty" example:"3"` // Number of minutes till user expiry
SendTo string `json:"send-to" example:"jeff@jellyf.in"` // Send invite to this address or discord name
MultipleUses bool `json:"multiple-uses" example:"true"` // Allow multiple uses
NoLimit bool `json:"no-limit" example:"false"` // No invite use limit
RemainingUses int `json:"remaining-uses" example:"5"` // Remaining invite uses
Profile string `json:"profile" example:"DefaultProfile"` // Name of profile to apply on this invite
Label string `json:"label" example:"For Friends"` // Optional label for the invite
Months int `json:"months" example:"0"` // Number of months
Days int `json:"days" example:"1"` // Number of days
Hours int `json:"hours" example:"2"` // Number of hours
Minutes int `json:"minutes" example:"3"` // Number of minutes
UserExpiry bool `json:"user-expiry"` // Whether or not user expiry is enabled
UserMonths int `json:"user-months,omitempty" example:"1"` // Number of months till user expiry
UserDays int `json:"user-days,omitempty" example:"1"` // Number of days till user expiry
UserHours int `json:"user-hours,omitempty" example:"2"` // Number of hours till user expiry
UserMinutes int `json:"user-minutes,omitempty" example:"3"` // Number of minutes till user expiry
SendTo string `json:"send-to" example:"jeff@jellyf.in"` // Send invite to this address or discord name
MultipleUses bool `json:"multiple-uses" example:"true"` // Allow multiple uses
NoLimit bool `json:"no-limit" example:"false"` // No invite use limit
RemainingUses int `json:"remaining-uses" example:"5"` // Remaining invite uses
Profile string `json:"profile" example:"DefaultProfile"` // Name of profile to apply on this invite
Label string `json:"label" example:"For Friends"` // Optional label for the invite
UserLabel string `json:"user_label,omitempty" example:"Friend"` // Label to apply to users created w/ this invite.
}
type inviteProfileDTO struct {
@ -114,6 +115,7 @@ type inviteDTO struct {
NotifyExpiry bool `json:"notify-expiry,omitempty"` // Whether to notify the requesting user of expiry or not
NotifyCreation bool `json:"notify-creation,omitempty"` // Whether to notify the requesting user of account creation or not
Label string `json:"label,omitempty" example:"For Friends"` // Optional label for the invite
UserLabel string `json:"user_label,omitempty" example:"Friend"` // Label to apply to users created w/ this invite.
}
type getInvitesDTO struct {

View File

@ -500,6 +500,7 @@ type Invite struct {
Notify map[string]map[string]bool `json:"notify"`
Profile string `json:"profile"`
Label string `json:"label,omitempty"`
UserLabel string `json:"user_label,omitempty" example:"Friend"` // Label to apply to users created w/ this invite.
Captchas map[string]Captcha // Map of Captcha IDs to images & answers
IsReferral bool `json:"is_referral" badgerhold:"index"`
ReferrerJellyfinID string `json:"referrer_id"`

View File

@ -39,6 +39,21 @@ class DOMInvite implements Invite {
}
}
private _userLabel: string = "";
get user_label(): string { return this._userLabel; }
set user_label(label: string) {
this._userLabel = label;
const labelLabel = this._middle.querySelector(".user-label-label");
const value = this._middle.querySelector(".user-label");
if (label) {
labelLabel.textContent = window.lang.strings("userLabel");
value.textContent = label;
} else {
labelLabel.textContent = "";
value.textContent = "";
}
}
private _code: string = "None";
get code(): string { return this._code; }
set code(code: string) {
@ -351,6 +366,7 @@ class DOMInvite implements Invite {
<p class="supra mb-4 top">${window.lang.strings("inviteDateCreated")} <strong class="inv-created"></strong></p>
<p class="supra mb-4">${window.lang.strings("inviteRemainingUses")} <strong class="inv-remaining"></strong></p>
<p class="supra mb-4"><span class="user-expiry"></span> <strong class="user-expiry-time"></strong></p>
<p class="mb-4 flex items-center"><span class="user-label-label supra mr-2"></span> <span class="user-label chip ~blue"></span></p>
`;
this._right = document.createElement('div') as HTMLDivElement;
@ -386,6 +402,9 @@ class DOMInvite implements Invite {
if (invite.label) {
this.label = invite.label;
}
if (invite.user_label) {
this.user_label = invite.user_label;
}
this.userExpiryTime = invite.userExpiryTime || "";
}
@ -486,6 +505,7 @@ function parseInvite(invite: { [f: string]: string | number | { [name: string]:
parsed.code = invite["code"] as string;
parsed.send_to = invite["send_to"] as string || "";
parsed.label = invite["label"] as string || "";
parsed.user_label = invite["user_label"] as string || "";
let time = "";
let userExpiryTime = "";
const fields = ["months", "days", "hours", "minutes"];
@ -530,6 +550,7 @@ export class createInvite {
private _createButton = document.getElementById("create-submit") as HTMLSpanElement;
private _profile = document.getElementById("create-profile") as HTMLSelectElement;
private _label = document.getElementById("create-label") as HTMLInputElement;
private _userLabel = document.getElementById("create-user-label") as HTMLInputElement;
private _months = document.getElementById("create-months") as HTMLSelectElement;
private _days = document.getElementById("create-days") as HTMLSelectElement;
@ -572,6 +593,9 @@ export class createInvite {
get label(): string { return this._label.value; }
set label(label: string) { this._label.value = label; }
get user_label(): string { return this._userLabel.value; }
set user_label(label: string) { this._userLabel.value = label; }
get sendToEnabled(): boolean {
return this._sendToEnabled.checked;
}
@ -749,7 +773,8 @@ export class createInvite {
"remaining-uses": this.uses,
"send-to": this.sendToEnabled ? this.sendTo : "",
"profile": this.profile,
"label": this.label
"label": this.label,
"user_label": this.user_label
};
_post("/invites", send, (req: XMLHttpRequest) => {
if (req.readyState == 4) {

View File

@ -129,6 +129,7 @@ interface Invite {
notifyCreation?: boolean;
profile?: string;
label?: string;
user_label?: string;
userExpiry?: boolean;
userExpiryTime?: string;
}