Ajoute le drapeau TOUS_ABONNES pour l'accès gratuit
Ouvre les fonctionnalités d'abonné à tout utilisateur connecté tant que Frisbii n'a pas validé la réception de paiements. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -63,3 +63,6 @@ FRISBII_API_BASE_URL=https://api.frisbii.com # base de l'API Frisbii
|
|||||||
FRISBII_PLAN_SIMPLE=abonnement-decp.info # handle du plan "abonnement simple" (20 € HT/mois)
|
FRISBII_PLAN_SIMPLE=abonnement-decp.info # handle du plan "abonnement simple" (20 € HT/mois)
|
||||||
FRISBII_PLAN_SOUTIEN=soutien-decp.info # handle du plan "abonnement de soutien" (50 € HT/mois)
|
FRISBII_PLAN_SOUTIEN=soutien-decp.info # handle du plan "abonnement de soutien" (50 € HT/mois)
|
||||||
FRISBII_WEBHOOK_SECRET= # secret de signature des webhooks
|
FRISBII_WEBHOOK_SECRET= # secret de signature des webhooks
|
||||||
|
|
||||||
|
# Accès gratuit temporaire
|
||||||
|
TOUS_ABONNES=false # true = ouvre gratuitement les fonctionnalités d'abonné à tout compte
|
||||||
|
|||||||
@@ -40,9 +40,12 @@ SECTIONS = [
|
|||||||
|
|
||||||
def current_user_has_subscription() -> bool:
|
def current_user_has_subscription() -> bool:
|
||||||
from src.subscriptions import db
|
from src.subscriptions import db
|
||||||
|
from src.utils import TOUS_ABONNES
|
||||||
|
|
||||||
if not current_user.is_authenticated:
|
if not current_user.is_authenticated:
|
||||||
return False
|
return False
|
||||||
|
if TOUS_ABONNES:
|
||||||
|
return True
|
||||||
return db.has_active_subscription(current_user.id)
|
return db.has_active_subscription(current_user.id)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ logging.basicConfig(
|
|||||||
datefmt="%Y-%m-%d %H:%M:%S",
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
)
|
)
|
||||||
DEVELOPMENT = os.getenv("DEVELOPMENT", "False").lower() == "true"
|
DEVELOPMENT = os.getenv("DEVELOPMENT", "False").lower() == "true"
|
||||||
|
# Accès gratuit temporaire à toutes les fonctionnalités d'abonné, le temps que
|
||||||
|
# la plateforme de paiement Frisbii valide la réception de paiements.
|
||||||
|
TOUS_ABONNES = os.getenv("TOUS_ABONNES", "False").lower() == "true"
|
||||||
logger = logging.getLogger("decp.info")
|
logger = logging.getLogger("decp.info")
|
||||||
|
|
||||||
if DEVELOPMENT:
|
if DEVELOPMENT:
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from src.pages import _compte_shell as shell
|
from src.pages import _compte_shell as shell
|
||||||
|
|
||||||
|
|
||||||
|
def _fake_user(authenticated: bool):
|
||||||
|
user = type("U", (), {})()
|
||||||
|
user.is_authenticated = authenticated
|
||||||
|
user.id = 1
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
def test_visible_sections_hides_gated_without_subscription():
|
def test_visible_sections_hides_gated_without_subscription():
|
||||||
keys = {s["key"] for s in shell.visible_sections(has_subscription=False)}
|
keys = {s["key"] for s in shell.visible_sections(has_subscription=False)}
|
||||||
assert "admin" in keys
|
assert "admin" in keys
|
||||||
@@ -41,3 +50,27 @@ def test_guard_redirect_allowed_returns_none():
|
|||||||
path="/compte/admin",
|
path="/compte/admin",
|
||||||
)
|
)
|
||||||
assert href is None
|
assert href is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_has_subscription_true_for_authenticated_when_tous_abonnes(monkeypatch):
|
||||||
|
monkeypatch.setattr("src.utils.TOUS_ABONNES", True)
|
||||||
|
with patch("src.pages._compte_shell.current_user", _fake_user(True)):
|
||||||
|
assert shell.current_user_has_subscription() is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_has_subscription_false_for_anonymous_even_with_tous_abonnes(monkeypatch):
|
||||||
|
monkeypatch.setattr("src.utils.TOUS_ABONNES", True)
|
||||||
|
with patch("src.pages._compte_shell.current_user", _fake_user(False)):
|
||||||
|
assert shell.current_user_has_subscription() is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_has_subscription_uses_db_when_flag_off(monkeypatch):
|
||||||
|
monkeypatch.setattr("src.utils.TOUS_ABONNES", False)
|
||||||
|
with (
|
||||||
|
patch("src.pages._compte_shell.current_user", _fake_user(True)),
|
||||||
|
patch(
|
||||||
|
"src.subscriptions.db.has_active_subscription", return_value=False
|
||||||
|
) as mocked,
|
||||||
|
):
|
||||||
|
assert shell.current_user_has_subscription() is False
|
||||||
|
mocked.assert_called_once_with(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user