feat: modify db models for role based system#113
Open
Khushal928 wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR shifts the backend toward a group-based, role-aware model and introduces JWT issuance during OTP verification, plus a new admin-gated group creation endpoint. The changes are broad and affect core ORM models, auth schemas/routes, routing registration, and dependencies.
Changes:
- Replaces track/mentor-mentee model concepts with group/user-group mapping concepts.
- Adds JWT token creation/decoding helpers and returns access tokens from OTP verification.
- Registers a new group creation route and adds JWT-related dependency/config entries.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
requirements.txt |
Adds PyJWT dependency and normalizes alembic entry. |
.env.sample |
Adds JWT key/algorithm placeholders. |
app/db/models.py |
Reworks users, tracks/groups, tasks, submissions, and membership mapping models. |
app/db/crud.py |
Removes shared user lookup helpers while leaving legacy CRUD otherwise intact. |
app/crud/auth.py |
Adds JWT auth helpers and user lookup helpers. |
app/routes/auth.py |
Updates OTP verification to issue JWT token responses. |
app/routes/group.py |
Adds admin-only group creation endpoint. |
app/routes/tracks.py |
Removes previous track listing/task listing routes. |
app/main.py |
Registers the new group router in place of tracks router. |
app/schemas/auth.py |
Adds token response/user auth schemas. |
app/schemas/group.py |
Renames track schemas to group schemas. |
app/schemas/user.py |
Removes previous user schemas. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
||
| def create_access_token(user_id: int) -> str: | ||
| expire = datetime.now(datetime.timezone.ist) + timedelta(days=token_expire_time) |
| id: int | ||
| email: EmailStr | ||
| name: str | ||
| role: str |
|
|
||
| __table_args__ = (UniqueConstraint("group_id", "title", name="unique_group_task"), | ||
| CheckConstraint( | ||
| "(individual_task = TRUE AND user_id IS NOT NULL) OR (individual_task = FALSE AND user_id IS NULL)", |
|
|
||
| track = relationship("Track", back_populates="tasks") | ||
| group = relationship("Group", back_populates="tasks") | ||
| user = relationship("User", back_populates="tasks") |
Comment on lines
+17
to
+20
| class Group(Base): | ||
| __tablename__ = "groups" | ||
| id = Column(Integer, primary_key=True, index=True) | ||
| title = Column(String, unique=True, nullable=False) | ||
| title = Column(String, nullable=False) |
Comment on lines
+17
to
+18
| class Group(Base): | ||
| __tablename__ = "groups" |
Comment on lines
+11
to
+13
| is_member = Column(Boolean, nullable=False) | ||
| is_admin = Column(Boolean, nullable=False) | ||
| is_faculty = Column(Boolean, nullable=False) |
Comment on lines
+72
to
+77
| class UserGroupMap(Base): | ||
| __tablename__ = "user_group_map" | ||
| id = Column(Integer, primary_key=True, index=True) | ||
| mentor_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True) | ||
| mentee_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True) | ||
| user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True) | ||
| group_id = Column(Integer, ForeignKey("groups.id"), nullable=False, index=True) | ||
| role = Column(String, nullable=False) # admin / member / mentor |
| __tablename__ = "submissions" | ||
| id = Column(Integer, primary_key=True, index=True) | ||
| mentee_id = Column(Integer, ForeignKey("users.id"), nullable=False) | ||
| submitee_id = Column(Integer, ForeignKey("users.id"), nullable=False) |
| task_no = Column(Integer, nullable=False) | ||
| reference_link = Column(Text, nullable=False) | ||
| status = Column(String, default="submitted") # submitted / approved / paused / rejected | ||
| explainantion = Column(Text, nullable=True) |
Member
|
@Khushal928 can you look up the suggestions given by co pilot :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR :