@@ -18,7 +18,7 @@ import (
18
18
)
19
19
20
20
//Import is able to create a new workflow and all its components
21
- func Import (ctx context.Context , db gorpmapper.SqlExecutorWithTx , store cache.Store , proj sdk.Project , oldW , w * sdk.Workflow , u sdk.Identifiable , force bool , msgChan chan <- sdk.Message ) error {
21
+ func Import (ctx context.Context , db gorpmapper.SqlExecutorWithTx , store cache.Store , proj sdk.Project , oldW , w * sdk.Workflow , u sdk.Identifiable , opts ImportOptions , msgChan chan <- sdk.Message ) error {
22
22
ctx , end := telemetry .Span (ctx , "workflow.Import" )
23
23
defer end ()
24
24
@@ -29,6 +29,30 @@ func Import(ctx context.Context, db gorpmapper.SqlExecutorWithTx, store cache.St
29
29
w .WorkflowData .Node .Context = & sdk.NodeContext {}
30
30
}
31
31
32
+ // If the import is not done by a direct user (ie. from a hook or if the content is coming from a repository)
33
+ // We don't take permission in account and we only keep permission of the oldWorkflow or projet permission
34
+ if opts .HookUUID != "" || opts .RepositoryName != "" {
35
+ log .Info (ctx , "Import is perform from 'as-code', we don't take groups in account (hookUUID=%q, repository=%q)" , opts .HookUUID , opts .RepositoryName )
36
+ // reset permissions at the workflow level
37
+ w .Groups = nil
38
+ if oldW != nil {
39
+ w .Groups = oldW .Groups
40
+ }
41
+ // reset permissions at the node level
42
+ w .VisitNode (func (n * sdk.Node , w * sdk.Workflow ) {
43
+ n .Groups = nil
44
+ if oldW != nil {
45
+ oldN := oldW .WorkflowData .NodeByName (n .Name )
46
+ if oldN != nil {
47
+ n .Groups = oldN .Groups
48
+ }
49
+ }
50
+ })
51
+ } else {
52
+ // The import is triggered by a user, we have to check the groups
53
+ // FIXME: call the same function than the handlers
54
+ }
55
+
32
56
// create the workflow if not exists
33
57
if oldW == nil {
34
58
if err := Insert (ctx , db , store , proj , w ); err != nil {
@@ -44,11 +68,11 @@ func Import(ctx context.Context, db gorpmapper.SqlExecutorWithTx, store cache.St
44
68
w .Icon = oldW .Icon
45
69
}
46
70
47
- if ! force {
71
+ if ! opts . Force {
48
72
return sdk .NewErrorFrom (sdk .ErrAlreadyExist , "workflow exists" )
49
73
}
50
74
51
- if force && oldW != nil && oldW .FromRepository != "" && w .FromRepository == "" {
75
+ if opts . Force && oldW != nil && oldW .FromRepository != "" && w .FromRepository == "" {
52
76
if err := detachResourceFromRepository (db , proj .ID , oldW , msgChan ); err != nil {
53
77
return err
54
78
}
0 commit comments