Howto make parts of report visible depending on users role

mgerhartzmgerhartz Member Posts: 50
Hi,

I want to know how I can manage to make only these parts visible for users, which are associated with the users role.

For example, the report stores content for the whole company, but the user has only the right to see content which concerns himselfe.


Thanks for your help!

Markus

Comments

  • krikikriki Member, Moderator Posts: 9,118
    You can create some new security-roles without permissions in them.
    Then before showing certain data, you can check if the user belongs to a certain security-role.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mgerhartzmgerhartz Member Posts: 50
    Hi again,

    and how do I check the users role? Maybe somebody can show the necessary part of the code :roll:
  • girish.joshigirish.joshi Member Posts: 407
    The information you want is in the Member Of table

    Primary Key - User, Role ID, Company

    Implements the many to many relationship between Users and User Roles.
  • krikikriki Member, Moderator Posts: 9,118
    mgerhartz wrote:
    Hi again,

    and how do I check the users role? Maybe somebody can show the necessary part of the code :roll:
    Function IsMemberOf(codUserID,codRoleID,txtCompanyname):BOOLEAN
    // this function returns a TRUE if "codUserID" belongs to role "codRoleID"  in company "txtCompanyname"
    
    // check DB-users
    recMemberOf.RESET;
    recMemberOf.SETCURRENTKEY("User ID","Role ID",Company);
    recMemberOf.SETRANGE("User ID",codUserID);
    recMemberOf.SETRANGE("Role ID",codRoleID);
    recMemberOf.SETFILTER(Company,'%1|%2',txtCompanyname,'');
    IF recMemberOf.FIND('-') THEN
      EXIT(TRUE);
    
    // check windows users
    recWindowsAccessControl.RESET;
    recWindowsAccessControl.SETCURRENTKEY("Login SID","Role ID",Company);
    recWindowsAccessControl.SETRANGE("Login SID",codUserID);
    recWindowsAccessControl.SETRANGE("Role ID",codRoleID);
    recWindowsAccessControl.SETFILTER(Company,'%1|%2',txtCompanyname,'');
    IF recWindowsAccessControl.FIND('-') THEN
      EXIT(TRUE);
    
    EXIT(FALSE);
    
    I didn't test the code, so especially for the Windows users there might be something extra to write to check it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mgerhartzmgerhartz Member Posts: 50
    Hi Kriki,

    thanks for the code. I've tested it, but there is a problem with the variable type in these lines:

    recMemberOf.SETRANGE("User ID",codUserID);
    recMemberOf.SETRANGE("Role ID",codRoleID);

    The variables CodRoleID and CodUserID are Boolean variables and the variable User ID and Role ID are Code variables. When I worte the follwing code infront of it:

    recMemberOf.SETRANGE("User ID",FORMAT(codUserID));
    recMemberOf.SETRANGE("Role ID",FORMAT(codRoleID));

    ..then I got problems with the line: EXIT(TRUE), because, at this time the format changed from boolean to code.
  • jmjm Member Posts: 156
    mgerhartz wrote:
    The variables CodRoleID and CodUserID are Boolean variables

    These variables are definitely code variavales.

    br
    Josef Metz
    br
    Josef Metz
  • mgerhartzmgerhartz Member Posts: 50
    I'm sorry, just take a look at the headline of the function. These variables are defined as Boolean, because they should give me a feedback of TRUE or FALSE.
  • krikikriki Member, Moderator Posts: 9,118
    mgerhartz wrote:
    I'm sorry, just take a look at the headline of the function. These variables are defined as Boolean, because they should give me a feedback of TRUE or FALSE.
    Some clarification:
    The function "IsMemberOf" must return a BOOLEAN
    But "codUserID","codRoleID" are code-fields (code20 or longer) and
    txtCompanyname is a text-field (text30 or longer)

    1 Remark:
    I didn't test it with Windows-users, so it is possible you need "codUserID" as a text for it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mgerhartzmgerhartz Member Posts: 50
    Thank's! That was my false. Now I was able to solve my problem. Have a nice day O:)
Sign In or Register to comment.