Patch/api v1.12.0 (#1296)
* fix(chalice): include metadata in sessions exp search * fix(chalice): fixed sessions exp search wrong col name * fix(chalice): removed cookies
This commit is contained in:
parent
7569c7f151
commit
cd77fd8804
4 changed files with 87 additions and 53 deletions
|
|
@ -1,8 +1,6 @@
|
|||
from typing import Union
|
||||
|
||||
from decouple import config
|
||||
from fastapi import Depends, Body, HTTPException, Response, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi import Depends, Body
|
||||
|
||||
import schemas
|
||||
from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assignments, projects, \
|
||||
|
|
@ -14,52 +12,12 @@ from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assig
|
|||
custom_metrics, saved_search, integrations_global
|
||||
from chalicelib.core.collaboration_msteams import MSTeams
|
||||
from chalicelib.core.collaboration_slack import Slack
|
||||
from chalicelib.utils import helper, captcha, s3
|
||||
from or_dependencies import OR_context
|
||||
from routers.base import get_routers
|
||||
|
||||
public_app, app, app_apikey = get_routers()
|
||||
|
||||
|
||||
@public_app.post('/login', tags=["authentication"])
|
||||
async def login(data: schemas.UserLoginSchema = Body(...)):
|
||||
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid captcha."
|
||||
)
|
||||
|
||||
r = users.authenticate(data.email, data.password)
|
||||
if r is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="You’ve entered invalid Email or Password."
|
||||
)
|
||||
if "errors" in r:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail=r["errors"][0]
|
||||
)
|
||||
|
||||
r["smtp"] = helper.has_smtp()
|
||||
content = {
|
||||
'jwt': r.pop('jwt'),
|
||||
'data': {
|
||||
"user": r
|
||||
}
|
||||
}
|
||||
response = JSONResponse(content=content)
|
||||
response.set_cookie(key="jwt", value=content['jwt'], domain=helper.get_domain(),
|
||||
expires=config("JWT_EXPIRATION", cast=int))
|
||||
return response
|
||||
|
||||
|
||||
@app.get('/logout', tags=["login", "logout"])
|
||||
async def logout_user(response: Response, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
response.delete_cookie("jwt")
|
||||
return {"data": "success"}
|
||||
|
||||
|
||||
@app.post('/{projectId}/sessions/search', tags=["sessions"])
|
||||
async def sessions_search(projectId: int, data: schemas.FlatSessionsSearchPayloadSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from typing import Optional, Union
|
|||
|
||||
from decouple import config
|
||||
from fastapi import Body, Depends, BackgroundTasks
|
||||
from fastapi import HTTPException, status
|
||||
from starlette.responses import RedirectResponse, FileResponse
|
||||
|
||||
import schemas
|
||||
|
|
@ -11,6 +12,7 @@ from chalicelib.core import sessions_viewed
|
|||
from chalicelib.core import tenants, users, projects, license
|
||||
from chalicelib.core import webhook
|
||||
from chalicelib.core.collaboration_slack import Slack
|
||||
from chalicelib.utils import captcha
|
||||
from chalicelib.utils import helper
|
||||
from chalicelib.utils.TimeUTC import TimeUTC
|
||||
from or_dependencies import OR_context
|
||||
|
|
@ -35,6 +37,42 @@ if not tenants.tenants_exists(use_pool=False):
|
|||
return signup.create_tenant(data)
|
||||
|
||||
|
||||
@public_app.post('/login', tags=["authentication"])
|
||||
async def login_user(data: schemas.UserLoginSchema = Body(...)):
|
||||
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid captcha."
|
||||
)
|
||||
|
||||
r = users.authenticate(data.email, data.password)
|
||||
if r is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="You’ve entered invalid Email or Password."
|
||||
)
|
||||
if "errors" in r:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail=r["errors"][0]
|
||||
)
|
||||
|
||||
r["smtp"] = helper.has_smtp()
|
||||
content = {
|
||||
'jwt': r.pop('jwt'),
|
||||
'data': {
|
||||
"user": r
|
||||
}
|
||||
}
|
||||
|
||||
return content
|
||||
|
||||
|
||||
@app.get('/logout', tags=["login", "logout"])
|
||||
async def logout_user(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": "success"}
|
||||
|
||||
|
||||
@app.get('/account', tags=['accounts'])
|
||||
async def get_account(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
r = users.get(tenant_id=context.tenant_id, user_id=context.user_id)
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ def search2_series(data: schemas.SessionsSearchPayloadSchema, project_id: int, d
|
|||
WHERE ev.datetime >= toDateTime(%(startDate)s / 1000)
|
||||
AND ev.datetime <= toDateTime(%(endDate)s / 1000)
|
||||
AND ev.project_id = %(project_id)s
|
||||
AND ev.EventType = 'LOCATION'"""
|
||||
AND ev.event_type = 'LOCATION'"""
|
||||
elif metric_of == schemas.MetricOfTable.issues and len(metric_value) > 0:
|
||||
data.filters.append(schemas.SessionSearchFilterSchema(value=metric_value, type=schemas.FilterType.issue,
|
||||
operator=schemas.SearchEventOperator._is))
|
||||
|
|
@ -707,7 +707,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
if is_not:
|
||||
event_where.append(_multiple_conditions(f"sub.{_column} {op} %({e_k})s", event.value,
|
||||
value_key=e_k))
|
||||
events_conditions_not.append({"type": f"sub.EventType='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not.append({"type": f"sub.event_type='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not[-1]["condition"] = event_where[-1]
|
||||
else:
|
||||
event_where.append(_multiple_conditions(f"main.{_column} {op} %({e_k})s", event.value,
|
||||
|
|
@ -723,7 +723,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
if is_not:
|
||||
event_where.append(_multiple_conditions(f"sub.{_column} {op} %({e_k})s", event.value,
|
||||
value_key=e_k))
|
||||
events_conditions_not.append({"type": f"sub.EventType='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not.append({"type": f"sub.event_type='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not[-1]["condition"] = event_where[-1]
|
||||
else:
|
||||
event_where.append(_multiple_conditions(f"main.{_column} {op} %({e_k})s", event.value,
|
||||
|
|
@ -743,7 +743,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
if is_not:
|
||||
event_where.append(_multiple_conditions(f"sub.{_column} {op} %({e_k})s", event.value,
|
||||
value_key=e_k))
|
||||
events_conditions_not.append({"type": f"sub.EventType='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not.append({"type": f"sub.event_type='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not[-1]["condition"] = event_where[-1]
|
||||
else:
|
||||
event_where.append(_multiple_conditions(f"main.{_column} {op} %({e_k})s",
|
||||
|
|
@ -758,7 +758,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
if is_not:
|
||||
event_where.append(_multiple_conditions(f"sub.{_column} {op} %({e_k})s", event.value,
|
||||
value_key=e_k))
|
||||
events_conditions_not.append({"type": f"sub.EventType='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not.append({"type": f"sub.event_type='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not[-1]["condition"] = event_where[-1]
|
||||
else:
|
||||
event_where.append(_multiple_conditions(f"main.{_column} {op} %({e_k})s", event.value,
|
||||
|
|
@ -773,7 +773,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
if is_not:
|
||||
event_where.append(_multiple_conditions(f"sub.{_column} {op} %({e_k})s", event.value,
|
||||
value_key=e_k))
|
||||
events_conditions_not.append({"type": f"sub.EventType='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not.append({"type": f"sub.event_type='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not[-1]["condition"] = event_where[-1]
|
||||
else:
|
||||
event_where.append(_multiple_conditions(f"main.{_column} {op} %({e_k})s", event.value,
|
||||
|
|
@ -785,7 +785,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
# events_conditions.append({"type": event_where[-1]})
|
||||
# if not is_any:
|
||||
# event_where.append(
|
||||
# _multiple_conditions(f"main.{events.EventType.GRAPHQL.column} {op} %({e_k})s", event.value,
|
||||
# _multiple_conditions(f"main.{events.event_type.GRAPHQL.column} {op} %({e_k})s", event.value,
|
||||
# value_key=e_k))
|
||||
# events_conditions[-1]["condition"] = event_where[-1]
|
||||
elif event_type == events.EventType.STATEACTION.ui_type:
|
||||
|
|
@ -797,7 +797,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
if is_not:
|
||||
event_where.append(_multiple_conditions(f"sub.{_column} {op} %({e_k})s", event.value,
|
||||
value_key=e_k))
|
||||
events_conditions_not.append({"type": f"sub.EventType='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not.append({"type": f"sub.event_type='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not[-1]["condition"] = event_where[-1]
|
||||
else:
|
||||
event_where.append(_multiple_conditions(f"main.{_column} {op} %({e_k})s",
|
||||
|
|
@ -834,7 +834,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
if is_not:
|
||||
event_where.append(_multiple_conditions(f"sub.{_column} {op} %({e_k})s", event.value,
|
||||
value_key=e_k))
|
||||
events_conditions_not.append({"type": f"sub.EventType='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not.append({"type": f"sub.event_type='{__get_event_type(event_type)}'"})
|
||||
events_conditions_not[-1]["condition"] = event_where[-1]
|
||||
else:
|
||||
event_where.append(_multiple_conditions(f"main.{_column} {op} %({e_k})s",
|
||||
|
|
@ -910,7 +910,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
|
|||
# TODO: no isNot for TimeBetweenEvents
|
||||
elif event_type == schemas.PerformanceEventType.time_between_events:
|
||||
event_from = event_from % f"{MAIN_EVENTS_TABLE} AS main "
|
||||
# event_from = event_from % f"{getattr(events.EventType, event.value[0].type).table} AS main INNER JOIN {getattr(events.EventType, event.value[1].type).table} AS main2 USING(session_id) "
|
||||
# event_from = event_from % f"{getattr(events.event_type, event.value[0].type).table} AS main INNER JOIN {getattr(events.event_type, event.value[1].type).table} AS main2 USING(session_id) "
|
||||
event_where.append(f"main.event_type='{__get_event_type(event.value[0].type)}'")
|
||||
events_conditions.append({"type": event_where[-1]})
|
||||
event_where.append(f"main.event_type='{__get_event_type(event.value[0].type)}'")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from typing import Optional, Union
|
|||
|
||||
from decouple import config
|
||||
from fastapi import Body, Depends, BackgroundTasks, Request
|
||||
from fastapi import HTTPException, status
|
||||
from starlette.responses import RedirectResponse, FileResponse
|
||||
|
||||
import schemas
|
||||
|
|
@ -13,6 +14,7 @@ from chalicelib.core import tenants, users, projects, license
|
|||
from chalicelib.core import webhook
|
||||
from chalicelib.core.collaboration_slack import Slack
|
||||
from chalicelib.utils import SAML2_helper
|
||||
from chalicelib.utils import captcha
|
||||
from chalicelib.utils import helper
|
||||
from chalicelib.utils.TimeUTC import TimeUTC
|
||||
from or_dependencies import OR_context, OR_scope
|
||||
|
|
@ -39,6 +41,42 @@ if config("MULTI_TENANTS", cast=bool, default=False) or not tenants.tenants_exis
|
|||
return signup.create_tenant(data)
|
||||
|
||||
|
||||
@public_app.post('/login', tags=["authentication"])
|
||||
async def login_user(data: schemas.UserLoginSchema = Body(...)):
|
||||
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid captcha."
|
||||
)
|
||||
|
||||
r = users.authenticate(data.email, data.password)
|
||||
if r is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="You’ve entered invalid Email or Password."
|
||||
)
|
||||
if "errors" in r:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail=r["errors"][0]
|
||||
)
|
||||
|
||||
r["smtp"] = helper.has_smtp()
|
||||
content = {
|
||||
'jwt': r.pop('jwt'),
|
||||
'data': {
|
||||
"user": r
|
||||
}
|
||||
}
|
||||
|
||||
return content
|
||||
|
||||
|
||||
@app.get('/logout', tags=["login", "logout"])
|
||||
async def logout_user(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": "success"}
|
||||
|
||||
|
||||
@app.get('/account', tags=['accounts'])
|
||||
async def get_account(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
r = users.get(tenant_id=context.tenant_id, user_id=context.user_id)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue