RA-1516 Added support to select the location from the userProperty in the Login Screen #47
Conversation
|
||
//TODO uncomment this to replace the if clause after it |
dkayiwa
Jul 26, 2018
Member
When do you plan to work on the above TODO?
When do you plan to work on the above TODO?
suthagar23
Jul 26, 2018
Author
Member
Actually this was came from the exiting code. I just moved that whole part. Do you want me to clear this as well?
Actually this was came from the exiting code. I just moved that whole part. Do you want me to clear this as well?
@SpringBean("locationService") LocationService locationService, | ||
@SpringBean("appFrameworkService") AppFrameworkService appFrameworkService) { | ||
UiUtils ui, | ||
PageRequest pageRequest, |
dkayiwa
Jul 26, 2018
Member
Did you intentionally change this indention?
Did you intentionally change this indention?
@@ -110,11 +114,24 @@ public String get(PageModel model, | |||
Context.removeProxyPrivilege(GET_LOCATIONS); | |||
} | |||
|
|||
model.addAttribute("showSessionLocations", !isLocationUserPropertyAvailable(administrationService)); | |||
Object showLocation = pageRequest.getAttribute("showSessionLocations"); |
dkayiwa
Jul 26, 2018
Member
The indention here does not look right
The indention here does not look right
@@ -110,11 +114,24 @@ public String get(PageModel model, | |||
Context.removeProxyPrivilege(GET_LOCATIONS); | |||
} | |||
|
|||
model.addAttribute("showSessionLocations", !isLocationUserPropertyAvailable(administrationService)); |
dkayiwa
Jul 26, 2018
Member
Did you intentionally duplicate the model.addAttribute call?
Did you intentionally duplicate the model.addAttribute call?
suthagar23
Jul 27, 2018
Author
Member
Nope @dkayiwa, It used to set that value always, and if wanted it will update this value by next line
Nope @dkayiwa, It used to set that value always, and if wanted it will update this value by next line
model.addAttribute("lastSessionLocation", lastSessionLocation); | ||
|
||
return null; | ||
} | ||
|
||
private boolean isLocationUserPropertyAvailable(AdministrationService administrationService) { | ||
String showLocationSelector = administrationService.getGlobalProperty(ReferenceApplicationConstants.LOCATION_USER_PROPERTY_NAME); |
dkayiwa
Jul 26, 2018
Member
What if it is available but does not have a value of true?
What if it is available but does not have a value of true?
suthagar23
Jul 27, 2018
Author
Member
Actually, I decided to use only one GP for this task, So if that GP contains any value except "false", it will return that value as the userProperty name
Actually, I decided to use only one GP for this task, So if that GP contains any value except "false", it will return that value as the userProperty name
dkayiwa
Jul 27, 2018
Member
You have a gp named "referenceapplication.locationUserPropertyName" and then expect a value of true or false? This does not look intuitive because from the look of the gp name, i would expect it to contain the actual name.
You have a gp named "referenceapplication.locationUserPropertyName" and then expect a value of true or false? This does not look intuitive because from the look of the gp name, i would expect it to contain the actual name.
suthagar23
Jul 27, 2018
Author
Member
We decided to use one GP for this, So when evet it is set, we know that it true, if not set or has value as "false" we know it is false.
We decided to use one GP for this, So when evet it is set, we know that it true, if not set or has value as "false" we know it is false.
dkayiwa
Jul 27, 2018
Member
What happens when it has a value of a non existing property?
What happens when it has a value of a non existing property?
@@ -187,7 +204,9 @@ private String getRedirectUrl(PageRequest pageRequest) { | |||
public String post(@RequestParam(value = "username", required = false) String username, | |||
@RequestParam(value = "password", required = false) String password, | |||
@RequestParam(value = "sessionLocation", required = false) Integer sessionLocationId, | |||
@SpringBean("locationService") LocationService locationService, UiUtils ui, PageRequest pageRequest, | |||
@SpringBean("locationService") LocationService locationService, | |||
@SpringBean("adminService") AdministrationService administrationService, |
dkayiwa
Jul 26, 2018
Member
Did you intentionally change the indention?
Did you intentionally change the indention?
return "redirect:" + redirectUrl; | ||
} else { | ||
if (log.isDebugEnabled()) | ||
log.debug("Redirect contains 'login.', redirecting to home page"); |
dkayiwa
Jul 26, 2018
Member
Can we avoid changing the indention such that we only get to see meaningful changes?
Can we avoid changing the indention such that we only get to see meaningful changes?
@@ -277,7 +316,8 @@ public String post(@RequestParam(value = "username", required = false) String us | |||
//TODO limit login attempts by IP Address | |||
|
|||
pageRequest.getSession().setAttribute(SESSION_ATTRIBUTE_REDIRECT_URL, redirectUrl); | |||
|
|||
// Since the user is already authenticated without location, need to logout before redirecting | |||
Context.logout(); |
dkayiwa
Jul 26, 2018
Member
Why would we log out from a method that is supposed to handle log in?
Why would we log out from a method that is supposed to handle log in?
suthagar23
Jul 27, 2018
Author
Member
Since I need to do the context.authenticate() before verifying the location restrictions. So if anything required isn't satisfied, then it will be redirected with the authenticated user. So the user should automatically log out from the system before the redirect.
Since I need to do the context.authenticate() before verifying the location restrictions. So if anything required isn't satisfied, then it will be redirected with the authenticated user. So the user should automatically log out from the system before the redirect.
listItem[i].addEventListener('keyup', function (event){ | ||
var keyCode = event.which || event.keyCode; | ||
switch (keyCode) { | ||
case 37: // move left |
dkayiwa
Jul 26, 2018
Member
Too many indention changes. Can we do or fix the indention using another pull request? It gets hard to see what actually changed.
Too many indention changes. Can we do or fix the indention using another pull request? It gets hard to see what actually changed.
suthagar23
Jul 27, 2018
Author
Member
I have done the refactor for those indentions. It occured automatically since I done it through the IntelliJ. Could be better to go through this 😄
I have done the refactor for those indentions. It occured automatically since I done it through the IntelliJ. Could be better to go through this
dkayiwa
Jul 27, 2018
Member
Just like i said above
Just like i said above
suthagar23
Jul 27, 2018
Author
Member
I have updated all the indentions changes
I have updated all the indentions changes
dkayiwa
Jul 27, 2018
Member
Isn't this another indention?
Isn't this another indention?
suthagar23
Jul 27, 2018
Author
Member
Extremely sorry @dkayiwa It happened automatically with my IDE. I just made it manually now. Please have a look again
Extremely sorry @dkayiwa It happened automatically with my IDE. I just made it manually now. Please have a look again
We also prefer to attach screenshot on the ticket instead of pull request as per https://wiki.openmrs.org/display/docs/Pull+Request+Tips |
2c88ce0
to
42ec855
4475672
to
ede8d9a
@@ -110,11 +114,24 @@ public String get(PageModel model, | |||
Context.removeProxyPrivilege(GET_LOCATIONS); | |||
} | |||
|
|||
model.addAttribute("showSessionLocations", !isLocationUserPropertyAvailable(administrationService)); | |||
Object showLocation = pageRequest.getAttribute("showSessionLocations"); |
dkayiwa
Jul 27, 2018
Member
I still do not understand why you call model.addAttribute twice instead of once
I still do not understand why you call model.addAttribute twice instead of once
suthagar23
Jul 27, 2018
Author
Member
Line 117 - Assign the showSessionLocations from the locationUserproperty
Line 119 - If the URL contains the "showSessionLocations" as the paramerter (while redirecting again to the users who haven't location property) then show the location selector (set model attribute as true) (Ignore what ever in the user location property)
Line 117 - Assign the showSessionLocations from the locationUserproperty
Line 119 - If the URL contains the "showSessionLocations" as the paramerter (while redirecting again to the users who haven't location property) then show the location selector (set model attribute as true) (Ignore what ever in the user location property)
dkayiwa
Jul 27, 2018
Member
Can't you do it once?
Can't you do it once?
@@ -110,11 +114,24 @@ public String get(PageModel model, | |||
Context.removeProxyPrivilege(GET_LOCATIONS); | |||
} | |||
|
|||
model.addAttribute("showSessionLocations", !isLocationUserPropertyAvailable(administrationService)); | |||
Object showLocation = pageRequest.getAttribute("showSessionLocations"); | |||
if(showLocation != null && showLocation.toString().equals("true")) { |
dkayiwa
Jul 27, 2018
Member
Are you sure we are expecting this value to be true?
Are you sure we are expecting this value to be true?
suthagar23
Jul 27, 2018
Author
Member
Yes, Initial login URL will be "http://localhost:8080/openmrs/login.htm", and then if the user doesn't have the location userproperty, then it will redirect to "http://localhost:8080/openmrs/referenceapplication/login.page?showSessionLocations=true&"
Yes, Initial login URL will be "http://localhost:8080/openmrs/login.htm", and then if the user doesn't have the location userproperty, then it will redirect to "http://localhost:8080/openmrs/referenceapplication/login.page?showSessionLocations=true&"
model.addAttribute("lastSessionLocation", lastSessionLocation); | ||
|
||
return null; | ||
} | ||
|
||
private boolean isLocationUserPropertyAvailable(AdministrationService administrationService) { | ||
String locationUserPropertyName = administrationService.getGlobalProperty(ReferenceApplicationConstants.LOCATION_USER_PROPERTY_NAME); | ||
if(StringUtils.isNotBlank(locationUserPropertyName) && !locationUserPropertyName.equals("false")) { |
dkayiwa
Jul 27, 2018
Member
I thought we agreed to simply use a valid user property name. Instead instead of true or false
I thought we agreed to simply use a valid user property name. Instead instead of true or false
suthagar23
Jul 27, 2018
Author
Member
Yes , Whenever it is set, we know that it is true. If not set, we know it is false.
Yes , Whenever it is set, we know that it is true. If not set, we know it is false.
} | ||
} | ||
catch (ContextAuthenticationException ex) { | ||
if (log.isDebugEnabled()) |
dkayiwa
Jul 27, 2018
Member
Did you take a look at this? https://wiki.openmrs.org/display/docs/Java+Conventions#JavaConventions-CodeStyle
Did you take a look at this? https://wiki.openmrs.org/display/docs/Java+Conventions#JavaConventions-CodeStyle
suthagar23
Jul 27, 2018
Author
Member
Actually, this came from the existing code. Do you want me to remove this as well?
Actually, this came from the existing code. Do you want me to remove this as well?
@@ -23,4 +23,6 @@ | |||
|
|||
public static final long PROCESS_HL7_TASK_INTERVAL = 5L; | |||
|
|||
public static final String LOCATION_USER_PROPERTY_NAME = "referenceapplication.locationUserPropertyName"; |
dkayiwa
Jul 27, 2018
Member
After looking at the other pull request, i have noticed that you expect the user property to be named as locationUuid
In such a case, of what value is this global property?
After looking at the other pull request, i have noticed that you expect the user property to be named as locationUuid
In such a case, of what value is this global property?
suthagar23
Jul 27, 2018
Author
Member
Using this Global property(name - referenceapplication.locationUserPropertyName), I want to fetch the userProperty Name(should be value of this GP). Then need to use this userPropertyName to fetch the location from the userProperty(should be value of that userProperty).
So in our module, I'm using "locationUuuid" as the userPropertyName to store the locationUuid. So setting "locationUuid" to this GP.
Using this Global property(name - referenceapplication.locationUserPropertyName), I want to fetch the userProperty Name(should be value of this GP). Then need to use this userPropertyName to fetch the location from the userProperty(should be value of that userProperty).
So in our module, I'm using "locationUuuid" as the userPropertyName to store the locationUuid. So setting "locationUuid" to this GP.
dkayiwa
Jul 27, 2018
Member
If you know that the property will be named as "locationUuuid", then of what value is the gp?
If you know that the property will be named as "locationUuuid", then of what value is the gp?
suthagar23
Jul 27, 2018
Author
Member
So can we move the locationUserProperty to a global property name as "locationbasedaccess.locationUserPropertyName"? So the userProperty name also will be fetched from the GP, and use that same value to this RefApp GP as well?
So can we move the locationUserProperty to a global property name as "locationbasedaccess.locationUserPropertyName"? So the userProperty name also will be fetched from the GP, and use that same value to this RefApp GP as well?
dkayiwa
Jul 27, 2018
Member
What do you think? What are the pros and cons of either side?
What do you think? What are the pros and cons of either side?
suthagar23
Jul 27, 2018
Author
Member
I think, We have already concluded this discussion 😄
I think, We have already concluded this discussion
Boolean isLocationUserPropertyAvailable = isLocationUserPropertyAvailable(administrationService); | ||
Object showLocation = pageRequest.getAttribute("showSessionLocations"); | ||
if(showLocation != null && showLocation.toString().equals("true")) { | ||
// if the request contains a attribute as showSessionLocations, then ignore isLocationUserPropertyAvailable |
dkayiwa
Jul 27, 2018
•
Member
Confusing how showLocation is true and then you set is location user property available to false?
Confusing how showLocation is true and then you set is location user property available to false?
suthagar23
Jul 27, 2018
Author
Member
if the URL has the parameter as "showSessionLocations" with value True, then we need to ignore the userProperty method(if exist or not). So simply setting isLocationUserPropertyAvailable=false to disable this feature to view the location selector in the login screen. (See the address bar of the browser in the attached images in the PR)
if the URL has the parameter as "showSessionLocations" with value True, then we need to ignore the userProperty method(if exist or not). So simply setting isLocationUserPropertyAvailable=false to disable this feature to view the location selector in the login screen. (See the address bar of the browser in the attached images in the PR)
dkayiwa
Jul 27, 2018
Member
who sets the showSessionLocations parameter to true and when?
who sets the showSessionLocations parameter to true and when?
suthagar23
Jul 27, 2018
Author
Member
When a user doesn't get the location userProperty, then it will redirect to the login page with showSessionLocations=true. So I'm checking this parameter to show/hide the location selector here. See this line - https://github.com/openmrs/openmrs-module-referenceapplication/pull/47/files#diff-bd998e9f6ec90d297ceba7fb14c2fe66R249
When a user doesn't get the location userProperty, then it will redirect to the login page with showSessionLocations=true. So I'm checking this parameter to show/hide the location selector here. See this line - https://github.com/openmrs/openmrs-module-referenceapplication/pull/47/files#diff-bd998e9f6ec90d297ceba7fb14c2fe66R249
if (Context.isAuthenticated() && Context.getUserContext().getAuthenticatedUser() != null) { | ||
String locationUuid = Context.getUserContext().getAuthenticatedUser().getUserProperty(locationUserPropertyName); | ||
if (StringUtils.isNotBlank(locationUuid)) { | ||
sessionLocation = locationService.getLocationByUuid(locationUuid); |
dkayiwa
Jul 27, 2018
Member
What happens when the uuid is for a non existing location?
What happens when the uuid is for a non existing location?
suthagar23
Jul 27, 2018
•
Author
Member
It will return the null object to the sessionLocation. So it might cause some issues to the next line.
Just added a fix to this problem. Please look at this line again @dkayiwa
It will return the null object to the sessionLocation. So it might cause some issues to the next line.
Just added a fix to this problem. Please look at this line again @dkayiwa
sessionLocation = locationService.getLocationByUuid(locationUuid); | ||
} | ||
if (sessionLocation != null) { | ||
sessionLocationId = sessionLocation.getLocationId(); |
dkayiwa
Jul 30, 2018
Member
Can you check the indention here?
Can you check the indention here?
sessionLocationId = sessionLocation.getLocationId(); | ||
} | ||
else { | ||
pageRequest.getSession().setAttribute(ReferenceApplicationWebConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, |
dkayiwa
Jul 30, 2018
Member
Can you look into the indention here?
Can you look into the indention here?
suthagar23
Aug 2, 2018
Author
Member
Fixed
Fixed
if (sessionLocation != null) { | ||
sessionLocationId = sessionLocation.getLocationId(); | ||
} | ||
else { |
dkayiwa
Aug 1, 2018
Member
The formatting or braces around here do not look correct.
The formatting or braces around here do not look correct.
suthagar23
Aug 2, 2018
Author
Member
Fixed
Fixed
a3965e8
to
d3a5ae1
… the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen RA-1516 Added support to select the location from the userProperty in the Login Screen Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes Indention changes LBAC-13 Added implementation to create RefApp location glopal property Added changes Added changes Added changes Added changes Added changes Added changes Added changes Added changes Added changes Added changes Added changes Added changes Added changes
Description
This PR contains the changes to select the session location from userProperty in the login screen. It will be worked according to these following steps,
Ticket
Ticket : https://issues.openmrs.org/browse/RA-1516