Skip to content

Commit

Permalink
PROBLEM-1292_iAuditor Exporter - group_users table not working with m…
Browse files Browse the repository at this point in the history
…ultiple orgs (#207)

* support upsert

* add to test mock files

* Fix test files

* Truncate to false and remove duplicate orgId

* Update feed_group_user.go
  • Loading branch information
atexAtewologun authored Feb 9, 2022
1 parent a0aa784 commit 7fc0751
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
12 changes: 8 additions & 4 deletions internal/app/feed/feed_group_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ func (f *GroupUserFeed) Export(ctx context.Context, apiClient *api.Client, expor
logger.Infof("%s: exporting for org_id: %s", feedName, orgID)

exporter.InitFeed(f, &InitFeedOptions{
// Clear this table before loading data.
// This table does not receive updates, it is only refreshed.
Truncate: true,
// Truncate files if upserts aren't supported.
// This ensure that the export does not contain duplicate rows
Truncate: false,
})

err := apiClient.DrainFeed(ctx, &api.GetFeedRequest{
// Delete the actions if already exist
err := exporter.DeleteRowsIfExist(f, "organisation_id = ?", orgID)
util.Check(err, "Failed to delete rows in exporter")

err = apiClient.DrainFeed(ctx, &api.GetFeedRequest{
InitialURL: "/feed/group_users",
Params: api.GetFeedParams{},
}, func(resp *api.GetFeedResponse) error {
Expand Down
12 changes: 8 additions & 4 deletions internal/app/feed/mocks/set_2/feed_group_users_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
"data": [
{
"user_id": "user_1",
"group_id": "role_group3"
"group_id": "role_group3",
"organisation_id": "role_123"
},
{
"user_id": "user_1",
"group_id": "role_group4"
"group_id": "role_group4",
"organisation_id": "role_123"
},
{
"user_id": "user_2",
"group_id": "role_group3"
"group_id": "role_group3",
"organisation_id": "role_123"
},
{
"user_id": "user_2",
"group_id": "role_group4"
"group_id": "role_group4",
"organisation_id": "role_123"
}
]
}
8 changes: 4 additions & 4 deletions internal/app/feed/mocks/set_2/outputs/group_users.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
user_id,group_id,organisation_id,exported_at
user_1,role_group3,,--date--
user_2,role_group3,,--date--
user_1,role_group4,,--date--
user_2,role_group4,,--date--
user_1,role_group3,role_123,--date--
user_2,role_group3,role_123,--date--
user_1,role_group4,role_123,--date--
user_2,role_group4,role_123,--date--

0 comments on commit 7fc0751

Please sign in to comment.