Skip to content

Commit 409c89d

Browse files
committed
issue tdjsnelling#38: enable sending of invites in open mode for admin users
1 parent 3ca0ddc commit 409c89d

2 files changed

Lines changed: 64 additions & 45 deletions

File tree

api/src/controllers/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export const login = async (req, res, next) => {
257257
};
258258

259259
export const generateInvite = (mail) => async (req, res, next) => {
260-
if (process.env.SQ_ALLOW_REGISTER !== "invite") {
260+
if (process.env.SQ_ALLOW_REGISTER !== "invite" && req.userRole !== "admin") {
261261
res
262262
.status(403)
263263
.send("Can only send invites when tracker is in invite only mode");

client/pages/account.js

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ const BuyItem = ({ text, cost, wallet, handleBuy }) => {
6262
disabled={unavailable || cannotAfford}
6363
mr={3}
6464
/>
65-
<Button disabled={unavailable || cannotAfford}>{getLocaleString("accBuy")}</Button>
65+
<Button disabled={unavailable || cannotAfford}>
66+
{getLocaleString("accBuy")}
67+
</Button>
6668
</Box>
6769
</Box>
6870
</Box>
@@ -131,15 +133,14 @@ const Account = ({ token, invites = [], user, userRole }) => {
131133
return currentInvitesList;
132134
});
133135

134-
addNotification("success",
135-
`${getLocaleString("accInviteSentSuccess")}`
136-
);
136+
addNotification("success", `${getLocaleString("accInviteSentSuccess")}`);
137137

138138
setRemainingInvites((r) => r - 1);
139139

140140
setShowInviteModal(false);
141141
} catch (e) {
142-
addNotification("error",
142+
addNotification(
143+
"error",
143144
`${getLocaleString("accCouldNotSendInvite")}: ${e.message}`
144145
);
145146
console.error(e);
@@ -174,17 +175,16 @@ const Account = ({ token, invites = [], user, userRole }) => {
174175
throw new Error(reason);
175176
}
176177

177-
addNotification("success",
178-
`${getLocaleString("accPassChangedSuccess")}`
179-
);
178+
addNotification("success", `${getLocaleString("accPassChangedSuccess")}`);
180179

181180
const fields = e.target.querySelectorAll("input");
182181
for (const field of fields) {
183182
field.value = "";
184183
field.blur();
185184
}
186185
} catch (e) {
187-
addNotification("error",
186+
addNotification(
187+
"error",
188188
`${getLocaleString("accCouldNotChangePass")}: ${e.message}`
189189
);
190190
console.error(e);
@@ -218,7 +218,8 @@ const Account = ({ token, invites = [], user, userRole }) => {
218218
throw new Error(reason);
219219
}
220220

221-
addNotification("success",
221+
addNotification(
222+
"success",
222223
`${getLocaleString("accItemsPurchasedSuccess")}`
223224
);
224225

@@ -233,7 +234,8 @@ const Account = ({ token, invites = [], user, userRole }) => {
233234
field.blur();
234235
}
235236
} catch (e) {
236-
addNotification("error",
237+
addNotification(
238+
"error",
237239
`${getLocaleString("accCouldNotBuyItems")}: ${e.message}`
238240
);
239241
console.error(e);
@@ -264,9 +266,7 @@ const Account = ({ token, invites = [], user, userRole }) => {
264266
setTotpBackupCodes(backupCodes);
265267
setTotpQrData(undefined);
266268
setTotpEnabled(true);
267-
addNotification("success",
268-
`${getLocaleString("acc2FAEnabled")}`
269-
);
269+
addNotification("success", `${getLocaleString("acc2FAEnabled")}`);
270270
} else {
271271
const message = await enableRes.text();
272272
addNotification("error", message);
@@ -298,16 +298,15 @@ const Account = ({ token, invites = [], user, userRole }) => {
298298

299299
if (disableRes.status === 200) {
300300
setTotpEnabled(false);
301-
addNotification("success",
302-
`${getLocaleString("acc2FADisabled")}`
303-
);
301+
addNotification("success", `${getLocaleString("acc2FADisabled")}`);
304302
} else {
305303
const message = await disableRes.text();
306304
addNotification("error", message);
307305
}
308306
}
309307
} catch (e) {
310-
addNotification("error",
308+
addNotification(
309+
"error",
311310
`${getLocaleString("accCouldNotToggle2FA")}: ${e.message}`
312311
);
313312
console.error(e);
@@ -337,7 +336,8 @@ const Account = ({ token, invites = [], user, userRole }) => {
337336

338337
await router.push("/logout");
339338
} catch (e) {
340-
addNotification("error",
339+
addNotification(
340+
"error",
341341
`${getLocaleString("accCouldNotDelAcc")}: ${e.message}`
342342
);
343343
console.error(e);
@@ -359,17 +359,29 @@ const Account = ({ token, invites = [], user, userRole }) => {
359359
{getLocaleString("accBonusPoints")}
360360
</Text>
361361
<Text mb={3}>
362-
{getLocaleString("accYouCurrentlyHave")} <strong>{bonusPoints}</strong> {getLocaleString("accBonusPointsHave")}.
362+
{getLocaleString("accYouCurrentlyHave")} <strong>{bonusPoints}</strong>{" "}
363+
{getLocaleString("accBonusPointsHave")}.
363364
</Text>
364365
<Box as="ul" mb={4}>
365366
<Text as="li">
366-
{getLocaleString("accYouWillEarn")} <strong>{SQ_BP_EARNED_PER_GB}</strong>{" "}
367-
{pluralize(`${getLocaleString("accBonusPointsHave")}`, SQ_BP_EARNED_PER_GB)} {getLocaleString("accForEveryGBYouUpload")}.
367+
{getLocaleString("accYouWillEarn")}{" "}
368+
<strong>{SQ_BP_EARNED_PER_GB}</strong>{" "}
369+
{pluralize(
370+
`${getLocaleString("accBonusPointsHave")}`,
371+
SQ_BP_EARNED_PER_GB
372+
)}{" "}
373+
{getLocaleString("accForEveryGBYouUpload")}.
368374
</Text>
369375
<Text as="li">
370-
{getLocaleString("accYouWillEarn")} <strong>{SQ_BP_EARNED_PER_FILLED_REQUEST}</strong>{" "}
371-
{pluralize(`${getLocaleString("accBonusPointsHave")}`, SQ_BP_EARNED_PER_FILLED_REQUEST)} {getLocaleString("accEveryRequestYouFulfill")}{" "}
372-
<strong>{SQ_BP_EARNED_PER_FILLED_REQUEST * 2}</strong> {getLocaleString("accIfYouAreAlsUploaderAcceptTorrent")}.
376+
{getLocaleString("accYouWillEarn")}{" "}
377+
<strong>{SQ_BP_EARNED_PER_FILLED_REQUEST}</strong>{" "}
378+
{pluralize(
379+
`${getLocaleString("accBonusPointsHave")}`,
380+
SQ_BP_EARNED_PER_FILLED_REQUEST
381+
)}{" "}
382+
{getLocaleString("accEveryRequestYouFulfill")}{" "}
383+
<strong>{SQ_BP_EARNED_PER_FILLED_REQUEST * 2}</strong>{" "}
384+
{getLocaleString("accIfYouAreAlsUploaderAcceptTorrent")}.
373385
</Text>
374386
</Box>
375387
<Box _css={{ "> * + *": { mt: 3 } }} mb={5}>
@@ -388,9 +400,8 @@ const Account = ({ token, invites = [], user, userRole }) => {
388400
handleBuy={(e) => handleBuy(e, "upload")}
389401
/>
390402
</Box>
391-
{SQ_ALLOW_REGISTER === "invite" && (
403+
{(SQ_ALLOW_REGISTER === "invite" || userRole === "admin") && (
392404
<>
393-
{" "}
394405
<Box
395406
display="flex"
396407
alignItems="center"
@@ -407,7 +418,8 @@ const Account = ({ token, invites = [], user, userRole }) => {
407418
pl={4}
408419
>
409420
<Text color="grey" mr={4}>
410-
{remainingInvites.toLocaleString()} {getLocaleString("accRemaining")}
421+
{remainingInvites.toLocaleString()}{" "}
422+
{getLocaleString("accRemaining")}
411423
</Text>
412424
<Button
413425
onClick={() => setShowInviteModal(true)}
@@ -450,7 +462,9 @@ const Account = ({ token, invites = [], user, userRole }) => {
450462
header: `${getLocaleString("accCreated")}`,
451463
accessor: "created",
452464
cell: ({ value }) => (
453-
<Text>{moment(value).format(`${getLocaleString("indexTime")}`)}</Text>
465+
<Text>
466+
{moment(value).format(`${getLocaleString("indexTime")}`)}
467+
</Text>
454468
),
455469
gridWidth: "175px",
456470
},
@@ -503,9 +517,7 @@ const Account = ({ token, invites = [], user, userRole }) => {
503517
<Text as="h2" mb={4}>
504518
{getLocaleString("acc2FAuth")}
505519
</Text>
506-
<Text mb={4}>
507-
{getLocaleString("acc2FAUseApp")}.
508-
</Text>
520+
<Text mb={4}>{getLocaleString("acc2FAUseApp")}.</Text>
509521
<form onSubmit={handleToggleTotp}>
510522
{totpQrData ? (
511523
<Box display="flex" alignItems="center">
@@ -558,9 +570,7 @@ const Account = ({ token, invites = [], user, userRole }) => {
558570
<>
559571
{totpBackupCodes ? (
560572
<>
561-
<Text mb={3}>
562-
{getLocaleString("acc2FAText1")}
563-
</Text>
573+
<Text mb={3}>{getLocaleString("acc2FAText1")}</Text>
564574
<Box as="ul">
565575
{totpBackupCodes.split(",").map((code) => (
566576
<Text
@@ -586,7 +596,12 @@ const Account = ({ token, invites = [], user, userRole }) => {
586596
mb={4}
587597
/>
588598
)}
589-
<Button>{totpEnabled ? `${getLocaleString("accDisable")}` : `${getLocaleString("accEnable")}`} 2FA</Button>
599+
<Button>
600+
{totpEnabled
601+
? `${getLocaleString("accDisable")}`
602+
: `${getLocaleString("accEnable")}`}{" "}
603+
2FA
604+
</Button>
590605
</>
591606
)}
592607
</>
@@ -635,11 +650,15 @@ const Account = ({ token, invites = [], user, userRole }) => {
635650
)}
636651
{showInviteModal && (
637652
<Modal close={() => setShowInviteModal(false)}>
638-
<Text mb={5}>
639-
{getLocaleString("accInviteText1")}
640-
</Text>
653+
<Text mb={5}>{getLocaleString("accInviteText1")}</Text>
641654
<form onSubmit={handleGenerateInvite}>
642-
<Input name="email" type="email" label={getLocaleString("email")} mb={4} required />
655+
<Input
656+
name="email"
657+
type="email"
658+
label={getLocaleString("email")}
659+
mb={4}
660+
required
661+
/>
643662
{userRole === "admin" && (
644663
<Select name="role" mb={4} required>
645664
<option value="user">{getLocaleString("accRoleUser")}</option>
@@ -662,9 +681,7 @@ const Account = ({ token, invites = [], user, userRole }) => {
662681
)}
663682
{showDeleteAccountModal && (
664683
<Modal close={() => setShowDeleteAccountModal(false)}>
665-
<Text mb={5}>
666-
{getLocaleString("accDelAccText1")}
667-
</Text>
684+
<Text mb={5}>{getLocaleString("accDelAccText1")}</Text>
668685
<form onSubmit={handleDeleteAccount}>
669686
<Input
670687
name="password"
@@ -682,7 +699,9 @@ const Account = ({ token, invites = [], user, userRole }) => {
682699
>
683700
{getLocaleString("accCancel")}
684701
</Button>
685-
<Button variant="danger">{getLocaleString("accDeleteMyAccYes")}</Button>
702+
<Button variant="danger">
703+
{getLocaleString("accDeleteMyAccYes")}
704+
</Button>
686705
</Box>
687706
</form>
688707
</Modal>

0 commit comments

Comments
 (0)