Skip to content

Commit

Permalink
ADD duplicate flow action API.
Browse files Browse the repository at this point in the history
  • Loading branch information
karminski committed Dec 19, 2023
1 parent 053cdde commit a55e85a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
47 changes: 37 additions & 10 deletions src/controller/flow_action_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,27 +299,54 @@ func (controller *Controller) RunFlowActionInternal(c *gin.Context) {
c.JSON(http.StatusOK, flowActionRunResult)
}

func (controller *Controller) ReleaseFlowActionsInternal(c *gin.Context) {
func (controller *Controller) DuplicateFlowActionsInternal(c *gin.Context) {
// fetch needed param
teamID, errInGetTeamID := controller.GetMagicIntParamFromRequest(c, PARAM_TEAM_ID)
teamIDInString, errInGetTeamIDInString := controller.GetStringParamFromRequest(c, PARAM_TEAM_ID)
workflowID, errInGetWorkflowID := controller.GetMagicIntParamFromRequest(c, PARAM_WORKFLOW_ID)
workflowIDInString, errInGetWorkflowIDInString := controller.GetStringParamFromRequest(c, PARAM_WORKFLOW_ID)
version, errInGetVersion := controller.GetMagicIntParamFromRequest(c, PARAM_VERSION)
versionInString, errInGetVersionInString := controller.GetStringParamFromRequest(c, PARAM_VERSION)
fromTeamID, errInGetFromTeamID := controller.GetMagicIntParamFromRequest(c, PARAM_FROM_TEAM_ID)
fromTeamIDInString, errInGetFromTeamIDInString := controller.GetStringParamFromRequest(c, PARAM_FROM_TEAM_ID)
toTeamID, errInGetToTeamID := controller.GetMagicIntParamFromRequest(c, PARAM_TO_TEAM_ID)
toTeamIDInString, errInGetToTeamIDInString := controller.GetStringParamFromRequest(c, PARAM_TO_TEAM_ID)
fromWorkflowID, errInGetFromWorkflowID := controller.GetMagicIntParamFromRequest(c, PARAM_FROM_WORKFLOW_ID)
fromWorkflowIDInString, errInGetFromWorkflowIDInString := controller.GetStringParamFromRequest(c, PARAM_FROM_WORKFLOW_ID)
toWorkflowID, errInGetToWorkflowID := controller.GetMagicIntParamFromRequest(c, PARAM_TO_WORKFLOW_ID)
toWorkflowIDInString, errInGetToWorkflowIDInString := controller.GetStringParamFromRequest(c, PARAM_TO_WORKFLOW_ID)

fromVersion, errInGetFromVersion := controller.GetIntParamFromRequest(c, PARAM_FROM_VERSION)
fromVersionInString, errInGetFromVersionInString := controller.GetStringParamFromRequest(c, PARAM_FROM_VERSION)
toVersion, errInGetToVersion := controller.GetIntParamFromRequest(c, PARAM_TO_VERSION)
toVersionInString, errInGetToVersionInString := controller.GetStringParamFromRequest(c, PARAM_TO_VERSION)

isForkWorkflowRaw, _ := controller.TestFirstStringParamValueFromURI(c, PARAM_IS_FORK_WORKFLOW)
isForkWorkflow := false
if isForkWorkflowRaw == "true" {
isForkWorkflow = true
}

userID, errInGetUserID := controller.GetUserIDFromAuth(c)
if errInGetTeamID != nil || errInGetWorkflowID != nil || errInGetTeamIDInString != nil || errInGetWorkflowIDInString != nil || errInGetVersion != nil || errInGetVersionInString != nil || errInGetUserID != nil {

if errInGetFromTeamID != nil ||
errInGetFromTeamIDInString != nil ||
errInGetToTeamID != nil ||
errInGetToTeamIDInString != nil ||
errInGetFromWorkflowID != nil ||
errInGetFromWorkflowIDInString != nil ||
errInGetToWorkflowID != nil ||
errInGetToWorkflowIDInString != nil ||
errInGetFromVersion != nil ||
errInGetFromVersionInString != nil ||
errInGetToVersion != nil ||
errInGetToVersionInString != nil ||
errInGetUserID != nil {
return
}

// validate request data
validated, errInValidate := controller.ValidateRequestTokenFromHeader(c, teamIDInString, workflowIDInString, versionInString)
validated, errInValidate := controller.ValidateRequestTokenFromHeader(c, fromTeamIDInString, toTeamIDInString, fromWorkflowIDInString, toWorkflowIDInString, fromVersionInString, toVersionInString)
if !validated && errInValidate != nil {
return
}

// dupliate flow actions
errInDuplicate := controller.duplicateFlowActionByVersion(c, teamID, teamID, workflowID, workflowID, model.FLOW_ACTION_EDIT_VERSION, version, userID, false)
errInDuplicate := controller.duplicateFlowActionByVersion(c, fromTeamID, toTeamID, fromWorkflowID, toWorkflowID, fromVersion, toVersion, userID, isForkWorkflow)
if errInDuplicate != nil {
return
}
Expand Down
6 changes: 6 additions & 0 deletions src/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const (
PARAM_FLOW_ACTION_ID = "flowActionID"
PARAM_EXPIRE_AT = "expireAt"
PARAM_ACTION_TYPE = "actionType"
PARAM_FROM_TEAM_ID = "fromTeamID"
PARAM_FROM_WORKFLOW_ID = "fromWorkflowID"
PARAM_TO_WORKFLOW_ID = "toWorkflowID"
PARAM_FROM_VERSION = "fromVersion"
PARAM_TO_VERSION = "toVersion"
PARAM_IS_FORK_WORKFLOW = "isForkWorkflow"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion src/internalrouter/internal_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (r *Router) RegisterRouters(engine *gin.Engine) {
teamsRouter := routerGroup.Group("/teams")
appRouter := routerGroup.Group("/apps")
flowActionRouter := routerGroup.Group("/teams/:teamID/workflow/:workflowID/flowActions")
flowActionRDuplicateouter := routerGroup.Group("/duplicateFlowActoins/fromTeamID/:fromTeamID/toTeamID/:toTeamID/fromWorkflowID/:fromWorkflowID/toWorkflowID/:toWorkflowID/fromVersion/:fromVersion/toVersion/:toVersion")

// teams routers
teamsRouter.PATCH("/:teamID/apps/:appID", r.Controller.PublishAppToMarketplaceInternal)
Expand All @@ -35,6 +36,6 @@ func (r *Router) RegisterRouters(engine *gin.Engine) {
flowActionRouter.GET("/version/:version/type/:actionType", r.Controller.GetWorkflowFlowActionsByTypeInternal)
flowActionRouter.GET("/id/:actionID", r.Controller.GetWorkflowFlowActionByIDInternal)
flowActionRouter.POST("/:flowActionID/run", r.Controller.RunFlowActionInternal)
flowActionRouter.POST("/version/:version/release", r.Controller.ReleaseFlowActionsInternal)
flowActionRDuplicateouter.POST("", r.Controller.DuplicateFlowActionsInternal)

}

0 comments on commit a55e85a

Please sign in to comment.