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(core): restrict modification of createdon and modifiedon #2188

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

yeshamavani
Copy link
Contributor

@yeshamavani yeshamavani commented Oct 25, 2024

gh-2158

Description

  • restrict modification of createdon and modifiedon

  • with this the existing functionality will be same

  • Introducing a service for future use as well so that such type of conditions can be handled in the future while keeping the code clean and easy to understand.

  • Set the restrictDateModification property in the core configuration to true to enforce date modification restrictions via the API; otherwise, the default behavior will allow unrestricted changes.

Fixes #2158

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Intermediate change (work in progress)

How Has This Been Tested?

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 it to an existing repository and tested it

Checklist:

  • Performed a self-review of my own code
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Any dependent changes have been merged and published in downstream modules

@yeshamavani yeshamavani requested a review from a team as a code owner October 25, 2024 11:52
Copy link

@a-ganguly a-ganguly left a comment

Choose a reason for hiding this comment

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

restrict modification of createdon and modifiedon

@@ -570,6 +570,29 @@ export class UserRepository extends DefaultUserModifyCrudRepository<
)
```

The repository by default allows to pass back dated or future dates for createdOn and modifiedOn values but to restrict the manual date modification we can pass overridingOptions like this
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The repository by default allows to pass back dated or future dates for createdOn and modifiedOn values but to restrict the manual date modification we can pass overridingOptions like this
The repository by default does not restrict setting up of createdOn and modifiedOn through API or external sources. However, you can restrict it using the overridingOptions like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -43,6 +46,10 @@ export abstract class DefaultTransactionalUserModifyRepository<
const uid = currentUser?.userTenantId ?? currentUser?.id;
entity.createdBy = uid;
entity.modifiedBy = uid;
if (this.overridingOptions?.restrictDateModification) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why cant we use the second parameter of the method options?: Options. That ways its consistent and easy to implement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the method's option parameter user will have to make changes in all the method calls
but with this only one change at repo level

Copy link
Contributor

Choose a reason for hiding this comment

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

But this introduces a new param whereas we already have such options in method param. The second param is for that purpose only. Moreover, using the method options param gives more flexibility at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now using the coreConfig for decision making

@@ -34,6 +35,8 @@ export abstract class DefaultTransactionalUserModifyRepository<
super(entityClass, dataSource);
}

public overridingOptions?: RepositoryOverridingOptions;
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont like this approach. This will mean they will have to do it for all the repo files. Why ? We need to support both mechanism. One using options and another using a global config.

Copy link
Contributor Author

@yeshamavani yeshamavani Oct 28, 2024

Choose a reason for hiding this comment

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

Tried passing an optional config to the repository but it still requires it from the derived class no mater what
making it a Breaking change - hence used this approach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now using the coreConfig for decision making

Copy link

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.

@sourceloop/core: CreatedOn and ModifiedOn columns should not be data driven
3 participants