Skip to content

Commit

Permalink
Merge pull request #18 from DakshChan/feature/IBS-16
Browse files Browse the repository at this point in the history
[IBS-16] Create add/delete/get view for task groups
  • Loading branch information
Kianoosh76 authored Jun 28, 2023
2 parents 8073b2c + 3ae6778 commit 381a7bd
Show file tree
Hide file tree
Showing 6 changed files with 705 additions and 9 deletions.
18 changes: 9 additions & 9 deletions backend/setup/rate_limit.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const rateLimit = require("express-rate-limit");

const general_limiter = rateLimit({
max: 1000,
windowMs: 60 * 60 * 1000,
message: "You sent too many requests! Try again in one hour!"
max: 1000,
windowMs: 60 * 60 * 1000,
message: "You sent too many requests! Try again in one hour!",
});

const email_limiter = rateLimit({
max: 20,
windowMs: 60 * 60 * 1000,
message: "You sent too many requests! Try again in one hour!"
max: 20,
windowMs: 60 * 60 * 1000,
message: "You sent too many requests! Try again in one hour!",
});

module.exports = {
general_limiter: general_limiter,
email_limiter: email_limiter,
}
general_limiter: general_limiter,
email_limiter: email_limiter,
};
9 changes: 9 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useSelector } from 'react-redux';
import RTL from './layouts/full-layout/customizer/RTL';
import StudentListPage from './components/Page/Student/StudentListPage';
import SubmitMarks from './components/Page/Instructor/SubmitMarks';
import TaskGroupPage from './components/Page/Instructor/TaskGroupPage';

function App() {
const theme = ThemeSettings();
Expand Down Expand Up @@ -86,6 +87,10 @@ function App() {
path="/instructor/course/:course_id/impersonate"
element={<InstructorImpersonate />}
></Route>
<Route
path="/instructor/course/:courseId/task-group"
element={<TaskGroupPage role="instructor" />}
/>
<Route
path="/instructor/course/:courseId/submit-marks"
element={<SubmitMarks />}
Expand All @@ -103,6 +108,10 @@ function App() {
element={<Admin_task />}
></Route>
<Route path="/admin/impersonate" element={<AdminImpersonate />}></Route>
<Route
path="/admin/course/:courseId/task-group"
element={<TaskGroupPage role="admin" />}
/>

<Route path="*" element={<Error />} />
</Routes>
Expand Down
139 changes: 139 additions & 0 deletions frontend/src/api/staff_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,148 @@ let getAllMarks = async (courseId) => {
}
};

/**
* GET All task group (Instructors + Admins)
* @param courseId string
* @returns {Promise<axios.AxiosResponse<any>|*|null>}
*/
let getAllTaskGroups = async (courseId) => {
const token = sessionStorage.getItem('token');

const role = findRoleInCourse(courseId);

const config = {
headers: { Authorization: `Bearer ${token}` }
};

let url = '';
if (role === 'admin') {
url = `${process.env.REACT_APP_API_URL}/admin/course/${courseId}/task_group/all`;
} else if (role === 'instructor') {
url = `${process.env.REACT_APP_API_URL}/instructor/course/${courseId}/task_group/all`;
} else {
// insufficient access
return null;
}

try {
return await axios.get(url, config);
} catch (err) {
return err.response;
}
};

/**
* POST Add task group (Instructors + Admins)
* @param courseId string
* @param maxTokens number
* @returns {Promise<axios.AxiosResponse<any>|*|null>}
*/
let addTaskGroup = async (courseId, maxTokens) => {
const token = sessionStorage.getItem('token');

const role = findRoleInCourse(courseId);

const config = {
headers: { Authorization: `Bearer ${token}` }
};

let url = '';
if (role === 'admin') {
url = `${process.env.REACT_APP_API_URL}/admin/course/${courseId}/task_group/add`;
} else if (role === 'instructor') {
url = `${process.env.REACT_APP_API_URL}/instructor/course/${courseId}/task_group/add`;
} else {
// insufficient access
return null;
}

try {
return await axios.post(url, { max_token: maxTokens }, config);
} catch (err) {
return err.response;
}
};

/**
* PUT Change task group (Instructors + Admins)
* @param courseId string
* @param taskGroupId string
* @param newMaxTokens number
* @returns {Promise<axios.AxiosResponse<any>|*|null>}
*/
let changeTaskGroup = async (courseId, taskGroupId, newMaxTokens) => {
const token = sessionStorage.getItem('token');

const role = findRoleInCourse(courseId);

const config = {
headers: { Authorization: `Bearer ${token}` }
};

let url = '';
if (role === 'admin') {
url = `${process.env.REACT_APP_API_URL}/admin/course/${courseId}/task_group/change`;
} else if (role === 'instructor') {
url = `${process.env.REACT_APP_API_URL}/instructor/course/${courseId}/task_group/change`;
} else {
// insufficient access
return null;
}

try {
return await axios.put(
url,
{ task_group_id: taskGroupId, max_token: newMaxTokens },
config
);
} catch (err) {
return err.response;
}
};

/**
* DELETE Delete task group (Instructors + Admins)
* @param courseId string
* @param taskGroupId string
* @returns {Promise<axios.AxiosResponse<any>|*|null>}
*/
let deleteTaskGroup = async (courseId, taskGroupId) => {
const token = sessionStorage.getItem('token');

const role = findRoleInCourse(courseId);

const config = {
headers: { Authorization: `Bearer ${token}` },
data: { task_group_id: taskGroupId }
};

let url = '';
if (role === 'admin') {
url = `${process.env.REACT_APP_API_URL}/admin/course/${courseId}/task_group/delete`;
} else if (role === 'instructor') {
url = `${process.env.REACT_APP_API_URL}/instructor/course/${courseId}/task_group/delete`;
} else {
// insufficient access
return null;
}

try {
return await axios.delete(url, config);
} catch (err) {
return err.response;
}
};

const StaffApi = {
get_students_in_course,
getAllMarks,

getAllTaskGroups,
addTaskGroup,
changeTaskGroup,
deleteTaskGroup,

getCriteriaForTask,
all_tasks
};
Expand Down
Loading

0 comments on commit 381a7bd

Please sign in to comment.