Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(authN) - Add updated_by to inserts #360 #410

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/samber/lo v1.47.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.10.0
github.com/vektah/gqlparser/v2 v2.5.19
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
)
Expand Down Expand Up @@ -85,7 +86,6 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/vektah/gqlparser/v2 v2.5.19 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions internal/app/activity/activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (a *activityHandler) CreateActivity(activity *entity.Activity) (*entity.Act
l.Error(err)
return nil, NewActivityHandlerError("Internal error while creating activity (GetUserId).")
}
activity.UpdatedBy = activity.CreatedBy

newActivity, err := a.database.CreateActivity(activity)

Expand Down
1 change: 1 addition & 0 deletions internal/app/component/component_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (cs *componentHandler) CreateComponent(component *entity.Component) (*entit
l.Error(err)
return nil, NewUserHandlerError("Internal error while creating component (GetUserId).")
}
component.UpdatedBy = component.CreatedBy

components, err := cs.ListComponents(f, &entity.ListOptions{})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (ci *componentInstanceHandler) CreateComponentInstance(componentInstance *e
l.Error(err)
return nil, NewComponentInstanceHandlerError("Internal error while creating componentInstance (GetUserId).")
}
componentInstance.UpdatedBy = componentInstance.CreatedBy

newComponentInstance, err := ci.database.CreateComponentInstance(componentInstance)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (cv *componentVersionHandler) CreateComponentVersion(componentVersion *enti
l.Error(err)
return nil, NewComponentVersionHandlerError("Internal error while creating componentVersion (GetUserId).")
}
componentVersion.UpdatedBy = componentVersion.CreatedBy

newComponent, err := cv.database.CreateComponentVersion(componentVersion)

Expand Down
1 change: 1 addition & 0 deletions internal/app/evidence/evidence_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (e *evidenceHandler) CreateEvidence(evidence *entity.Evidence) (*entity.Evi
l.Error(err)
return nil, NewEvidenceHandlerError("Internal error while creating evidence (GetUserId).")
}
evidence.UpdatedBy = evidence.CreatedBy

newEvidence, err := e.database.CreateEvidence(evidence)

Expand Down
1 change: 1 addition & 0 deletions internal/app/issue/issue_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (is *issueHandler) CreateIssue(issue *entity.Issue) (*entity.Issue, error)
l.Error(err)
return nil, NewIssueHandlerError("Internal error while creating issue (GetUserId).")
}
issue.UpdatedBy = issue.CreatedBy

issues, err := is.ListIssues(f, &entity.IssueListOptions{})

Expand Down
1 change: 1 addition & 0 deletions internal/app/issue_match/issue_match_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (im *issueMatchHandler) CreateIssueMatch(issueMatch *entity.IssueMatch) (*e
l.Error(err)
return nil, NewIssueMatchHandlerError("Internal error while retrieving effective severity (GetUserId).")
}
issueMatch.UpdatedBy = issueMatch.CreatedBy

