Skip to content

feat: modify db models for role based system#113

Open
Khushal928 wants to merge 3 commits into
amfoss:developfrom
Khushal928:develop
Open

feat: modify db models for role based system#113
Khushal928 wants to merge 3 commits into
amfoss:developfrom
Khushal928:develop

Conversation

@Khushal928

@Khushal928 Khushal928 commented May 19, 2026

Copy link
Copy Markdown
Member

This PR :

  • modifies existing database models to support groups in ammentor
  • implement jwt auth and modifies related schema
  • add group creation endpoint and adds required schema

@Khushal928 Khushal928 requested a review from thet1nk3r3r May 19, 2026 11:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread app/crud/auth.py


def create_access_token(user_id: int) -> str:
expire = datetime.now(datetime.timezone.ist) + timedelta(days=token_expire_time)
Comment thread app/schemas/auth.py
id: int
email: EmailStr
name: str
role: str
Comment thread app/db/models.py

__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)",
Comment thread app/db/models.py

track = relationship("Track", back_populates="tasks")
group = relationship("Group", back_populates="tasks")
user = relationship("User", back_populates="tasks")
Comment thread app/db/models.py
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 thread app/db/models.py
Comment on lines +17 to +18
class Group(Base):
__tablename__ = "groups"
Comment thread app/db/models.py
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 thread app/db/models.py
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
Comment thread app/db/models.py
__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)
Comment thread app/db/models.py
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)
@thet1nk3r3r

thet1nk3r3r commented May 29, 2026

Copy link
Copy Markdown
Member

@Khushal928 can you look up the suggestions given by co pilot :)

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