Skip to content

Commit

Permalink
API & Client - display user report actions in admin (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamR1 committed Nov 10, 2024
1 parent f5f62d3 commit 59559d3
Show file tree
Hide file tree
Showing 26 changed files with 1,027 additions and 90 deletions.
2 changes: 1 addition & 1 deletion fittrackee/reports/reports_email_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _send_user_warning_email(
fittrackee_url,
)
email_data["appeal_url"] = (
f"{fittrackee_url}/profile/warning/{report_action.short_id}/appeal"
f"{fittrackee_url}/profile/sanctions/{report_action.short_id}/appeal"
)
user_warning_email.send(user_data, email_data)

Expand Down
10 changes: 5 additions & 5 deletions fittrackee/tests/reports/test_reports_email_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_it_sends_an_email_on_user_warning_for_user_report(
'username': user_3.username,
'fittrackee_url': app.config['UI_URL'],
'appeal_url': (
f'{app.config["UI_URL"]}/profile/warning'
f'{app.config["UI_URL"]}/profile/sanctions'
f'/{user_warning.short_id}/appeal' # type:ignore
),
'reason': input_reason.get('reason'),
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_it_sends_an_email_on_user_warning_for_comment_report(
},
{
'appeal_url': (
f'{app.config["UI_URL"]}/profile/warning'
f'{app.config["UI_URL"]}/profile/sanctions'
f'/{user_warning.short_id}/appeal' # type:ignore
),
'comment_url': (
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_it_sends_an_email_on_user_warning_for_comment_report_when_workout_is_de
},
{
'appeal_url': (
f'{app.config["UI_URL"]}/profile/warning'
f'{app.config["UI_URL"]}/profile/sanctions'
f'/{user_warning.short_id}/appeal' # type:ignore
),
'comment_url': (
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_it_sends_an_email_on_user_warning_for_workout_report(
},
{
'appeal_url': (
f'{app.config["UI_URL"]}/profile/warning'
f'{app.config["UI_URL"]}/profile/sanctions'
f'/{user_warning.short_id}/appeal' # type:ignore
),
'fittrackee_url': app.config['UI_URL'],
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_it_sends_an_email_on_user_warning_for_workout_with_gpx_report(
},
{
'appeal_url': (
f'{app.config["UI_URL"]}/profile/warning'
f'{app.config["UI_URL"]}/profile/sanctions'
f'/{user_warning.short_id}/appeal' # type:ignore
),
'fittrackee_url': app.config['UI_URL'],
Expand Down
107 changes: 93 additions & 14 deletions fittrackee/tests/users/test_auth_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from fittrackee.equipments.models import Equipment
from fittrackee.privacy_levels import PrivacyLevel
from fittrackee.reports.models import ReportActionAppeal
from fittrackee.tests.comments.mixins import CommentMixin
from fittrackee.users.models import (
BlacklistedToken,
User,
Expand All @@ -21,7 +22,7 @@
UserSportPreferenceEquipment,
)
from fittrackee.users.utils.token import get_user_token
from fittrackee.workouts.models import Sport
from fittrackee.workouts.models import Sport, Workout

from ..mixins import ApiTestCaseMixin, ReportMixin
from ..utils import OAUTH_SCOPES, jsonify_dict
Expand Down Expand Up @@ -4263,8 +4264,8 @@ def test_expected_scopes_are_defined(
self.assert_response_scope(response, can_access)


class TestGetUserWarning(UserSuspensionTestCase):
route = "/api/auth/account/warning/{action_short_id}"
class TestGetUserSanction(UserSuspensionTestCase, CommentMixin):
route = "/api/auth/account/sanctions/{action_short_id}"

def test_it_returns_error_when_user_is_not_authenticated(
self, app: Flask
Expand All @@ -4278,7 +4279,7 @@ def test_it_returns_error_when_user_is_not_authenticated(

self.assert_401(response)

def test_it_returns_404_when_warning_does_not_exist(
def test_it_returns_404_when_sanction_does_not_exist(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
Expand All @@ -4293,10 +4294,10 @@ def test_it_returns_404_when_warning_does_not_exist(

self.assert_404_with_message(
response,
"no warning found",
"no sanction found",
)

def test_it_returns_404_when_warning_is_for_another_user(
def test_it_returns_404_when_sanction_is_for_another_user(
self, app: Flask, user_1_admin: User, user_2: User, user_3: User
) -> None:
action = self.create_report_user_action(
Expand All @@ -4314,7 +4315,7 @@ def test_it_returns_404_when_warning_is_for_another_user(

self.assert_404_with_message(
response,
"no warning found",
"no sanction found",
)

def test_it_returns_user_warning(
Expand All @@ -4336,7 +4337,85 @@ def test_it_returns_user_warning(
assert response.status_code == 200
assert response.json == {
"status": "success",
"user_warning": jsonify_dict(action.serialize(user_2, full=True)),
"sanction": jsonify_dict(action.serialize(user_2, full=True)),
}

def test_it_returns_user_suspension(
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
action = self.create_report_user_action(
user_1_admin, user_2, action_type="user_suspension"
)
user_2.suspended_at = None
client, auth_token = self.get_test_client_and_auth_token(
app, user_2.email
)

response = client.get(
self.route.format(action_short_id=action.short_id),
content_type='application/json',
headers=dict(Authorization=f'Bearer {auth_token}'),
)

assert response.status_code == 200
assert response.json == {
"status": "success",
"sanction": jsonify_dict(action.serialize(user_2, full=True)),
}

def test_it_returns_workout_suspension(
self,
app: Flask,
user_1_admin: User,
user_2: User,
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
action = self.create_report_workout_action(
user_1_admin, user_2, workout_cycling_user_2
)
client, auth_token = self.get_test_client_and_auth_token(
app, user_2.email
)

response = client.get(
self.route.format(action_short_id=action.short_id),
content_type='application/json',
headers=dict(Authorization=f'Bearer {auth_token}'),
)

assert response.status_code == 200
assert response.json == {
"status": "success",
"sanction": jsonify_dict(action.serialize(user_2, full=True)),
}

def test_it_returns_comment_suspension(
self,
app: Flask,
user_1_admin: User,
user_2: User,
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
comment = self.create_comment(user_2, workout_cycling_user_2)
action = self.create_report_comment_action(
user_1_admin, user_2, comment
)
client, auth_token = self.get_test_client_and_auth_token(
app, user_2.email
)

response = client.get(
self.route.format(action_short_id=action.short_id),
content_type='application/json',
headers=dict(Authorization=f'Bearer {auth_token}'),
)

assert response.status_code == 200
assert response.json == {
"status": "success",
"sanction": jsonify_dict(action.serialize(user_2, full=True)),
}

@pytest.mark.parametrize(
Expand Down Expand Up @@ -4364,8 +4443,8 @@ def test_expected_scopes_are_defined(
self.assert_response_scope(response, can_access)


class TestPostUserWarningAppeal(UserSuspensionTestCase):
route = "/api/auth/account/warning/{action_short_id}/appeal"
class TestPostUserSanctionAppeal(UserSuspensionTestCase):
route = "/api/auth/account/sanctions/{action_short_id}/appeal"

def test_it_returns_error_when_user_is_not_authenticated(
self, app: Flask
Expand All @@ -4380,7 +4459,7 @@ def test_it_returns_error_when_user_is_not_authenticated(

self.assert_401(response)

def test_it_returns_404_when_when_no_user_warning(
def test_it_returns_404_when_when_no_sanction(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
Expand All @@ -4396,7 +4475,7 @@ def test_it_returns_404_when_when_no_user_warning(

self.assert_404_with_message(
response,
"no warning found",
"no sanction found",
)

@pytest.mark.parametrize(
Expand All @@ -4422,7 +4501,7 @@ def test_it_returns_400_when_no_text_provided(

self.assert_400(response, 'no text provided')

def test_user_can_appeal_user_warning(
def test_user_can_appeal_sanction(
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
action = self.create_report_user_action(
Expand Down Expand Up @@ -4453,7 +4532,7 @@ def test_user_can_appeal_user_warning(
assert appeal.user_id == user_2.id
assert appeal.updated_at is None

def test_user_can_appeal_user_warning_only_once(
def test_user_can_appeal_sanction_only_once(
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
action = self.create_report_user_action(
Expand Down
Loading

0 comments on commit 59559d3

Please sign in to comment.