feat(chalice): session mobsUrl exp
feat(chalice): notes in replay response
This commit is contained in:
parent
eda3bb3dcb
commit
0d26b1cc9a
7 changed files with 55 additions and 44 deletions
|
|
@ -3,7 +3,7 @@ from typing import List
|
|||
import schemas
|
||||
from chalicelib.core import events, metadata, events_ios, \
|
||||
sessions_mobs, issues, projects, errors, resources, assist, performance_event, sessions_viewed, sessions_favorite, \
|
||||
sessions_devtool
|
||||
sessions_devtool, sessions_notes
|
||||
from chalicelib.utils import pg_client, helper, metrics_helper
|
||||
|
||||
SESSION_PROJECTION_COLS = """s.project_id,
|
||||
|
|
@ -40,8 +40,8 @@ def __group_metadata(session, project_metadata):
|
|||
return meta
|
||||
|
||||
|
||||
def get_by_id2_pg(project_id, session_id, user_id, full_data=False, include_fav_viewed=False, group_metadata=False,
|
||||
live=True):
|
||||
def get_by_id2_pg(tenant_id, project_id, session_id, user_id, full_data=False, include_fav_viewed=False,
|
||||
group_metadata=False, live=True):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
extra_query = []
|
||||
if include_fav_viewed:
|
||||
|
|
@ -100,6 +100,8 @@ def get_by_id2_pg(project_id, session_id, user_id, full_data=False, include_fav_
|
|||
data['resources'] = resources.get_by_session_id(session_id=session_id, project_id=project_id,
|
||||
start_ts=data["startTs"], duration=data["duration"])
|
||||
|
||||
data['notes'] = sessions_notes.get_session_notes(tenant_id=tenant_id, project_id=project_id,
|
||||
session_id=session_id, user_id=user_id)
|
||||
data['metadata'] = __group_metadata(project_metadata=data.pop("projectMetadata"), session=data)
|
||||
data['issues'] = issues.get_by_session_id(session_id=session_id, project_id=project_id)
|
||||
data['live'] = live and assist.is_live(project_id=project_id,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from chalicelib.core import sessions
|
|||
from chalicelib.utils import pg_client
|
||||
|
||||
|
||||
def add_favorite_session(project_id, user_id, session_id):
|
||||
def add_favorite_session(tenant_id, project_id, user_id, session_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(f"""\
|
||||
|
|
@ -10,11 +10,11 @@ def add_favorite_session(project_id, user_id, session_id):
|
|||
VALUES (%(userId)s,%(session_id)s);""",
|
||||
{"userId": user_id, "session_id": session_id})
|
||||
)
|
||||
return sessions.get_by_id2_pg(project_id=project_id, session_id=session_id, user_id=user_id, full_data=False,
|
||||
include_fav_viewed=True)
|
||||
return sessions.get_by_id2_pg(tenant_id=tenant_id, project_id=project_id, session_id=session_id, user_id=user_id,
|
||||
full_data=False, include_fav_viewed=True)
|
||||
|
||||
|
||||
def remove_favorite_session(project_id, user_id, session_id):
|
||||
def remove_favorite_session(tenant_id, project_id, user_id, session_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(f"""\
|
||||
|
|
@ -23,15 +23,16 @@ def remove_favorite_session(project_id, user_id, session_id):
|
|||
AND session_id = %(session_id)s;""",
|
||||
{"userId": user_id, "session_id": session_id})
|
||||
)
|
||||
return sessions.get_by_id2_pg(project_id=project_id, session_id=session_id, user_id=user_id, full_data=False,
|
||||
include_fav_viewed=True)
|
||||
return sessions.get_by_id2_pg(tenant_id=tenant_id, project_id=project_id, session_id=session_id, user_id=user_id,
|
||||
full_data=False, include_fav_viewed=True)
|
||||
|
||||
|
||||
def favorite_session(project_id, user_id, session_id):
|
||||
def favorite_session(tenant_id, project_id, user_id, session_id):
|
||||
if favorite_session_exists(user_id=user_id, session_id=session_id):
|
||||
return remove_favorite_session(project_id=project_id, user_id=user_id, session_id=session_id)
|
||||
return remove_favorite_session(tenant_id=tenant_id, project_id=project_id, user_id=user_id,
|
||||
session_id=session_id)
|
||||
|
||||
return add_favorite_session(project_id=project_id, user_id=user_id, session_id=session_id)
|
||||
return add_favorite_session(tenant_id=tenant_id, project_id=project_id, user_id=user_id, session_id=session_id)
|
||||
|
||||
|
||||
def favorite_session_exists(user_id, session_id):
|
||||
|
|
|
|||
|
|
@ -175,8 +175,8 @@ def get_session(projectId: int, sessionId: Union[int, str], background_tasks: Ba
|
|||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
if isinstance(sessionId, str):
|
||||
return {"errors": ["session not found"]}
|
||||
data = sessions.get_by_id2_pg(project_id=projectId, session_id=sessionId, full_data=True, user_id=context.user_id,
|
||||
include_fav_viewed=True, group_metadata=True)
|
||||
data = sessions.get_by_id2_pg(tenant_id=context.tenant_id, project_id=projectId, session_id=sessionId,
|
||||
full_data=True, user_id=context.user_id, include_fav_viewed=True, group_metadata=True)
|
||||
if data is None:
|
||||
return {"errors": ["session not found"]}
|
||||
if data.get("inDB"):
|
||||
|
|
@ -265,8 +265,9 @@ def get_live_session(projectId: int, sessionId: str, background_tasks: Backgroun
|
|||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
data = assist.get_live_session_by_id(project_id=projectId, session_id=sessionId)
|
||||
if data is None:
|
||||
data = sessions.get_by_id2_pg(project_id=projectId, session_id=sessionId, full_data=True,
|
||||
user_id=context.user_id, include_fav_viewed=True, group_metadata=True, live=False)
|
||||
data = sessions.get_by_id2_pg(tenant_id=context.tenant_id, project_id=projectId, session_id=sessionId,
|
||||
full_data=True, user_id=context.user_id, include_fav_viewed=True,
|
||||
group_metadata=True, live=False)
|
||||
if data is None:
|
||||
return {"errors": ["session not found"]}
|
||||
if data.get("inDB"):
|
||||
|
|
@ -328,8 +329,8 @@ def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema =
|
|||
def add_remove_favorite_session2(projectId: int, sessionId: int,
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {
|
||||
"data": sessions_favorite.favorite_session(project_id=projectId, user_id=context.user_id,
|
||||
session_id=sessionId)}
|
||||
"data": sessions_favorite.favorite_session(tenant_id=context.tenant_id, project_id=projectId,
|
||||
user_id=context.user_id, session_id=sessionId)}
|
||||
|
||||
|
||||
@app.get('/{projectId}/sessions/{sessionId}/assign', tags=["sessions"])
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import schemas
|
|||
import schemas_ee
|
||||
from chalicelib.core import events, metadata, events_ios, \
|
||||
sessions_mobs, issues, projects, errors, resources, assist, performance_event, sessions_viewed, sessions_favorite, \
|
||||
sessions_devtool
|
||||
sessions_devtool, sessions_notes
|
||||
from chalicelib.utils import pg_client, helper, metrics_helper
|
||||
|
||||
SESSION_PROJECTION_COLS = """s.project_id,
|
||||
|
|
@ -41,7 +41,7 @@ def __group_metadata(session, project_metadata):
|
|||
return meta
|
||||
|
||||
|
||||
def get_by_id2_pg(project_id, session_id, user_id, context: schemas_ee.CurrentContext, full_data=False,
|
||||
def get_by_id2_pg(project_id, session_id, context: schemas_ee.CurrentContext, full_data=False,
|
||||
include_fav_viewed=False, group_metadata=False, live=True):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
extra_query = []
|
||||
|
|
@ -65,7 +65,7 @@ def get_by_id2_pg(project_id, session_id, user_id, context: schemas_ee.CurrentCo
|
|||
FROM public.sessions AS s {"INNER JOIN public.projects AS p USING (project_id)" if group_metadata else ""}
|
||||
WHERE s.project_id = %(project_id)s
|
||||
AND s.session_id = %(session_id)s;""",
|
||||
{"project_id": project_id, "session_id": session_id, "userId": user_id}
|
||||
{"project_id": project_id, "session_id": session_id, "userId": context.user_id}
|
||||
)
|
||||
# print("===============")
|
||||
# print(query)
|
||||
|
|
@ -102,6 +102,8 @@ def get_by_id2_pg(project_id, session_id, user_id, context: schemas_ee.CurrentCo
|
|||
data['resources'] = resources.get_by_session_id(session_id=session_id, project_id=project_id,
|
||||
start_ts=data["startTs"], duration=data["duration"])
|
||||
|
||||
data['notes'] = sessions_notes.get_session_notes(tenant_id=context.tenant_id, project_id=project_id,
|
||||
session_id=session_id, user_id=context.user_id)
|
||||
data['metadata'] = __group_metadata(project_metadata=data.pop("projectMetadata"), session=data)
|
||||
data['issues'] = issues.get_by_session_id(session_id=session_id, project_id=project_id)
|
||||
data['live'] = live and assist.is_live(project_id=project_id,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ from typing import List, Union
|
|||
import schemas
|
||||
import schemas_ee
|
||||
from chalicelib.core import events, metadata, events_ios, \
|
||||
sessions_mobs, issues, projects, errors, resources, assist, performance_event, metrics
|
||||
sessions_mobs, issues, projects, errors, resources, assist, performance_event, metrics, sessions_devtool, \
|
||||
sessions_notes
|
||||
from chalicelib.utils import pg_client, helper, metrics_helper, ch_client, exp_ch_helper
|
||||
|
||||
SESSION_PROJECTION_COLS_CH = """\
|
||||
|
|
@ -58,8 +59,8 @@ def __group_metadata(session, project_metadata):
|
|||
return meta
|
||||
|
||||
|
||||
def get_by_id2_pg(project_id, session_id, user_id, full_data=False, include_fav_viewed=False, group_metadata=False,
|
||||
live=True):
|
||||
def get_by_id2_pg(project_id, session_id, context: schemas_ee.CurrentContext, full_data=False, include_fav_viewed=False,
|
||||
group_metadata=False, live=True):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
extra_query = []
|
||||
if include_fav_viewed:
|
||||
|
|
@ -82,7 +83,7 @@ def get_by_id2_pg(project_id, session_id, user_id, full_data=False, include_fav_
|
|||
FROM public.sessions AS s {"INNER JOIN public.projects AS p USING (project_id)" if group_metadata else ""}
|
||||
WHERE s.project_id = %(project_id)s
|
||||
AND s.session_id = %(session_id)s;""",
|
||||
{"project_id": project_id, "session_id": session_id, "userId": user_id}
|
||||
{"project_id": project_id, "session_id": session_id, "userId": context.user_id}
|
||||
)
|
||||
# print("===============")
|
||||
# print(query)
|
||||
|
|
@ -112,11 +113,16 @@ def get_by_id2_pg(project_id, session_id, user_id, full_data=False, include_fav_
|
|||
:500] # limit the number of errors to reduce the response-body size
|
||||
data['userEvents'] = events.get_customs_by_sessionId2_pg(project_id=project_id,
|
||||
session_id=session_id)
|
||||
data['mobsUrl'] = sessions_mobs.get_web(sessionId=session_id)
|
||||
data['domURL'] = sessions_mobs.get_urls(session_id=session_id, project_id=project_id)
|
||||
data['mobsUrl'] = sessions_mobs.get_urls_depercated(session_id=session_id)
|
||||
data['devtoolsURL'] = sessions_devtool.get_urls(session_id=session_id, project_id=project_id,
|
||||
context=context)
|
||||
data['resources'] = resources.get_by_session_id(session_id=session_id, project_id=project_id,
|
||||
start_ts=data["startTs"],
|
||||
duration=data["duration"])
|
||||
|
||||
data['notes'] = sessions_notes.get_session_notes(tenant_id=context.tenant_id, project_id=project_id,
|
||||
session_id=session_id, user_id=context.user_id)
|
||||
data['metadata'] = __group_metadata(project_metadata=data.pop("projectMetadata"), session=data)
|
||||
data['issues'] = issues.get_by_session_id(session_id=session_id, project_id=project_id)
|
||||
data['live'] = live and assist.is_live(project_id=project_id,
|
||||
|
|
|
|||
|
|
@ -5,35 +5,35 @@ from chalicelib.core import sessions, sessions_favorite_exp
|
|||
from chalicelib.utils import pg_client, s3_extra
|
||||
|
||||
|
||||
def add_favorite_session(project_id, user_id, session_id, context: schemas_ee.CurrentContext):
|
||||
def add_favorite_session(project_id, session_id, context: schemas_ee.CurrentContext):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(f"""\
|
||||
INSERT INTO public.user_favorite_sessions(user_id, session_id)
|
||||
VALUES (%(userId)s,%(sessionId)s);""",
|
||||
{"userId": user_id, "sessionId": session_id})
|
||||
{"userId": context.user_id, "sessionId": session_id})
|
||||
)
|
||||
|
||||
sessions_favorite_exp.add_favorite_session(project_id=project_id, user_id=user_id, session_id=session_id)
|
||||
return sessions.get_by_id2_pg(project_id=project_id, session_id=session_id, user_id=user_id, full_data=False,
|
||||
include_fav_viewed=True, context=context)
|
||||
sessions_favorite_exp.add_favorite_session(project_id=project_id, user_id=context.user_id, session_id=session_id)
|
||||
return sessions.get_by_id2_pg(project_id=project_id, session_id=session_id,
|
||||
full_data=False, include_fav_viewed=True, context=context)
|
||||
|
||||
|
||||
def remove_favorite_session(project_id, user_id, session_id, context: schemas_ee.CurrentContext):
|
||||
def remove_favorite_session(project_id, session_id, context: schemas_ee.CurrentContext):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(f"""\
|
||||
DELETE FROM public.user_favorite_sessions
|
||||
WHERE user_id = %(userId)s
|
||||
AND session_id = %(sessionId)s;""",
|
||||
{"userId": user_id, "sessionId": session_id})
|
||||
{"userId": context.user_id, "sessionId": session_id})
|
||||
)
|
||||
sessions_favorite_exp.remove_favorite_session(project_id=project_id, user_id=user_id, session_id=session_id)
|
||||
return sessions.get_by_id2_pg(project_id=project_id, session_id=session_id, user_id=user_id, full_data=False,
|
||||
include_fav_viewed=True, context=context)
|
||||
sessions_favorite_exp.remove_favorite_session(project_id=project_id, user_id=context.user_id, session_id=session_id)
|
||||
return sessions.get_by_id2_pg(project_id=project_id, session_id=session_id,
|
||||
full_data=False, include_fav_viewed=True, context=context)
|
||||
|
||||
|
||||
def favorite_session(project_id, user_id, session_id, context: schemas_ee.CurrentContext):
|
||||
def favorite_session(tenant_id, project_id, user_id, session_id, context: schemas_ee.CurrentContext):
|
||||
if favorite_session_exists(user_id=user_id, session_id=session_id):
|
||||
key = str(session_id)
|
||||
try:
|
||||
|
|
@ -47,7 +47,7 @@ def favorite_session(project_id, user_id, session_id, context: schemas_ee.Curren
|
|||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {key} to default")
|
||||
print(str(e))
|
||||
return remove_favorite_session(project_id=project_id, user_id=user_id, session_id=session_id)
|
||||
return remove_favorite_session(project_id=project_id, session_id=session_id, context=context)
|
||||
key = str(session_id)
|
||||
try:
|
||||
s3_extra.tag_file(session_id=key, tag_value=config('RETENTION_L_VALUE', default='vault'))
|
||||
|
|
@ -60,7 +60,7 @@ def favorite_session(project_id, user_id, session_id, context: schemas_ee.Curren
|
|||
except Exception as e:
|
||||
print(f"!!!Error while tagging: {key} to vault")
|
||||
print(str(e))
|
||||
return add_favorite_session(project_id=project_id, user_id=user_id, session_id=session_id, context=context)
|
||||
return add_favorite_session(project_id=project_id, session_id=session_id, context=context)
|
||||
|
||||
|
||||
def favorite_session_exists(user_id, session_id):
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ def get_session(projectId: int, sessionId: Union[int, str], background_tasks: Ba
|
|||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
if isinstance(sessionId, str):
|
||||
return {"errors": ["session not found"]}
|
||||
data = sessions.get_by_id2_pg(project_id=projectId, session_id=sessionId, full_data=True, user_id=context.user_id,
|
||||
data = sessions.get_by_id2_pg(project_id=projectId, session_id=sessionId, full_data=True,
|
||||
include_fav_viewed=True, group_metadata=True, context=context)
|
||||
if data is None:
|
||||
return {"errors": ["session not found"]}
|
||||
|
|
@ -275,8 +275,7 @@ def get_live_session(projectId: int, sessionId: str, background_tasks: Backgroun
|
|||
data = assist.get_live_session_by_id(project_id=projectId, session_id=sessionId)
|
||||
if data is None:
|
||||
data = sessions.get_by_id2_pg(project_id=projectId, session_id=sessionId, full_data=True,
|
||||
user_id=context.user_id, include_fav_viewed=True, group_metadata=True, live=False,
|
||||
context=context)
|
||||
include_fav_viewed=True, group_metadata=True, live=False, context=context)
|
||||
if data is None:
|
||||
return {"errors": ["session not found"]}
|
||||
if data.get("inDB"):
|
||||
|
|
@ -344,8 +343,8 @@ def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema =
|
|||
def add_remove_favorite_session2(projectId: int, sessionId: int,
|
||||
context: schemas_ee.CurrentContext = Depends(OR_context)):
|
||||
return {
|
||||
"data": sessions_favorite.favorite_session(project_id=projectId, user_id=context.user_id,
|
||||
session_id=sessionId, context=context)}
|
||||
"data": sessions_favorite.favorite_session(tenant_id=context.tenant_id, project_id=projectId,
|
||||
user_id=context.user_id, session_id=sessionId, context=context)}
|
||||
|
||||
|
||||
@app.get('/{projectId}/sessions/{sessionId}/assign', tags=["sessions"],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue