Skip to content
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

Add isAdmin to auth for admin pages #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function App(props: {}) {
username: "",
isStudent: false,
isTeacher: false,
isAdmin: false,
});

const existingToken = localStorage.getItem("token") || "";
Expand All @@ -50,6 +51,7 @@ function App(props: {}) {
username: result.data.username,
isStudent: result.data.is_student,
isTeacher: result.data.is_teacher,
isAdmin: result.data.is_admin,
});
});
}
Expand Down
1 change: 1 addition & 0 deletions client/src/context/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const AuthContext = createContext({
username: "",
isStudent: false,
isTeacher: false,
isAdmin: false,
});

export function useAuth() {
Expand Down
5 changes: 5 additions & 0 deletions server/core/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def is_student(self):
def is_teacher(self):
return hasattr(self, "teacher_profile")

@property
def is_admin(self):
# TODO define what it means to be an admin
return self.is_superuser and self.is_staff

@property
def profile(self):
if self.is_student:
Expand Down
2 changes: 1 addition & 1 deletion server/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = ESPUser
fields = ("username", "is_student", "is_teacher")
fields = ("username", "is_student", "is_teacher", "is_admin")


# TODO: The following two serializers are used for account creation and eventually should be fleshed
Expand Down