From c0caa107b3cd7f9ef48244decb71d0cce20b4541 Mon Sep 17 00:00:00 2001 From: Josh XT Date: Fri, 24 Jan 2025 20:17:24 -0500 Subject: [PATCH] ignore team on check --- agixt/MagicalAuth.py | 152 ++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/agixt/MagicalAuth.py b/agixt/MagicalAuth.py index 8dad2ba811ef..d1f86fa0dcf4 100644 --- a/agixt/MagicalAuth.py +++ b/agixt/MagicalAuth.py @@ -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: