-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed is_teacher and is_admin, changed to role enum #127
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2ab31c1
Removed is_teacher and is_admin, changed to role enum
JibrilExe 6682bfc
sql enum type
JibrilExe 9751348
usage of enum and fixed sql
JibrilExe 9c2d7e4
merged
JibrilExe a59eae1
made role serializable
JibrilExe fa590d9
clean
JibrilExe 9888390
docs
JibrilExe a585d45
fixed user patch
JibrilExe 5ae35dc
args vs json
JibrilExe 49ff160
test
JibrilExe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
"""User model""" | ||
|
||
from enum import Enum | ||
from dataclasses import dataclass | ||
from sqlalchemy import Boolean, Column, String | ||
from sqlalchemy import Column, String, Enum as EnumField | ||
from project.db_in import db | ||
|
||
class Role(Enum): | ||
"""This class defines the roles of a user""" | ||
STUDENT = 0 | ||
TEACHER = 1 | ||
ADMIN = 2 | ||
|
||
@dataclass | ||
class User(db.Model): | ||
"""This class defines the users table, | ||
a user has a uid, | ||
is_teacher and is_admin booleans because a user | ||
a user has a uid and a role, a user | ||
can be either a student,admin or teacher""" | ||
|
||
__tablename__ = "users" | ||
uid: str = Column(String(255), primary_key=True) | ||
is_teacher: bool = Column(Boolean) | ||
is_admin: bool = Column(Boolean) | ||
role: Role = Column(EnumField(Role)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be nullable |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,13 +62,13 @@ def return_authenticated_user_id(): | |
|
||
if user: | ||
return auth_user_id | ||
is_teacher = False | ||
role = 'student' | ||
if user_info["jobTitle"] != None: | ||
is_teacher = True | ||
role = 'teacher' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the enum for this instead |
||
|
||
# add user if not yet in database | ||
try: | ||
new_user = User(uid=auth_user_id, is_teacher=is_teacher, is_admin=False) | ||
new_user = User(uid=auth_user_id, role=role) | ||
db.session.add(new_user) | ||
db.session.commit() | ||
except SQLAlchemyError: | ||
|
@@ -89,7 +89,7 @@ def is_teacher(auth_user_id): | |
"url": f"{API_URL}/users"}, 500 | ||
if not user: # should realistically never happen | ||
abort(500, "A database error occured") | ||
if user.is_teacher: | ||
if user.role == 'teacher': | ||
return True | ||
return False | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a type for this, see https://www.postgresql.org/docs/current/datatype-enum.html