Skip to content

Conversation

@tra371
Copy link
Collaborator

@tra371 tra371 commented Oct 30, 2025

Note

Introduce dedicated teacher/student add-to-school endpoints with serializers, handling roles, memberships, and class assignments.

  • Backend/API:
    • New endpoints: POST /schools/<school_id>/add-teacher-school/ (add_teacher_to_school) and POST /schools/<school_id>/add-student-school/ (add_student_to_school).
      • Validates permissions, ensures User role (teacher/student), creates/activates SchoolMembership.
      • Creates corresponding TeacherProfile/StudentProfile; validates and assigns Class(es) for teachers and students.
  • Serializers:
    • Add SchoolAddTeacherSerializer (email, teacher_role, assigned_classes) and SchoolAddStudentSerializer (email, assigned_class).
  • Routing:
    • Wire new endpoints in core/urls.py; import serializers in core/views.py.

Written by Cursor Bugbot for commit 385a398. This will update automatically on new commits. Configure here.

@Agneskoinange Agneskoinange merged commit ce69479 into main Nov 13, 2025
1 check passed
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

# Check permission
if (school.admin != request.user or request.user.role != "teacher") and not request.user.is_staff:
return Response({'error': 'Only school admins and teachers can add students to schools'},
status=status.HTTP_403_FORBIDDEN)
Copy link

Choose a reason for hiding this comment

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

Bug: Faulty Logic Denies Teacher Student Access

The permission check uses or instead of and, preventing teachers from adding students. The condition (school.admin != request.user or request.user.role != "teacher") evaluates to True when the user is a teacher but not the admin, incorrectly denying access. This contradicts the docstring stating "school admins and teachers can add students".

Fix in Cursor Fix in Web

)

valid_classes_qs = Class.objects.filter(name__in=assigned_class_names, school=school)
teacher_profile.assigned_classes.set(valid_classes_qs)
Copy link

Choose a reason for hiding this comment

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

Bug: Missing Default Breaks Class Filtering

When assigned_classes is not provided in the request, data.get('assigned_classes') returns None, which causes Class.objects.filter(name__in=assigned_class_names, ...) to fail since name__in expects an iterable. The code should default to an empty list when the field is absent.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants