mirror of
https://github.com/simple-login/app.git
synced 2025-09-06 06:34:20 +08:00
Move unmark to abuser file
This commit is contained in:
parent
0211e044bf
commit
71330c7703
4 changed files with 30 additions and 29 deletions
|
@ -3,12 +3,14 @@ from typing import Optional
|
|||
from app.abuser_audit_log_utils import emit_abuser_audit_log, AbuserAuditLogAction
|
||||
from app.db import Session
|
||||
from app.jobs.mark_abuser_job import MarkAbuserJob
|
||||
from app.models import User
|
||||
from app.log import LOG
|
||||
from app.models import User, AbuserData
|
||||
|
||||
|
||||
def mark_user_as_abuser(
|
||||
abuse_user: User, note: str, admin_id: Optional[int] = None
|
||||
) -> None:
|
||||
LOG.i(f"Marking user {abuse_user.id} as an abuser.")
|
||||
abuse_user.disabled = True
|
||||
|
||||
emit_abuser_audit_log(
|
||||
|
@ -20,3 +22,28 @@ def mark_user_as_abuser(
|
|||
job = MarkAbuserJob(user=abuse_user)
|
||||
job.store_job_in_db()
|
||||
Session.commit()
|
||||
|
||||
|
||||
def unmark_as_abusive_user(
|
||||
user_id: int, note: str, admin_id: Optional[int] = None
|
||||
) -> None:
|
||||
"""
|
||||
Fully remove abuser archive and lookup data for a given user_id.
|
||||
This reverses the effects of archive_abusive_user().
|
||||
"""
|
||||
LOG.i(f"Unmarking user {user_id} as an abuser.")
|
||||
abuser_data_entry = AbuserData.filter_by(user_id=user_id).first()
|
||||
|
||||
if abuser_data_entry:
|
||||
Session.delete(abuser_data_entry)
|
||||
|
||||
user = User.get(user_id)
|
||||
user.disabled = False
|
||||
|
||||
emit_abuser_audit_log(
|
||||
user_id=user.id,
|
||||
admin_id=admin_id,
|
||||
action=AbuserAuditLogAction.UnmarkAbuser,
|
||||
message=note,
|
||||
)
|
||||
Session.commit()
|
||||
|
|
|
@ -163,31 +163,6 @@ def store_abuse_data(user: User) -> None:
|
|||
raise
|
||||
|
||||
|
||||
def unmark_as_abusive_user(
|
||||
user_id: int, note: str, admin_id: Optional[int] = None
|
||||
) -> None:
|
||||
"""
|
||||
Fully remove abuser archive and lookup data for a given user_id.
|
||||
This reverses the effects of archive_abusive_user().
|
||||
"""
|
||||
LOG.i(f"Removing user {user_id} as an abuser.")
|
||||
abuser_data_entry = AbuserData.filter_by(user_id=user_id).first()
|
||||
|
||||
if abuser_data_entry:
|
||||
Session.delete(abuser_data_entry)
|
||||
|
||||
user = User.get(user_id)
|
||||
user.disabled = False
|
||||
|
||||
emit_abuser_audit_log(
|
||||
user_id=user.id,
|
||||
admin_id=admin_id,
|
||||
action=AbuserAuditLogAction.UnmarkAbuser,
|
||||
message=note,
|
||||
)
|
||||
Session.commit()
|
||||
|
||||
|
||||
def get_abuser_bundles_for_address(target_address: str, admin_id: int) -> List[Dict]:
|
||||
"""
|
||||
Given a target address (email, alias, or mailbox address),
|
||||
|
|
|
@ -17,10 +17,9 @@ from flask_login import current_user
|
|||
from markupsafe import Markup
|
||||
|
||||
from app import models, s3, config
|
||||
from app.abuser import mark_user_as_abuser, unmark_as_abusive_user
|
||||
from app.abuser_audit_log_utils import AbuserAuditLog
|
||||
from app.abuser import mark_user_as_abuser
|
||||
from app.abuser_utils import (
|
||||
unmark_as_abusive_user,
|
||||
get_abuser_bundles_for_address,
|
||||
)
|
||||
from app.custom_domain_validation import (
|
||||
|
|
|
@ -8,10 +8,10 @@ from cryptography.hazmat.primitives import hashes as crypto_hashes
|
|||
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
||||
|
||||
from app import constants
|
||||
from app.abuser import unmark_as_abusive_user
|
||||
from app.abuser_utils import (
|
||||
check_if_abuser_email,
|
||||
get_abuser_bundles_for_address,
|
||||
unmark_as_abusive_user,
|
||||
_derive_key_for_identifier,
|
||||
store_abuse_data,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue