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.
pull/298/head
Harvey Tindall 1 year ago
parent 4ea2dfdfb7
commit 7c76b58ab8
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -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{}

@ -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>

@ -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",

@ -63,6 +63,7 @@ type generateInviteDTO struct {
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 {

@ -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"`

@ -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) {

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

Loading…
Cancel
Save