-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add support for d2:inUserGroup function[DHIS2-19426] #84
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this related to the rest of the PR? Seems the change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change seems more aligned with the current update. The |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.hisp.dhis.lib.expression.function | ||
|
|
||
| import org.hisp.dhis.lib.expression.Expression | ||
| import org.hisp.dhis.lib.expression.ExpressionMode | ||
| import org.hisp.dhis.lib.expression.spi.ExpressionData | ||
| import org.hisp.dhis.lib.expression.spi.IllegalExpressionException | ||
| import kotlin.test.* | ||
|
|
||
| /** | ||
| * Test of the `d2:inUserGroup` function. | ||
| * | ||
| * @author Zubair Asghar | ||
| */ | ||
| internal class InUserGroupTest { | ||
|
|
||
| @Test | ||
| fun testInUserGroup_Null() { | ||
| assertFalse(evaluate("d2:inUserGroup(null)", mapOf("USER_GROUPS" to listOf("uidusgroup0")))) | ||
| } | ||
|
|
||
| @Test | ||
| fun testInUserGroup_NoData() { | ||
| val ex = assertFailsWith(IllegalExpressionException::class) { evaluate("d2:inUserGroup(\"uidougroup1\")", mapOf()) } | ||
| assertEquals("Supplementary data for user needs to be provided", ex.message) | ||
| } | ||
|
|
||
| @Test | ||
| fun testInUserGroup() { | ||
| assertTrue(evaluate("d2:inUserGroup(\"uidusgroup0\")", mapOf("USER_GROUPS" to listOf("uidusgroup0")))) | ||
| assertFalse(evaluate("d2:inUserGroup(\"uidusgroup0\")", mapOf("USER_GROUPS" to listOf("uidusgroup1")))) | ||
| } | ||
|
|
||
| private fun evaluate(expression: String, supplementaryValues: Map<String, List<String>>): Boolean { | ||
| val data: ExpressionData = ExpressionData().copy(supplementaryValues = supplementaryValues) | ||
| return Expression(expression, ExpressionMode.RULE_ENGINE_ACTION).evaluate( { _: String -> null }, data) as Boolean | ||
| } | ||
| } |
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 think this will introduce a breaking change in the integrations. In the case of Android, this
supplementaryValuesproperty is passed by the Android app and it has the keyUSER(check this line in the Android app). I guess it would happen the same for the backend, @enricocolasante?This change must be warned in the release notes. Or change, at least, the minor digit of the version instead of the patch one.
@jbee @zubaira
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.
Clients will have to update to support
USER_GROUPSthis could also be the right opportunity to introduce the breaking change of renamingUSERtoUSER_ROLESfor better consistency. But if we all agree otherwise, then we can revert this change.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 agree, we should add some warn somewhere and change the minor digit of the version.
I would also take the opportunity to make the
supplementaryValuesmore explicit and structured and not rely on strings, so the breaking change would fail at compilation and it would be easier for the client fix it.With the current change, rule-engine will continue to work but some strange behavior will happen around users and it is not really easy for the client to discover and understanding what is happening