Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Groups backend #338

Merged
merged 26 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3c386de
temp bad
JibrilExe Apr 29, 2024
27a1aed
db_constr, model and first attempt at endpoint for group
JibrilExe Apr 29, 2024
41277ed
group prim key (group_id,project_id) added delete endpoint to leave g…
JibrilExe Apr 29, 2024
1108688
allow students in max 1 group
JibrilExe Apr 29, 2024
8cb023f
model tests
JibrilExe Apr 29, 2024
4904a19
lint
JibrilExe Apr 29, 2024
329cd6c
group menu frontend
JibrilExe Apr 29, 2024
88b38ce
hm
JibrilExe Apr 30, 2024
9ecef84
working endpoint for create and delete group
JibrilExe Apr 30, 2024
5975542
translations
JibrilExe Apr 30, 2024
5a0c548
Merge branch 'development' into nicetohave/groups
JibrilExe May 7, 2024
44de8a6
begone front
JibrilExe May 7, 2024
c47f02d
front removal
JibrilExe May 7, 2024
38b5282
lintr
JibrilExe May 7, 2024
dad08e7
fixed changes, untested tho
JibrilExe May 12, 2024
6014315
Merge branch 'development' into nicetohave/groups
JibrilExe May 12, 2024
ebec22c
groups locked var should not mess up all older code
JibrilExe May 12, 2024
3ed5561
only student or teacher can get groups ; unlock groups
JibrilExe May 12, 2024
19175d5
linter mad
JibrilExe May 12, 2024
4aa55db
Very mad lintr
JibrilExe May 12, 2024
d8a42c2
vscode linter errors should be more obvi
JibrilExe May 12, 2024
20bdd60
removed some teacher_id = None
JibrilExe May 14, 2024
590e402
removed unused import
JibrilExe May 14, 2024
d623a7f
Merge branch 'development' into nicetohave/groups
JibrilExe May 14, 2024
e145bd2
bad prints
JibrilExe May 16, 2024
54a0795
Merge branch 'development' into nicetohave/groups
JibrilExe May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions backend/project/endpoints/projects/groups/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from project.models.course import Course
from project.models.group import Group
from project.utils.query_agent import query_selected_from_model, insert_into_model
from project.utils.authentication import login_required, authorize_teacher_of_project
from project.utils.authentication import authorize_teacher_or_student_of_project, authorize_teacher_of_project
from project import db

load_dotenv()
Expand All @@ -24,8 +24,16 @@ class Groups(Resource):
@authorize_teacher_of_project
def patch(self, project_id, teacher_id=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can the teacher unlock groups again?

"""
This function will lock all groups of the project
This function will set locked state of project groups,
need to pass locked field in the body
"""
req = request.json
locked = req.get("locked")
if locked is None:
return {
"message": "Bad request: locked field is required",
"url": RESPONSE_URL
}, 400

try:
project = db.session.query(Project).filter_by(
Expand All @@ -35,7 +43,7 @@ def patch(self, project_id, teacher_id=None):
"message": "Project does not exist",
"url": RESPONSE_URL
}, 404
project.groups_locked = True
project.groups_locked = locked
AronBuzogany marked this conversation as resolved.
Show resolved Hide resolved
db.session.commit()

return {
Expand All @@ -48,7 +56,7 @@ def patch(self, project_id, teacher_id=None):
"url": RESPONSE_URL
}, 500

@login_required
@authorize_teacher_or_student_of_project
def get(self, project_id):
"""
Get function for /project/project_id/groups this will be the main endpoint
Expand Down
24 changes: 24 additions & 0 deletions backend/project/utils/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def wrap(*args, **kwargs):
return f(*args, **kwargs)
return wrap


def login_required_return_uid(f):
"""
This function will check if the person sending a request to the API is logged in
Expand All @@ -62,6 +63,7 @@ def wrap(*args, **kwargs):
return f(*args, **kwargs)
return wrap


def authorize_admin(f):
"""
This function will check if the person sending a request to the API is logged in and an admin.
Expand Down Expand Up @@ -169,6 +171,27 @@ def wrap(*args, **kwargs):
return wrap


def authorize_teacher_or_student_of_project(f):
"""
This function will check if the person sending a request to the API is logged in,
and the teacher or student of the course which the project in the request belongs to.
Returns 403: Not Authorized if either condition is false
"""
@wraps(f)
def wrap(*args, **kwargs):
auth_user_id = return_authenticated_user_id()
project_id = kwargs["project_id"]
course_id = get_course_of_project(project_id)

if (is_teacher_of_course(auth_user_id, course_id) or
is_student_of_course(auth_user_id, course_id)):
return f(*args, **kwargs)

abort(make_response(({"message": """You are not authorized to perfom this action,
you are not the teacher OR student of this project"""}, 403)))
return wrap


def authorize_teacher_or_project_admin(f):
"""
This function will check if the person sending a request to the API is logged in,
Expand Down Expand Up @@ -210,6 +233,7 @@ def wrap(*args, **kwargs):
({"message": "You're not authorized to perform this action"}, 403)))
return wrap


def authorize_submissions_request(f):
"""This function will check if the person sending a request to the API is logged in,
and either the teacher/admin of the course or the student
Expand Down
Loading