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

Server limits #25

Merged
merged 2 commits into from
Oct 6, 2020
Merged
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
5 changes: 4 additions & 1 deletion server/server/api/clasrooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from server.parsing import parser
from server.parsing.utils import create_students_df
import pandas as pd
from server.config import RestErrors
from server.config import RestErrors, ValidatorsConfig
from server.models.marshals import classrooms_list_fields, classroom_resource_fields


Expand Down Expand Up @@ -34,6 +34,9 @@ def get(self, class_id=None):
def post(self, class_id=None):
if class_id:
abort(404, message=RestErrors.INVALID_ROUTE)
if len(auth.current_user().classrooms) >= ValidatorsConfig.MAX_CLASSROOMS:
abort(400, message=RestErrors.MAX_CLASSROOMS)

args = self._post_args.parse_args()
filename, stream = args['students_file'].filename.replace('"', ""), args['students_file'].stream #TODO: replace here because of postman post request
students_df = create_students_df(filename, stream)
Expand Down
6 changes: 5 additions & 1 deletion server/server/api/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from server.models.orm import StudentModel, ClassroomModel, ReportModel, SessionModel, ZoomNamesModel, StudentStatus
from server.parsing.utils import create_chat_df
from server.api.utils import validate_classroom
from server.config import RestErrors
from server.config import RestErrors, ValidatorsConfig
from server.models.marshals import student_status_field, reports_list_fields


Expand Down Expand Up @@ -35,6 +35,10 @@ def get(self, class_id, report_id=None):
def post(self, class_id, report_id=None):
if report_id:
abort(404, message=RestErrors.INVALID_REPORT)

if len(ReportModel.query.filter_by(class_id=class_id).all()) >= ValidatorsConfig.MAX_REPORTS:
abort(400, message=RestErrors.MAX_REPORTS)

args = self._post_args.parse_args()

students_df = pd.read_sql(StudentModel.query.filter_by(class_id=class_id).statement, con=db.engine)
Expand Down
36 changes: 19 additions & 17 deletions server/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ class ValidatorsConfig:
DATE_FORMAT = '%d/%m/%y'
CHAT_FILE_EXT = [".txt"]
STUDENTS_FILE_EXT = [".xls", ".xlsx", ".csv"]

MAX_CLASSROOMS = 10 # Maximum classrooms per students
MAX_REPORTS = 7 # Max reports per classroom

class RestErrors:
INVALID_ROUTE = "Route does't exist"
INVALID_CLASS = "Invalid class id"
INVALID_REPORT = "Invalid report id"
INVALID_STATUS = "Invalid status id"
USERNAME_TAKEN = "Username already taken"
EMAIL_TAKEN = "Email already taken"
ILLEGAL_USERNAME_CHARS = f'Username can\'t contain the following characthers: "{list(ValidatorsConfig.INVALID_USERNAME_CHARS)}"'
PASSWORD_TO_SHORT = f'Password to short, must be at least {ValidatorsConfig.MIN_PASSWORD_LEN} chars long'
PASSWORD_MUST_CONTAIN = 'Password must contain at least one lower case letter one upper case letter and a digit'
INVALID_TIME_DELTA = "Time delta must be an int represnting number of minutes"
INVALID_STUDENTS_FILE = "Students file must be one of the following formats: " + str(ValidatorsConfig.STUDENTS_FILE_EXT)
INVALID_CHAT_FILE = "Chat file must be one of the following formats: " + str(ValidatorsConfig.CHAT_FILE_EXT)
INVALID_CREDENTIALS = "Invalid credentials"
INVALID_TOKEN = "Token is invalid"
TOKEN_EXPIRED = "Token expired"

INVALID_ROUTE = "route_doesn't_exists"
INVALID_CLASS = "invalid_class_id"
INVALID_REPORT = "invalid_report_id"
INVALID_STATUS = "invalid_status_id"
USERNAME_TAKEN = "username_taken"
EMAIL_TAKEN = "email_taken"
ILLEGAL_USERNAME_CHARS = "username_contains_illegal_chars"
PASSWORD_TO_SHORT = 'passowrd_to_short'
PASSWORD_MUST_CONTAIN = "password_dosen't_contain_required_chars"
INVALID_TIME_DELTA = "invalid_time_delta"
INVALID_STUDENTS_FILE = "invalid_student_file"
INVALID_CHAT_FILE = "invalid_chat_file"
INVALID_CREDENTIALS = "credentials_invalid"
INVALID_TOKEN = "token_invalid"
TOKEN_EXPIRED = "token_expired"
MAX_REPORTS = "to_many_reports"
MAX_CLASSROOMS = "to_many_classrooms"

class SerializeConfig:
LOGIN_SALT = 'login'
Expand Down
14 changes: 0 additions & 14 deletions server/test.py

This file was deleted.