mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-10 12:38:35 +03:00
users in domains are active
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
VERSION = "0.7.1"
|
||||
VERSION = "0.7.2"
|
||||
API_DESCRIPTION = """
|
||||
#### API for the Auto-Archiver project, a tool to archive web pages and Google Sheets.
|
||||
|
||||
|
||||
@@ -106,6 +106,11 @@ def create_tag(db: Session, tag: str):
|
||||
|
||||
def is_active_user(db: Session, email: str) -> bool:
|
||||
email = email.lower()
|
||||
if "@" not in email: return False
|
||||
global DOMAIN_GROUPS, DOMAIN_GROUPS_LOADED
|
||||
if not DOMAIN_GROUPS_LOADED: upsert_user_groups(db)
|
||||
domain = email.split('@')[1]
|
||||
if domain in DOMAIN_GROUPS: return True
|
||||
return len(email) and db.query(models.User).filter(models.User.email == email, models.User.is_active == True).first() is not None
|
||||
|
||||
def is_user_in_group(db: Session, group_name: str, email: str) -> models.Group:
|
||||
|
||||
@@ -298,9 +298,10 @@ def test_is_active_user(test_data, db_session):
|
||||
|
||||
assert crud.is_active_user(db_session, "") == False
|
||||
assert crud.is_active_user(db_session, "example.com") == False
|
||||
assert crud.is_active_user(db_session, "unknown@example.com") == False
|
||||
assert crud.is_active_user(db_session, "unknown@example.com") == True
|
||||
assert crud.is_active_user(db_session, "rick@example.com") == True
|
||||
assert crud.is_active_user(db_session, "RICK@example.com") == True
|
||||
assert crud.is_active_user(db_session, "rick@not-in-groups.com") == False
|
||||
|
||||
|
||||
def test_is_user_in_group(test_data, db_session):
|
||||
|
||||
@@ -55,11 +55,13 @@ def test_endpoint_active_true_user(client_with_auth):
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"active": True}
|
||||
|
||||
def test_endpoint_active_true_user(client_with_auth, db_session):
|
||||
from db import models
|
||||
db_session.query(models.User).delete()
|
||||
db_session.commit()
|
||||
r = client_with_auth.get("/user/active")
|
||||
def test_endpoint_active_false_user(app):
|
||||
from web.security import get_user_auth
|
||||
|
||||
app.dependency_overrides[get_user_auth] = lambda: "morty@not-recognized-group.com"
|
||||
client = TestClient(app)
|
||||
r = client.get("/user/active")
|
||||
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"active": False}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user