Skip to content

Commit

Permalink
fix db pool issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Jan 15, 2024
1 parent 2cbd694 commit 9c1e09e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions plugins/quetz_googleiap/quetz_googleiap/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ async def dispatch(self, request, call_next):
count = request.session.get("count", 0)
request.session["count"] = count + 1

db = next(get_db(get_config()))
dao = Dao(db)

user_id = request.headers.get("x-goog-authenticated-user-id")
email = request.headers.get("x-goog-authenticated-user-email")

if user_id and email:
db = next(get_db(get_config()))
dao = Dao(db)

_, email = email.split(":", 1)
_, user_id = user_id.split(":", 1)

Expand All @@ -77,8 +77,8 @@ async def dispatch(self, request, call_next):
)
user_channel = email_to_channel_name(email)

logger.info(f"Creating channel for user: {user_channel}")
if dao.get_channel(email_to_channel_name(user_channel)) is None:
logger.info(f"Creating channel for user: {user_channel}")
channel = rest_models.Channel(
name=user_channel,
private=False,
Expand All @@ -87,10 +87,12 @@ async def dispatch(self, request, call_next):
dao.create_channel(channel, user.id, "owner")

self.google_role_for_user(user_id, dao)

user_id = uuid.UUID(bytes=user.id)
# drop the db and dao to remove the connection
del db, dao
# we also need to find the role of the user
request.session['identity_provider'] = "dummy"
request.session["user_id"] = str(uuid.UUID(bytes=user.id))
request.session["user_id"] = str(user_id)
else:
request.session["user_id"] = None
request.session["identity_provider"] = None
Expand Down

0 comments on commit 9c1e09e

Please sign in to comment.