diff --git a/frontend/src/components/OrgHeaderexpanded.jsx b/frontend/src/components/OrgHeaderexpanded.jsx
index 268350a2..6946de94 100644
--- a/frontend/src/components/OrgHeaderexpanded.jsx
+++ b/frontend/src/components/OrgHeaderexpanded.jsx
@@ -2,7 +2,10 @@ import React, { useEffect } from "react";
import { makeStyles } from "@mui/styles";
import theme from '../theme.jsx';
-import { toast } from "react-toastify"
+import { toast } from "react-toastify"
+import Chip from '@mui/material/Chip';
+import Stack from '@mui/material/Stack';
+import AuthenticationData from "./AuthenticationWindow";
import {
FormControl,
@@ -25,6 +28,11 @@ import {
Grid,
IconButton,
Autocomplete,
+ Dialog,
+ DialogTitle,
+ DialogActions,
+ DialogContent,
+ Box
} from "@mui/material";
import {
@@ -158,7 +166,26 @@ const OrgHeaderexpanded = (props) => {
const [workflows, setWorkflows] = React.useState([])
const [workflow, setWorkflow] = React.useState({})
- const getAvailableWorkflows = (trigger_index) => {
+ // notification workflow
+ const [notificationWorkflowModal, setNotificationWorkflowModal] = React.useState(false);
+ const [selectedAppDetails, setSelectedAppDetails] = React.useState({});
+ const [notificationWorkflowTestModal, setNotificationWorkflowTestModal] = React.useState(false);
+ const [selectedAuth, setSelectedAuth] = React.useState('');
+ const [emailData,setEmailData] = React.useState([]);
+ const [notificationAppDetails, setNotificationAppDetails] = React.useState([]);
+ const [generatedWorkflow, setGeneatedWorkflow] = React.useState({});
+
+
+ // for jira & email modal
+ const [textFieldValue, setTextFieldValue] = React.useState("");
+ const [textFieldOneValue, setTextFieldOneValue] = React.useState("");
+
+ useEffect(() => {
+ let nameList = notificationAppList.length > 0? notificationAppList.map(item => item.name): ["email"];
+ prepareNotificationAppList(nameList)
+ }, [notificationAppList,workflows]);
+
+ const getAvailableWorkflows = (trigger_index) => {
fetch(globalUrl + "/api/v1/workflows", {
method: "GET",
headers: {
@@ -295,17 +322,684 @@ const OrgHeaderexpanded = (props) => {
);
+ const getAppIDs = async (appList) => {
+ fetch(globalUrl + "/api/v1/apps", {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ credentials: "include",
+ }).then((response) => {
+ if (response.status !== 200) {
+ toast("Failed getting app ids: ", response.reason);
+ console.log("Status not 200 for app ids :O!");
+ return;
+ }
+ return response.json();
+ }).then((responseJson) => {
+ if (responseJson !== undefined) {
+ // console.log("App ids: ", responseJson)
+ // console.log("App list: ", appList)
+ const filteredApps = responseJson.filter(app => appList.includes(app.name));
+ const appDetails = filteredApps.map(app => ({ name: app.name, id: app.id }));
+ return appDetails
+ // console.log("App IDs: ", appDetails)
+ }
+ }).catch((error) => {
+ console.log("Error getting app ids: " + error);
+ })
+}
+
+ // getting comms & cases app from app framework
+ var notificationAppList = [];
+ if (selectedOrganization.security_framework.cases && selectedOrganization.security_framework.cases.name.length > 0) {
+ notificationAppList = notificationAppList.concat(selectedOrganization.security_framework.cases);
+ }
+ if (selectedOrganization.security_framework.communication && selectedOrganization.security_framework.communication.name.length > 0) {
+ notificationAppList = notificationAppList.concat(selectedOrganization.security_framework.communication);
+ }
+
+ const mergeAuthData = (result, responseJson) => {
+ const updatedResult = result.map(item => {
+ const matches = responseJson.filter(authItem => authItem.app.name === item.name);
+ return {
+ ...item,
+ authentication_data: matches.length > 0 ? matches : null
+ };
+ });
+ return updatedResult;
+ };
+
+ const prepareNotificationAppList = async (appList) => {
+ // getting App ID,Authentication fields and saved auths for each app
+ var result = []
+ fetch(globalUrl + "/api/v1/apps", {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ credentials: "include",
+ }).then((response) => {
+ if (response.status !== 200) {
+ toast("Failed getting app ids: ", response.reason);
+ console.log("Status not 200 for app ids :O!");
+ return;
+ }
+ return response.json();
+ }).then((responseJson) => {
+ if (responseJson !== undefined) {
+ const filteredApps = responseJson.filter(app => appList.includes(app.name));
+ const emailData = responseJson.filter(app => app.name === "email")
+ setEmailData(emailData)
+ const appDetails = filteredApps.map(app => ({ name: app.name, id: app.id })); //mapped apps with IDs as sometime Ids were not correct in security framework
+ // console.log("appDetails: ", appDetails)
+ // result = appDetails
+
+ fetch(globalUrl + "/api/v1/apps/authentication", {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ credentials: "include",
+ })
+ .then((response) => {
+ if (response.status !== 200) {
+ toast(`Failed getting auth for : `, response.reason);
+ console.log("Status not 200 for app auth :O!");
+ return;
+ }
+ return response.json();
+ }).then(async (responseJson) => {
+ if (!responseJson.success) {
+ console.log("Could not get app auth")
+ return;
+ }
+ // console.log("responseJson of auth: ", responseJson.data)
+ result = await mergeAuthData(appDetails, responseJson.data)
+ // console.log("merged auth data: ", result)
+ // console.log("result", result)
+ result.map(item => {
+ fetch(globalUrl + `/api/v1/apps/${item.id}/config`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ credentials: "include",
+ }).then((response) => {
+ if (response.status !== 200) {
+ toast(`Failed getting config for ${item.id}: `, response.reason);
+ console.log("Status not 200 for app config :O!");
+ return;
+ }
+ return response.json();
+ }).then((responseJson) => {
+ if (!responseJson.success) {
+ console.log("Could not get app config")
+ return;
+ }
+ var decodedString = JSON.parse(atob(responseJson.app));
+ // console.log("dcodedString: ",decodedString)
+ item.auth_config = decodedString.authentication
+ item.large_image = decodedString.large_image
+ setNotificationAppDetails(result)
+ console.log("notificationAppDetails: ", notificationAppDetails)
+ }).then(async()=>{
+ await checkIfAlreadyGenerated(appList,workflows);
+
+ }).catch((error) => {
+ console.log("Error getting app config: " + error);
+ toast("Error getting app config: " + error);
+ })
+ })
+ })
+ }
+ }).catch((error) => {
+ console.log("Error getting app ids: " + error);
+ })
+ }
+
+
+ const executeTestWorkflow = async (workflowid) => {
+ const data = { "execution_argument": '{"title":"THIS IS TEST ALERT","description":"TEST ALERT FROM SHUFFLE","reference_url": "shuffler.io"}' }
+ fetch(globalUrl + `/api/v1/workflows/${workflowid}/execute`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ body: JSON.stringify(data),
+ credentials: "include",
+ })
+ .then((response) => {
+ if (response.status !== 200) {
+ toast("Failed setting notification workflow: ", response.reason);
+ console.log("Status not 200 for workflows :O!");
+ return;
+ }
+ toast("Notification workflow ran successfully");
+ return response.json();
+ }).catch((error) => {
+ console.log("Error getting workflows: " + error);
+ })
+}
+
+const generateNotificationWorkflow = async (appname,appImage,appAuthId,projectId,issuetype) => {
+ //currently only supports JIRA figure out a way to support more apps
+ var workflowName = `[GENERATED] ${appname} notification workflow`
+ var workflowDescription = "Generated by Shuffle for sending info/error notifications."
+ var data = {
+ "name": workflowName,
+ "description": workflowDescription,
+ }
+
+ fetch(globalUrl + "/api/v1/workflows", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ body: JSON.stringify(data),
+ credentials: "include",
+ })
+ .then((response) => {
+ if (response.status !== 200) {
+ toast("Failed setting notification workflow: ", response.reason);
+ console.log("Status not 200 for workflows :O!");
+ return;
+ }
+ return response.json();
+ }).then((responseJson)=>{
+ if (responseJson !== undefined) {
+ console.log("Notification workflow created successfully")
+ var workflow_id = responseJson.id
+ if (appname.toLowerCase() === "jira"){
+ console.log("updating workflow for JIRA")
+ var workflowBody = {
+ "name": workflowName,
+ "Description": workflowDescription,
+ "id": workflow_id,
+ "actions": [
+ {
+ "app_name": "Jira",
+ "name": "post_create_issue",
+ "authentication_id":appAuthId,
+ "large_image":appImage,
+ "isStartNode": true,
+ "label": "create_issue",
+ "app_version": "1.1.0",
+ "parameters": [
+ {
+ "name": "body",
+ "value": `{"fields": { "project": {"key": "${projectId}"},"summary": "$exec.title","issuetype": {"name": "${issuetype}"},"description": {"content": [{"content":[{"type":"text","text":"$exec.description"}],"type": "paragraph"}],"type": "doc","version": 1}}}`
+ },
+ {
+ "name": "username_basic",
+ "value": ""
+ },
+ {
+ "name": "password_basic",
+ "value": ""
+ },
+ {
+ "name": "url",
+ "value": ""
+ },
+ {
+ "name": "headers",
+ "value": "Content-type=application/json \nAccept=application/json"
+ },
+ {
+ "name": "queries",
+ "value": ""
+ },
+ {
+ "name": "ssl_verify",
+ "value": "False"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ fetch(globalUrl + `/api/v1/workflows/${workflow_id}`, {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ body: JSON.stringify(workflowBody),
+ credentials: "include",
+ })
+ .then((response) => {
+ if (response.status !== 200) {
+ toast("Failed setting notification workflow: ", response.reason);
+ console.log("Status not 200 for workflows :O!");
+ return;
+ }
+ return response.json();
+ }).then((responseJson)=>{
+ if (responseJson !== undefined) {
+ handleEditOrg(
+ orgName,
+ orgDescription,
+ selectedOrganization.id,
+ selectedOrganization.image,
+ {
+ app_download_repo: appDownloadUrl,
+ app_download_branch: appDownloadBranch,
+ workflow_download_repo: workflowDownloadUrl,
+ workflow_download_branch: workflowDownloadBranch,
+ notification_workflow: workflow_id,
+ documentation_reference: documentationReference,
+ },
+ {
+ sso_entrypoint: ssoEntrypoint,
+ sso_certificate: ssoCertificate,
+ client_id: openidClientId,
+ client_secret: openidClientSecret,
+ openid_authorization: openidAuthorization,
+ openid_token: openidToken,
+ }
+ )
+ console.log("Notification workflow updated successfully")
+ toast("Notification workflow updated successfully")
+ }
+ })
+ }
+ }).catch((error) => {
+ console.log("Error setting workflows: " + error);
+ })
+}
+
+const generateEmailNotificationWorkflow = async (appname,appImage,shuffleAPIKey,recepients) => {
+ //currently only supports figure out a way to support more apps
+ var workflowName = `[GENERATED] ${appname} notification workflow`
+ var workflowDescription = "Generated by Shuffle for sending info/error notifications."
+ var data = {
+ "name": workflowName,
+ "description": workflowDescription,
+ }
+
+ fetch(globalUrl + "/api/v1/workflows", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ body: JSON.stringify(data),
+ credentials: "include",
+ })
+ .then((response) => {
+ if (response.status !== 200) {
+ toast("Failed setting notification workflow: ", response.reason);
+ console.log("Status not 200 for workflows :O!");
+ return;
+ }
+ return response.json();
+ }).then((responseJson)=>{
+ if (responseJson !== undefined) {
+ console.log("Notification workflow created successfully")
+ var workflow_id = responseJson.id
+ if (appname.toLowerCase() === "email"){
+ console.log("updating workflow for email")
+ var workflowBody = {
+ "name": workflowName,
+ "Description": workflowDescription,
+ "id": workflow_id,
+ "actions": [
+ {
+ "app_name": "email",
+ "name": "send_email_shuffle",
+ "large_image":appImage,
+ "isStartNode": true,
+ "label": "send_email_shuffle",
+ "app_version": "1.3.0",
+ "parameters": [
+ {
+ "name": "apikey",
+ "value": shuffleAPIKey
+ },
+ {
+ "name": "recipients",
+ "value": recepients
+ },
+ {
+ "name": "subject",
+ "value": "$exec.title"
+ },
+ {
+ "name":"body",
+ "value":"$exec.description"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ fetch(globalUrl + `/api/v1/workflows/${workflow_id}`, {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ body: JSON.stringify(workflowBody),
+ credentials: "include",
+ })
+ .then((response) => {
+ if (response.status !== 200) {
+ toast("Failed setting notification workflow: ", response.reason);
+ console.log("Status not 200 for workflows :O!");
+ return;
+ }
+ return response.json();
+ }).then((responseJson)=>{
+ if (responseJson !== undefined) {
+ handleEditOrg(
+ orgName,
+ orgDescription,
+ selectedOrganization.id,
+ selectedOrganization.image,
+ {
+ app_download_repo: appDownloadUrl,
+ app_download_branch: appDownloadBranch,
+ workflow_download_repo: workflowDownloadUrl,
+ workflow_download_branch: workflowDownloadBranch,
+ notification_workflow: workflow_id,
+ documentation_reference: documentationReference,
+ },
+ {
+ sso_entrypoint: ssoEntrypoint,
+ sso_certificate: ssoCertificate,
+ client_id: openidClientId,
+ client_secret: openidClientSecret,
+ openid_authorization: openidAuthorization,
+ openid_token: openidToken,
+ }
+ )
+ console.log("Notification workflow updated successfully")
+ toast("Notification workflow updated successfully")
+ }
+ })
+ }
+ }).catch((error) => {
+ console.log("Error setting workflows: " + error);
+ })
+}
+
+
+const testWorkflowModal = notificationWorkflowTestModal ?
+ () : null
+
+const modalView = notificationWorkflowModal ? (
+
+) : null
+
+
+ const checkIfAlreadyGenerated = async (appList, workflows) => { // fixxxxxxxxxxxxxxxxxxxxx
+
+ var workflowName = workflows.find(workflow => workflow.id === notificationWorkflow)
+ if (workflowName) {
+ workflowName = workflowName.name
+ }
+ else {
+ console.log("no workflow set")
+ return
+ }
+ if (workflowName) {
+ const parts = workflowName.split(' ');
+ console.log("parts", parts)
+ if (parts[0].toString() === "[GENERATED]" && parts.length > 1) {
+ console.log("parts1", parts[1])
+ if ((appList.includes(parts[1]))) {
+ console.log("workflow already generated")
+ setGeneatedWorkflow({"app_name": parts[1]})
+ }
+ }
+ }
+ else {
+ return
+ }
+ }
+
+const renderChips = (apps) => {
+ return (
+ }
+
+ />
+ ))}
+