-
Notifications
You must be signed in to change notification settings - Fork 46
Added audit fields created_by, last_modified_by, filled_by across program_encounter and encounter tables #895
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
Open
Jayesh445
wants to merge
6
commits into
avniproject:master
Choose a base branch
from
Jayesh445:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51675a8
Fix: Added created_by, last_modified_by, and filled_by fields
Jayesh445 11f398e
Fix: Added created_by, last_modified_by, and filled_by fields
Jayesh445 fe74746
Fix: Added created_by, last_modified_by, and filled_by fields
Jayesh445 d08311b
Merge remote-tracking branch 'upstream/master'
Jayesh445 e68807c
Refactor user assignment in ProgramEncounterService to ensure created…
Jayesh445 e4a647f
Refactor getters and setters for createdBy and lastModifiedBy in Abst…
Jayesh445 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
avni-server-api/src/main/resources/db/migration/V1_353__AddAuditFields.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| -- Add audit fields to existing tables | ||
| ALTER TABLE encounter | ||
| ADD COLUMN IF NOT EXISTS created_by_id bigint REFERENCES users(id), | ||
| ADD COLUMN IF NOT EXISTS last_modified_by_id bigint REFERENCES users(id), | ||
| ADD COLUMN IF NOT EXISTS filled_by_id bigint REFERENCES users(id); | ||
|
|
||
| ALTER TABLE program_encounter | ||
| ADD COLUMN IF NOT EXISTS created_by_id bigint REFERENCES users(id), | ||
| ADD COLUMN IF NOT EXISTS last_modified_by_id bigint REFERENCES users(id), | ||
| ADD COLUMN IF NOT EXISTS filled_by_id bigint REFERENCES users(id); | ||
|
|
||
| -- Create policies for the new audit fields | ||
| CREATE POLICY encounter_created_by_id_rls_policy ON encounter | ||
| USING (created_by_id = current_user_id()) | ||
| WITH CHECK (created_by_id = current_user_id()); | ||
| CREATE POLICY encounter_last_modified_by_id_rls_policy ON encounter | ||
| USING (last_modified_by_id = current_user_id()) | ||
| WITH CHECK (last_modified_by_id = current_user_id()); | ||
| CREATE POLICY encounter_filled_by_id_rls_policy ON encounter | ||
| USING (filled_by_id = current_user_id()) | ||
| WITH CHECK (filled_by_id = current_user_id()); | ||
Jayesh445 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| CREATE INDEX IF NOT EXISTS encounter_created_by_id_idx ON encounter(created_by_id); | ||
| CREATE INDEX IF NOT EXISTS encounter_last_modified_by_id_idx ON encounter(last_modified_by_id); | ||
| CREATE INDEX IF NOT EXISTS encounter_filled_by_id_idx ON encounter(filled_by_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS program_encounter_created_by_id_idx ON program_encounter(created_by_id); | ||
| CREATE INDEX IF NOT EXISTS program_encounter_last_modified_by_id_idx ON program_encounter(last_modified_by_id); | ||
| CREATE INDEX IF NOT EXISTS program_encounter_filled_by_id_idx ON program_encounter(filled_by_id); | ||
52 changes: 52 additions & 0 deletions
52
avni-server-api/src/test/java/org/avni/server/service/ProgramEncounterServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package org.avni.server.service; | ||
|
|
||
| import org.avni.server.dao.ProgramEncounterRepository; | ||
| import org.avni.server.domain.ProgramEncounter; | ||
| import org.avni.server.domain.User; | ||
| import org.avni.server.web.request.ProgramEncounterRequest; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| public class ProgramEncounterServiceTest { | ||
|
|
||
| @Mock | ||
| private ProgramEncounterRepository programEncounterRepository; | ||
|
|
||
| @Mock | ||
| private UserService userService; | ||
|
|
||
| @InjectMocks | ||
| private ProgramEncounterService programEncounterService; | ||
|
|
||
| @Test | ||
| public void shouldSetAuditFieldsWhenSavingProgramEncounter() { | ||
| // Arrange | ||
| User currentUser = new User(); | ||
| currentUser.setId(1L); | ||
| currentUser.setUsername("testUser"); | ||
|
|
||
| when(userService.getCurrentUser()).thenReturn(currentUser); | ||
| when(programEncounterRepository.saveEntity(any())).thenAnswer(i -> i.getArguments()[0]); | ||
|
|
||
| ProgramEncounter encounter = new ProgramEncounter(); | ||
|
|
||
| // Act | ||
| ProgramEncounter savedEncounter = programEncounterService.save(encounter); | ||
|
|
||
| // Assert | ||
| assertNotNull(savedEncounter.getCreatedBy()); | ||
| assertNotNull(savedEncounter.getLastModifiedBy()); | ||
| assertNotNull(savedEncounter.getFilledBy()); | ||
| assertEquals(currentUser, savedEncounter.getCreatedBy()); | ||
| assertEquals(currentUser, savedEncounter.getLastModifiedBy()); | ||
| assertEquals(currentUser, savedEncounter.getFilledBy()); | ||
| } | ||
Jayesh445 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,4 +41,4 @@ public void createNewEncounter() { | |
| Assert.fail(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.