refactor(chalice): cleaned code (#1699)

This commit is contained in:
Kraiem Taha Yassine 2023-11-24 11:19:48 +01:00 committed by Taha Yassine Kraiem
parent 0a9d0e63ac
commit 83f2b0c12c
10 changed files with 126 additions and 130 deletions

View file

@ -1,7 +1,7 @@
from typing import Union, Optional from typing import Union
from decouple import config from decouple import config
from fastapi import Depends, Body, Query from fastapi import Depends, Body
import schemas import schemas
from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assignments, projects, \ from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assignments, projects, \
@ -13,8 +13,8 @@ from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assig
custom_metrics, saved_search, integrations_global custom_metrics, saved_search, integrations_global
from chalicelib.core.collaboration_msteams import MSTeams from chalicelib.core.collaboration_msteams import MSTeams
from chalicelib.core.collaboration_slack import Slack from chalicelib.core.collaboration_slack import Slack
from or_dependencies import OR_context, OR_role
from chalicelib.core.usability_testing.routes import app as usability_testing_routes from chalicelib.core.usability_testing.routes import app as usability_testing_routes
from or_dependencies import OR_context, OR_role
from routers.base import get_routers from routers.base import get_routers
public_app, app, app_apikey = get_routers() public_app, app, app_apikey = get_routers()
@ -63,7 +63,7 @@ def get_integrations_status(projectId: int, context: schemas.CurrentContext = De
@app.post('/{projectId}/integrations/{integration}/notify/{webhookId}/{source}/{sourceId}', tags=["integrations"]) @app.post('/{projectId}/integrations/{integration}/notify/{webhookId}/{source}/{sourceId}', tags=["integrations"])
def integration_notify(projectId: int, integration: str, webhookId: int, source: str, sourceId: str, def integration_notify(projectId: int, integration: str, webhookId: int, source: str, sourceId: str,
data: schemas.IntegrationNotificationSchema = Body(...), data: schemas.IntegrationNotificationSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
comment = None comment = None
if data.comment: if data.comment:
@ -97,7 +97,7 @@ def get_sentry(projectId: int, context: schemas.CurrentContext = Depends(OR_cont
@app.post('/{projectId}/integrations/sentry', tags=["integrations"]) @app.post('/{projectId}/integrations/sentry', tags=["integrations"])
def add_edit_sentry(projectId: int, data: schemas.IntegrationSentrySchema = Body(...), def add_edit_sentry(projectId: int, data: schemas.IntegrationSentrySchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_sentry.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_sentry.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -123,7 +123,7 @@ def get_datadog(projectId: int, context: schemas.CurrentContext = Depends(OR_con
@app.post('/{projectId}/integrations/datadog', tags=["integrations"]) @app.post('/{projectId}/integrations/datadog', tags=["integrations"])
def add_edit_datadog(projectId: int, data: schemas.IntegrationDatadogSchema = Body(...), def add_edit_datadog(projectId: int, data: schemas.IntegrationDatadogSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_datadog.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_datadog.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -144,7 +144,7 @@ def get_stackdriver(projectId: int, context: schemas.CurrentContext = Depends(OR
@app.post('/{projectId}/integrations/stackdriver', tags=["integrations"]) @app.post('/{projectId}/integrations/stackdriver', tags=["integrations"])
def add_edit_stackdriver(projectId: int, data: schemas.IntegartionStackdriverSchema = Body(...), def add_edit_stackdriver(projectId: int, data: schemas.IntegartionStackdriverSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_stackdriver.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_stackdriver.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -165,7 +165,7 @@ def get_newrelic(projectId: int, context: schemas.CurrentContext = Depends(OR_co
@app.post('/{projectId}/integrations/newrelic', tags=["integrations"]) @app.post('/{projectId}/integrations/newrelic', tags=["integrations"])
def add_edit_newrelic(projectId: int, data: schemas.IntegrationNewrelicSchema = Body(...), def add_edit_newrelic(projectId: int, data: schemas.IntegrationNewrelicSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_newrelic.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_newrelic.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -186,7 +186,7 @@ def get_rollbar(projectId: int, context: schemas.CurrentContext = Depends(OR_con
@app.post('/{projectId}/integrations/rollbar', tags=["integrations"]) @app.post('/{projectId}/integrations/rollbar', tags=["integrations"])
def add_edit_rollbar(projectId: int, data: schemas.IntegrationRollbarSchema = Body(...), def add_edit_rollbar(projectId: int, data: schemas.IntegrationRollbarSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_rollbar.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_rollbar.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -197,7 +197,7 @@ def delete_datadog(projectId: int, _=Body(None), context: schemas.CurrentContext
@app.post('/integrations/bugsnag/list_projects', tags=["integrations"]) @app.post('/integrations/bugsnag/list_projects', tags=["integrations"])
def list_projects_bugsnag(data: schemas.IntegrationBugsnagBasicSchema = Body(...), def list_projects_bugsnag(data: schemas.IntegrationBugsnagBasicSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_bugsnag.list_projects(auth_token=data.authorization_token)} return {"data": log_tool_bugsnag.list_projects(auth_token=data.authorization_token)}
@ -213,7 +213,7 @@ def get_bugsnag(projectId: int, context: schemas.CurrentContext = Depends(OR_con
@app.post('/{projectId}/integrations/bugsnag', tags=["integrations"]) @app.post('/{projectId}/integrations/bugsnag', tags=["integrations"])
def add_edit_bugsnag(projectId: int, data: schemas.IntegrationBugsnagSchema = Body(...), def add_edit_bugsnag(projectId: int, data: schemas.IntegrationBugsnagSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_bugsnag.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_bugsnag.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -224,7 +224,7 @@ def delete_bugsnag(projectId: int, _=Body(None), context: schemas.CurrentContext
@app.post('/integrations/cloudwatch/list_groups', tags=["integrations"]) @app.post('/integrations/cloudwatch/list_groups', tags=["integrations"])
def list_groups_cloudwatch(data: schemas.IntegrationCloudwatchBasicSchema = Body(...), def list_groups_cloudwatch(data: schemas.IntegrationCloudwatchBasicSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_cloudwatch.list_log_groups(aws_access_key_id=data.awsAccessKeyId, return {"data": log_tool_cloudwatch.list_log_groups(aws_access_key_id=data.awsAccessKeyId,
aws_secret_access_key=data.awsSecretAccessKey, aws_secret_access_key=data.awsSecretAccessKey,
@ -242,7 +242,7 @@ def get_cloudwatch(projectId: int, context: schemas.CurrentContext = Depends(OR_
@app.post('/{projectId}/integrations/cloudwatch', tags=["integrations"]) @app.post('/{projectId}/integrations/cloudwatch', tags=["integrations"])
def add_edit_cloudwatch(projectId: int, data: schemas.IntegrationCloudwatchSchema = Body(...), def add_edit_cloudwatch(projectId: int, data: schemas.IntegrationCloudwatchSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_cloudwatch.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_cloudwatch.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -263,13 +263,13 @@ def get_elasticsearch(projectId: int, context: schemas.CurrentContext = Depends(
@app.post('/integrations/elasticsearch/test', tags=["integrations"]) @app.post('/integrations/elasticsearch/test', tags=["integrations"])
def test_elasticsearch_connection(data: schemas.IntegrationElasticsearchTestSchema = Body(...), def test_elasticsearch_connection(data: schemas.IntegrationElasticsearchTestSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_elasticsearch.ping(tenant_id=context.tenant_id, data=data)} return {"data": log_tool_elasticsearch.ping(tenant_id=context.tenant_id, data=data)}
@app.post('/{projectId}/integrations/elasticsearch', tags=["integrations"]) @app.post('/{projectId}/integrations/elasticsearch', tags=["integrations"])
def add_edit_elasticsearch(projectId: int, data: schemas.IntegrationElasticsearchSchema = Body(...), def add_edit_elasticsearch(projectId: int, data: schemas.IntegrationElasticsearchSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return { return {
"data": log_tool_elasticsearch.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} "data": log_tool_elasticsearch.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -291,7 +291,7 @@ def get_sumologic(projectId: int, context: schemas.CurrentContext = Depends(OR_c
@app.post('/{projectId}/integrations/sumologic', tags=["integrations"]) @app.post('/{projectId}/integrations/sumologic', tags=["integrations"])
def add_edit_sumologic(projectId: int, data: schemas.IntegrationSumologicSchema = Body(...), def add_edit_sumologic(projectId: int, data: schemas.IntegrationSumologicSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": log_tool_sumologic.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)} return {"data": log_tool_sumologic.add_edit(tenant_id=context.tenant_id, project_id=projectId, data=data)}
@ -331,7 +331,7 @@ def get_integration_status_github(context: schemas.CurrentContext = Depends(OR_c
@app.post('/integrations/jira', tags=["integrations"]) @app.post('/integrations/jira', tags=["integrations"])
def add_edit_jira_cloud(data: schemas.IssueTrackingJiraSchema = Body(...), def add_edit_jira_cloud(data: schemas.IssueTrackingJiraSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if not data.url.endswith('atlassian.net'): if not data.url.endswith('atlassian.net'):
return {"errors": ["url must be a valid JIRA URL (example.atlassian.net)"]} return {"errors": ["url must be a valid JIRA URL (example.atlassian.net)"]}
@ -344,7 +344,7 @@ def add_edit_jira_cloud(data: schemas.IssueTrackingJiraSchema = Body(...),
@app.post('/integrations/github', tags=["integrations"]) @app.post('/integrations/github', tags=["integrations"])
def add_edit_github(data: schemas.IssueTrackingGithubSchema = Body(...), def add_edit_github(data: schemas.IssueTrackingGithubSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
error, integration = integrations_manager.get_integration(tool=integration_github.PROVIDER, error, integration = integrations_manager.get_integration(tool=integration_github.PROVIDER,
tenant_id=context.tenant_id, tenant_id=context.tenant_id,
@ -419,7 +419,7 @@ def get_all_assignments(projectId: int, context: schemas.CurrentContext = Depend
@app.post('/{projectId}/sessions/{sessionId}/assign/projects/{integrationProjectId}', tags=["assignment"]) @app.post('/{projectId}/sessions/{sessionId}/assign/projects/{integrationProjectId}', tags=["assignment"])
def create_issue_assignment(projectId: int, sessionId: int, integrationProjectId, def create_issue_assignment(projectId: int, sessionId: int, integrationProjectId,
data: schemas.AssignmentSchema = Body(...), data: schemas.AssignmentSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions_assignments.create_new_assignment(tenant_id=context.tenant_id, project_id=projectId, data = sessions_assignments.create_new_assignment(tenant_id=context.tenant_id, project_id=projectId,
session_id=sessionId, session_id=sessionId,
@ -440,7 +440,7 @@ def get_gdpr(projectId: int, context: schemas.CurrentContext = Depends(OR_contex
@app.post('/{projectId}/gdpr', tags=["projects", "gdpr"]) @app.post('/{projectId}/gdpr', tags=["projects", "gdpr"])
def edit_gdpr(projectId: int, data: schemas.GdprSchema = Body(...), def edit_gdpr(projectId: int, data: schemas.GdprSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
result = projects.edit_gdpr(project_id=projectId, gdpr=data) result = projects.edit_gdpr(project_id=projectId, gdpr=data)
if "errors" in result: if "errors" in result:
@ -449,7 +449,7 @@ def edit_gdpr(projectId: int, data: schemas.GdprSchema = Body(...),
@public_app.post('/password/reset-link', tags=["reset password"]) @public_app.post('/password/reset-link', tags=["reset password"])
def reset_password_handler(data: schemas.ForgetPasswordPayloadSchema = Body(...)): def reset_password_handler(data: schemas.ForgetPasswordPayloadSchema):
if len(data.email) < 5: if len(data.email) < 5:
return {"errors": ["please provide a valid email address"]} return {"errors": ["please provide a valid email address"]}
return reset_password.reset(data=data) return reset_password.reset(data=data)
@ -461,19 +461,19 @@ def get_metadata(projectId: int, context: schemas.CurrentContext = Depends(OR_co
# @app.post('/{projectId}/metadata/list', tags=["metadata"]) # @app.post('/{projectId}/metadata/list', tags=["metadata"])
# def add_edit_delete_metadata(projectId: int, data: schemas.MetadataListSchema = Body(...), # def add_edit_delete_metadata(projectId: int, data: schemas.MetadataListSchema ,
# context: schemas.CurrentContext = Depends(OR_context)): # context: schemas.CurrentContext = Depends(OR_context)):
# return metadata.add_edit_delete(tenant_id=context.tenant_id, project_id=projectId, new_metas=data.list) # return metadata.add_edit_delete(tenant_id=context.tenant_id, project_id=projectId, new_metas=data.list)
@app.post('/{projectId}/metadata', tags=["metadata"]) @app.post('/{projectId}/metadata', tags=["metadata"])
def add_metadata(projectId: int, data: schemas.MetadataSchema = Body(...), def add_metadata(projectId: int, data: schemas.MetadataSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return metadata.add(tenant_id=context.tenant_id, project_id=projectId, new_name=data.key) return metadata.add(tenant_id=context.tenant_id, project_id=projectId, new_name=data.key)
@app.post('/{projectId}/metadata/{index}', tags=["metadata"]) @app.post('/{projectId}/metadata/{index}', tags=["metadata"])
def edit_metadata(projectId: int, index: int, data: schemas.MetadataSchema = Body(...), def edit_metadata(projectId: int, index: int, data: schemas.MetadataSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return metadata.edit(tenant_id=context.tenant_id, project_id=projectId, index=index, return metadata.edit(tenant_id=context.tenant_id, project_id=projectId, index=index,
new_name=data.key) new_name=data.key)
@ -507,7 +507,7 @@ def get_capture_status(projectId: int, context: schemas.CurrentContext = Depends
@app.post('/{projectId}/sample_rate', tags=["projects"]) @app.post('/{projectId}/sample_rate', tags=["projects"])
def update_capture_status(projectId: int, data: schemas.SampleRateSchema = Body(...), def update_capture_status(projectId: int, data: schemas.SampleRateSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": projects.update_capture_status(project_id=projectId, changes=data)} return {"data": projects.update_capture_status(project_id=projectId, changes=data)}
@ -528,7 +528,7 @@ def errors_merge(context: schemas.CurrentContext = Depends(OR_context)):
@app.post('/{projectId}/alerts', tags=["alerts"]) @app.post('/{projectId}/alerts', tags=["alerts"])
def create_alert(projectId: int, data: schemas.AlertSchema = Body(...), def create_alert(projectId: int, data: schemas.AlertSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return alerts.create(project_id=projectId, data=data) return alerts.create(project_id=projectId, data=data)
@ -550,7 +550,7 @@ def get_alert(projectId: int, alertId: int, context: schemas.CurrentContext = De
@app.post('/{projectId}/alerts/{alertId}', tags=["alerts"]) @app.post('/{projectId}/alerts/{alertId}', tags=["alerts"])
def update_alert(projectId: int, alertId: int, data: schemas.AlertSchema = Body(...), def update_alert(projectId: int, alertId: int, data: schemas.AlertSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return alerts.update(id=alertId, data=data) return alerts.update(id=alertId, data=data)
@ -563,7 +563,7 @@ def delete_alert(projectId: int, alertId: int, _=Body(None),
@app_apikey.put('/{projectKey}/sourcemaps/', tags=["sourcemaps"]) @app_apikey.put('/{projectKey}/sourcemaps/', tags=["sourcemaps"])
@app_apikey.put('/{projectKey}/sourcemaps', tags=["sourcemaps"]) @app_apikey.put('/{projectKey}/sourcemaps', tags=["sourcemaps"])
def sign_sourcemap_for_upload(projectKey: str, data: schemas.SourcemapUploadPayloadSchema = Body(...), def sign_sourcemap_for_upload(projectKey: str, data: schemas.SourcemapUploadPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": sourcemaps.presign_upload_urls(project_id=context.project.project_id, urls=data.urls)} return {"data": sourcemaps.presign_upload_urls(project_id=context.project.project_id, urls=data.urls)}
@ -574,7 +574,7 @@ def get_weekly_report_config(context: schemas.CurrentContext = Depends(OR_contex
@app.post('/config/weekly_report', tags=["weekly report config"]) @app.post('/config/weekly_report', tags=["weekly report config"])
def edit_weekly_report_config(data: schemas.WeeklyReportConfigSchema = Body(...), def edit_weekly_report_config(data: schemas.WeeklyReportConfigSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": weekly_report.edit_config(user_id=context.user_id, weekly_report=data.weekly_report)} return {"data": weekly_report.edit_config(user_id=context.user_id, weekly_report=data.weekly_report)}
@ -596,20 +596,20 @@ def get_sessions_live(projectId: int, userId: str = None, context: schemas.Curre
@app.post('/{projectId}/assist/sessions', tags=["assist"]) @app.post('/{projectId}/assist/sessions', tags=["assist"])
def sessions_live(projectId: int, data: schemas.LiveSessionsSearchPayloadSchema = Body(...), def sessions_live(projectId: int, data: schemas.LiveSessionsSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = assist.get_live_sessions_ws(projectId, body=data) data = assist.get_live_sessions_ws(projectId, body=data)
return {'data': data} return {'data': data}
@app.post('/{projectId}/mobile/{sessionId}/urls', tags=['mobile']) @app.post('/{projectId}/mobile/{sessionId}/urls', tags=['mobile'])
def mobile_signe(projectId: int, sessionId: int, data: schemas.MobileSignPayloadSchema = Body(...), def mobile_signe(projectId: int, sessionId: int, data: schemas.MobileSignPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": mobile.sign_keys(project_id=projectId, session_id=sessionId, keys=data.keys)} return {"data": mobile.sign_keys(project_id=projectId, session_id=sessionId, keys=data.keys)}
@app.post('/projects', tags=['projects'], dependencies=[OR_role("owner", "admin")]) @app.post('/projects', tags=['projects'], dependencies=[OR_role("owner", "admin")])
def create_project(data: schemas.CreateProjectSchema = Body(...), def create_project(data: schemas.CreateProjectSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return projects.create(tenant_id=context.tenant_id, user_id=context.user_id, data=data) return projects.create(tenant_id=context.tenant_id, user_id=context.user_id, data=data)
@ -624,7 +624,7 @@ def get_project(projectId: int, context: schemas.CurrentContext = Depends(OR_con
@app.put('/projects/{projectId}', tags=['projects'], dependencies=[OR_role("owner", "admin")]) @app.put('/projects/{projectId}', tags=['projects'], dependencies=[OR_role("owner", "admin")])
def edit_project(projectId: int, data: schemas.CreateProjectSchema = Body(...), def edit_project(projectId: int, data: schemas.CreateProjectSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return projects.edit(tenant_id=context.tenant_id, user_id=context.user_id, data=data, project_id=projectId) return projects.edit(tenant_id=context.tenant_id, user_id=context.user_id, data=data, project_id=projectId)
@ -642,8 +642,7 @@ def generate_new_tenant_token(context: schemas.CurrentContext = Depends(OR_conte
@app.post('/users/modules', tags=['users']) @app.post('/users/modules', tags=['users'])
def update_user_module(context: schemas.CurrentContext = Depends(OR_context), def update_user_module(data: schemas.ModuleStatus, context: schemas.CurrentContext = Depends(OR_context)):
data: schemas.ModuleStatus = Body(...)):
return {"data": users.update_user_module(context.user_id, data)} return {"data": users.update_user_module(context.user_id, data)}
@ -715,7 +714,7 @@ def delete_slack_integration(webhookId: int, _=Body(None), context: schemas.Curr
@app.put('/webhooks', tags=["webhooks"]) @app.put('/webhooks', tags=["webhooks"])
def add_edit_webhook(data: schemas.WebhookSchema = Body(...), def add_edit_webhook(data: schemas.WebhookSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": webhook.add_edit(tenant_id=context.tenant_id, data=data, replace_none=True)} return {"data": webhook.add_edit(tenant_id=context.tenant_id, data=data, replace_none=True)}
@ -751,7 +750,7 @@ def generate_new_user_token(context: schemas.CurrentContext = Depends(OR_context
@app.post('/account/password', tags=["account"]) @app.post('/account/password', tags=["account"])
def change_client_password(data: schemas.EditUserPasswordSchema = Body(...), def change_client_password(data: schemas.EditUserPasswordSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return users.change_password(email=context.email, old_password=data.old_password.get_secret_value(), return users.change_password(email=context.email, old_password=data.old_password.get_secret_value(),
new_password=data.new_password.get_secret_value(), tenant_id=context.tenant_id, new_password=data.new_password.get_secret_value(), tenant_id=context.tenant_id,
@ -759,7 +758,7 @@ def change_client_password(data: schemas.EditUserPasswordSchema = Body(...),
@app.post('/{projectId}/saved_search', tags=["savedSearch"]) @app.post('/{projectId}/saved_search', tags=["savedSearch"])
def add_saved_search(projectId: int, data: schemas.SavedSearchSchema = Body(...), def add_saved_search(projectId: int, data: schemas.SavedSearchSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return saved_search.create(project_id=projectId, user_id=context.user_id, data=data) return saved_search.create(project_id=projectId, user_id=context.user_id, data=data)
@ -775,7 +774,7 @@ def get_saved_search(projectId: int, search_id: int, context: schemas.CurrentCon
@app.post('/{projectId}/saved_search/{search_id}', tags=["savedSearch"]) @app.post('/{projectId}/saved_search/{search_id}', tags=["savedSearch"])
def update_saved_search(projectId: int, search_id: int, data: schemas.SavedSearchSchema = Body(...), def update_saved_search(projectId: int, search_id: int, data: schemas.SavedSearchSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": saved_search.update(user_id=context.user_id, search_id=search_id, data=data, project_id=projectId)} return {"data": saved_search.update(user_id=context.user_id, search_id=search_id, data=data, project_id=projectId)}
@ -814,7 +813,7 @@ def add_msteams_integration(data: schemas.AddCollaborationSchema,
@app.post('/integrations/msteams/{webhookId}', tags=['integrations']) @app.post('/integrations/msteams/{webhookId}', tags=['integrations'])
def edit_msteams_integration(webhookId: int, data: schemas.EditCollaborationSchema = Body(...), def edit_msteams_integration(webhookId: int, data: schemas.EditCollaborationSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if len(data.url.unicode_string()) > 0: if len(data.url.unicode_string()) > 0:
old = MSTeams.get_integration(tenant_id=context.tenant_id, integration_id=webhookId) old = MSTeams.get_integration(tenant_id=context.tenant_id, integration_id=webhookId)

View file

@ -33,7 +33,7 @@ def get_all_signup():
if not tenants.tenants_exists(use_pool=False): if not tenants.tenants_exists(use_pool=False):
@public_app.post('/signup', tags=['signup']) @public_app.post('/signup', tags=['signup'])
@public_app.put('/signup', tags=['signup']) @public_app.put('/signup', tags=['signup'])
def signup_handler(data: schemas.UserSignupSchema = Body(...)): def signup_handler(data: schemas.UserSignupSchema):
content = signup.create_tenant(data) content = signup.create_tenant(data)
if "errors" in content: if "errors" in content:
return content return content
@ -46,7 +46,7 @@ if not tenants.tenants_exists(use_pool=False):
@public_app.post('/login', tags=["authentication"]) @public_app.post('/login', tags=["authentication"])
def login_user(response: JSONResponse, data: schemas.UserLoginSchema = Body(...)): def login_user(response: JSONResponse, data: schemas.UserLoginSchema):
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response): if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
@ -115,7 +115,7 @@ def get_account(context: schemas.CurrentContext = Depends(OR_context)):
@app.post('/account', tags=["account"]) @app.post('/account', tags=["account"])
def edit_account(data: schemas.EditAccountSchema = Body(...), def edit_account(data: schemas.EditAccountSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return users.edit_account(tenant_id=context.tenant_id, user_id=context.user_id, changes=data) return users.edit_account(tenant_id=context.tenant_id, user_id=context.user_id, changes=data)
@ -133,7 +133,7 @@ def add_slack_integration(data: schemas.AddCollaborationSchema,
@app.post('/integrations/slack/{integrationId}', tags=['integrations']) @app.post('/integrations/slack/{integrationId}', tags=['integrations'])
def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSchema = Body(...), def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if len(data.url) > 0: if len(data.url) > 0:
old = Slack.get_integration(tenant_id=context.tenant_id, integration_id=integrationId) old = Slack.get_integration(tenant_id=context.tenant_id, integration_id=integrationId)
@ -150,7 +150,7 @@ def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSc
@app.post('/client/members', tags=["client"], dependencies=[OR_role("owner", "admin")]) @app.post('/client/members', tags=["client"], dependencies=[OR_role("owner", "admin")])
def add_member(background_tasks: BackgroundTasks, data: schemas.CreateMemberSchema = Body(...), def add_member(background_tasks: BackgroundTasks, data: schemas.CreateMemberSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return users.create_member(tenant_id=context.tenant_id, user_id=context.user_id, data=data, return users.create_member(tenant_id=context.tenant_id, user_id=context.user_id, data=data,
background_tasks=background_tasks) background_tasks=background_tasks)
@ -174,7 +174,7 @@ def process_invitation_link(token: str):
@public_app.post('/password/reset', tags=["users"]) @public_app.post('/password/reset', tags=["users"])
def change_password_by_invitation(data: schemas.EditPasswordByInvitationSchema = Body(...)): def change_password_by_invitation(data: schemas.EditPasswordByInvitationSchema):
if data is None or len(data.invitation) < 64 or len(data.passphrase) < 8: if data is None or len(data.invitation) < 64 or len(data.passphrase) < 8:
return {"errors": ["please provide a valid invitation & pass"]} return {"errors": ["please provide a valid invitation & pass"]}
user = users.get_by_invitation_token(token=data.invitation, pass_token=data.passphrase) user = users.get_by_invitation_token(token=data.invitation, pass_token=data.passphrase)
@ -233,7 +233,7 @@ def get_session(projectId: int, sessionId: Union[int, str], background_tasks: Ba
@app.post('/{projectId}/sessions/search', tags=["sessions"]) @app.post('/{projectId}/sessions/search', tags=["sessions"])
def sessions_search(projectId: int, data: schemas.SessionsSearchPayloadSchema = Body(...), def sessions_search(projectId: int, data: schemas.SessionsSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id, data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id,
platform=context.project.platform) platform=context.project.platform)
@ -241,7 +241,7 @@ def sessions_search(projectId: int, data: schemas.SessionsSearchPayloadSchema =
@app.post('/{projectId}/sessions/search/ids', tags=["sessions"]) @app.post('/{projectId}/sessions/search/ids', tags=["sessions"])
def session_ids_search(projectId: int, data: schemas.SessionsSearchPayloadSchema = Body(...), def session_ids_search(projectId: int, data: schemas.SessionsSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id, ids_only=True, data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id, ids_only=True,
platform=context.project.platform) platform=context.project.platform)
@ -392,7 +392,7 @@ def get_live_session_devtools_file(projectId: int, sessionId: Union[int, str],
@app.post('/{projectId}/heatmaps/url', tags=["heatmaps"]) @app.post('/{projectId}/heatmaps/url', tags=["heatmaps"])
def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema = Body(...), def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": heatmaps.get_by_url(project_id=projectId, data=data)} return {"data": heatmaps.get_by_url(project_id=projectId, data=data)}
@ -429,7 +429,7 @@ def assign_session(projectId: int, sessionId: int, issueId: str,
@app.post('/{projectId}/sessions/{sessionId}/assign/{issueId}/comment', tags=["sessions", "issueTracking"]) @app.post('/{projectId}/sessions/{sessionId}/assign/{issueId}/comment', tags=["sessions", "issueTracking"])
def comment_assignment(projectId: int, sessionId: int, issueId: str, def comment_assignment(projectId: int, sessionId: int, issueId: str,
data: schemas.CommentAssignmentSchema = Body(...), data: schemas.CommentAssignmentSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions_assignments.comment(tenant_id=context.tenant_id, project_id=projectId, data = sessions_assignments.comment(tenant_id=context.tenant_id, project_id=projectId,
session_id=sessionId, assignment_id=issueId, session_id=sessionId, assignment_id=issueId,
@ -442,7 +442,7 @@ def comment_assignment(projectId: int, sessionId: int, issueId: str,
@app.post('/{projectId}/sessions/{sessionId}/notes', tags=["sessions", "notes"]) @app.post('/{projectId}/sessions/{sessionId}/notes', tags=["sessions", "notes"])
def create_note(projectId: int, sessionId: int, data: schemas.SessionNoteSchema = Body(...), def create_note(projectId: int, sessionId: int, data: schemas.SessionNoteSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if not sessions.session_exists(project_id=projectId, session_id=sessionId): if not sessions.session_exists(project_id=projectId, session_id=sessionId):
return {"errors": ["Session not found"]} return {"errors": ["Session not found"]}
@ -467,7 +467,7 @@ def get_session_notes(projectId: int, sessionId: int, context: schemas.CurrentCo
@app.post('/{projectId}/notes/{noteId}', tags=["sessions", "notes"]) @app.post('/{projectId}/notes/{noteId}', tags=["sessions", "notes"])
def edit_note(projectId: int, noteId: int, data: schemas.SessionUpdateNoteSchema = Body(...), def edit_note(projectId: int, noteId: int, data: schemas.SessionUpdateNoteSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions_notes.edit(tenant_id=context.tenant_id, project_id=projectId, user_id=context.user_id, data = sessions_notes.edit(tenant_id=context.tenant_id, project_id=projectId, user_id=context.user_id,
note_id=noteId, data=data) note_id=noteId, data=data)
@ -500,7 +500,7 @@ def share_note_to_msteams(projectId: int, noteId: int, webhookId: int,
@app.post('/{projectId}/notes', tags=["sessions", "notes"]) @app.post('/{projectId}/notes', tags=["sessions", "notes"])
def get_all_notes(projectId: int, data: schemas.SearchNoteSchema = Body(...), def get_all_notes(projectId: int, data: schemas.SearchNoteSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions_notes.get_all_notes_by_project_id(tenant_id=context.tenant_id, project_id=projectId, data = sessions_notes.get_all_notes_by_project_id(tenant_id=context.tenant_id, project_id=projectId,
user_id=context.user_id, data=data) user_id=context.user_id, data=data)
@ -510,14 +510,14 @@ def get_all_notes(projectId: int, data: schemas.SearchNoteSchema = Body(...),
@app.post('/{projectId}/click_maps/search', tags=["click maps"]) @app.post('/{projectId}/click_maps/search', tags=["click maps"])
def click_map_search(projectId: int, data: schemas.ClickMapSessionsSearch = Body(...), def click_map_search(projectId: int, data: schemas.ClickMapSessionsSearch,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": click_maps.search_short_session(user_id=context.user_id, data=data, project_id=projectId)} return {"data": click_maps.search_short_session(user_id=context.user_id, data=data, project_id=projectId)}
@app.post('/{project_id}/feature-flags/search', tags=["feature flags"]) @app.post('/{project_id}/feature-flags/search', tags=["feature flags"])
def search_feature_flags(project_id: int, def search_feature_flags(project_id: int,
data: schemas.SearchFlagsSchema = Body(...), data: schemas.SearchFlagsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return feature_flags.search_feature_flags(project_id=project_id, user_id=context.user_id, data=data) return feature_flags.search_feature_flags(project_id=project_id, user_id=context.user_id, data=data)
@ -528,13 +528,13 @@ def get_feature_flag(project_id: int, feature_flag_id: int):
@app.post('/{project_id}/feature-flags', tags=["feature flags"]) @app.post('/{project_id}/feature-flags', tags=["feature flags"])
def add_feature_flag(project_id: int, data: schemas.FeatureFlagSchema = Body(...), def add_feature_flag(project_id: int, data: schemas.FeatureFlagSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return feature_flags.create_feature_flag(project_id=project_id, user_id=context.user_id, feature_flag_data=data) return feature_flags.create_feature_flag(project_id=project_id, user_id=context.user_id, feature_flag_data=data)
@app.put('/{project_id}/feature-flags/{feature_flag_id}', tags=["feature flags"]) @app.put('/{project_id}/feature-flags/{feature_flag_id}', tags=["feature flags"])
def update_feature_flag(project_id: int, feature_flag_id: int, data: schemas.FeatureFlagSchema = Body(...), def update_feature_flag(project_id: int, feature_flag_id: int, data: schemas.FeatureFlagSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return feature_flags.update_feature_flag(project_id=project_id, feature_flag_id=feature_flag_id, return feature_flags.update_feature_flag(project_id=project_id, feature_flag_id=feature_flag_id,
user_id=context.user_id, feature_flag=data) user_id=context.user_id, feature_flag=data)
@ -547,6 +547,6 @@ def delete_feature_flag(project_id: int, feature_flag_id: int, _=Body(None)):
@app.post('/{project_id}/feature-flags/{feature_flag_id}/status', tags=["feature flags"]) @app.post('/{project_id}/feature-flags/{feature_flag_id}/status', tags=["feature flags"])
def update_feature_flag_status(project_id: int, feature_flag_id: int, def update_feature_flag_status(project_id: int, feature_flag_id: int,
data: schemas.FeatureFlagStatus = Body(...)): data: schemas.FeatureFlagStatus):
return {"data": feature_flags.update_feature_flag_status(project_id=project_id, feature_flag_id=feature_flag_id, return {"data": feature_flags.update_feature_flag_status(project_id=project_id, feature_flag_id=feature_flag_id,
is_active=data.is_active)} is_active=data.is_active)}

View file

@ -1,7 +1,3 @@
from fastapi import Body
import schemas
from chalicelib.core import product_analytics
from routers.base import get_routers from routers.base import get_routers
public_app, app, app_apikey = get_routers() public_app, app, app_apikey = get_routers()

View file

@ -3,7 +3,7 @@ from typing import Union
from fastapi import Body, Depends, Request from fastapi import Body, Depends, Request
import schemas import schemas
from chalicelib.core import dashboards, custom_metrics, funnels from chalicelib.core import dashboards, custom_metrics
from or_dependencies import OR_context from or_dependencies import OR_context
from routers.base import get_routers from routers.base import get_routers
@ -11,7 +11,7 @@ public_app, app, app_apikey = get_routers()
@app.post('/{projectId}/dashboards', tags=["dashboard"]) @app.post('/{projectId}/dashboards', tags=["dashboard"])
def create_dashboards(projectId: int, data: schemas.CreateDashboardSchema = Body(...), def create_dashboards(projectId: int, data: schemas.CreateDashboardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return dashboards.create_dashboard(project_id=projectId, user_id=context.user_id, data=data) return dashboards.create_dashboard(project_id=projectId, user_id=context.user_id, data=data)
@ -30,7 +30,7 @@ def get_dashboard(projectId: int, dashboardId: int, context: schemas.CurrentCont
@app.put('/{projectId}/dashboards/{dashboardId}', tags=["dashboard"]) @app.put('/{projectId}/dashboards/{dashboardId}', tags=["dashboard"])
def update_dashboard(projectId: int, dashboardId: int, data: schemas.EditDashboardSchema = Body(...), def update_dashboard(projectId: int, dashboardId: int, data: schemas.EditDashboardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": dashboards.update_dashboard(project_id=projectId, user_id=context.user_id, return {"data": dashboards.update_dashboard(project_id=projectId, user_id=context.user_id,
dashboard_id=dashboardId, data=data)} dashboard_id=dashboardId, data=data)}
@ -49,7 +49,7 @@ def pin_dashboard(projectId: int, dashboardId: int, context: schemas.CurrentCont
@app.post('/{projectId}/dashboards/{dashboardId}/cards', tags=["cards"]) @app.post('/{projectId}/dashboards/{dashboardId}/cards', tags=["cards"])
def add_card_to_dashboard(projectId: int, dashboardId: int, def add_card_to_dashboard(projectId: int, dashboardId: int,
data: schemas.AddWidgetToDashboardPayloadSchema = Body(...), data: schemas.AddWidgetToDashboardPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": dashboards.add_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId, return {"data": dashboards.add_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId,
data=data)} data=data)}
@ -58,7 +58,7 @@ def add_card_to_dashboard(projectId: int, dashboardId: int,
@app.post('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"]) @app.post('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"])
# @app.put('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"]) # @app.put('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"])
def create_metric_and_add_to_dashboard(projectId: int, dashboardId: int, def create_metric_and_add_to_dashboard(projectId: int, dashboardId: int,
data: schemas.CardSchema = Body(...), data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": dashboards.create_metric_add_widget(project_id=projectId, user_id=context.user_id, return {"data": dashboards.create_metric_add_widget(project_id=projectId, user_id=context.user_id,
dashboard_id=dashboardId, data=data)} dashboard_id=dashboardId, data=data)}
@ -66,7 +66,7 @@ def create_metric_and_add_to_dashboard(projectId: int, dashboardId: int,
@app.put('/{projectId}/dashboards/{dashboardId}/widgets/{widgetId}', tags=["dashboard"]) @app.put('/{projectId}/dashboards/{dashboardId}/widgets/{widgetId}', tags=["dashboard"])
def update_widget_in_dashboard(projectId: int, dashboardId: int, widgetId: int, def update_widget_in_dashboard(projectId: int, dashboardId: int, widgetId: int,
data: schemas.UpdateWidgetPayloadSchema = Body(...), data: schemas.UpdateWidgetPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return dashboards.update_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId, return dashboards.update_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId,
widget_id=widgetId, data=data) widget_id=widgetId, data=data)
@ -80,20 +80,20 @@ def remove_widget_from_dashboard(projectId: int, dashboardId: int, widgetId: int
@app.post('/{projectId}/cards/try', tags=["cards"]) @app.post('/{projectId}/cards/try', tags=["cards"])
def try_card(projectId: int, data: schemas.CardSchema = Body(...), def try_card(projectId: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": custom_metrics.get_chart(project_id=projectId, data=data, user_id=context.user_id)} return {"data": custom_metrics.get_chart(project_id=projectId, data=data, user_id=context.user_id)}
@app.post('/{projectId}/cards/try/sessions', tags=["cards"]) @app.post('/{projectId}/cards/try/sessions', tags=["cards"])
def try_card_sessions(projectId: int, data: schemas.CardSessionsSchema = Body(...), def try_card_sessions(projectId: int, data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_sessions(project_id=projectId, user_id=context.user_id, data=data) data = custom_metrics.get_sessions(project_id=projectId, user_id=context.user_id, data=data)
return {"data": data} return {"data": data}
@app.post('/{projectId}/cards/try/issues', tags=["cards"]) @app.post('/{projectId}/cards/try/issues', tags=["cards"])
def try_card_issues(projectId: int, data: schemas.CardSchema = Body(...), def try_card_issues(projectId: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": custom_metrics.get_issues(project_id=projectId, user_id=context.user_id, data=data)} return {"data": custom_metrics.get_issues(project_id=projectId, user_id=context.user_id, data=data)}
@ -104,13 +104,13 @@ def get_cards(projectId: int, context: schemas.CurrentContext = Depends(OR_conte
@app.post('/{projectId}/cards', tags=["cards"]) @app.post('/{projectId}/cards', tags=["cards"])
def create_card(projectId: int, data: schemas.CardSchema = Body(...), def create_card(projectId: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return custom_metrics.create_card(project_id=projectId, user_id=context.user_id, data=data) return custom_metrics.create_card(project_id=projectId, user_id=context.user_id, data=data)
@app.post('/{projectId}/cards/search', tags=["cards"]) @app.post('/{projectId}/cards/search', tags=["cards"])
def search_cards(projectId: int, data: schemas.SearchCardsSchema = Body(...), def search_cards(projectId: int, data: schemas.SearchCardsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": custom_metrics.search_all(project_id=projectId, user_id=context.user_id, data=data)} return {"data": custom_metrics.search_all(project_id=projectId, user_id=context.user_id, data=data)}
@ -129,7 +129,7 @@ def get_card(projectId: int, metric_id: Union[int, str], context: schemas.Curren
@app.post('/{projectId}/cards/{metric_id}/sessions', tags=["cards"]) @app.post('/{projectId}/cards/{metric_id}/sessions', tags=["cards"])
def get_card_sessions(projectId: int, metric_id: int, def get_card_sessions(projectId: int, metric_id: int,
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_sessions_by_card_id(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data = custom_metrics.get_sessions_by_card_id(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
data=data) data=data)
@ -140,7 +140,7 @@ def get_card_sessions(projectId: int, metric_id: int,
@app.post('/{projectId}/cards/{metric_id}/issues', tags=["cards"]) @app.post('/{projectId}/cards/{metric_id}/issues', tags=["cards"])
def get_card_funnel_issues(projectId: int, metric_id: Union[int, str], def get_card_funnel_issues(projectId: int, metric_id: Union[int, str],
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if metric_id.isnumeric(): if metric_id.isnumeric():
metric_id = int(metric_id) metric_id = int(metric_id)
@ -156,7 +156,7 @@ def get_card_funnel_issues(projectId: int, metric_id: Union[int, str],
@app.post('/{projectId}/cards/{metric_id}/issues/{issueId}/sessions', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}/issues/{issueId}/sessions', tags=["dashboard"])
def get_metric_funnel_issue_sessions(projectId: int, metric_id: int, issueId: str, def get_metric_funnel_issue_sessions(projectId: int, metric_id: int, issueId: str,
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_funnel_sessions_by_issue(project_id=projectId, user_id=context.user_id, data = custom_metrics.get_funnel_sessions_by_issue(project_id=projectId, user_id=context.user_id,
metric_id=metric_id, issue_id=issueId, data=data) metric_id=metric_id, issue_id=issueId, data=data)
@ -167,7 +167,7 @@ def get_metric_funnel_issue_sessions(projectId: int, metric_id: int, issueId: st
@app.post('/{projectId}/cards/{metric_id}/errors', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}/errors', tags=["dashboard"])
def get_card_errors_list(projectId: int, metric_id: int, def get_card_errors_list(projectId: int, metric_id: int,
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_errors_list(project_id=projectId, user_id=context.user_id, data = custom_metrics.get_errors_list(project_id=projectId, user_id=context.user_id,
metric_id=metric_id, data=data) metric_id=metric_id, data=data)
@ -177,7 +177,7 @@ def get_card_errors_list(projectId: int, metric_id: int,
@app.post('/{projectId}/cards/{metric_id}/chart', tags=["card"]) @app.post('/{projectId}/cards/{metric_id}/chart', tags=["card"])
def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardSessionsSchema = Body(...), def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.make_chart_from_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data = custom_metrics.make_chart_from_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
data=data) data=data)
@ -185,7 +185,7 @@ def get_card_chart(projectId: int, metric_id: int, request: Request, data: schem
@app.post('/{projectId}/cards/{metric_id}', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}', tags=["dashboard"])
def update_card(projectId: int, metric_id: int, data: schemas.CardSchema = Body(...), def update_card(projectId: int, metric_id: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.update_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data=data) data = custom_metrics.update_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data=data)
if data is None: if data is None:
@ -195,7 +195,7 @@ def update_card(projectId: int, metric_id: int, data: schemas.CardSchema = Body(
@app.post('/{projectId}/cards/{metric_id}/status', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}/status', tags=["dashboard"])
def update_card_state(projectId: int, metric_id: int, def update_card_state(projectId: int, metric_id: int,
data: schemas.UpdateCardStatusSchema = Body(...), data: schemas.UpdateCardStatusSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return { return {
"data": custom_metrics.change_state(project_id=projectId, user_id=context.user_id, metric_id=metric_id, "data": custom_metrics.change_state(project_id=projectId, user_id=context.user_id, metric_id=metric_id,

View file

@ -89,7 +89,7 @@ def get_project(projectKey: str, context: schemas.CurrentContext = Depends(OR_co
@app_apikey.post('/v1/projects', tags=["api"]) @app_apikey.post('/v1/projects', tags=["api"])
def create_project(data: schemas.CreateProjectSchema = Body(...), def create_project(data: schemas.CreateProjectSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
record = projects.create( record = projects.create(
tenant_id=context.tenant_id, tenant_id=context.tenant_id,

View file

@ -38,7 +38,7 @@ def get_all_signup():
if config("MULTI_TENANTS", cast=bool, default=False) or not tenants.tenants_exists(use_pool=False): if config("MULTI_TENANTS", cast=bool, default=False) or not tenants.tenants_exists(use_pool=False):
@public_app.post('/signup', tags=['signup']) @public_app.post('/signup', tags=['signup'])
@public_app.put('/signup', tags=['signup']) @public_app.put('/signup', tags=['signup'])
def signup_handler(data: schemas.UserSignupSchema = Body(...)): def signup_handler(data: schemas.UserSignupSchema):
content = signup.create_tenant(data) content = signup.create_tenant(data)
if "errors" in content: if "errors" in content:
return content return content
@ -51,7 +51,7 @@ if config("MULTI_TENANTS", cast=bool, default=False) or not tenants.tenants_exis
@public_app.post('/login', tags=["authentication"]) @public_app.post('/login', tags=["authentication"])
def login_user(response: JSONResponse, data: schemas.UserLoginSchema = Body(...)): def login_user(response: JSONResponse, data: schemas.UserLoginSchema):
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response): if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
@ -121,7 +121,7 @@ def get_account(context: schemas.CurrentContext = Depends(OR_context)):
@app.post('/account', tags=["account"]) @app.post('/account', tags=["account"])
def edit_account(data: schemas.EditAccountSchema = Body(...), def edit_account(data: schemas.EditAccountSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return users.edit_account(tenant_id=context.tenant_id, user_id=context.user_id, changes=data) return users.edit_account(tenant_id=context.tenant_id, user_id=context.user_id, changes=data)
@ -139,7 +139,7 @@ def add_slack_integration(data: schemas.AddCollaborationSchema,
@app.post('/integrations/slack/{integrationId}', tags=['integrations']) @app.post('/integrations/slack/{integrationId}', tags=['integrations'])
def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSchema = Body(...), def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if len(data.url) > 0: if len(data.url) > 0:
old = Slack.get_integration(tenant_id=context.tenant_id, integration_id=integrationId) old = Slack.get_integration(tenant_id=context.tenant_id, integration_id=integrationId)
@ -156,7 +156,7 @@ def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSc
@app.post('/client/members', tags=["client"], dependencies=[OR_role("owner", "admin")]) @app.post('/client/members', tags=["client"], dependencies=[OR_role("owner", "admin")])
def add_member(background_tasks: BackgroundTasks, data: schemas.CreateMemberSchema = Body(...), def add_member(background_tasks: BackgroundTasks, data: schemas.CreateMemberSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return users.create_member(tenant_id=context.tenant_id, user_id=context.user_id, data=data, return users.create_member(tenant_id=context.tenant_id, user_id=context.user_id, data=data,
background_tasks=background_tasks) background_tasks=background_tasks)
@ -182,7 +182,7 @@ async def process_invitation_link(token: str, request: Request):
@public_app.post('/password/reset', tags=["users"]) @public_app.post('/password/reset', tags=["users"])
def change_password_by_invitation(data: schemas.EditPasswordByInvitationSchema = Body(...)): def change_password_by_invitation(data: schemas.EditPasswordByInvitationSchema):
if data is None or len(data.invitation) < 64 or len(data.passphrase) < 8: if data is None or len(data.invitation) < 64 or len(data.passphrase) < 8:
return {"errors": ["please provide a valid invitation & pass"]} return {"errors": ["please provide a valid invitation & pass"]}
user = users.get_by_invitation_token(token=data.invitation, pass_token=data.passphrase) user = users.get_by_invitation_token(token=data.invitation, pass_token=data.passphrase)
@ -249,7 +249,7 @@ def get_session(projectId: int, sessionId: Union[int, str], background_tasks: Ba
@app.post('/{projectId}/sessions/search', tags=["sessions"], @app.post('/{projectId}/sessions/search', tags=["sessions"],
dependencies=[OR_scope(Permissions.session_replay)]) dependencies=[OR_scope(Permissions.session_replay)])
def sessions_search(projectId: int, data: schemas.SessionsSearchPayloadSchema = Body(...), def sessions_search(projectId: int, data: schemas.SessionsSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id, data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id,
platform=context.project.platform) platform=context.project.platform)
@ -258,7 +258,7 @@ def sessions_search(projectId: int, data: schemas.SessionsSearchPayloadSchema =
@app.post('/{projectId}/sessions/search/ids', tags=["sessions"], @app.post('/{projectId}/sessions/search/ids', tags=["sessions"],
dependencies=[OR_scope(Permissions.session_replay)]) dependencies=[OR_scope(Permissions.session_replay)])
def session_ids_search(projectId: int, data: schemas.SessionsSearchPayloadSchema = Body(...), def session_ids_search(projectId: int, data: schemas.SessionsSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id, ids_only=True, data = sessions.search_sessions(data=data, project_id=projectId, user_id=context.user_id, ids_only=True,
platform=context.project.platform) platform=context.project.platform)
@ -418,7 +418,7 @@ def get_live_session_devtools_file(projectId: int, sessionId: Union[int, str],
@app.post('/{projectId}/heatmaps/url', tags=["heatmaps"], dependencies=[OR_scope(Permissions.session_replay)]) @app.post('/{projectId}/heatmaps/url', tags=["heatmaps"], dependencies=[OR_scope(Permissions.session_replay)])
def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema = Body(...), def get_heatmaps_by_url(projectId: int, data: schemas.GetHeatmapPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": heatmaps.get_by_url(project_id=projectId, data=data)} return {"data": heatmaps.get_by_url(project_id=projectId, data=data)}
@ -459,7 +459,7 @@ def assign_session(projectId: int, sessionId: int, issueId: str,
@app.post('/{projectId}/sessions/{sessionId}/assign/{issueId}/comment', tags=["sessions", "issueTracking"], @app.post('/{projectId}/sessions/{sessionId}/assign/{issueId}/comment', tags=["sessions", "issueTracking"],
dependencies=[OR_scope(Permissions.session_replay)]) dependencies=[OR_scope(Permissions.session_replay)])
def comment_assignment(projectId: int, sessionId: int, issueId: str, def comment_assignment(projectId: int, sessionId: int, issueId: str,
data: schemas.CommentAssignmentSchema = Body(...), data: schemas.CommentAssignmentSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions_assignments.comment(tenant_id=context.tenant_id, project_id=projectId, data = sessions_assignments.comment(tenant_id=context.tenant_id, project_id=projectId,
session_id=sessionId, assignment_id=issueId, session_id=sessionId, assignment_id=issueId,
@ -473,7 +473,7 @@ def comment_assignment(projectId: int, sessionId: int, issueId: str,
@app.post('/{projectId}/sessions/{sessionId}/notes', tags=["sessions", "notes"], @app.post('/{projectId}/sessions/{sessionId}/notes', tags=["sessions", "notes"],
dependencies=[OR_scope(Permissions.session_replay)]) dependencies=[OR_scope(Permissions.session_replay)])
def create_note(projectId: int, sessionId: int, data: schemas.SessionNoteSchema = Body(...), def create_note(projectId: int, sessionId: int, data: schemas.SessionNoteSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if not sessions.session_exists(project_id=projectId, session_id=sessionId): if not sessions.session_exists(project_id=projectId, session_id=sessionId):
return {"errors": ["Session not found"]} return {"errors": ["Session not found"]}
@ -500,7 +500,7 @@ def get_session_notes(projectId: int, sessionId: int, context: schemas.CurrentCo
@app.post('/{projectId}/notes/{noteId}', tags=["sessions", "notes"], @app.post('/{projectId}/notes/{noteId}', tags=["sessions", "notes"],
dependencies=[OR_scope(Permissions.session_replay)]) dependencies=[OR_scope(Permissions.session_replay)])
def edit_note(projectId: int, noteId: int, data: schemas.SessionUpdateNoteSchema = Body(...), def edit_note(projectId: int, noteId: int, data: schemas.SessionUpdateNoteSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions_notes.edit(tenant_id=context.tenant_id, project_id=projectId, user_id=context.user_id, data = sessions_notes.edit(tenant_id=context.tenant_id, project_id=projectId, user_id=context.user_id,
note_id=noteId, data=data) note_id=noteId, data=data)
@ -535,7 +535,7 @@ def share_note_to_msteams(projectId: int, noteId: int, webhookId: int,
@app.post('/{projectId}/notes', tags=["sessions", "notes"], dependencies=[OR_scope(Permissions.session_replay)]) @app.post('/{projectId}/notes', tags=["sessions", "notes"], dependencies=[OR_scope(Permissions.session_replay)])
def get_all_notes(projectId: int, data: schemas.SearchNoteSchema = Body(...), def get_all_notes(projectId: int, data: schemas.SearchNoteSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = sessions_notes.get_all_notes_by_project_id(tenant_id=context.tenant_id, project_id=projectId, data = sessions_notes.get_all_notes_by_project_id(tenant_id=context.tenant_id, project_id=projectId,
user_id=context.user_id, data=data) user_id=context.user_id, data=data)
@ -545,7 +545,7 @@ def get_all_notes(projectId: int, data: schemas.SearchNoteSchema = Body(...),
@app.post('/{projectId}/click_maps/search', tags=["click maps"], dependencies=[OR_scope(Permissions.session_replay)]) @app.post('/{projectId}/click_maps/search', tags=["click maps"], dependencies=[OR_scope(Permissions.session_replay)])
def click_map_search(projectId: int, data: schemas.ClickMapSessionsSearch = Body(...), def click_map_search(projectId: int, data: schemas.ClickMapSessionsSearch,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": click_maps.search_short_session(user_id=context.user_id, data=data, project_id=projectId)} return {"data": click_maps.search_short_session(user_id=context.user_id, data=data, project_id=projectId)}
@ -553,7 +553,7 @@ def click_map_search(projectId: int, data: schemas.ClickMapSessionsSearch = Body
@app.post('/{project_id}/feature-flags/search', tags=["feature flags"], @app.post('/{project_id}/feature-flags/search', tags=["feature flags"],
dependencies=[OR_scope(Permissions.feature_flags)]) dependencies=[OR_scope(Permissions.feature_flags)])
def search_feature_flags(project_id: int, def search_feature_flags(project_id: int,
data: schemas.SearchFlagsSchema = Body(...), data: schemas.SearchFlagsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return feature_flags.search_feature_flags(project_id=project_id, user_id=context.user_id, data=data) return feature_flags.search_feature_flags(project_id=project_id, user_id=context.user_id, data=data)
@ -565,14 +565,14 @@ def get_feature_flag(project_id: int, feature_flag_id: int):
@app.post('/{project_id}/feature-flags', tags=["feature flags"], dependencies=[OR_scope(Permissions.feature_flags)]) @app.post('/{project_id}/feature-flags', tags=["feature flags"], dependencies=[OR_scope(Permissions.feature_flags)])
def add_feature_flag(project_id: int, data: schemas.FeatureFlagSchema = Body(...), def add_feature_flag(project_id: int, data: schemas.FeatureFlagSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return feature_flags.create_feature_flag(project_id=project_id, user_id=context.user_id, feature_flag_data=data) return feature_flags.create_feature_flag(project_id=project_id, user_id=context.user_id, feature_flag_data=data)
@app.put('/{project_id}/feature-flags/{feature_flag_id}', tags=["feature flags"], @app.put('/{project_id}/feature-flags/{feature_flag_id}', tags=["feature flags"],
dependencies=[OR_scope(Permissions.feature_flags)]) dependencies=[OR_scope(Permissions.feature_flags)])
def update_feature_flag(project_id: int, feature_flag_id: int, data: schemas.FeatureFlagSchema = Body(...), def update_feature_flag(project_id: int, feature_flag_id: int, data: schemas.FeatureFlagSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return feature_flags.update_feature_flag(project_id=project_id, feature_flag_id=feature_flag_id, return feature_flags.update_feature_flag(project_id=project_id, feature_flag_id=feature_flag_id,
user_id=context.user_id, feature_flag=data) user_id=context.user_id, feature_flag=data)
@ -587,6 +587,6 @@ def delete_feature_flag(project_id: int, feature_flag_id: int, _=Body(None)):
@app.post('/{project_id}/feature-flags/{feature_flag_id}/status', tags=["feature flags"], @app.post('/{project_id}/feature-flags/{feature_flag_id}/status', tags=["feature flags"],
dependencies=[OR_scope(Permissions.feature_flags)]) dependencies=[OR_scope(Permissions.feature_flags)])
def update_feature_flag_status(project_id: int, feature_flag_id: int, def update_feature_flag_status(project_id: int, feature_flag_id: int,
data: schemas.FeatureFlagStatus = Body(...)): data: schemas.FeatureFlagStatus):
return {"data": feature_flags.update_feature_flag_status(project_id=project_id, feature_flag_id=feature_flag_id, return {"data": feature_flags.update_feature_flag_status(project_id=project_id, feature_flag_id=feature_flag_id,
is_active=data.is_active)} is_active=data.is_active)}

View file

@ -24,7 +24,7 @@ def get_roles(context: schemas.CurrentContext = Depends(OR_context)):
@app.post('/client/roles', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")]) @app.post('/client/roles', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")])
@app.put('/client/roles', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")]) @app.put('/client/roles', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")])
def add_role(data: schemas.RolePayloadSchema = Body(...), def add_role(data: schemas.RolePayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = roles.create(tenant_id=context.tenant_id, user_id=context.user_id, data=data) data = roles.create(tenant_id=context.tenant_id, user_id=context.user_id, data=data)
if "errors" in data: if "errors" in data:
@ -37,7 +37,7 @@ def add_role(data: schemas.RolePayloadSchema = Body(...),
@app.post('/client/roles/{roleId}', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")]) @app.post('/client/roles/{roleId}', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")])
@app.put('/client/roles/{roleId}', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")]) @app.put('/client/roles/{roleId}', tags=["client", "roles"], dependencies=[OR_role("owner", "admin")])
def edit_role(roleId: int, data: schemas.RolePayloadSchema = Body(...), def edit_role(roleId: int, data: schemas.RolePayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = roles.update(tenant_id=context.tenant_id, user_id=context.user_id, role_id=roleId, data=data) data = roles.update(tenant_id=context.tenant_id, user_id=context.user_id, role_id=roleId, data=data)
if "errors" in data: if "errors" in data:
@ -65,7 +65,7 @@ def get_assist_credentials():
@app.post('/trails', tags=["traces", "trails"], dependencies=[OR_role("owner", "admin")]) @app.post('/trails', tags=["traces", "trails"], dependencies=[OR_role("owner", "admin")])
def get_trails(data: schemas.TrailSearchPayloadSchema = Body(...), def get_trails(data: schemas.TrailSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return { return {
'data': traces.get_all(tenant_id=context.tenant_id, data=data) 'data': traces.get_all(tenant_id=context.tenant_id, data=data)
@ -78,7 +78,7 @@ def get_available_trail_actions(context: schemas.CurrentContext = Depends(OR_con
@app.put('/{projectId}/assist/save', tags=["assist"]) @app.put('/{projectId}/assist/save', tags=["assist"])
def sign_record_for_upload(projectId: int, data: schemas.AssistRecordPayloadSchema = Body(...), def sign_record_for_upload(projectId: int, data: schemas.AssistRecordPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if not sessions.session_exists(project_id=projectId, session_id=data.session_id): if not sessions.session_exists(project_id=projectId, session_id=data.session_id):
return {"errors": ["Session not found"]} return {"errors": ["Session not found"]}
@ -86,7 +86,7 @@ def sign_record_for_upload(projectId: int, data: schemas.AssistRecordPayloadSche
@app.put('/{projectId}/assist/save/done', tags=["assist"]) @app.put('/{projectId}/assist/save/done', tags=["assist"])
def save_record_after_upload(projectId: int, data: schemas.AssistRecordSavePayloadSchema = Body(...), def save_record_after_upload(projectId: int, data: schemas.AssistRecordSavePayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if not sessions.session_exists(project_id=projectId, session_id=data.session_id): if not sessions.session_exists(project_id=projectId, session_id=data.session_id):
return {"errors": ["Session not found"]} return {"errors": ["Session not found"]}
@ -94,7 +94,7 @@ def save_record_after_upload(projectId: int, data: schemas.AssistRecordSavePaylo
@app.post('/{projectId}/assist/records', tags=["assist"]) @app.post('/{projectId}/assist/records', tags=["assist"])
def search_records(projectId: int, data: schemas.AssistRecordSearchPayloadSchema = Body(...), def search_records(projectId: int, data: schemas.AssistRecordSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": assist_records.search_records(project_id=projectId, data=data, context=context)} return {"data": assist_records.search_records(project_id=projectId, data=data, context=context)}
@ -105,7 +105,7 @@ def get_record(projectId: int, recordId: int, context: schemas.CurrentContext =
@app.post('/{projectId}/assist/records/{recordId}', tags=["assist"]) @app.post('/{projectId}/assist/records/{recordId}', tags=["assist"])
def update_record(projectId: int, recordId: int, data: schemas.AssistRecordUpdatePayloadSchema = Body(...), def update_record(projectId: int, recordId: int, data: schemas.AssistRecordUpdatePayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
result = assist_records.update_record(project_id=projectId, record_id=recordId, data=data, context=context) result = assist_records.update_record(project_id=projectId, record_id=recordId, data=data, context=context)
if "errors" in result: if "errors" in result:
@ -123,7 +123,7 @@ def delete_record(projectId: int, recordId: int, _=Body(None),
@app.post('/{projectId}/signals', tags=['signals']) @app.post('/{projectId}/signals', tags=['signals'])
def send_interactions(projectId: int, data: schemas.SignalsSchema = Body(...), def send_interactions(projectId: int, data: schemas.SignalsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = signals.handle_frontend_signals_queued(project_id=projectId, user_id=context.user_id, data=data) data = signals.handle_frontend_signals_queued(project_id=projectId, user_id=context.user_id, data=data)
@ -134,7 +134,7 @@ def send_interactions(projectId: int, data: schemas.SignalsSchema = Body(...),
@app.post('/{projectId}/dashboard/insights', tags=["insights"]) @app.post('/{projectId}/dashboard/insights', tags=["insights"])
@app.post('/{projectId}/dashboard/insights', tags=["insights"]) @app.post('/{projectId}/dashboard/insights', tags=["insights"])
def sessions_search(projectId: int, data: schemas.GetInsightsSchema = Body(...), def sessions_search(projectId: int, data: schemas.GetInsightsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {'data': sessions_insights.fetch_selected(data=data, project_id=projectId)} return {'data': sessions_insights.fetch_selected(data=data, project_id=projectId)}
@ -188,7 +188,7 @@ def get_assist_stats_top_members(
) )
def get_assist_stats_sessions( def get_assist_stats_sessions(
project_id: int, project_id: int,
data: schemas.AssistStatsSessionsRequest = Body(...), data: schemas.AssistStatsSessionsRequest,
): ):
return assist_stats.get_sessions( return assist_stats.get_sessions(
project_id=project_id, project_id=project_id,

View file

@ -1,9 +1,10 @@
import logging
from fastapi import HTTPException, Request, Response, status from fastapi import HTTPException, Request, Response, status
from chalicelib.utils import SAML2_helper from chalicelib.utils import SAML2_helper
from chalicelib.utils.SAML2_helper import prepare_request, init_saml_auth from chalicelib.utils.SAML2_helper import prepare_request, init_saml_auth
from routers.base import get_routers from routers.base import get_routers
import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -3,7 +3,7 @@ from typing import Union
from fastapi import Body, Depends, Request from fastapi import Body, Depends, Request
import schemas import schemas
from chalicelib.core import dashboards, custom_metrics, funnels from chalicelib.core import dashboards, custom_metrics
from or_dependencies import OR_context, OR_scope from or_dependencies import OR_context, OR_scope
from routers.base import get_routers from routers.base import get_routers
@ -11,7 +11,7 @@ public_app, app, app_apikey = get_routers([OR_scope(schemas.Permissions.metrics)
@app.post('/{projectId}/dashboards', tags=["dashboard"]) @app.post('/{projectId}/dashboards', tags=["dashboard"])
def create_dashboards(projectId: int, data: schemas.CreateDashboardSchema = Body(...), def create_dashboards(projectId: int, data: schemas.CreateDashboardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return dashboards.create_dashboard(project_id=projectId, user_id=context.user_id, data=data) return dashboards.create_dashboard(project_id=projectId, user_id=context.user_id, data=data)
@ -30,7 +30,7 @@ def get_dashboard(projectId: int, dashboardId: int, context: schemas.CurrentCont
@app.put('/{projectId}/dashboards/{dashboardId}', tags=["dashboard"]) @app.put('/{projectId}/dashboards/{dashboardId}', tags=["dashboard"])
def update_dashboard(projectId: int, dashboardId: int, data: schemas.EditDashboardSchema = Body(...), def update_dashboard(projectId: int, dashboardId: int, data: schemas.EditDashboardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": dashboards.update_dashboard(project_id=projectId, user_id=context.user_id, return {"data": dashboards.update_dashboard(project_id=projectId, user_id=context.user_id,
dashboard_id=dashboardId, data=data)} dashboard_id=dashboardId, data=data)}
@ -49,7 +49,7 @@ def pin_dashboard(projectId: int, dashboardId: int, context: schemas.CurrentCont
@app.post('/{projectId}/dashboards/{dashboardId}/cards', tags=["cards"]) @app.post('/{projectId}/dashboards/{dashboardId}/cards', tags=["cards"])
def add_card_to_dashboard(projectId: int, dashboardId: int, def add_card_to_dashboard(projectId: int, dashboardId: int,
data: schemas.AddWidgetToDashboardPayloadSchema = Body(...), data: schemas.AddWidgetToDashboardPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": dashboards.add_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId, return {"data": dashboards.add_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId,
data=data)} data=data)}
@ -58,7 +58,7 @@ def add_card_to_dashboard(projectId: int, dashboardId: int,
@app.post('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"]) @app.post('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"])
# @app.put('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"]) # @app.put('/{projectId}/dashboards/{dashboardId}/metrics', tags=["dashboard"])
def create_metric_and_add_to_dashboard(projectId: int, dashboardId: int, def create_metric_and_add_to_dashboard(projectId: int, dashboardId: int,
data: schemas.CardSchema = Body(...), data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": dashboards.create_metric_add_widget(project_id=projectId, user_id=context.user_id, return {"data": dashboards.create_metric_add_widget(project_id=projectId, user_id=context.user_id,
dashboard_id=dashboardId, data=data)} dashboard_id=dashboardId, data=data)}
@ -66,7 +66,7 @@ def create_metric_and_add_to_dashboard(projectId: int, dashboardId: int,
@app.put('/{projectId}/dashboards/{dashboardId}/widgets/{widgetId}', tags=["dashboard"]) @app.put('/{projectId}/dashboards/{dashboardId}/widgets/{widgetId}', tags=["dashboard"])
def update_widget_in_dashboard(projectId: int, dashboardId: int, widgetId: int, def update_widget_in_dashboard(projectId: int, dashboardId: int, widgetId: int,
data: schemas.UpdateWidgetPayloadSchema = Body(...), data: schemas.UpdateWidgetPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return dashboards.update_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId, return dashboards.update_widget(project_id=projectId, user_id=context.user_id, dashboard_id=dashboardId,
widget_id=widgetId, data=data) widget_id=widgetId, data=data)
@ -80,20 +80,20 @@ def remove_widget_from_dashboard(projectId: int, dashboardId: int, widgetId: int
@app.post('/{projectId}/cards/try', tags=["cards"]) @app.post('/{projectId}/cards/try', tags=["cards"])
def try_card(projectId: int, data: schemas.CardSchema = Body(...), def try_card(projectId: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": custom_metrics.get_chart(project_id=projectId, data=data, user_id=context.user_id)} return {"data": custom_metrics.get_chart(project_id=projectId, data=data, user_id=context.user_id)}
@app.post('/{projectId}/cards/try/sessions', tags=["cards"]) @app.post('/{projectId}/cards/try/sessions', tags=["cards"])
def try_card_sessions(projectId: int, data: schemas.CardSessionsSchema = Body(...), def try_card_sessions(projectId: int, data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_sessions(project_id=projectId, user_id=context.user_id, data=data) data = custom_metrics.get_sessions(project_id=projectId, user_id=context.user_id, data=data)
return {"data": data} return {"data": data}
@app.post('/{projectId}/cards/try/issues', tags=["cards"]) @app.post('/{projectId}/cards/try/issues', tags=["cards"])
def try_card_issues(projectId: int, data: schemas.CardSchema = Body(...), def try_card_issues(projectId: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": custom_metrics.get_issues(project_id=projectId, user_id=context.user_id, data=data)} return {"data": custom_metrics.get_issues(project_id=projectId, user_id=context.user_id, data=data)}
@ -104,13 +104,13 @@ def get_cards(projectId: int, context: schemas.CurrentContext = Depends(OR_conte
@app.post('/{projectId}/cards', tags=["cards"]) @app.post('/{projectId}/cards', tags=["cards"])
def create_card(projectId: int, data: schemas.CardSchema = Body(...), def create_card(projectId: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return custom_metrics.create_card(project_id=projectId, user_id=context.user_id, data=data) return custom_metrics.create_card(project_id=projectId, user_id=context.user_id, data=data)
@app.post('/{projectId}/cards/search', tags=["cards"]) @app.post('/{projectId}/cards/search', tags=["cards"])
def search_cards(projectId: int, data: schemas.SearchCardsSchema = Body(...), def search_cards(projectId: int, data: schemas.SearchCardsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return {"data": custom_metrics.search_all(project_id=projectId, user_id=context.user_id, data=data)} return {"data": custom_metrics.search_all(project_id=projectId, user_id=context.user_id, data=data)}
@ -129,7 +129,7 @@ def get_card(projectId: int, metric_id: Union[int, str], context: schemas.Curren
@app.post('/{projectId}/cards/{metric_id}/sessions', tags=["cards"]) @app.post('/{projectId}/cards/{metric_id}/sessions', tags=["cards"])
def get_card_sessions(projectId: int, metric_id: int, def get_card_sessions(projectId: int, metric_id: int,
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_sessions_by_card_id(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data = custom_metrics.get_sessions_by_card_id(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
data=data) data=data)
@ -140,7 +140,7 @@ def get_card_sessions(projectId: int, metric_id: int,
@app.post('/{projectId}/cards/{metric_id}/issues', tags=["cards"]) @app.post('/{projectId}/cards/{metric_id}/issues', tags=["cards"])
def get_card_funnel_issues(projectId: int, metric_id: Union[int, str], def get_card_funnel_issues(projectId: int, metric_id: Union[int, str],
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
if metric_id.isnumeric(): if metric_id.isnumeric():
metric_id = int(metric_id) metric_id = int(metric_id)
@ -156,7 +156,7 @@ def get_card_funnel_issues(projectId: int, metric_id: Union[int, str],
@app.post('/{projectId}/cards/{metric_id}/issues/{issueId}/sessions', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}/issues/{issueId}/sessions', tags=["dashboard"])
def get_metric_funnel_issue_sessions(projectId: int, metric_id: int, issueId: str, def get_metric_funnel_issue_sessions(projectId: int, metric_id: int, issueId: str,
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_funnel_sessions_by_issue(project_id=projectId, user_id=context.user_id, data = custom_metrics.get_funnel_sessions_by_issue(project_id=projectId, user_id=context.user_id,
metric_id=metric_id, issue_id=issueId, data=data) metric_id=metric_id, issue_id=issueId, data=data)
@ -167,7 +167,7 @@ def get_metric_funnel_issue_sessions(projectId: int, metric_id: int, issueId: st
@app.post('/{projectId}/cards/{metric_id}/errors', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}/errors', tags=["dashboard"])
def get_card_errors_list(projectId: int, metric_id: int, def get_card_errors_list(projectId: int, metric_id: int,
data: schemas.CardSessionsSchema = Body(...), data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.get_errors_list(project_id=projectId, user_id=context.user_id, data = custom_metrics.get_errors_list(project_id=projectId, user_id=context.user_id,
metric_id=metric_id, data=data) metric_id=metric_id, data=data)
@ -177,7 +177,7 @@ def get_card_errors_list(projectId: int, metric_id: int,
@app.post('/{projectId}/cards/{metric_id}/chart', tags=["card"]) @app.post('/{projectId}/cards/{metric_id}/chart', tags=["card"])
def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardSessionsSchema = Body(...), def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardSessionsSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.make_chart_from_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data = custom_metrics.make_chart_from_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
data=data) data=data)
@ -185,7 +185,7 @@ def get_card_chart(projectId: int, metric_id: int, request: Request, data: schem
@app.post('/{projectId}/cards/{metric_id}', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}', tags=["dashboard"])
def update_card(projectId: int, metric_id: int, data: schemas.CardSchema = Body(...), def update_card(projectId: int, metric_id: int, data: schemas.CardSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
data = custom_metrics.update_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data=data) data = custom_metrics.update_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data=data)
if data is None: if data is None:
@ -195,7 +195,7 @@ def update_card(projectId: int, metric_id: int, data: schemas.CardSchema = Body(
@app.post('/{projectId}/cards/{metric_id}/status', tags=["dashboard"]) @app.post('/{projectId}/cards/{metric_id}/status', tags=["dashboard"])
def update_card_state(projectId: int, metric_id: int, def update_card_state(projectId: int, metric_id: int,
data: schemas.UpdateCardStatusSchema = Body(...), data: schemas.UpdateCardStatusSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return { return {
"data": custom_metrics.change_state(project_id=projectId, user_id=context.user_id, metric_id=metric_id, "data": custom_metrics.change_state(project_id=projectId, user_id=context.user_id, metric_id=metric_id,

View file

@ -1,4 +1,4 @@
from fastapi import Depends, Body from fastapi import Depends
import schemas import schemas
from chalicelib.utils import assist_helper from chalicelib.utils import assist_helper
@ -23,6 +23,6 @@ def get_sessions_live(projectKey: str, userId: str = None, context: schemas.Curr
@app_apikey.post('/v1/{projectKey}/assist/sessions', tags=["api"]) @app_apikey.post('/v1/{projectKey}/assist/sessions', tags=["api"])
def sessions_live(projectKey: str, data: schemas.LiveSessionsSearchPayloadSchema = Body(...), def sessions_live(projectKey: str, data: schemas.LiveSessionsSearchPayloadSchema,
context: schemas.CurrentContext = Depends(OR_context)): context: schemas.CurrentContext = Depends(OR_context)):
return core.sessions_live(projectId=context.project.project_id, data=data, context=context) return core.sessions_live(projectId=context.project.project_id, data=data, context=context)