Filtering Roles

I create local administrators on the systems I develop, I do not give them access to Builder. I setup many screens for them to do what the ordinary user cant/shouldn't do, i.e add users, assign users to roles etc..

I want to limit what roles these Administrators can assign, at the moment once I give them the Roles field there is no way of filtering it so some Roles are not visible, its either all or nothing.

I would like to be able to filter the Roles field.

Hi Norm

I really appreciate that, works like a charm,  I should have known how to do that!!

I am just north of you, just outside of The Villages.

Anyway thanks again and if I can ever be of service just let me know.

Regards

John

Thanks John for the nice comment :)

Don't worry, less than a year ago, I knew nothing about Javascript, CCS and Knack!  So I copy and learn a lot from other's code too.

If you want to remove more than one Role, you just need to add an OR condition.  I have updated the code above to reflect that for you.

 

Cheers,

Norm

Hi Norm

Thanks so much for that, I have no knowledge of Java and am relegated to copying others hard work :(

This works great and whilst is not ideal (nothing ever is) enables me to restrict roles in a view.

Without imposing too much, using this code is there an easy way to hide more than one Role?

Again many thanks for sharing.

John

I had the same problem and came up with my own solution.

https://forums.knack.com/t/javascript-how-to-remove-entries-from-a-dropdown-ex-to-limit-account-roles/6509

 

Enjoy!
Norm

Cortex R&D Inc.

I am looking for a similar User Role data field capability...

The way I intend to use this role type is to enable say the Super User (ie. Portal owner to assign a User Admin role to a (level 1) business service provider. This User Admin role would then be able to create and manage their own level 2 normal users. (think of a 2 level tree structure). The User Admin role however cannot and must not be able to assign a Super User role to itself or to any of its normal Users.

There will ever be only 1 Super User role (i.e. the Portal owner),

There can be 1 or more User Admin roles (eg. individual shop owners using the Portal),

Following on, each of the User Admin (show owners) can create or manage their own shop User logins of which there can be multiple User logins belong to a specific shop...

Hi Norm

I have been using your snippet of code to filter User Roles for 18 months now and it has worked just great, thanks again.

I was wondering if you had refined it at all, I have just found out that if a user searches for a Role they can find it even though it has been hidden from view? Also it would be so much better if I could define what Roles to view as apposed to what Roles to hide.
If you have done anything more with this I would be very interested.

Thanks again for your help.

John

Hi Guys,

Thank you for the topic. It was very helpful. I had to build a similar code for more than one access roles (similar teams) but I had to hide the access from a team to another.
Blow is my code.
//Team A & Roles field for edit user role
$(document).on(‘mousedown keyup’,
#view_37_field_10_chzn’ +
‘, #view_107_field_10_chzn’ +
‘, view_134_field_10_chzn’

, function () {
  console.log (Knack.getUserAttributes().roles);
  	if (Knack.getUserRoles().includes("object_17")) 
    {	
      	if (!Knack.getUserRoles().includes("object_18"))
      $("ul.chzn-results li:contains('Super user - Team B')").remove();
        if (!Knack.getUserRoles().includes("object_19"))
      $("ul.chzn-results li:contains('Super user - Team C')").remove();
      $("ul.chzn-results li:contains('Admin')").remove();
      console.log ('2');
      }    
      console.log ('3');      
}

);

//Team B & Roles field for edit user role
$(document).on(‘mousedown keyup’,
#view_37_field_10_chzn’ +
‘, #view_107_field_10_chzn’ +
‘, view_134_field_10_chzn’

, function () {
  console.log (Knack.getUserAttributes().roles);
  	if (Knack.getUserRoles().includes("object_18")) 
    {	
        if (!Knack.getUserRoles().includes("object_17"))
      $("ul.chzn-results li:contains('Super user - Team A')").remove();
        if (!Knack.getUserRoles().includes("object_19"))
      $("ul.chzn-results li:contains('Super user - Team C')").remove();
      $("ul.chzn-results li:contains('Admin')").remove();
      console.log ('2');
      }    
      console.log ('3');      
}

);

//Team C & Roles field for edit user role
$(document).on(‘mousedown keyup’,
#view_37_field_10_chzn’ +
‘, #view_107_field_10_chzn’ +
‘, view_134_field_10_chzn’

, function () {
  console.log (Knack.getUserAttributes().roles);
  	if (Knack.getUserRoles().includes("object_19")) 
    {	
        if (!Knack.getUserRoles().includes("object_18"))
      $("ul.chzn-results li:contains('Super user - Team B')").remove();
        if (!Knack.getUserRoles().includes("object_17"))
      $("ul.chzn-results li:contains('Super user - Team A')").remove();
      $("ul.chzn-results li:contains('Admin')").remove();
      console.log ('2');
      }    
      console.log ('3');      
}

);