Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/spectator
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Sep 15, 2024
2 parents fd97043 + f15a6f8 commit 80cc7cb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ SCOREKEEPER_REPO_OWNER=
SCOREKEEPER_REPO_NAME=

AZURE_CHALLENGE_UPLOAD_SAS_TOKEN=
AZURE_SOLUTION_DOWNLOAD_SAS_TOKEN=
AZURE_SOLUTION_DOWNLOAD_SAS_TOKEN=
AZURE_SOLUTION_UPLOAD_STORAGE_ACCOUNT=
AZURE_STORAGE_CONTAINER=
Binary file removed src/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion src/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const verifyUser = async (req, res) => {
res.end(
template({
login_link: `${process.env.FRONTEND_DOMAIN}/login`,
verified: !!user
verified: !!user,
year: new Date().getFullYear()
})
);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/html/verification.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="https://bashaway.sliitfoss.org/assets/icons/favicon.svg" />
<title>Bashaway | 2023</title>
<title>Bashaway | {{year}}</title>
<link href="https://fonts.googleapis.com/css?family=Inter" rel="stylesheet" />
<style>
body,
Expand Down
7 changes: 3 additions & 4 deletions src/repository/question/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const findAllQuestions = (user, query = {}) => {
const filter = questionFilters(user, query.filter);

const options = {
select: '-creator -creator_lock',
select: '-creator',
lean: true,
sort: query.sort
};
Expand All @@ -38,16 +38,15 @@ export const findQuestion = (filters) => {
return Question.findOne(filters).lean();
};

export const getQuestionById = (id, user, filterFields = true) => {
export const getQuestionById = (id, user) => {
const filters = {
_id: { $eq: new ObjectId(id) },
$or: [{ creator_lock: false }, { creator_lock: true, creator: user._id }]
};
if (user.role !== ROLE.ADMIN) {
filters.enabled = true;
}
let query = Question.findOne(filters).lean();
if (filterFields) query = query.select('-creator_lock');
const query = Question.findOne(filters).lean();
return query.exec();
};

Expand Down
6 changes: 4 additions & 2 deletions src/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export const authLogin = async ({ email, password }) => {
};

export const verifyMailTemplate = async (email, verification_code) => {
const year = new Date().getFullYear();
const replacements = {
header: 'Welcome To Bashaway!',
text: `We are excited to have you here. To get started, you need to confirm your account. Just press the
button below.`,
action_link: `${process.env.APP_DOMAIN}/api/auth/verify/${verification_code}`,
action_text: 'Confirm',
disclaimer_text: "You've received this email because you have opted to participate in Bashaway 2023."
disclaimer_text: `You've received this email because you have opted to participate in Bashaway ${year}.`,
year
};
const subject = 'Bashaway - Account Verification';
await sendMail(email, 'call_to_action', replacements, subject);
Expand Down Expand Up @@ -68,7 +70,7 @@ export const resetPasswordMailTemplate = async (email, verification_code) => {
isFromAdmin() ? process.env.ADMIN_FRONTEND_DOMAIN : process.env.FRONTEND_DOMAIN
}/reset-password/${verification_code}`,
action_text: 'Reset Password',
disclaimer_text: "You've received this email because you have opted to participate in Bashaway 2023."
disclaimer_text: `You've received this email because you have opted to participate in Bashaway ${new Date().getFullYear()}.`
};
const subject = 'Bashaway - Reset Account Password';
await sendMail(email, 'call_to_action', replacements, subject);
Expand Down
10 changes: 9 additions & 1 deletion src/services/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import createError from 'http-errors';
import { ROLE } from '@/constants';
import { findQuestion, getMaxScore } from '@/repository/question';
import { getSubmissionById, getSubmissions, insertGrade, insertSubmission } from '@/repository/submission';
import { isFromAdmin } from '@/utils';
import { triggerScorekeeper as initiateTesting } from './github';

export const createSubmission = async ({ question: questionId, link }, user) => {
const question = await findQuestion({ _id: questionId });
if (!question) throw new createError(422, 'Invalid question ID');
if (!question.enabled) throw new createError(400, 'You cannot make a submission for a disabled question');

const checkUrl = `https://${process.env.AZURE_SOLUTION_UPLOAD_STORAGE_ACCOUNT}.blob.core.windows.net/${
process.env.AZURE_STORAGE_CONTAINER
}/${encodeURIComponent(user.name)}`;

if (!link.startsWith(checkUrl)) throw new createError(422, 'Invalid submission link');

const submission = await insertSubmission(user._id, questionId, link);
initiateTesting(
user.name,
Expand All @@ -21,7 +29,7 @@ export const createSubmission = async ({ question: questionId, link }, user) =>
};

export const viewSubmissions = (query, user) => {
if (user.role != ROLE.ADMIN) {
if (user.role != ROLE.ADMIN || !isFromAdmin()) {
if (!query.filter) query.filter = {};
query.filter.user = user._id;
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const updateUserdetails = async (userId, user, payload) => {
}
delete payload.is_active;
delete payload.eliminated;
delete payload.name;
}
if (payload.name) {
const existingUser = await getOneUser({ name: payload.name, _id: { $ne: userId } });
Expand Down Expand Up @@ -71,7 +72,7 @@ const sendAdminPassword = (email, password) => {
highlight_text: password,
action_link: `${process.env.ADMIN_FRONTEND_DOMAIN || 'https://admin.bashaway.sliitfoss.org'}/login`,
action_text: 'Login',
disclaimer_text: "You've received this email because you have been chosen as a member of Bashaway 2023."
disclaimer_text: `You've received this email because you have been chosen as a member of Bashaway ${new Date().getFullYear()}.`
};
const subject = 'Bashaway - Admin Account Password';
return sendMail(email, 'call_to_action', replacements, subject);
Expand Down

0 comments on commit 80cc7cb

Please sign in to comment.