Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/DrDroidLab/PlayBooks into @…
Browse files Browse the repository at this point in the history
…feature/unit_tests
  • Loading branch information
jayeshsadhwani99 committed Aug 12, 2024
2 parents c98bf8e + 0c5948b commit 51ac767
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 83 deletions.
2 changes: 2 additions & 0 deletions deploy.docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-pass}
- POSTGRES_HOST=${POSTGRES_HOST:-db}
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
- OKTA_DOMAIN=${OKTA_DOMAIN}
- OKTA_CLIENT_ID=${OKTA_CLIENT_ID}
depends_on:
- db
- redis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def register_step_result_evaluator(self, step_rule_type: PlaybookStepResultRule.

def evaluate(self, condition: PlaybookStepResultCondition,
playbook_task_execution_log: [PlaybookTaskExecutionLog]) -> (bool, Dict):
if not condition:
if not condition.rule_sets:
return True, {}
rule_sets: [PlaybookStepResultCondition.RuleSet] = condition.rule_sets
rs_logical_operator = condition.logical_operator
Expand Down
10 changes: 7 additions & 3 deletions executor/source_managers/grafana_loki_source_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta

from google.protobuf.wrappers_pb2 import StringValue, UInt64Value, Int64Value

Expand Down Expand Up @@ -39,12 +39,16 @@ def __init__(self):
display_name=StringValue(value="Start Time"),
data_type=LiteralType.LONG,
is_date_time_field=True,
form_field_type=FormFieldType.TEXT_FT),
default_value=Literal(type=LiteralType.LONG, long=Int64Value(
value=int((datetime.now() - timedelta(minutes=30)).timestamp()))),
form_field_type=FormFieldType.DATE_FT),
FormField(key_name=StringValue(value="end_time"),
display_name=StringValue(value="End Time"),
data_type=LiteralType.LONG,
is_date_time_field=True,
form_field_type=FormFieldType.TEXT_FT),
default_value=Literal(type=LiteralType.LONG, long=Int64Value(
value=int((datetime.now()).timestamp()))),
form_field_type=FormFieldType.DATE_FT),
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion executor/workflows/crud/workflows_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def update_or_create_db_workflow(account: Account, created_by, workflow_proto: W
db_playbooks = get_db_playbooks(account, playbook_ids=playbook_ids, is_active=True)
if update_mode and db_playbooks.count() != len(playbook_ids):
return None, 'Invalid Playbooks in Workflow Config'
elif not update_mode:
elif not update_mode and db_playbooks.count() != len(playbook_ids):
try:
db_playbooks = []
for pb in playbooks:
Expand Down
15 changes: 10 additions & 5 deletions executor/workflows/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,14 @@ def test_workflow_notification(user, account_id, workflow, message_type):
playbook_execution = playbook_executions.first()
pe_proto: PlaybookExecution = playbook_execution.proto
p_proto = pe_proto.playbook
playbook_url = build_absolute_uri(None, settings.PLATFORM_PLAYBOOKS_PAGE_LOCATION.format(p_proto.id.value),
settings.PLATFORM_PLAYBOOKS_PAGE_SITE_HTTP_PROTOCOL,
settings.PLATFORM_PLAYBOOKS_PAGE_USE_SITE)

pb_exec_location = settings.PLATFORM_PLAYBOOKS_EXECUTION_PAGE_LOCATION.format(
p_proto.id.value, pe_proto.playbook_run_id.value)
pb_exec_protocol = settings.PLATFORM_PLAYBOOKS_PAGE_SITE_HTTP_PROTOCOL
pb_exec_use_sites = settings.PLATFORM_PLAYBOOKS_PAGE_USE_SITE

playbook_execution_url = build_absolute_uri(None, pb_exec_location, pb_exec_protocol, pb_exec_use_sites)

step_execution_logs = pe_proto.step_execution_logs
execution_output: [InterpretationProto] = playbook_step_execution_result_interpret(step_execution_logs)
if workflow.actions[0].type == WorkflowActionProto.Type.SLACK_MESSAGE or workflow.actions[
Expand All @@ -370,15 +375,15 @@ def test_workflow_notification(user, account_id, workflow, message_type):
type=InterpretationProto.Type.TEXT,
title=StringValue(value=f'Testing Workflow: "{workflow.name.value}"'),
description=StringValue(
value=f'This is a sample run of <{playbook_url}|{p_proto.name.value}> playbook.'),
value=f'This is a sample run of <{playbook_execution_url}|{p_proto.name.value}> playbook.'),
model_type=InterpretationProto.ModelType.WORKFLOW_EXECUTION
)
else:
workflow_test_message = InterpretationProto(
type=InterpretationProto.Type.TEXT,
title=StringValue(value=f'Testing Workflow: "{workflow.name.value}"'),
description=StringValue(
value=f'This is a sample run of [{p_proto.name.value}]({playbook_url}) playbook.'),
value=f'This is a sample run of [{p_proto.name.value}]({playbook_execution_url}) playbook.'),
model_type=InterpretationProto.ModelType.WORKFLOW_EXECUTION
)
execution_output.insert(0, workflow_test_message)
Expand Down
4 changes: 4 additions & 0 deletions helm/charts/server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ spec:
value: {{ .Values.redisUrl }}
- name: EMAIL_PASSWORD_AUTH_ENABLED
value: {{ .Values.emailPasswordAuthEnabled }}
- name: OKTA_DOMAIN
value: {{ .Values.oktaDomain }}
- name: OKTA_CLIENT_ID
value: {{ .Values.oktaClientId }}
ports:
- containerPort: 8080
command: ["/bin/sh","-c"]
Expand Down
2 changes: 2 additions & 0 deletions playbooks.docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-pass}
- POSTGRES_HOST=${POSTGRES_HOST:-db}
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
- OKTA_DOMAIN=${OKTA_DOMAIN}
- OKTA_CLIENT_ID=${OKTA_CLIENT_ID}
depends_on:
- db
- redis
Expand Down
1 change: 1 addition & 0 deletions protos/ui_definition.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum FormFieldType {
WYSIWYG_FT = 8;
COMPOSITE_FT = 9;
STRING_ARRAY_FT = 10;
DATE_FT = 11;
}

