BUG: Added organization for workflow imports

This commit is contained in:
frikky
2020-12-08 11:12:39 +01:00
parent 6ae79cc87d
commit 0adb4bbaaf
3 changed files with 30 additions and 8 deletions
+6 -1
View File
@@ -7361,7 +7361,12 @@ func runInit(ctx context.Context) {
if len(workflows) == 0 { if len(workflows) == 0 {
username := os.Getenv("SHUFFLE_DOWNLOAD_WORKFLOW_USERNAME") username := os.Getenv("SHUFFLE_DOWNLOAD_WORKFLOW_USERNAME")
password := os.Getenv("SHUFFLE_DOWNLOAD_WORKFLOW_PASSWORD") password := os.Getenv("SHUFFLE_DOWNLOAD_WORKFLOW_PASSWORD")
err = loadGithubWorkflows(workflowLocation, username, password, "", os.Getenv("SHUFFLE_DOWNLOAD_WORKFLOW_BRANCH")) orgId := ""
if len(activeOrgs) > 0 {
orgId = activeOrgs[0].Id
}
err = loadGithubWorkflows(workflowLocation, username, password, "", os.Getenv("SHUFFLE_DOWNLOAD_WORKFLOW_BRANCH"), orgId)
if err != nil { if err != nil {
log.Printf("Failed to upload workflows from github: %s", err) log.Printf("Failed to upload workflows from github: %s", err)
} else { } else {
+23 -6
View File
@@ -4906,7 +4906,7 @@ func deployWebhookFunction(ctx context.Context, name, localization, applocation
return nil return nil
} }
func loadGithubWorkflows(url, username, password, userId, branch string) error { func loadGithubWorkflows(url, username, password, userId, branch, orgId string) error {
fs := memfs.New() fs := memfs.New()
log.Printf("Starting load of %s with branch %s", url, branch) log.Printf("Starting load of %s with branch %s", url, branch)
@@ -4943,7 +4943,7 @@ func loadGithubWorkflows(url, username, password, userId, branch string) error {
_ = r _ = r
log.Printf("Starting workflow folder iteration") log.Printf("Starting workflow folder iteration")
iterateWorkflowGithubFolders(fs, dir, "", "", userId) iterateWorkflowGithubFolders(fs, dir, "", "", userId, orgId)
} else if strings.Contains(url, "s3") { } else if strings.Contains(url, "s3") {
//https://docs.aws.amazon.com/sdk-for-go/api/service/s3/ //https://docs.aws.amazon.com/sdk-for-go/api/service/s3/
@@ -5018,7 +5018,7 @@ func loadSpecificWorkflows(resp http.ResponseWriter, request *http.Request) {
} }
// Field3 = branch // Field3 = branch
err = loadGithubWorkflows(tmpBody.URL, tmpBody.Field1, tmpBody.Field2, user.Id, tmpBody.Field3) err = loadGithubWorkflows(tmpBody.URL, tmpBody.Field1, tmpBody.Field2, user.Id, tmpBody.Field3, user.ActiveOrg.Id)
if err != nil { if err != nil {
log.Printf("Failed to update workflows: %s", err) log.Printf("Failed to update workflows: %s", err)
resp.WriteHeader(401) resp.WriteHeader(401)
@@ -5326,7 +5326,7 @@ func iterateOpenApiGithub(fs billy.Filesystem, dir []os.FileInfo, extra string,
} }
// Onlyname is used to // Onlyname is used to
func iterateWorkflowGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra string, onlyname string, userId string) error { func iterateWorkflowGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra string, onlyname, userId, orgId string) error {
var err error var err error
for _, file := range dir { for _, file := range dir {
@@ -5345,7 +5345,7 @@ func iterateWorkflowGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra
} }
// Go routine? Hmm, this can be super quick I guess // Go routine? Hmm, this can be super quick I guess
err = iterateWorkflowGithubFolders(fs, dir, tmpExtra, "", userId) err = iterateWorkflowGithubFolders(fs, dir, tmpExtra, "", userId, orgId)
if err != nil { if err != nil {
continue continue
} }
@@ -5377,13 +5377,30 @@ func iterateWorkflowGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra
workflow.Owner = userId workflow.Owner = userId
} }
workflow.ID = uuid.NewV4().String()
workflow.OrgId = orgId
workflow.ExecutingOrg = Org{
Id: orgId,
}
workflow.Org = append(workflow.Org, Org{
Id: orgId,
})
/*
q := datastore.NewQuery("workflow").Filter("owner =", user.Id)
if user.Role == "admin" {
q = datastore.NewQuery("workflow").Filter("org_id =", user.ActiveOrg.Id)
*/
ctx := context.Background() ctx := context.Background()
err = setWorkflow(ctx, workflow, workflow.ID) err = setWorkflow(ctx, workflow, workflow.ID)
if err != nil { if err != nil {
log.Printf("Failed setting (download) workflow: %s", err) log.Printf("Failed setting (download) workflow: %s", err)
continue continue
} }
log.Printf("Uploaded workflow %s for user %s!", filename, userId)
log.Printf("Uploaded workflow %s for user %s and org %s!", filename, userId, orgId)
} }
} }
} }
+1 -1
View File
@@ -1204,7 +1204,7 @@ const Workflows = (props) => {
<div style={workflowViewStyle}> <div style={workflowViewStyle}>
<div style={{display: "flex"}}> <div style={{display: "flex"}}>
<div style={{flex: "4"}}> <div style={{flex: "4"}}>
<h2>Workflows</h2> <h2>Workflows ({workflows.length})</h2>
</div> </div>
<div style={{marginTop: 20}}> <div style={{marginTop: 20}}>
{workflowButtons} {workflowButtons}