XPath - Association Equals Current User - How Does This Makes Sense?

0
This Crash Course part: https://academy.mendix.com/link/modules/325/lectures/2498/9.7.1-Set-Up-Entity-Security-Basics As I understand it: KeyUser (a manager) should have acces only to employees (Employee) that belong to departments that he manages. To do that, we use this XPath: So, we go through: Employee_Department association > Department entity > Employee_Department_Security association > Employee entity > Employee_Account association. Now I do not understand the last part. I would think, well to see the Employee entity is enough. But why is there the last line and how it even makes sense? How can Employee_Account association be equal to Current user? Does association (which is probably a link table with 2 columns) have a value that can be compared to something? And if we accept only value equal to current user (KeyUser or the hospital manager), the user should see only himself and not other users? Can somebody knowledgeable explain this, please?
asked
3 answers
1

If you're leaving out the last part, so just employee > department > employee, you would constrain the access to employees belonging to departments that have employees, which would be true for all employees (if all of them are assigned to a department), since there wouldn't even be a constraint on employees other than themselves.

 

The last part is needed to constrain access for the user to employees belonging to his/her own department. The association is enough, although it can be confusing at first and actually I think I read somewhere that Mendix accepts the ”extended” expression too in recent versions, but if you write it out all the way to account it will make no difference. An association is just another table, with two columns: the IDs from both ends of the association.

answered
0

The first paragraph of your comment showed me something, thank you. Still, I do not really understand the last line /UserManager.Employee_Account='[%CurrentUser%]']. Since we do visual programming, I tried to express this XPath visually:

image.png

Is this image OK? Maybe let's imagine other, very simple example of XPath constraint such as [UserManager.Employee_Account='[%CurrentUser%]'] which we use for Employee, so he/she can edit only his/her account. Still, even this simple example looks weird. How can association (which is a link table with 2 columns with account id and employee id, 1-to-1 because every employee has 1 account) be equal to Current User GUID (which is probably a string like"123456789")? List table object = string? That can never be equal.

If it was something like UserManager.Employee_Account.Employee.getGUID()='[%CurrentUser%]'], I would believe that it can be equal.

Back to our former example with KeyUser from the course. Even if in a sense we "identify that employee's account is equal to current user" how does this allow to see accounts of employees who are not equal to current user? Or if the meaning of this line is actually different, for example, "employee's account is equal to one of account in a certain set of accounts" (=accounts of users that belong to my mananged departments), why the line is not /UserManager.Employee_Account='(some code here listing the needed accounts)']?

Because all of this is generated by clicking on "Path to user..." and it is a XPath, it is a question into what code is this actually translated. It would help to understand better the underlying implementation.

Maybe the authors had the idea that let's traverse it like: "employee > department > employee" where the starting point are not all employees, but only me (current user?). So XPath code is like "employee > department > employee > current user" but more understandable would be "current user > employee > department > employee"? So, the image would look different, like this:

image.png

Well probably not, it seems somehow off :-)

answered
0

Thank you very much. My colleague also found this, which explains how association can be equal to something: https://academy.mendix.com/link/modules/385/lectures/3111/5.1-Different-Ways-to-Optimize-XPath-Queries

answered