Skip to content

Commit 80cc7cb

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/spectator
2 parents fd97043 + f15a6f8 commit 80cc7cb

File tree

8 files changed

+24
-11
lines changed

8 files changed

+24
-11
lines changed

.env.example

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ SCOREKEEPER_REPO_OWNER=
1919
SCOREKEEPER_REPO_NAME=
2020

2121
AZURE_CHALLENGE_UPLOAD_SAS_TOKEN=
22-
AZURE_SOLUTION_DOWNLOAD_SAS_TOKEN=
22+
AZURE_SOLUTION_DOWNLOAD_SAS_TOKEN=
23+
AZURE_SOLUTION_UPLOAD_STORAGE_ACCOUNT=
24+
AZURE_STORAGE_CONTAINER=

src/.DS_Store

-6 KB
Binary file not shown.

src/controllers/auth.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export const verifyUser = async (req, res) => {
4343
res.end(
4444
template({
4545
login_link: `${process.env.FRONTEND_DOMAIN}/login`,
46-
verified: !!user
46+
verified: !!user,
47+
year: new Date().getFullYear()
4748
})
4849
);
4950
} catch (e) {

src/html/verification.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<link rel="icon" type="image/svg+xml" href="https://bashaway.sliitfoss.org/assets/icons/favicon.svg" />
7-
<title>Bashaway | 2023</title>
7+
<title>Bashaway | {{year}}</title>
88
<link href="https://fonts.googleapis.com/css?family=Inter" rel="stylesheet" />
99
<style>
1010
body,

src/repository/question/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const findAllQuestions = (user, query = {}) => {
1414
const filter = questionFilters(user, query.filter);
1515

1616
const options = {
17-
select: '-creator -creator_lock',
17+
select: '-creator',
1818
lean: true,
1919
sort: query.sort
2020
};
@@ -38,16 +38,15 @@ export const findQuestion = (filters) => {
3838
return Question.findOne(filters).lean();
3939
};
4040

41-
export const getQuestionById = (id, user, filterFields = true) => {
41+
export const getQuestionById = (id, user) => {
4242
const filters = {
4343
_id: { $eq: new ObjectId(id) },
4444
$or: [{ creator_lock: false }, { creator_lock: true, creator: user._id }]
4545
};
4646
if (user.role !== ROLE.ADMIN) {
4747
filters.enabled = true;
4848
}
49-
let query = Question.findOne(filters).lean();
50-
if (filterFields) query = query.select('-creator_lock');
49+
const query = Question.findOne(filters).lean();
5150
return query.exec();
5251
};
5352

src/services/auth.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ export const authLogin = async ({ email, password }) => {
3030
};
3131

3232
export const verifyMailTemplate = async (email, verification_code) => {
33+
const year = new Date().getFullYear();
3334
const replacements = {
3435
header: 'Welcome To Bashaway!',
3536
text: `We are excited to have you here. To get started, you need to confirm your account. Just press the
3637
button below.`,
3738
action_link: `${process.env.APP_DOMAIN}/api/auth/verify/${verification_code}`,
3839
action_text: 'Confirm',
39-
disclaimer_text: "You've received this email because you have opted to participate in Bashaway 2023."
40+
disclaimer_text: `You've received this email because you have opted to participate in Bashaway ${year}.`,
41+
year
4042
};
4143
const subject = 'Bashaway - Account Verification';
4244
await sendMail(email, 'call_to_action', replacements, subject);
@@ -68,7 +70,7 @@ export const resetPasswordMailTemplate = async (email, verification_code) => {
6870
isFromAdmin() ? process.env.ADMIN_FRONTEND_DOMAIN : process.env.FRONTEND_DOMAIN
6971
}/reset-password/${verification_code}`,
7072
action_text: 'Reset Password',
71-
disclaimer_text: "You've received this email because you have opted to participate in Bashaway 2023."
73+
disclaimer_text: `You've received this email because you have opted to participate in Bashaway ${new Date().getFullYear()}.`
7274
};
7375
const subject = 'Bashaway - Reset Account Password';
7476
await sendMail(email, 'call_to_action', replacements, subject);

src/services/submission.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import createError from 'http-errors';
22
import { ROLE } from '@/constants';
33
import { findQuestion, getMaxScore } from '@/repository/question';
44
import { getSubmissionById, getSubmissions, insertGrade, insertSubmission } from '@/repository/submission';
5+
import { isFromAdmin } from '@/utils';
56
import { triggerScorekeeper as initiateTesting } from './github';
67

78
export const createSubmission = async ({ question: questionId, link }, user) => {
89
const question = await findQuestion({ _id: questionId });
910
if (!question) throw new createError(422, 'Invalid question ID');
1011
if (!question.enabled) throw new createError(400, 'You cannot make a submission for a disabled question');
12+
13+
const checkUrl = `https://${process.env.AZURE_SOLUTION_UPLOAD_STORAGE_ACCOUNT}.blob.core.windows.net/${
14+
process.env.AZURE_STORAGE_CONTAINER
15+
}/${encodeURIComponent(user.name)}`;
16+
17+
if (!link.startsWith(checkUrl)) throw new createError(422, 'Invalid submission link');
18+
1119
const submission = await insertSubmission(user._id, questionId, link);
1220
initiateTesting(
1321
user.name,
@@ -21,7 +29,7 @@ export const createSubmission = async ({ question: questionId, link }, user) =>
2129
};
2230

2331
export const viewSubmissions = (query, user) => {
24-
if (user.role != ROLE.ADMIN) {
32+
if (user.role != ROLE.ADMIN || !isFromAdmin()) {
2533
if (!query.filter) query.filter = {};
2634
query.filter.user = user._id;
2735
}

src/services/user.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const updateUserdetails = async (userId, user, payload) => {
3636
}
3737
delete payload.is_active;
3838
delete payload.eliminated;
39+
delete payload.name;
3940
}
4041
if (payload.name) {
4142
const existingUser = await getOneUser({ name: payload.name, _id: { $ne: userId } });
@@ -71,7 +72,7 @@ const sendAdminPassword = (email, password) => {
7172
highlight_text: password,
7273
action_link: `${process.env.ADMIN_FRONTEND_DOMAIN || 'https://admin.bashaway.sliitfoss.org'}/login`,
7374
action_text: 'Login',
74-
disclaimer_text: "You've received this email because you have been chosen as a member of Bashaway 2023."
75+
disclaimer_text: `You've received this email because you have been chosen as a member of Bashaway ${new Date().getFullYear()}.`
7576
};
7677
const subject = 'Bashaway - Admin Account Password';
7778
return sendMail(email, 'call_to_action', replacements, subject);

0 commit comments

Comments
 (0)