Skip to content

Commit

Permalink
Don't include db-trigger maintained status groups in engine assets
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Oct 7, 2024
1 parent a6e5e46 commit e539e9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 8 additions & 3 deletions core/models/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,21 @@ func NewOrgAssets(ctx context.Context, rt *runtime.Runtime, orgID OrgID, prev *O
}

if prev == nil || refresh&RefreshGroups > 0 {
oa.groups, err = loadAssetType(ctx, db, orgID, "groups", loadGroups)
groups, err := loadAssetType(ctx, db, orgID, "groups", loadGroups)
if err != nil {
return nil, fmt.Errorf("error loading group assets for org %d: %w", orgID, err)
}
oa.groupsByID = make(map[GroupID]*Group)
oa.groupsByUUID = make(map[assets.GroupUUID]*Group)
oa.groups = make([]assets.Group, 0, len(groups))
oa.groupsByID = make(map[GroupID]*Group, len(groups))
oa.groupsByUUID = make(map[assets.GroupUUID]*Group, len(groups))
for _, g := range oa.groups {
group := g.(*Group)
oa.groupsByID[group.ID()] = group
oa.groupsByUUID[group.UUID()] = group

if group.Visible() {
oa.groups = append(oa.groups, g)
}
}
} else {
oa.groups = prev.groups
Expand Down
4 changes: 2 additions & 2 deletions core/models/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ func (c *Contact) FlowContact(oa *OrgAssets) (*flows.Contact, error) {
// convert our groups to a list of references
groups := make([]*assets.GroupReference, 0, len(c.groups))
for _, g := range c.groups {
// exclude the db-trigger based status groups for now
if g.Type() == GroupTypeManual || g.Type() == GroupTypeSmart {
// exclude the db-trigger based status groups
if g.Visible() {
groups = append(groups, assets.NewGroupReference(g.UUID(), g.Name()))
}
}
Expand Down
12 changes: 9 additions & 3 deletions core/models/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ const (
type GroupType string

const (
GroupTypeManual = GroupType("M")
GroupTypeSmart = GroupType("Q")
GroupTypeDBStopped = GroupType("S")
GroupTypeDBActive = GroupType("A")
GroupTypeDBBlocked = GroupType("B")
GroupTypeDBStopped = GroupType("S")
GroupTypeDBArchived = GroupType("V")
GroupTypeManual = GroupType("M")
GroupTypeSmart = GroupType("Q")
)

// Group is our mailroom type for contact groups
Expand Down Expand Up @@ -60,6 +63,9 @@ func (g *Group) Status() GroupStatus { return g.Status_ }
// Type returns the type of this group
func (g *Group) Type() GroupType { return g.Type_ }

// Visible returns whether this group is visible to the engine (status groups are not)
func (g *Group) Visible() bool { return g.Type_ == GroupTypeManual || g.Type_ == GroupTypeSmart }

// loads the groups for the passed in org
func loadGroups(ctx context.Context, db *sql.DB, orgID OrgID) ([]assets.Group, error) {
rows, err := db.QueryContext(ctx, sqlSelectGroupsByOrg, orgID)
Expand Down

0 comments on commit e539e9e

Please sign in to comment.