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 udpated_by for delete operations #417

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions internal/api/graphql/graph/baseResolver/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func ActivityBaseResolver(app app.Heureka, ctx context.Context, filter *model.Ac
ServiceCCRN: filter.ServiceCcrn,
ServiceId: sId,
IssueId: issueId,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
1 change: 1 addition & 0 deletions internal/api/graphql/graph/baseResolver/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func ComponentBaseResolver(app app.Heureka, ctx context.Context, filter *model.C
f := &entity.ComponentFilter{
Paginated: entity.Paginated{First: first, After: afterId},
CCRN: filter.ComponentCcrn,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func ComponentInstanceBaseResolver(app app.Heureka, ctx context.Context, filter
ServiceCcrn: filter.ServiceCcrn,
ComponentVersionId: copmonentVersionId,
Search: filter.Search,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -146,6 +147,7 @@ func CcrnBaseResolver(app app.Heureka, ctx context.Context, filter *model.Compon
f := &entity.ComponentInstanceFilter{
CCRN: filter.Ccrn,
Search: filter.Search,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func ComponentVersionBaseResolver(app app.Heureka, ctx context.Context, filter *
ComponentId: componentId,
ComponentCCRN: filter.ComponentCcrn,
Version: filter.Version,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
1 change: 1 addition & 0 deletions internal/api/graphql/graph/baseResolver/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func EvidenceBaseResolver(app app.Heureka, ctx context.Context, filter *model.Ev
Paginated: entity.Paginated{First: first, After: afterId},
ActivityId: activityId,
IssueMatchId: imId,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
2 changes: 2 additions & 0 deletions internal/api/graphql/graph/baseResolver/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func IssueBaseResolver(app app.Heureka, ctx context.Context, filter *model.Issue
IssueMatchStatus: nil, //@todo Implement
IssueMatchDiscoveryDate: nil, //@todo Implement
IssueMatchTargetRemediationDate: nil, //@todo Implement
State: entity.GetStateFilterType(filter.State),
}

opt := GetIssueListOptions(requestedFields)
Expand Down Expand Up @@ -177,6 +178,7 @@ func IssueNameBaseResolver(app app.Heureka, ctx context.Context, filter *model.I
IssueMatchStatus: nil, //@todo Implement
IssueMatchDiscoveryDate: nil, //@todo Implement
IssueMatchTargetRemediationDate: nil, //@todo Implement
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
1 change: 1 addition & 0 deletions internal/api/graphql/graph/baseResolver/issue_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func IssueMatchBaseResolver(app app.Heureka, ctx context.Context, filter *model.
ComponentCCRN: filter.ComponentCcrn,
PrimaryName: filter.PrimaryName,
IssueType: lo.Map(filter.IssueType, func(item *model.IssueTypes, _ int) *string { return pointer.String(item.String()) }),
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func IssueMatchChangeBaseResolver(app app.Heureka, ctx context.Context, filter *
Action: lo.Map(filter.Action, func(item *model.IssueMatchChangeActions, _ int) *string { return pointer.String(item.String()) }),
ActivityId: aId,
IssueMatchId: imId,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func IssueRepositoryBaseResolver(app app.Heureka, ctx context.Context, filter *m
ServiceId: serviceId,
Name: filter.Name,
ServiceCCRN: filter.ServiceCcrn,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
2 changes: 2 additions & 0 deletions internal/api/graphql/graph/baseResolver/issue_variant.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func IssueVariantBaseResolver(app app.Heureka, ctx context.Context, filter *mode
IssueId: issueId,
IssueRepositoryId: irId,
SecondaryName: filter.SecondaryName,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -163,6 +164,7 @@ func EffectiveIssueVariantBaseResolver(app app.Heureka, ctx context.Context, fil
f := &entity.IssueVariantFilter{
Paginated: entity.Paginated{First: first, After: afterId},
IssueMatchId: imId,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
2 changes: 2 additions & 0 deletions internal/api/graphql/graph/baseResolver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func ServiceBaseResolver(app app.Heureka, ctx context.Context, filter *model.Ser
IssueRepositoryId: irId,
SupportGroupId: sgId,
Search: filter.Search,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -159,6 +160,7 @@ func ServiceCcrnBaseResolver(app app.Heureka, ctx context.Context, filter *model
SupportGroupCCRN: filter.SupportGroupCcrn,
CCRN: filter.ServiceCcrn,
OwnerName: filter.UserName,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
2 changes: 2 additions & 0 deletions internal/api/graphql/graph/baseResolver/support_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func SupportGroupBaseResolver(app app.Heureka, ctx context.Context, filter *mode
ServiceId: serviceId,
UserId: userId,
CCRN: filter.SupportGroupCcrn,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -112,6 +113,7 @@ func SupportGroupCcrnBaseResolver(app app.Heureka, ctx context.Context, filter *
Paginated: entity.Paginated{},
UserId: userIds,
CCRN: filter.SupportGroupCcrn,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
3 changes: 3 additions & 0 deletions internal/api/graphql/graph/baseResolver/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func UserBaseResolver(app app.Heureka, ctx context.Context, filter *model.UserFi
ServiceId: serviceId,
Name: filter.UserName,
UniqueUserID: filter.UniqueUserID,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -140,6 +141,7 @@ func UserNameBaseResolver(app app.Heureka, ctx context.Context, filter *model.Us
Paginated: entity.Paginated{},
Name: filter.UserName,
UniqueUserID: filter.UniqueUserID,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -178,6 +180,7 @@ func UniqueUserIDBaseResolver(app app.Heureka, ctx context.Context, filter *mode
Paginated: entity.Paginated{},
UniqueUserID: filter.UniqueUserID,
Name: filter.UserName,
State: entity.GetStateFilterType(filter.State),
}

opt := GetListOptions(requestedFields)
Expand Down
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/activity.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ActivityEdge implements Edge {
input ActivityFilter {
serviceCcrn: [String]
status: [ActivityStatusValues]
state: Int
}

enum ActivityStatusValues {
Expand Down
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/component.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum ComponentTypeValues {

input ComponentFilter {
componentCcrn: [String]
state: Int
}

type ComponentConnection implements Connection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ input ComponentInstanceFilter {
ccrn: [String],
supportGroup: [String],
search:[String],
state: Int,
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ input ComponentVersionFilter {
componentCcrn: [String]
issueId: [String]
version: [String]
state: Int
}
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/evidence.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ type EvidenceEdge implements Edge {

input EvidenceFilter {
placeholder: [Boolean]
state: Int
}
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/issue.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ input IssueFilter {
primaryName: [String],
issueMatchStatus: [IssueMatchStatusValues],
issueType: [IssueTypes],
state: Int,

componentVersionId: [String],

Expand Down
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/issue_match.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ input IssueMatchFilter {
severity: [SeverityValues]
affectedService: [String]
supportGroupCcrn: [String]
state: Int
}

#type CCloudSeverity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ input IssueMatchChangeInput {

input IssueMatchChangeFilter {
action: [IssueMatchChangeActions]
state: Int
}

type IssueMatchChangeConnection implements Connection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ type IssueMatchFilterValue {
affectedService(filter: ServiceFilter): FilterItem
componentCcrn(filter: ComponentFilter): FilterItem
supportGroupCcrn(filter: SupportGroupFilter): FilterItem
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ input IssueRepositoryFilter {
serviceCcrn: [String]
serviceId: [String]
name: [String]
state: Int
}
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/issue_variant.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ type IssueVariantEdge implements Edge {

input IssueVariantFilter {
secondaryName: [String]
state: Int
}
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/service.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ input ServiceFilter {
userName: [String]
supportGroupCcrn: [String]
search: [String]
state: Int
}
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/support_group.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ type SupportGroupEdge implements Edge {
input SupportGroupFilter {
supportGroupCcrn: [String],
userIds: [String],
state: Int,
}
1 change: 1 addition & 0 deletions internal/api/graphql/graph/schema/user.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ input UserFilter {
userName: [String],
supportGroupIds: [String],
uniqueUserId: [String],
state: Int,
}
8 changes: 7 additions & 1 deletion internal/app/activity/activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ func (a *activityHandler) DeleteActivity(id int64) error {
"id": id,
})

err := a.database.DeleteActivity(id)
userId, err := common.GetCurrentUserId(a.database)
if err != nil {
l.Error(err)
return NewActivityHandlerError("Internal error while deleting activity (GetUserId).")
}

err = a.database.DeleteActivity(id, userId)

if err != nil {
l.Error(err)
Expand Down
3 changes: 2 additions & 1 deletion internal/app/activity/activity_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ var _ = Describe("When deleting Activity", Label("app", "DeleteActivity"), func(
})

It("deletes activity", func() {
db.On("DeleteActivity", id).Return(nil)
db.On("GetAllUserIds", mock.Anything).Return([]int64{}, nil)
db.On("DeleteActivity", id, mock.Anything).Return(nil)
activityHandler = a.NewActivityHandler(db, er)
db.On("GetActivities", filter).Return([]entity.Activity{}, nil)
err := activityHandler.DeleteActivity(id)
Expand Down
9 changes: 6 additions & 3 deletions internal/app/common/user_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import (
"github.com/cloudoperators/heureka/internal/entity"
)

const systemUserUniqueUserId = "S0000000"
const unknownUser = int64(0)

func GetCurrentUserId(db database.Database) (int64, error) {
return getUserIdFromDb(db, "S0000000")
return getUserIdFromDb(db, systemUserUniqueUserId)
}

func getUserIdFromDb(db database.Database, uniqueUserId string) (int64, error) {
filter := &entity.UserFilter{UniqueUserID: []*string{&uniqueUserId}}
ids, err := db.GetAllUserIds(filter)
if err != nil {
return 0, fmt.Errorf("Unable to get user ids %w", err)
return unknownUser, fmt.Errorf("Unable to get user ids %w", err)
} else if len(ids) < 1 {
return 0, nil
return unknownUser, nil
}
return ids[0], nil
}
8 changes: 7 additions & 1 deletion internal/app/component/component_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ func (cs *componentHandler) DeleteComponent(id int64) error {
"id": id,
})

err := cs.database.DeleteComponent(id)
userId, err := common.GetCurrentUserId(cs.database)
if err != nil {
l.Error(err)
return NewUserHandlerError("Internal error while deleting component (GetUserId).")
}

err = cs.database.DeleteComponent(id, userId)

if err != nil {
l.Error(err)
Expand Down
3 changes: 2 additions & 1 deletion internal/app/component/component_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ var _ = Describe("When deleting Component", Label("app", "DeleteComponent"), fun
})

It("deletes component", func() {
db.On("DeleteComponent", id).Return(nil)
db.On("GetAllUserIds", mock.Anything).Return([]int64{}, nil)
db.On("DeleteComponent", id, mock.Anything).Return(nil)
componentHandler = c.NewComponentHandler(db, er)
db.On("GetComponents", filter).Return([]entity.Component{}, nil)
err := componentHandler.DeleteComponent(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ func (ci *componentInstanceHandler) DeleteComponentInstance(id int64) error {
"id": id,
})

err := ci.database.DeleteComponentInstance(id)
userId, err := common.GetCurrentUserId(ci.database)
if err != nil {
l.Error(err)
return NewComponentInstanceHandlerError("Internal error while deleting componentInstance (GetUserId).")
}

err = ci.database.DeleteComponentInstance(id, userId)

if err != nil {
l.Error(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ var _ = Describe("When deleting ComponentInstance", Label("app", "DeleteComponen
})

It("deletes componentInstance", func() {
db.On("DeleteComponentInstance", id).Return(nil)
db.On("GetAllUserIds", mock.Anything).Return([]int64{}, nil)
db.On("DeleteComponentInstance", id, mock.Anything).Return(nil)
componentInstanceHandler = ci.NewComponentInstanceHandler(db, er)
db.On("GetComponentInstances", filter).Return([]entity.ComponentInstance{}, nil)
err := componentInstanceHandler.DeleteComponentInstance(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ func (cv *componentVersionHandler) DeleteComponentVersion(id int64) error {
"id": id,
})

err := cv.database.DeleteComponentVersion(id)
userId, err := common.GetCurrentUserId(cv.database)
if err != nil {
l.Error(err)
return NewComponentVersionHandlerError("Internal error while deleting componentVersion (GetUserId).")
}

err = cv.database.DeleteComponentVersion(id, userId)

if err != nil {
l.Error(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ var _ = Describe("When deleting ComponentVersion", Label("app", "DeleteComponent
})

It("deletes componentVersion", func() {
db.On("DeleteComponentVersion", id).Return(nil)
db.On("GetAllUserIds", mock.Anything).Return([]int64{}, nil)
db.On("DeleteComponentVersion", id, mock.Anything).Return(nil)
componenVersionService = cv.NewComponentVersionHandler(db, er)
db.On("GetComponentVersions", filter).Return([]entity.ComponentVersion{}, nil)
err := componenVersionService.DeleteComponentVersion(id)
Expand Down
8 changes: 7 additions & 1 deletion internal/app/evidence/evidence_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ func (e *evidenceHandler) DeleteEvidence(id int64) error {
"id": id,
})

err := e.database.DeleteEvidence(id)
userId, err := common.GetCurrentUserId(e.database)
if err != nil {
l.Error(err)
return NewEvidenceHandlerError("Internal error while deleting evidence (GetUserId).")
}

err = e.database.DeleteEvidence(id, userId)

if err != nil {
l.Error(err)
Expand Down
Loading