Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 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
40 changes: 40 additions & 0 deletions labconnect/main/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,46 @@
db.session.commit()
return make_response({"msg": "New user added"})

# promotes/demotes User to a Lab Manager
# requires a super admin to promote
@main_blueprint.patch("/users/<string:email>/permissions")
@jwt_required()
def promoteUser(email: str) -> Response:
json_data = request.json
if not json_data or not json_data.get("change_status"):
abort(400)

# if user accessing doesn't have the right perms then they can't assign perms
promoter_id = get_jwt_identity()
promoter_perms = db.session.query(ManagementPermissions).filter_by(
user_id=promoter_id
).first()
if not promoter_perms or not promoter_perms.super_admin:
return make_response({"msg": "Missing permissions"}, 401)

# look for the user that will be promoted
manager = db.session.query(User).filter_by(email=email).first()
if not manager:
return make_response({"msg": "No user matches RCS ID"}, 500)

management_permissions = db.session.query(ManagementPermissions).filter_by(
user_id=manager.id
).first()

if management_permissions.admin == True:

Check failure on line 223 in labconnect/main/auth_routes.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E712)

labconnect/main/auth_routes.py:223:8: E712 Avoid equality comparisons to `True`; use `management_permissions.admin:` for truth checks
management_permissions.admin = False
elif management_permissions.admin == False:

Check failure on line 225 in labconnect/main/auth_routes.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E712)

labconnect/main/auth_routes.py:225:10: E712 Avoid equality comparisons to `False`; use `not management_permissions.admin:` for false checks
management_permissions.admin = True

if management_permissions is None:
management_permissions = ManagementPermissions(user_id=manager.id, admin=True)
db.session.add(management_permissions)

db.session.commit()

return make_response({"msg": "User Lab Manager permissions changed!"}, 200)



