fix org invites

This commit is contained in:
Kenneth Kehl
2025-09-08 08:23:04 -07:00
parent f1b87f56ca
commit 31e72ea24b
2 changed files with 47 additions and 0 deletions

View File

@@ -1,5 +1,14 @@
import json
import secrets
from urllib.parse import unquote
from flask import current_app, request
from app import redis_client
from app.enums import InvitedOrgUserStatus
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
from app.utils import hilite
from notifications_utils.url_safe_token import generate_token
class OrgInviteApiClient(NotifyAdminAPIClient):
@@ -15,7 +24,42 @@ class OrgInviteApiClient(NotifyAdminAPIClient):
"invite_link_host": self.admin_url,
}
data = _attach_current_user(data)
ttl = 24 * 60 * 60
# make and store the state
state = generate_token(
str(request.remote_addr),
current_app.config["SECRET_KEY"],
current_app.config["DANGEROUS_SALT"],
)
state_key = f"login-state-{unquote(state)}"
redis_client.set(state_key, state, ex=ttl)
current_app.logger.debug(
hilite(f"SET THE STATE KEY TO {state} with state_key {state_key}")
)
# make and store the nonce
nonce = secrets.token_urlsafe()
nonce_key = f"login-nonce-{unquote(nonce)}"
redis_client.set(nonce_key, nonce, ex=ttl) # save the nonce to redis.
current_app.logger.debug(
hilite(f"SET THE STATE KEY TO {state} with state_key {state_key}")
)
data["nonce"] = nonce # This is passed to api for the invite url.
data["state"] = state # This is passed to api for the invite url.
resp = self.post(url="/organization/{}/invite".format(org_id), data=data)
current_app.logger.debug(hilite(f"RESP is {resp}"))
invite_data_key = f"invitedata-{unquote(state)}"
redis_invite_data = resp["invite"]
redis_invite_data = json.dumps(redis_invite_data)
redis_client.set(invite_data_key, redis_invite_data, ex=ttl)
current_app.logger.debug(
hilite(f"SET invite_data_key {invite_data_key} to {redis_invite_data}")
)
return resp["data"]
def get_invites_for_organization(self, org_id):