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

Merged
merged 7 commits into from
Feb 10, 2025
Merged

Conversation

michalkrzyz
Copy link
Collaborator

@michalkrzyz michalkrzyz commented Dec 3, 2024

Description

Add updated_by update for delete operation. This way deleted item can be checked for user who deleted an item (under circumstances that the item was not changed/updated after deletion).
Add possibility to filter through deleted items, active and all (deleted and active). Default is active.
Fix seeding test data in fixture.go for db tests

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

Sorry, something went wrong.

@michalkrzyz michalkrzyz self-assigned this Dec 3, 2024
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-358 branch 4 times, most recently from 98e0706 to eda02c8 Compare December 5, 2024 20:49
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-358 branch 3 times, most recently from 1f5b22b to e4c14f7 Compare December 11, 2024 12:27
@michalkrzyz michalkrzyz marked this pull request as ready for review December 11, 2024 14:36
type StateFilterType int

const (
Active StateFilterType = 0
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@reviewers - wouldn't it be better to use string value instead of int for that? Please help me with your opinion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Int is okay. I suggest following this enum pattern:

type StateFilterType int

const (
    Active StateFilterType = iota
    Deleted
    All
)

var StateFilterTypeMap = map[StateFilterType]string{
  Active: "active",
  Deleted: "deleted",
  All: "all",
}

func (sft StateFilterType) String() string {
    return StateFilterTypeMap[sft]
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@michalkrzyz @MR2011 What about using strings like this ? Looks like a nice solution IMHO.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's also an option. We should align however on one way to implement enums instead of having multiple different approaches in the codebase

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -30,6 +30,7 @@ type ActivityEdge implements Edge {
input ActivityFilter {
serviceCcrn: [String]
status: [ActivityStatusValues]
state: Int
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please create a enum for the API layer.
All filter options are lists. In this case it might not be so useful, but if we add more states it could be possible that we want to filter for multiple states

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So maybe 'All' does not make a sense here, We could have list with State which is Active or Deleted (for all both)?
Anyway why do we want to make an enum here? it will need an extra conversion to convert model enum to entity enum.
As an example of not enum values in similar case there is a user type which is int value in the model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -259,20 +259,22 @@ func (s *SqlDatabase) UpdateActivity(activity *entity.Activity) error {
return err
}

func (s *SqlDatabase) DeleteActivity(id int64) error {
func (s *SqlDatabase) DeleteActivity(id int64, userId int64) error {
l := logrus.WithFields(logrus.Fields{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add a check on the db layer that the userId can't be 0 (Unknown user)?
@drochow @dorneanu @copyonwrite

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we want to do sanity checks for user ids, would they be more elaborate than just checking for a zero userId? What about 'historical' users which are not 'active' anymore and similar scenarios?

Saying that, as a rule of thump everything concerning sanity checks for data should be enforced IN the database, not on the db layer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-358 branch 2 times, most recently from c44743b to 4fa44a9 Compare February 6, 2025 11:42
@MR2011 MR2011 merged commit a483e5a into main Feb 10, 2025
7 checks passed
@MR2011 MR2011 deleted the mikrzyz/issue-358 branch February 10, 2025 13:07
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.

3 participants