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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

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

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

Signed-off-by: Michal Krzyz <[email protected]>
internal/entity/common.go Outdated Show resolved Hide resolved
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-81 branch 5 times, most recently from b4e30a8 to 024bc5b Compare September 25, 2024 12:28
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-81 branch 2 times, most recently from 94c222f to 2cdfe8c Compare September 26, 2024 17:39

var ()

func createUser(port string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice if we use this function in the user_query_test.go too. I would remove the expect checks from the helper function here and only add it to the test that calls this helper function so that its not hidden when a test runs

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 am not sure we should remove expect checks from helper function/test framework function. Usually common test functions are checking for invalid operation, raising assertions and stopping the test execution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahh yes. Now I get it. You are right, It is not good idea to hide expects in test for user create, so I would like to keep this function (createUser with expects), but it will use another function which is named queryCreateUser (without expects).

Expect(err).Should(BeNil())
Expect(createdAt).Should(BeTemporally("~", time.Now().UTC(), 3*time.Second))

Expect(*user.Metadata.UpdatedBy).To(BeEmpty())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really check for BeEmpty()? in the UpdatedBy field?

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 wanted to highlight that UpdatedBy is not assigned when the object is created. In some solutions of such problems we see that modified/updated time is assigned by created time at creation of an object (eg. Linux File)

Add metadata for activity, IssueVariant and IssueRepository
Add metadata for componentInstance, componentVersion
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 IssueMatchChange, Service and SupportGroup
@@ -23,6 +24,7 @@ type ActivityConnection implements Connection {
type ActivityEdge implements Edge {
node: Activity!
cursor: String
metadata: Metadata
Copy link
Collaborator

Choose a reason for hiding this comment

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

why intended differently?

Copy link
Collaborator

Choose a reason for hiding this comment

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

--> looks like 8 spaces instead of 4

@@ -12,8 +12,10 @@ create table if not exists Component
component_name varchar(256) not null,
component_type varchar(256) not null,
component_created_at timestamp default current_timestamp() not null,
component_created_by varchar(256) null,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, well this needs to be a foreign key to a User I guess!

@MR2011 @dorneanu WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think User is misleading here. A component can be as well created by a scanner, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it should be foreign key to a User object. Users have a type; for scanners it's TechnicalUserType, so I don't think it's misleading

@@ -132,6 +132,7 @@ func (a *activityHandler) ListActivities(filter *entity.ActivityFilter, options
}

func (a *activityHandler) CreateActivity(activity *entity.Activity) (*entity.Activity, error) {
activity.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.

I guess that's a placeholder. Based on the comment I made we need to decide if that should really be a freetext field or rather a foreign key reference to a User

Comment on lines 23 to 24
CreatedAt: &createdAt,
CreatedBy: &em.CreatedBy,
Copy link
Collaborator

Choose a reason for hiding this comment

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

As commented this might need to be a sub-resolver for users?!

@@ -152,6 +153,7 @@ func (a *activityHandler) CreateActivity(activity *entity.Activity) (*entity.Act
}

func (a *activityHandler) UpdateActivity(activity *entity.Activity) (*entity.Activity, error) {
activity.UpdatedBy = "Updater"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also a placeholder.

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?

@@ -10,8 +10,7 @@ type IssueVariant implements Node {
issueRepository: IssueRepository
issueId: String
issue: Issue
created_at: DateTime
updated_at: DateTime
metadata: Metadata
Copy link
Collaborator

Choose a reason for hiding this comment

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

wrong indentation

@@ -105,6 +105,7 @@ func (cs *componentHandler) ListComponents(filter *entity.ComponentFilter, optio
}

func (cs *componentHandler) CreateComponent(component *entity.Component) (*entity.Component, error) {
component.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

@@ -139,6 +140,7 @@ func (cs *componentHandler) CreateComponent(component *entity.Component) (*entit
}

func (cs *componentHandler) UpdateComponent(component *entity.Component) (*entity.Component, error) {
component.UpdatedBy = "Updater"
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

@@ -111,6 +111,7 @@ func (ci *componentInstanceHandler) ListComponentInstances(filter *entity.Compon
}

func (ci *componentInstanceHandler) CreateComponentInstance(componentInstance *entity.ComponentInstance) (*entity.ComponentInstance, error) {
componentInstance.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

@@ -131,6 +132,7 @@ func (ci *componentInstanceHandler) CreateComponentInstance(componentInstance *e
}

func (ci *componentInstanceHandler) UpdateComponentInstance(componentInstance *entity.ComponentInstance) (*entity.ComponentInstance, error) {
componentInstance.UpdatedBy = "Updater"
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

@@ -109,6 +109,7 @@ func (cv *componentVersionHandler) ListComponentVersions(filter *entity.Componen
}

func (cv *componentVersionHandler) CreateComponentVersion(componentVersion *entity.ComponentVersion) (*entity.ComponentVersion, error) {
componentVersion.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

@@ -129,6 +130,7 @@ func (cv *componentVersionHandler) CreateComponentVersion(componentVersion *enti
}

func (cv *componentVersionHandler) UpdateComponentVersion(componentVersion *entity.ComponentVersion) (*entity.ComponentVersion, error) {
componentVersion.UpdatedBy = "Updater"
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

@@ -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

@@ -122,6 +123,7 @@ func (e *evidenceHandler) CreateEvidence(evidence *entity.Evidence) (*entity.Evi
}

func (e *evidenceHandler) UpdateEvidence(evidence *entity.Evidence) (*entity.Evidence, error) {
evidence.UpdatedBy = "Updater"
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

@@ -160,6 +160,7 @@ func (is *issueHandler) ListIssues(filter *entity.IssueFilter, options *entity.I
}

func (is *issueHandler) CreateIssue(issue *entity.Issue) (*entity.Issue, error) {
issue.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?

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