@main_blueprint.get("/metadata/")
def metadataRoute() -> Response:
Expand Down
11 changes: 7 additions & 4 deletions labconnect/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ def index() -> dict[str, str]:
@main_blueprint.get("/departments")
def departmentCards():
data = db.session.execute(
db.select(RPIDepartments.name, RPIDepartments.school_id, RPIDepartments.id)
db.select(RPIDepartments.name, RPIDepartments.school_id, RPIDepartments.id,
RPIDepartments.description, RPIDepartments.website)
).all()
results = [
{
"title": department.name,
"department_id": department.id,
"school": department.school_id,
"name": department.name,
"description": department.description,
"id": department.id,
"school_id": department.school_id,
"website": department.website,
"image": "https://cdn-icons-png.flaticon.com/512/5310/5310672.png",
}
for department in data
Expand Down
5 changes: 3 additions & 2 deletions labconnect/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from labconnect.models import Courses, Opportunities


def serialize_course(course: Courses) -> str:
return f"{course.code} {course.name}"
def serialize_course(course: Courses) -> dict:
course = {'code': course.code, 'name': course.name}
return course


def serialize_opportunity(
Expand Down
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
def test_client():
# Set the Testing configuration prior to creating the Flask application
flask_app = create_app()
flask_app.config.update({"TESTING": True, "DEBUG": True})
flask_app.config.update({
"TESTING": True,
"DEBUG": True,
'JWT_TOKEN_LOCATION': ['cookies', 'headers'],
'JWT_COOKIE_CSRF_PROTECT': True
})


# Create a test client using the Flask application configured for testing
with flask_app.test_client() as testing_client:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# from flask import json
# from flask.testing import FlaskClient
# import pytest


# def test_login_route_one(test_client: FlaskClient) -> None:
Expand Down Expand Up @@ -158,4 +159,4 @@

# response = test_client.post("/login")

# assert response.status_code == 400
# assert response.status_code == 400
35 changes: 18 additions & 17 deletions tests/test_departments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,40 @@
"Computer Science",
"Biology",
"Materials Engineering",
"Math",
"Environmental Engineering",
"Math",
"Aerospace Engineering",
"Areonautical Engineering",
"Aeronautical Engineering",
"Mechanical, Aerospace, and Nuclear Engineering"
],
},
{
"field": "description",
"values": [
"DS",
"life",
"DS is rough",
"life science",
"also pretty cool",
"water stuff",
"quick maths",
"water",
"space, the final frontier",
"flying, need for speed",
],
},
{
"field": "school_id",
"values": [
"School of science",
"School of science",
"School of engineering",
"School of science",
"School of engineering",
"School of engineering",
"School of engineering",
"School of Science",
"School of Science",
"School of Engineering",
"School of Science",
"School of Engineering",
"School of Engineering",
"School of Engineering",
],
},
{
"field": "id",
"values": ["CSCI", "BIOL", "MTLE", "MATH", "ENVI", "MANE", "MANE"],
"values": ["CSCI", "BIOL", "MTLE", "MATH", "ENVE", "MANE"],
},
{
"field": "image",
Expand All @@ -62,12 +63,12 @@
]
* 7,
},
{"field": "webcite", "values": ["https://www.rpi.edu"] * 7},
{"field": "website", "values": ["https://www.rpi.edu"] * 7},
],
),
(
"/department",
{"department": "Computer Science"},
"/departments/CSCI",
None,
200,
[
{"field": "name", "values": ["Computer Science"]},
Expand All @@ -80,7 +81,7 @@
"https://cdn-icons-png.flaticon.com/512/5310/5310672.png"
],
},
{"field": "webcite", "values": ["https://www.rpi.edu"]},
{"field": "website", "values": ["https://www.rpi.edu"]},
{
"field": "professors",
"subfields": [
Expand Down
41 changes: 18 additions & 23 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from flask import json
from flask.testing import FlaskClient
from flask_jwt_extended import create_access_token


def test_home_page(test_client: FlaskClient) -> None:
Expand All @@ -19,25 +20,6 @@ def test_home_page(test_client: FlaskClient) -> None:
assert {"Hello": "There"} == json.loads(response.data)


def test_discover_route(test_client: FlaskClient) -> None:
"""
GIVEN a Flask application configured for testing
WHEN the '/discover' page is requested (GET)
THEN check that the response is valid
"""
response = test_client.get("/discover")

assert response.status_code == 200
# Uncomment and modify the following line with expected response data
# data = json.loads(response.data.decode("utf-8"))
# assert data["data"][0] == {
# "title": "Nelson",
# "major": "CS",
# "attributes": ["Competitive Pay", "Four Credits", "Three Credits"],
# "pay": 9000.0,
# }


@pytest.mark.parametrize(
"input_id, expected_profile",
[
Expand All @@ -46,7 +28,8 @@ def test_discover_route(test_client: FlaskClient) -> None:
{
"id": "cenzar",
"first_name": "Rafael",
"opportunities": [...], # Replace with expected opportunities data
"opportunities": ["opportunity1"],
# Replace with expected opportunities data
},
)
],
Expand All @@ -57,7 +40,19 @@ def test_profile_page(test_client: FlaskClient, input_id, expected_profile) -> N
WHEN the '/profile/<user>' page is requested (GET)
THEN check that the response is valid
"""
response = test_client.get("/profile", json={"id": input_id})
# login_response = test_client.post("/login",
# json={"username": "test_user", "password": "password123"})
# login_data = json.loads(login_response.data)
with test_client.application.app_context():
access_token = create_access_token(identity='[email protected]')

# response = test_client.get("/profile", json={"id": input_id})
# Make the request with the JWT token
response = test_client.get(
"/profile",
json={"id": input_id},
headers={'Authorization': f'Bearer {access_token}'}
)

assert response.status_code == 200

Expand Down Expand Up @@ -108,7 +103,7 @@ def test_years_route(test_client: FlaskClient) -> None:
response = test_client.get("/years")

assert response.status_code == 200
assert [2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031] == json.loads(response.data)
assert [2025, 2026, 2027, 2028, 2029, 2030, 2031] == json.loads(response.data)


def test_professor_profile(test_client: FlaskClient) -> None:
Expand All @@ -117,7 +112,7 @@ def test_professor_profile(test_client: FlaskClient) -> None:
WHEN the '/getProfessorProfile/<id>' page is requested (GET)
THEN check that the response is valid
"""
response = test_client.get("/getProfessorProfile/1")
response = test_client.get("/staff/cenzar")

assert response.status_code == 200

Expand Down
Loading
Loading