message FormField {
Expand Down
4 changes: 2 additions & 2 deletions protos/ui_definition_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions protos/ui_definition_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _FormFieldTypeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._
WYSIWYG_FT: _FormFieldType.ValueType # 8
COMPOSITE_FT: _FormFieldType.ValueType # 9
STRING_ARRAY_FT: _FormFieldType.ValueType # 10
DATE_FT: _FormFieldType.ValueType # 11

class FormFieldType(_FormFieldType, metaclass=_FormFieldTypeEnumTypeWrapper): ...

Expand All @@ -51,6 +52,7 @@ TYPING_DROPDOWN_MULTIPLE_FT: FormFieldType.ValueType # 7
WYSIWYG_FT: FormFieldType.ValueType # 8
COMPOSITE_FT: FormFieldType.ValueType # 9
STRING_ARRAY_FT: FormFieldType.ValueType # 10
DATE_FT: FormFieldType.ValueType # 11
global___FormFieldType = FormFieldType

@typing_extensions.final
Expand Down
8 changes: 2 additions & 6 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import RequireAuth from "./components/RequireAuth";
import "nprogress/nprogress.css";
import { useGetUserQuery } from "./store/features/auth/api";
import Loading from "./components/common/Loading";
import {
generateNoLayoutRoutes,
generateOtherRoutes,
generateUnauthRoutes,
} from "./generateRoutes";
import { generateOtherRoutes, generateUnauthRoutes } from "./generateRoutes";
import useDefaultPage from "./hooks/useDefaultPage";

const App = () => {
Expand All @@ -24,7 +20,7 @@ const App = () => {
<Routes key={location.pathname} location={location}>
{generateUnauthRoutes()}

<Route element={<RequireAuth />}>{generateNoLayoutRoutes()}</Route>
{/* <Route element={<RequireAuth />}>{generateNoLayoutRoutes()}</Route> */}

<Route element={<RequireAuth />}>
<Route element={<Layout />}>{generateOtherRoutes()}</Route>
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const Heading = ({ subHeading = "", heading }) => {
style={{ zIndex: "90" }}
className="w-full h-[80px] top-0 py-3 flex justify-between bg-white border-b border-gray-300 px-4 items-center sticky">
<div className="flex gap-2 items-center">
{isOnPlaybookPage && (
{/* {isOnPlaybookPage && (
<div
className="cursor-pointer text-xl font-bold hover:text-violet-500 transition-all"
onClick={goBack}>
<HomeRounded />
</div>
)}
)} */}
<div className="flex-col justify-items-center">
<div>
<div className="text-xs sm:text-lg font-semibold text-gray-800">
Expand Down
12 changes: 1 addition & 11 deletions web/src/components/Playbooks/create/Builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ import CreateFlow from "./CreateFlow.js";
import GlobalVariables from "../../common/GlobalVariable/index.js";
import AddDataDrawer from "../../common/Drawers/AddDataDrawer.js";
import TemplatesDrawer from "../../common/Drawers/TemplatesDrawer.js";
import useDrawerState from "../../../hooks/common/useDrawerState.ts";
import { DrawerTypes } from "../../../store/features/drawers/drawerTypes.ts";
import CustomButton from "../../common/CustomButton/index.tsx";

function Builder({ isLog = false }) {
const { toggle: toggleAddData } = useDrawerState(DrawerTypes.ADD_DATA);

function Builder() {
return (
<div className="h-full w-full">
<div className="absolute top-2 left-2 flex flex-col items-start gap-4 z-10">
{!isLog && (
<>
<CustomButton onClick={toggleAddData}>Add Data</CustomButton>
</>
)}
<GlobalVariables />
</div>
<AddDataDrawer />
Expand Down
19 changes: 2 additions & 17 deletions web/src/components/Playbooks/task/TaskBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useState } from "react";
import { useEffect } from "react";
import { fetchData } from "../../../utils/fetchAssetModelOptions.ts";
import CustomButton from "../../common/CustomButton/index.tsx";
import Details from "./Details.tsx";
import HandleOutput from "./HandleOutput.tsx";
import useIsPrefetched from "../../../hooks/playbooks/useIsPrefetched.ts";
Expand All @@ -10,17 +9,8 @@ import TaskConfiguration from "./taskConfiguration";
const TaskBlock = ({ id }) => {
const [task, currentStepId] = useCurrentTask(id);
const showOutput = task?.ui_requirement?.showOutput;
const [showConfig, setShowConfig] = useState(!showOutput);
const isPrefetched = useIsPrefetched();

const toggleConfig = () => {
setShowConfig(!showConfig);
};

useEffect(() => {
setShowConfig(!showOutput);
}, [showOutput]);

useEffect(() => {
if (
currentStepId !== null &&
Expand All @@ -41,12 +31,7 @@ const TaskBlock = ({ id }) => {

return (
<div className="flex flex-col gap-2 mt-2">
{showOutput && (
<CustomButton className="w-fit" onClick={toggleConfig}>
{showConfig ? "Hide" : "Show"} Config
</CustomButton>
)}
{showConfig && task && <Details id={id} />}
{task && <Details id={id} />}

<TaskConfiguration id={id} />
<HandleOutput id={id} />
Expand Down
9 changes: 8 additions & 1 deletion web/src/components/RequireAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const RequireAuth = () => {
const location = useLocation();
const { isOpen, toggle } = useToggle(true);

const handleClose = () => {
window.location.reload();
toggle();
};

return (
<>
<FakeLoading />
Expand All @@ -23,7 +28,9 @@ const RequireAuth = () => {
<Navigate to="/signup" state={{ from: location }} replace />
)}

{!lastLogin && <RecieveUpdatesModal close={toggle} isOpen={isOpen} />}
{/* {!lastLogin && (
<RecieveUpdatesModal close={handleClose} isOpen={isOpen} />
)} */}
</>
);
};
Expand Down
24 changes: 12 additions & 12 deletions web/src/generateRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ export const generateUnauthRoutes = () => {
));
};

export const generateNoLayoutRoutes = () => {
return Object.entries(components)
.filter(([pageKey]) => noLayoutPages.includes(pageKey as PageKeys))
.map(([pageKey, importFn]) => (
<Route
key={pageKey}
path={routes[pageKey]}
element={<LazyComponent importFn={importFn} />}
/>
));
};
// export const generateNoLayoutRoutes = () => {
// return Object.entries(components)
// .filter(([pageKey]) => noLayoutPages.includes(pageKey as PageKeys))
// .map(([pageKey, importFn]) => (
// <Route
// key={pageKey}
// path={routes[pageKey]}
// element={<LazyComponent importFn={importFn} />}
// />
// ));
// };

export const generateOtherRoutes = () => {
return Object.entries(components)
.filter(
([pageKey]) =>
!noLayoutPages.includes(pageKey as PageKeys) &&
// !noLayoutPages.includes(pageKey as PageKeys) &&
!unAuthPages.includes(pageKey as PageKeys),
)
.map(([pageKey, importFn]) => (
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/playbooks/Playbook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Playbook() {
<Heading heading={"Untitled Playbook"} />
<div className="flex h-[calc(100%-80px)]">
<main className="relative flex flex-1">
<Builder isLog={!!isPrefetched} />
<Builder />
{!isEditing && (
<div
className={`${
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/playbooks/PlaybookLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function PlaybookLog() {
<Heading heading={playbook.name} />
<div className="flex flex-col h-[calc(100%-80px)]">
<main className="relative flex flex-1">
<Builder isLog={true} />
<Builder />
</main>
</div>
</div>
Expand Down
36 changes: 23 additions & 13 deletions web/src/utils/execution/executeStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ import checkId from "../common/checkId.ts";
import { Task } from "../../types/index.ts";
import { updateCardById } from "./updateCardById.ts";
import { extractTimeFromHours } from "../../components/Playbooks/task/taskConfiguration/comparison/utils/extractTimeFromHours.ts";
import { setCurrentVisibleStepFunction } from "../playbook/step/setCurrentVisibleStepFunction.ts";

const handleOutput = (output: any, list: any[], id: string | undefined) => {
const outputError = output?.result?.error;
list.push({
data: { ...output?.result, timestamp: output?.timestamp },
interpretation: output?.interpretation,
execution_global_variable_set: output?.execution_global_variable_set,
error: outputError ? outputError : undefined,
});
if (outputError) {
updateCardById("ui_requirement.showError", true, id);
updateCardById("ui_requirement.outputError", true, id);
}
};

export async function executeStep(id?: string) {
const { executionId, currentPlaybook } = playbookSelector(store.getState());
Expand Down Expand Up @@ -101,20 +116,13 @@ export async function executeStep(id?: string) {
const list: any = [];
const taskId: Task | string | undefined = step?.tasks[index];
const id = typeof taskId === "string" ? taskId : taskId?.id;

outputs.forEach((output) => {
const outputError = output?.result?.error;
list.push({
data: { ...output?.result, timestamp: output?.timestamp },
interpretation: output?.interpretation,
execution_global_variable_set: output?.execution_global_variable_set,
error: outputError ? outputError : undefined,
if (Array.isArray(outputs)) {
outputs.forEach((output) => {
handleOutput(output, list, id);
});
if (outputError) {
updateCardById("ui_requirement.showError", true, id);
updateCardById("ui_requirement.outputError", true, id);
}
});
} else {
handleOutput(outputs, list, id);
}

updateCardById("ui_requirement.outputs", list, id);
});
Expand Down Expand Up @@ -154,5 +162,7 @@ export async function executeStep(id?: string) {
updateCardById("ui_requirement.outputLoading", false, task?.id);
updateCardById("ui_requirement.showOutput", true, task?.id);
});

if (!executionId) setCurrentVisibleStepFunction(currentStepId);
}
}
2 changes: 2 additions & 0 deletions web/src/utils/execution/executeTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import checkId from "../common/checkId.ts";
import updateStepById from "../playbook/step/updateStepById.ts";
import { executionBulkTaskExecute } from "../../store/features/playbook/api/executions/executionBulkTaskExecuteApi.ts";
import { extractTimeFromHours } from "../../components/Playbooks/task/taskConfiguration/comparison/utils/extractTimeFromHours.ts";
import { setCurrentVisibleTaskFunction } from "../playbook/task/setCurrentVisibleTaskFunction.ts";

export async function executeTask(id?: string) {
const [task] = getCurrentTask(id);
Expand Down Expand Up @@ -111,5 +112,6 @@ export async function executeTask(id?: string) {

updateStepById("ui_requirement.showOutput", true, stepId);
updateStepById("ui_requirement.outputLoading", false, stepId);
setCurrentVisibleTaskFunction(id ?? "");
}
}
Loading

0 comments on commit 51ac767

Please sign in to comment.