Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

[UI Script] Permissions for specific Custom fields


#1

I was wondering if there was a way that we could restrict specific Custom fields based on the user’s Role in the project.

For example,

  • Maybe I create a “Test Inaccurate” field that I only want the Lead’s on the project to view and update.

Could this be possible?

Thanks, Rich


Feature request - restrict R/W of Custom fields based on the user’s Role
#2

Hello Rich,

Thanks for your posting. While it would be possible to hide fields based on user roles with UI scripts (at least on the forms), this does not prevent users from submitting those fields manually and this would be a client-side feature only. So, it’s currently not really supported to hide single fields based on the user permissions or roles and I would recommend solving this “organizationally”, if possible.

Regards,
Tobias


#3

Not too sure what you mean by “does not prevent users from submitting those fields manually”. Please could you provide some more information around that.
Basically all I need is a Boolean field checkbox that is not visible to specific roles in TestRail (if possible)


#4

Hello Rich,

Thanks for your reply. If you just hide this field on the client side via a UI script, tech-savvy users could simply re-enable the field via the browser developer tools, for example, and then submit the form as usual. So, just hiding or removing the field from the form wouldn’t add any additional security (it would only make it a bit more difficult to submit the field).

If this is okay with you, you could hide or remove the field via a UI script. Do you need help with this or do you have a colleague with JavaScript experience?

Regards,
Tobias


#5

Oh ok I see what you are saying. I don’t think anyone on my team would go to the trouble of trying to enable the hidden field to change it and if they do, it doesn’t really matter, :slight_smile:

We basically just want to capture whether the test case was tested correctly and start reporting the metrics as a way of measuring success or identify training needs for individual testers.

If you could help provide the UI script that would be perfect.


#6

Hello Rich,

Good to hear that this works for you and we will make sure to implement a small example for this (and get back to you then).

Regards,
Tobias


#7

Just following up on this to see if you were able to provide a script that we could use.


#8

Hello Rich,

My apologies for the delay. Here’s an example script you can use:

[code]name: Hides the Test Inaccurate field on the case form
description: Hides the Test Inaccurate field on the case form
author: Gurock Software
version: 1.0
includes: ^cases/(add|edit)
excludes:

js:
(document).ready( function() { if (uiscripts.context.user.role_id != 1) { (’#somefield’).parent(‘td’).remove();
}
}
);
[/code]

You would need to replace ‘#somefield’ with the system name of your custom field (e.g. ‘#custom_testinaccurate’). This script would remove the field for all users on the test case form if they don’t have the Lead role (globally) and you can change this as needed by modifying the following line:

The default role IDs are:

[list=]
[
]1: Lead[/]
[
]2: Designer[/]
[
]3: Tester[/]
[
]4: Guest[/*]
[/list]

I hope this helps and please let me know in case you have any questions.

Regards,
Tobias


#9

Tobias,

Thank you very much for sending this along. I have added a CustomField called testaccuracy and added

     $('#custom_testaccuracy').parent('td').remove(); 

to the UI script… but the field is still visible to all role levels.

This custom field has been added to the [Test Result field] types. As this field will be used once the Test Run has been completed. Is this the reason why it is still visible?

Thanks, Rich


#10

Hello Rich,

Thanks for your reply. The UI script would be for the test case form but we are happy to add a UI script for the Add Test Result dialog as well. We will make sure to prepare an example for this as well.

Regards,
Tobias


#11

That would be excellent… thank you. It would be great to have both options available to us.


#12

Hello Rich,

Here’s the same script for your Test Accuracy field for the Add Test Result dialog (assuming that this field is displayed on the right side of this dialog):

[code]name: Hides the Test Accuracy field on the result dialog
description: Hides the Test Accuracy field on the result dialog
author: Gurock Software
version: 1.0
includes:
excludes:

js:
(document).ready( function() { .subscribe(
‘result_dialog.loaded’,
‘uiscript_hide_version’,
function()
{
if (uiscripts.context.user.role_id != 1)
{
$(’#custom_testaccuracy’).parent(‘div’).remove();
}
}
);
}
);[/code]

I hope this helps!

Regards,
Tobias


#13

Thank you very much for this… works great!

Is it possible to remove the text label that appears in the “TestResult” history?
The reason we want this field invisible to our testers is that we don’t want to call them out for not testing something correctly, but use it as a teaching moment, :slight_smile: However, the field still appears on the Test Pass history so regardless of whether they can see the field, it still shows up for them to see.


#14

Hello Rich,

Thanks for your reply. I understand what you are looking for but this wouldn’t be fully supported currently. While it should be possible (difficult, but possible) to hide this on the the initial page request, there are situations where the result list is regenerated/reloaded (e.g. when you add a new test result) and there’s currently no option to intercept this with UI scripts (and change the list then again).

Regards,
Tobias


#15

Ok no problem… I understand. Thank you for your reply.


#16

Hello Rich,

Thanks for your reply and I hope that this would still work for you.

Regards,
Tobias