Skip to content

feat(remediation): user id is set for remediation#1134

Merged
MR2011 merged 3 commits intomainfrom
kanstantsinbuklis-sap/issue-1122/set-user-id-for-remediation
Mar 19, 2026
Merged

feat(remediation): user id is set for remediation#1134
MR2011 merged 3 commits intomainfrom
kanstantsinbuklis-sap/issue-1122/set-user-id-for-remediation

Conversation

@kanstantsinbuklis-sap
Copy link
Collaborator

Description

In this PR I've added saving unique user id to remediation

What type of PR is this? (check all applicable)

  • [+] 🍕 Feature

Related Tickets & Documents

Added tests?

  • [+] 👍 yes

Little bit change test to check if the remediatedBy was set

Added to documentation?

  • [+] 🙅 no documentation needed

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates remediation creation to persist a “unique user id” on newly created remediations, and adjusts E2E coverage to validate that the remediatedBy field is set in API responses.

Changes:

  • Populate RemediatedBy (unique user id) and RemediatedById during CreateRemediation using the current request context user.
  • Add common.GetCurrentUniqueUserId(...) helper for extracting the unique user id from the auth context (or falling back to the system user).
  • Update E2E remediation creation tests to assert remediatedBy is not empty and stop sending remediatedBy in one of the create mutation inputs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
internal/app/remediation/remediation_handler.go Sets RemediatedBy/RemediatedById during remediation creation based on the current user context.
internal/app/common/user_id.go Adds helper to retrieve the current user’s unique user id (with system fallback).
internal/e2e/remediation_query_test.go Updates E2E remediation create assertions around remediatedBy being set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Expect(*respData.Remediation.Vulnerability).To(Equal(remediation.Issue))
Expect(*respData.Remediation.Image).To(Equal(remediation.Component))
Expect(*respData.Remediation.RemediatedBy).To(Equal(remediation.RemediatedBy))
Expect(*respData.Remediation.RemediatedBy).ToNot(BeEmpty())
Expect(*respData.Remediation.Vulnerability).To(Equal(remediation.Issue))
Expect(*respData.Remediation.Image).To(Equal(remediation.Component))
Expect(*respData.Remediation.RemediatedBy).To(Equal(remediation.RemediatedBy))
Expect(*respData.Remediation.RemediatedBy).ToNot(BeEmpty())
Comment on lines +149 to +152
remediation.UpdatedBy = remediation.CreatedBy
remediation.RemediatedById = remediation.CreatedBy

remediation.RemediatedBy, err = common.GetCurrentUniqueUserId(ctx, rh.database)
Comment on lines +34 to +45
func GetCurrentUniqueUserId(ctx context.Context, db database.Database) (string, error) {
if authentication_context.IsAuthenticationRequired(ctx) {
uniqueUserId, err := authentication_context.UserNameFromContext(ctx)
if err != nil {
return "", fmt.Errorf("Could not get user name from context: %w", err)
}

return uniqueUserId, nil
} else {
return systemUserUniqueUserId, nil
}
}
@kanstantsinbuklis-sap kanstantsinbuklis-sap force-pushed the kanstantsinbuklis-sap/issue-1122/set-user-id-for-remediation branch from f3c80b0 to 429215c Compare March 13, 2026 14:11
michalkrzyz
michalkrzyz previously approved these changes Mar 13, 2026
@MR2011
Copy link
Collaborator

MR2011 commented Mar 17, 2026

The RemediatedBy can be set via API because the remediation could be performed by someone else then the authenticated user:
https://github.com/cloudoperators/heureka/blob/main/internal/api/graphql/graph/schema/remediation.graphqls#L65

In the mutation resolver, we need to check if a user with the unique user id exists, if not, we create a new user
https://github.com/cloudoperators/heureka/blob/main/internal/api/graphql/graph/resolver/mutation.go#L686

@kanstantsinbuklis-sap kanstantsinbuklis-sap force-pushed the kanstantsinbuklis-sap/issue-1122/set-user-id-for-remediation branch from 429215c to 8a71838 Compare March 18, 2026 12:59
return nil, wrappedErr
}

remediation.CreatedBy = remediation.RemediatedById
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Remediation could be created by User A, but the RemediationBy is set to User B. The CreatedBy and UpdatedBy needs to be set to the authenticated user

@kanstantsinbuklis-sap kanstantsinbuklis-sap force-pushed the kanstantsinbuklis-sap/issue-1122/set-user-id-for-remediation branch from 8a71838 to 1c1b1c9 Compare March 19, 2026 10:27
@MR2011 MR2011 merged commit c12e0ec into main Mar 19, 2026
9 checks passed
@MR2011 MR2011 deleted the kanstantsinbuklis-sap/issue-1122/set-user-id-for-remediation branch March 19, 2026 12:19
@kanstantsinbuklis-sap kanstantsinbuklis-sap linked an issue Mar 19, 2026 that may be closed by this pull request
2 tasks
kanstantsinbuklis-sap added a commit that referenced this pull request Mar 24, 2026
Co-authored-by: Michael Reimsbach <michael.reimsbach@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(remediation): user id is set for remediation

4 participants