Skip to content

Commit

Permalink
ignore team on check
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Jan 25, 2025
1 parent 8e17ae0 commit c0caa10
Showing 1 changed file with 77 additions and 75 deletions.
152 changes: 77 additions & 75 deletions agixt/MagicalAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,95 +1008,97 @@ def get_user_preferences(self):
.all()
)
is_subscription = False
for user_company in user_companies:
# Get the company admins
company_admins = (
session.query(User)
.filter(Company.id == user_company.company_id)
.filter(UserCompany.role_id <= 2)
.all()
)
for company_admin in company_admins:
company_admin_preferences = (
session.query(UserPreferences)
.filter(UserPreferences.user_id == company_admin.id)
if not user.email.endswith(".xt"):
for user_company in user_companies:
# Get the company admins
company_admins = (
session.query(User)
.filter(Company.id == user_company.company_id)
.filter(UserCompany.role_id <= 2)
.all()
)
company_admin_preferences = {
x.pref_key: x.pref_value for x in company_admin_preferences
}
if "stripe_id" in company_admin_preferences:
# add to users preferences
user_preferences["stripe_id"] = company_admin_preferences[
"stripe_id"
]
# check if it has an active subscription
relevant_subscriptions = self.get_subscribed_products(
api_key, company_admin_preferences["stripe_id"]
)
if relevant_subscriptions:
is_subscription = True
break
if not is_subscription:
if "stripe_id" not in user_preferences or not user_preferences[
"stripe_id"
].startswith("cus_"):
logging.info("No Stripe ID found in user preferences.")
customer = stripe.Customer.create(email=user.email)
user_preferences["stripe_id"] = customer.id
user_preference = UserPreferences(
user_id=self.user_id,
pref_key="stripe_id",
pref_value=customer.id,
)
session.add(user_preference)
session.commit()
raise HTTPException(
status_code=402,
detail={
"message": "No active subscriptions.",
"customer_id": customer.id,
},
)
else:
logging.info(
"Stripe ID found: " + user_preferences["stripe_id"]
)
relevant_subscriptions = self.get_subscribed_products(
api_key, user_preferences["stripe_id"]
)
if not relevant_subscriptions:
logging.info(
f"No active subscriptions for this app detected."
for company_admin in company_admins:
company_admin_preferences = (
session.query(UserPreferences)
.filter(UserPreferences.user_id == company_admin.id)
.all()
)
if getenv("STRIPE_PRICING_TABLE_ID"):
c_session = stripe.CustomerSession.create(
customer=user_preferences["stripe_id"],
components={"pricing_table": {"enabled": True}},
company_admin_preferences = {
x.pref_key: x.pref_value
for x in company_admin_preferences
}
if "stripe_id" in company_admin_preferences:
# add to users preferences
user_preferences["stripe_id"] = (
company_admin_preferences["stripe_id"]
)
else:
c_session = ""

user = (
session.query(User)
.filter(User.id == self.user_id)
.first()
# check if it has an active subscription
relevant_subscriptions = self.get_subscribed_products(
api_key, company_admin_preferences["stripe_id"]
)
if relevant_subscriptions:
is_subscription = True
break
if not is_subscription:
if "stripe_id" not in user_preferences or not user_preferences[
"stripe_id"
].startswith("cus_"):
logging.info("No Stripe ID found in user preferences.")
customer = stripe.Customer.create(email=user.email)
user_preferences["stripe_id"] = customer.id
user_preference = UserPreferences(
user_id=self.user_id,
pref_key="stripe_id",
pref_value=customer.id,
)
user.is_active = False
session.add(user_preference)
session.commit()
session.close()
raise HTTPException(
status_code=402,
detail={
"message": f"No active subscriptions.",
"customer_session": c_session,
"customer_id": user_preferences["stripe_id"],
"message": "No active subscriptions.",
"customer_id": customer.id,
},
)
else:
logging.info(
f"{len(relevant_subscriptions)} subscriptions relevant to this app detected."
"Stripe ID found: " + user_preferences["stripe_id"]
)
relevant_subscriptions = self.get_subscribed_products(
api_key, user_preferences["stripe_id"]
)
if not relevant_subscriptions:
logging.info(
f"No active subscriptions for this app detected."
)
if getenv("STRIPE_PRICING_TABLE_ID"):
c_session = stripe.CustomerSession.create(
customer=user_preferences["stripe_id"],
components={"pricing_table": {"enabled": True}},
)
else:
c_session = ""

user = (
session.query(User)
.filter(User.id == self.user_id)
.first()
)
user.is_active = False
session.commit()
session.close()
raise HTTPException(
status_code=402,
detail={
"message": f"No active subscriptions.",
"customer_session": c_session,
"customer_id": user_preferences["stripe_id"],
},
)
else:
logging.info(
f"{len(relevant_subscriptions)} subscriptions relevant to this app detected."
)
if "email" in user_preferences:
del user_preferences["email"]
if "first_name" in user_preferences:
Expand Down

0 comments on commit c0caa10

Please sign in to comment.