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 to all DB entries 'Modified_by'... (#81) #230

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

michalkrzyz
Copy link
Collaborator

@michalkrzyz michalkrzyz commented Sep 17, 2024

Move 'CreatedAt', 'DeletedAt' and 'UpdatedAt' to common entity.Info struct
Add 'CreatedBy' and 'UpdatedBy' to common entity.Info struct

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

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

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

  • Related Issue # (issue)
  • Closes # (issue)
  • Fixes # (issue)

Remove if not applicable

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

internal/entity/common.go Outdated Show resolved Hide resolved
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-81 branch 7 times, most recently from 94c222f to 2cdfe8c Compare September 26, 2024 17:39
internal/api/graphql/graph/schema/activity.graphqls Outdated Show resolved Hide resolved
internal/database/mariadb/init/schema.sql Outdated Show resolved Hide resolved
internal/app/activity/activity_handler.go Outdated Show resolved Hide resolved
internal/api/graphql/graph/model/models.go Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Most queries don't include the createdBy and updatedBy fields. Do we want to add them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have added them only in the files used directly in testing of 'createdBy'/'updatedBy'

@@ -104,6 +104,7 @@ func (e *evidenceHandler) ListEvidences(filter *entity.EvidenceFilter, options *
}

func (e *evidenceHandler) CreateEvidence(evidence *entity.Evidence) (*entity.Evidence, error) {
evidence.CreatedBy = "Creator"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another placeholder

@@ -208,9 +211,11 @@ func (s *SqlDatabase) CreateActivity(activity *entity.Activity) (*entity.Activit

query := `
INSERT INTO Activity (
Copy link
Collaborator

Choose a reason for hiding this comment

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

aren't we missing the updated_by field? This is also in the other db queries the case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we need to insert it during creation of an object? is it possible that updatedBy will be given when the object is created in database?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In theory we can do that via a trigger on the DB layer, yes. But than we need to add the trigger to each DB Table. Its probably more work then just adding it here.

internal/entity/activity.go Outdated Show resolved Hide resolved
internal/entity/activity.go Outdated Show resolved Hide resolved
internal/entity/component.go Outdated Show resolved Hide resolved
internal/entity/common.go Outdated Show resolved Hide resolved
internal/entity/common.go Outdated Show resolved Hide resolved
@MR2011
Copy link
Collaborator

MR2011 commented Nov 7, 2024

I think we need to update the updated_by field also in all delete operations

Copy link
Collaborator

@drochow drochow left a comment

Choose a reason for hiding this comment

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

From my perspective, I'd like in this PR the metadata removed from the entities where it should not be part of. @MR2011 did a good job spotting them.

For the other open topics I would suggest creating tickets:

  • As well the topic of adding udpated_by for delete operations

  • instead of getting users by fixed "uniuqeUserId" in each handler write a functionality on the app layer to get the authenticated user (this can then for now do this "statical" fetching)

  • Address Todos

  • Add updated_by to inserts

internal/app/activity/activity_handler.go Outdated Show resolved Hide resolved
internal/app/activity/activity_handler.go Outdated Show resolved Hide resolved

func GetUserId(db database.Database, uniqueUserId string) (int64, error) {
filter := &entity.UserFilter{UniqueUserID: []*string{&uniqueUserId}}
ids, err := db.GetAllUserIds(filter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better get the whole User, we probably going to replace the "AllUserIDs" thing with a "AllCursors" thing

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also keep the "GetAllUserIds" function though. Have no strong opinion here!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"S0000000" is current placeholder, when OIDC auth will be ready we will have correct user name and these name will be existing entry in database.
Anyway we have an option to disable authentication so in this case it will be needed to have some "nobody", "anonymous", "guest" or "none" user, whatever we will name it.
Second problem will be authentication via JWT token, I guess we would need some scannerUser, or we would need to validate user name from JWT (or use systemuser for mentioned purpose).

internal/app/activity/activity_handler.go Outdated Show resolved Hide resolved
@@ -208,9 +211,11 @@ func (s *SqlDatabase) CreateActivity(activity *entity.Activity) (*entity.Activit

query := `
INSERT INTO Activity (
Copy link
Collaborator

Choose a reason for hiding this comment

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

In theory we can do that via a trigger on the DB layer, yes. But than we need to add the trigger to each DB Table. Its probably more work then just adding it here.

internal/entity/severity.go Outdated Show resolved Hide resolved
internal/entity/support_group.go Outdated Show resolved Hide resolved
internal/entity/support_group.go Outdated Show resolved Hide resolved
internal/entity/user.go Outdated Show resolved Hide resolved
internal/entity/user.go Outdated Show resolved Hide resolved
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-81 branch 3 times, most recently from 90403c6 to ca99077 Compare November 12, 2024 10:45
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-81 branch 7 times, most recently from e1718c2 to 7b188a6 Compare November 14, 2024 15:21
@drochow drochow marked this pull request as ready for review November 15, 2024 08:05
Copy link
Collaborator

@drochow drochow left a comment

Choose a reason for hiding this comment

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

LGTM; as discussed remaining comments can be addressed in separate issues.

drochow
drochow previously approved these changes Nov 18, 2024
Move 'CreatedAt', 'DeletedAt' and 'UpdatedAt' to common
entity.Info struct
Add 'CreatedBy' and 'UpdatedBy' to common entity.Info struct
Add metadata for user
Add tests
Add metadata for activity, IssueVariant and IssueRepository
Add metadata for component
Add metadata for componentInstance, componentVersion
Add metadata for evidence
Issue Metadata rename to IssueMetadata, because now metadata
means data related to creation time, creation user, update time
and update user
Add Metadata for Issue
Add metadata for IssueMatch
Add Metadata for IssueMatchChange, Service and SupportGroup
Refactor and review fixes
Test foreign key
Add Foreign Key
changed issueMetadata and serviceMetadata to objectMetadata
drochow
drochow previously approved these changes Nov 18, 2024
@drochow drochow merged commit 04a4f2f into main Nov 18, 2024
@drochow drochow deleted the mikrzyz/issue-81 branch November 18, 2024 15:59
dustindemmerle pushed a commit that referenced this pull request Nov 25, 2024
* feat(authN): Add to all DB entries 'Modified_by'... (#81)

Move 'CreatedAt', 'DeletedAt' and 'UpdatedAt' to common
entity.Info struct
Add 'CreatedBy' and 'UpdatedBy' to common entity.Info struct
Add metadata for user
Add tests
Add metadata for activity, IssueVariant and IssueRepository
Add metadata for component
Add metadata for componentInstance, componentVersion
Add metadata for evidence
Issue Metadata rename to IssueMetadata, because now metadata
means data related to creation time, creation user, update time
and update user
Add Metadata for Issue
Add metadata for IssueMatch
Add Metadata for IssueMatchChange, Service and SupportGroup
Refactor and review fixes
Test foreign key
Add Foreign Key
changed issueMetadata and serviceMetadata to objectMetadata

* chore: bumping for re-trigger

* Automatic application of license header

---------

Co-authored-by: David Rochow <[email protected]>
Co-authored-by: License Bot <[email protected]>
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.

4 participants