mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-12-18 02:27:10 +00:00
Use the state.billing_enabled field to determine whether to use the subscribed scope
This commit is contained in:
parent
69c8f45830
commit
9c868ee10b
1 changed files with 15 additions and 9 deletions
|
@ -75,11 +75,14 @@ class UserAuthenticationBackend(AuthenticationBackend):
|
||||||
.afirst()
|
.afirst()
|
||||||
)
|
)
|
||||||
if user:
|
if user:
|
||||||
|
if state.billing_enabled:
|
||||||
subscription_state = await aget_user_subscription_state(user)
|
subscription_state = await aget_user_subscription_state(user)
|
||||||
subscribed = subscription_state == SubscriptionState.SUBSCRIBED.value
|
subscribed = subscription_state == SubscriptionState.SUBSCRIBED.value
|
||||||
if subscribed:
|
if subscribed:
|
||||||
return AuthCredentials(["authenticated", "subscribed"]), AuthenticatedKhojUser(user)
|
return AuthCredentials(["authenticated", "subscribed"]), AuthenticatedKhojUser(
|
||||||
return AuthCredentials(["authenticated", "subscribed"]), AuthenticatedKhojUser(user)
|
user_with_token.user
|
||||||
|
)
|
||||||
|
return AuthCredentials(["authenticated"]), AuthenticatedKhojUser(user)
|
||||||
if len(request.headers.get("Authorization", "").split("Bearer ")) == 2:
|
if len(request.headers.get("Authorization", "").split("Bearer ")) == 2:
|
||||||
# Get bearer token from header
|
# Get bearer token from header
|
||||||
bearer_token = request.headers["Authorization"].split("Bearer ")[1]
|
bearer_token = request.headers["Authorization"].split("Bearer ")[1]
|
||||||
|
@ -91,10 +94,13 @@ class UserAuthenticationBackend(AuthenticationBackend):
|
||||||
.afirst()
|
.afirst()
|
||||||
)
|
)
|
||||||
if user_with_token:
|
if user_with_token:
|
||||||
|
if state.billing_enabled:
|
||||||
subscription_state = await aget_user_subscription_state(user_with_token.user)
|
subscription_state = await aget_user_subscription_state(user_with_token.user)
|
||||||
subscribed = subscription_state == SubscriptionState.SUBSCRIBED.value
|
subscribed = subscription_state == SubscriptionState.SUBSCRIBED.value
|
||||||
if subscribed:
|
if subscribed:
|
||||||
return AuthCredentials(["authenticated", "subscribed"]), AuthenticatedKhojUser(user_with_token.user)
|
return AuthCredentials(["authenticated", "subscribed"]), AuthenticatedKhojUser(
|
||||||
|
user_with_token.user
|
||||||
|
)
|
||||||
return AuthCredentials(["authenticated"]), AuthenticatedKhojUser(user_with_token.user)
|
return AuthCredentials(["authenticated"]), AuthenticatedKhojUser(user_with_token.user)
|
||||||
if state.anonymous_mode:
|
if state.anonymous_mode:
|
||||||
user = await self.khojuser_manager.filter(username="default").prefetch_related("subscription").afirst()
|
user = await self.khojuser_manager.filter(username="default").prefetch_related("subscription").afirst()
|
||||||
|
|
Loading…
Reference in a new issue