severityFilter := &entity.SeverityFilter{
IssueId: []*int64{&issueMatch.IssueId},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (imc *issueMatchChangeHandler) CreateIssueMatchChange(issueMatchChange *ent
l.Error(err)
return nil, NewIssueMatchChangeHandlerError("Internal error while creating issueMatchChange (GetUserId).")
}
issueMatchChange.UpdatedBy = issueMatchChange.CreatedBy

newIssueMatchChange, err := imc.database.CreateIssueMatchChange(issueMatchChange)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (ir *issueRepositoryHandler) CreateIssueRepository(issueRepository *entity.
l.Error(err)
return nil, NewIssueRepositoryHandlerError("Internal error while creating issueRepository (GetUserId).")
}
issueRepository.BaseIssueRepository.UpdatedBy = issueRepository.BaseIssueRepository.CreatedBy

issueRepositories, err := ir.ListIssueRepositories(f, &entity.ListOptions{})

Expand Down
1 change: 1 addition & 0 deletions internal/app/issue_variant/issue_variant_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (iv *issueVariantHandler) CreateIssueVariant(issueVariant *entity.IssueVari
l.Error(err)
return nil, NewIssueVariantHandlerError("Internal error while creating issueVariant (GetUserId).")
}
issueVariant.UpdatedBy = issueVariant.CreatedBy

issueVariants, err := iv.ListIssueVariants(f, &entity.ListOptions{})

Expand Down
1 change: 1 addition & 0 deletions internal/app/service/service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (s *serviceHandler) CreateService(service *entity.Service) (*entity.Service
l.Error(err)
return nil, NewServiceHandlerError("Internal error while creating service (GetUserId).")
}
service.BaseService.UpdatedBy = service.BaseService.CreatedBy

services, err := s.ListServices(f, &entity.ListOptions{})

Expand Down
1 change: 1 addition & 0 deletions internal/app/support_group/support_group_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (sg *supportGroupHandler) CreateSupportGroup(supportGroup *entity.SupportGr
l.Error(err)
return nil, NewSupportGroupHandlerError("Internal error while creating supportGroup (GetUserId).")
}
supportGroup.UpdatedBy = supportGroup.CreatedBy

supportGroups, err := sg.ListSupportGroups(f, &entity.ListOptions{})

Expand Down
1 change: 1 addition & 0 deletions internal/app/user/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (u *userHandler) CreateUser(user *entity.User) (*entity.User, error) {
l.Error(err)
return nil, NewUserHandlerError("Internal error while creating user (GetUserId).")
}
user.UpdatedBy = user.CreatedBy

users, err := u.ListUsers(f, &entity.ListOptions{})

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ func (s *SqlDatabase) CreateActivity(activity *entity.Activity) (*entity.Activit
query := `
INSERT INTO Activity (
activity_status,
activity_created_by
activity_created_by,
activity_updated_by
) VALUES (
:activity_status,
:activity_created_by
:activity_created_by,
:activity_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ func (s *SqlDatabase) CreateComponent(component *entity.Component) (*entity.Comp
INSERT INTO Component (
component_ccrn,
component_type,
component_created_by
component_created_by,
component_updated_by
) VALUES (
:component_ccrn,
:component_type,
:component_created_by
:component_created_by,
:component_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/component_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ func (s *SqlDatabase) CreateComponentInstance(componentInstance *entity.Componen
componentinstance_count,
componentinstance_component_version_id,
componentinstance_service_id,
componentinstance_created_by
componentinstance_created_by,
componentinstance_updated_by
) VALUES (
:componentinstance_ccrn,
:componentinstance_count,
:componentinstance_component_version_id,
:componentinstance_service_id,
:componentinstance_created_by
:componentinstance_created_by,
:componentinstance_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/component_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ func (s *SqlDatabase) CreateComponentVersion(componentVersion *entity.ComponentV
INSERT INTO ComponentVersion (
componentversion_component_id,
componentversion_version,
componentversion_created_by
componentversion_created_by,
componentversion_updated_by
) VALUES (
:componentversion_component_id,
:componentversion_version,
:componentversion_created_by
:componentversion_created_by,
:componentversion_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func (s *SqlDatabase) CreateEvidence(evidence *entity.Evidence) (*entity.Evidenc
evidence_vector,
evidence_rating,
evidence_raa_end,
evidence_created_by
evidence_created_by,
evidence_updated_by
) VALUES (
:evidence_author_id,
:evidence_activity_id,
Expand All @@ -233,7 +234,8 @@ func (s *SqlDatabase) CreateEvidence(evidence *entity.Evidence) (*entity.Evidenc
:evidence_vector,
:evidence_rating,
:evidence_raa_end,
:evidence_created_by
:evidence_created_by,
:evidence_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,14 @@ func (s *SqlDatabase) CreateIssue(issue *entity.Issue) (*entity.Issue, error) {
issue_primary_name,
issue_type,
issue_description,
issue_created_by
issue_created_by,
issue_updated_by
) VALUES (
:issue_primary_name,
:issue_type,
:issue_description,
:issue_created_by
:issue_created_by,
:issue_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/issue_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ func (s *SqlDatabase) CreateIssueMatch(issueMatch *entity.IssueMatch) (*entity.I
issuematch_user_id,
issuematch_component_instance_id,
issuematch_issue_id,
issuematch_created_by
issuematch_created_by,
issuematch_updated_by
) VALUES (
:issuematch_status,
:issuematch_remediation_date,
Expand All @@ -284,7 +285,8 @@ func (s *SqlDatabase) CreateIssueMatch(issueMatch *entity.IssueMatch) (*entity.I
:issuematch_user_id,
:issuematch_component_instance_id,
:issuematch_issue_id,
:issuematch_created_by
:issuematch_created_by,
:issuematch_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/issue_match_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ func (s *SqlDatabase) CreateIssueMatchChange(imc *entity.IssueMatchChange) (*ent
issuematchchange_action,
issuematchchange_activity_id,
issuematchchange_issue_match_id,
issuematchchange_created_by
issuematchchange_created_by,
issuematchchange_updated_by
) VALUES (
:issuematchchange_action,
:issuematchchange_activity_id,
:issuematchchange_issue_match_id,
:issuematchchange_created_by
:issuematchchange_created_by,
:issuematchchange_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/issue_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,13 @@ func (s *SqlDatabase) CreateIssueRepository(issueRepository *entity.IssueReposit
INSERT INTO IssueRepository (
issuerepository_name,
issuerepository_url,
issuerepository_created_by
issuerepository_created_by,
issuerepository_updated_by
) VALUES (
:issuerepository_name,
:issuerepository_url,
:issuerepository_created_by
:issuerepository_created_by,
:issuerepository_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/issue_variant.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,17 @@ func (s *SqlDatabase) CreateIssueVariant(issueVariant *entity.IssueVariant) (*en
issuevariant_rating,
issuevariant_secondary_name,
issuevariant_description,
issuevariant_created_by
issuevariant_created_by,
issuevariant_updated_by
) VALUES (
:issuevariant_issue_id,
:issuevariant_repository_id,
:issuevariant_vector,
:issuevariant_rating,
:issuevariant_secondary_name,
:issuevariant_description,
:issuevariant_created_by
:issuevariant_created_by,
:issuevariant_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,12 @@ func (s *SqlDatabase) CreateService(service *entity.Service) (*entity.Service, e
query := `
INSERT INTO Service (
service_ccrn,
service_created_by
service_created_by,
service_updated_by
) VALUES (
:service_ccrn,
:service_created_by
:service_created_by,
:service_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/support_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ func (s *SqlDatabase) CreateSupportGroup(supportGroup *entity.SupportGroup) (*en
query := `
INSERT INTO SupportGroup (
supportgroup_ccrn,
supportgroup_created_by
supportgroup_created_by,
supportgroup_updated_by
) VALUES (
:supportgroup_ccrn,
:supportgroup_created_by
:supportgroup_created_by,
:supportgroup_updated_by
)
`

Expand Down
6 changes: 4 additions & 2 deletions internal/database/mariadb/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ func (s *SqlDatabase) CreateUser(user *entity.User) (*entity.User, error) {
user_name,
user_unique_user_id,
user_type,
user_created_by
user_created_by,
user_updated_by
) VALUES (
:user_name,
:user_unique_user_id,
:user_type,
:user_created_by
:user_created_by,
:user_updated_by
)
`

Expand Down
4 changes: 2 additions & 2 deletions internal/e2e/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var _ = Describe("Creating and updating entity via API", Label("e2e", "Entities"
createTestIssue(cfg.Port)
issue = getTestIssue(cfg.Port)
})
It("shall assign CreatedBy and CreatedAt metadata fields and shall keep nil in UpdatedBy, UpdatedAt and DeltedAt metadata fields", func() {
It("shall assign CreatedBy, CreatedAt, UpdatedBy and UpdatedAt metadata fields and shall keep nil in DeltedAt metadata fields", func() {
Expect(*issue.Description).To(Equal(testCreatedIssueDescription))
Expect(issue.Type.String()).To(Equal(testCreatedIssueType))

Expand All @@ -85,7 +85,7 @@ var _ = Describe("Creating and updating entity via API", Label("e2e", "Entities"
Expect(err).Should(BeNil())
Expect(createdAt).Should(BeTemporally("~", time.Now().UTC(), 3*time.Second))

Expect(*issue.Metadata.UpdatedBy).To(Equal(fmt.Sprintf("%d", e2e_common.EmptyUserId)))
Expect(*issue.Metadata.UpdatedBy).To(Equal(fmt.Sprintf("%d", e2e_common.SystemUserId)))

updatedAt, err := time.Parse(dbDateLayout, *issue.Metadata.UpdatedAt)
Expect(err).Should(BeNil())
Expand Down
Loading