Display Records Based on Login User

StatusIDPriorityType
Closed24245TrivialQuestion
ProfileReply
doorscomputersClient

Hi,
May I kidnly ask for an example on how to use the xafari security feature on how to display or filter records based on logged in user? If an employee login then he/she can be able to see just his/her records and edit it.Thanks!

Replies

UserDescriptionPosted On
Sasha (Xafari Support)Agent

Hello,

At first we recommend reading these tickets:
Error while access IDCUser's DetailView
Adding arm’s permission access
and in the article Work Places.

If you need any further assistance on this subject, please feel free to write this ticket.

Thanks, Sasha.

doorscomputers

Hi, Hope you can provide a working example on this. Where employee ABC logged in then he cannot see the record of Employee JKL. Thanks!

doorscomputers

By the way , In my xaf application, I have inherited the Xaf Security systemuser with my employee class
public class Employee : SecuritySystemUser
public Employee(Session session)
: base(session)
{
}

private string _PhoneNumber;
private string _HomeAddress;
private Gender _Gender;
private DateTime _BirthDay;
private string _MiddleName;
private string _FirstName;
private string _LastName;
........ etc.

At run time I have created new users Like "John", Luis and Ray, and made some relationship to the employee to other classes like Savings and deposit at design time , If I run the application , I want that if John Logged in, he will not see any record associated with Luis and Ray, John can only see and edit his own personal Employee record and can only read his own deposit and withdrawal transaction but he cannot edit it. Is this possible in Xaf Security ? Thanks much!

Sasha (Xafari Support)Agent

Hello,

Thank you for the additional information.
Give us some time to researching this scenario.

Regards, Sasha.

Sasha (Xafari Support)Agent

Hello,

 

You can see the video to solve your issue with the Login User,
where you use specific properties CurrentUserName, RegistryUserName and set filter in Model.
(See attached file EmployeeUserTest)

 

I hope you find this information helpful.
Let me know if you need further assistance.
Regards, Sasha.

Attached files:
doorscomputers

Hi, thanks so much for the very detailed explanation. Does it matter if I use this in my code below?

My Code Below
public class Employee : SecuritySystemUser
public Employee(Session session)
: base(session)
{
}.......

I have used the built in xaf Security system user. I tried but it does not work, Will I strictly follow then the code you have given to me? And How do I begin the exaample you have shown on the video, I guess I will use the xafari security system right ma'am? Please be patient on me, Thanks!

Sasha (Xafari Support)Agent

Hello,

 

To solve your issue you can read the DevExpress tutorials: How to: Implement a Custom Security System User Based on an Existing Business Class, How to: Implement Custom Security Objects (Users, Roles, Operation Permissions).

Also you can see video and simple sample for your issue "Display Records Based on Login User" and use the settings for Xafari Security or DevExpress Security.
See attached files.

 

Let me know if you need further assistance.
Thanks, Sasha.

doorscomputers

Thanks so much for the demo. I assume that for every user created by admin, and admin will create a related record of another class for example like payroll then when that user or employee log in then he/she cannot see other records of other employees. The employee at the same time user can only see his own records whether it is the personal information or the payroll class which I intend to add then the employee cannot update it.

BTW, once last question on this topic, I am planning to add other classes related to the employee like , a table for attendance and a table for payroll, then for the employee to view only his own attendance and payroll then I will need to put the ListViewFilter for the Attendance and payroll class right?

for example do I need to do this on these two classes

[DefaultClassOptions]
ListViewFilter("CurrentUser", "[CurrentUsername]" = [RegistryUserName]", true)

Public class Attendance ; XpObject
{
...... Codes here for Attendance class
}

[DefaultClassOptions]
ListViewFilter("CurrentUser", "[CurrentUsername]" = [RegistryUserName]", true)

Public class Payroll; XpObject
{
...... Codes here for Payrollclass
}

Is this the important code 'ListViewFilter("CurrentUser", "[CurrentUsername]" = [RegistryUserName]", true)" for me to be able to filter the records on
the Attendance class and Payroll class for each user?

Thanks so much for being very patient to me! I appreciate so much your help

doorscomputers

Hi,
I modified a bit the sample test xaf project and just added an attendance class and associated it with the employee class.
I created 2 new employees with their corresponding login information. Then I tried to create Attendance records for each employee.For example the First employee is John, and the second is Mark each with their own attendance inputed by admin user or employee.
However, when I login as John , I see the attendance record of Mark, the same with Mark, he can also see the attendance record of John. What I just want is if I login as John then I can only see my attendance but not edit, readonly permission. And one last additional request, How can I make each employee created or added to default in all as read only mode access to all the classes to be created in the future?

Attached files:
doorscomputers

I forgot to pest the video Link
http://www.screencast.com/t/U94htQTj

Sasha (Xafari Support)Agent

Hello,

 

Firstly, if you want set filters to each views, you can use attribute [ListViewFilter], or use the filter from the Model, or create ViewController.
And yes, you can use your strategy like Attendance class or like EmployeeUserTest class.
Attribute for Attendance class:

[ListViewFilter("Current User", "[Employee.Oid]=CurrentUserId()", true)]

You can see the details in attached video.

 

Feel free to contact us if you have any questions.
Regards, Sasha.

doorscomputers

Wow!!!! Thank you so much for the great support from xafari , Thanks very much Sasha. Thanks so much for the patience in answering all my newbie questions. The last video is what I am trying to accomplish, all the previous video tutorials are also very helpful.

× This ticket is closed.

Write US