Coverage for superuser/model.py: 95%

22 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-05 14:02 +0000

1"""This module contains the Superuser class that is responsible for handling""" 

2 

3from flask import session, jsonify 

4 

5from core import handlers, shared 

6 

7 

8class Superuser: 

9 """A class used to represent a Superuser and handle superuser-related""" 

10 

11 def login(self, attempt_user): 

12 """Validates user credentials and returns a JSON response indicating 

13 invalid login credentials.""" 

14 if not attempt_user: 

15 return jsonify({"error": "Missing email or password"}), 400 

16 

17 if "email" not in attempt_user or "password" not in attempt_user: 

18 return jsonify({"error": "Missing email or password"}), 400 

19 

20 if attempt_user["email"] == shared.getenv("SUPERUSER_EMAIL") and attempt_user[ 

21 "password" 

22 ] == shared.getenv("SUPERUSER_PASSWORD"): 

23 session["user"] = {"email": attempt_user["email"]} 

24 session["superuser"] = True 

25 return jsonify({"message": "/user/search"}), 200 

26 

27 handlers.clear_session_save_theme() 

28 

29 return jsonify({"error": "Invalid login credentials"}), 401 

30 

31 def configure_settings(self, max_skills, min_num_ranking_student_to_opportunity): 

32 """Configures the settings for the superuser.""" 

33 from app import CONFIG_MANAGER 

34 

35 try: 

36 CONFIG_MANAGER.set_num_of_skills(max_skills) 

37 CONFIG_MANAGER.set_min_num_ranking_student_to_opportunities( 

38 min_num_ranking_student_to_opportunity 

39 ) 

40 return jsonify({"message": "Settings updated successfully"}), 200 

41 except Exception as e: 

42 return jsonify({"error": str(e)}), 500