-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
TRUNK-6235: auto deactivate users after XX days of inactivity #4650
TRUNK-6235: auto deactivate users after XX days of inactivity #4650
Conversation
updated-dependencies: - dependency-name: org.codehaus.mojo:build-helper-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
api/src/main/java/org/openmrs/api/db/hibernate/HibernateContextDAO.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/openmrs/api/db/hibernate/HibernateContextDAO.java
Outdated
Show resolved
Hide resolved
api/src/main/resources/org/openmrs/liquibase/snapshots/core-data/liquibase-core-data-2.6.x.xml
Outdated
Show resolved
Hide resolved
…/dicksonmulli/openmrs-core into TRUNK-6235/auto-deactivate-users
api/src/main/java/org/openmrs/api/db/hibernate/HibernateContextDAO.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/openmrs/api/db/hibernate/HibernateUserDAO.java
Outdated
Show resolved
Hide resolved
Can we also look into the build failures? |
@dicksonmulli can you look into the build failures. |
We generally tend to avoid being too permissive. Especially when it has not been explicitly requested for. 😊 |
I see, however, I genuinely think this ability will be beneficial not only to testing but also preventing errors when the user accidentally adds numbers with decimal places. |
For preventing errors, our error handling should take care of it. |
Yes, I did this to enable us to call these methods from the unit tests. [Note] It could be that you can't see my replies anymore. I am not sure what changed. |
Ummmmm, it does not generally smell good, to make methods more visible than they should, just for the sake of testing them. We naturally test them via their public contract. Or in the worst case, at least access them via reflection in the tests. 😊 |
public class AutoRetireUsersTask extends AbstractTask { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(AutoRetireUsersTask.class); | ||
static final String AUTO_RETIRE_REASON = "User retired due to inactivity"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the above be private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using it in tests but I can still use anyString()
instead of passing the actual reason.
administrationService.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GP_NUMBER_OF_DAYS_TO_AUTO_RETIRE_USERS, ONE_DAY_PROPERTY_VALUE)); | ||
|
||
User adminUser = getDefaultUser(); | ||
adminUser.addRole(new Role(RoleConstants.SUPERUSER)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this test fail if i remove the above line of adding the super user role?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dicksonmulli did you see the above comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting should be working now.
Regarding the above concern, kindly refer to the other reply that I shared with you on slack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to share the reply here. These are public comments that are usually read by other community members who may join the discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally it should fail but the reason it won't fail when you remove this line is because the algorithm will check if the inactivity exceeds the number of days to retire, of which it doesn't, unless we add unnecessary stubbings of a last login time or created date - e.g. when(userService.getLastLoginTime(any())).thenReturn(String.valueOf(System.currentTimeMillis() - TWO_DAYS_IN_MILLISECONDS));
Note that these unnecessary stubbing would cause an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not properly understood your response. Let me ask differently, if i removed the line which adds the super user role to the user, will this test fail?
administrationService.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GP_NUMBER_OF_DAYS_TO_AUTO_RETIRE_USERS, ONE_DAY_PROPERTY_VALUE)); | ||
|
||
User retiredUser = getDefaultUser(); | ||
retiredUser.setRetired(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this test fail if i remove the above line of setRetired(true)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dicksonmulli did you see the above comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a response to the above comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shared the response here:
#4650 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i do not retire the user in this test, and the test still passes, what then would i be testing for? 😊
I was using it in tests but I can still use anyString() instead of passing the actual reason. |
Ideally it should fail but the reason it won't fail when you remove this line is because the algorithm will check if the inactivity exceeds the number of days to retire, of which it doesn't, unless we add unnecessary stubbings of a last login time or created date - e.g.
Same case as the above |
Would this catch a bug which changes the expected string to a different one? |
… TRUNK-6235/auto-deactivate-users
I have updated the tests with the actual string. This may have resulted to duplication of code but on the positive side, we achieve separation of concerns. |
@dicksonmulli can you look at these merge conflicts? |
api/src/test/java/org/openmrs/scheduler/tasks/AutoRetireUsersTaskTest.java
Outdated
Show resolved
Hide resolved
api/src/test/java/org/openmrs/scheduler/tasks/AutoRetireUsersTaskTest.java
Outdated
Show resolved
Hide resolved
api/src/test/java/org/openmrs/scheduler/tasks/AutoRetireUsersTaskTest.java
Outdated
Show resolved
Hide resolved
api/src/test/java/org/openmrs/scheduler/tasks/AutoRetireUsersTaskTest.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/openmrs/api/db/hibernate/HibernateUserDAO.java
Outdated
Show resolved
Hide resolved
…s#4650) * TRUNK-6235 - auto deactivate users * --- (openmrs#4643) updated-dependencies: - dependency-name: org.codehaus.mojo:build-helper-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update to Tomcat 9 * --- (openmrs#4647) updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * --- (openmrs#4648) updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Updating tests * Changes from Pull request * Reverting refactor * Adding property in core global property * Using matchers in place of empty string * Adding licence * Adding tests for auto-retire * Changing an access modifier * Improving documentation * Updating tests * escaping superusers while auto retiring users * Code refactor * Improving tests * Improving tests * Code refactor * Using TimeUnit for time conversion * Changing method modifiers to private * Fixing a failing build * making a static variable private * Using exact retire reason in tests * Fixing tests * correcting the expected values * Removing import of a constant --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Isaiah <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ian <[email protected]> Co-authored-by: Isaiah Muli <[email protected]>
Description of what I changed
Issue I worked on
see https://issues.openmrs.org/browse/TRUNK-6235
Checklist: I completed these to help reviewers :)
My IDE is configured to follow the code style of this project.
No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amend
I have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amend
I ran
mvn clean package
right before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
All new and existing tests passed.
No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
My pull request is based on the latest changes of the master branch.
No? Unsure? -> execute command
git pull --rebase upstream master