Skip to content

Commit e00239e

Browse files
committed
added function to check of an organization name already exists in the session scope
1 parent bf7f495 commit e00239e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

engine/plugins/support/org/find.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func dedupChecks(sess et.Session, obj *dbt.Entity, o *oamorg.Organization) *dbt.
5858
}
5959
}
6060

61+
if org, found := nameExistsInSessionScope(sess, o); found {
62+
return org
63+
}
64+
6165
return nil
6266
}
6367

@@ -83,6 +87,26 @@ func nameExistsInContactRecord(sess et.Session, cr *dbt.Entity, names []string)
8387
return nil, false
8488
}
8589

90+
func nameExistsInSessionScope(sess et.Session, o *oamorg.Organization) (*dbt.Entity, bool) {
91+
ctx, cancel := context.WithTimeout(sess.Ctx(), 10*time.Second)
92+
defer cancel()
93+
94+
ents, err := sess.DB().FindEntitiesByContent(ctx, oam.Organization, time.Time{}, 0, dbt.ContentFilters{
95+
"name": o.Name,
96+
})
97+
if err != nil || len(ents) == 0 {
98+
return nil, false
99+
}
100+
101+
for _, ent := range ents {
102+
if _, err := sess.Scope().IsAssociated(&et.Association{Submission: ent}); err == nil {
103+
return ent, true
104+
}
105+
}
106+
107+
return nil, false
108+
}
109+
86110
func nameRelatedToOrganization(sess et.Session, orgent *dbt.Entity, names []string) (*dbt.Entity, bool) {
87111
if orgent == nil {
88112
return nil, false

0 commit comments

Comments
 (0)