Action access control hook example
Access-control hooks restrict access to particular actions based on a specific set of criteria. In HCL Compass Designer, you can restrict actions to specific groups of users by choosing a hook type of User Group, or you can give everyone access to the action by choosing All Users. You can also choose the Scripts option and write a VBScript or Perl hook to determine access.
The following example shows how to limit access to a user named "Pat."
VBScript
Function swbug_AccessControl(actionname, actiontype, username)
' actionname As String
' actiontype As Long
' username As String
' swbug_AccessControl As Boolean
' action = close
Dim is_ok
' Test whether the current user has the privilege to close this bug
If username = "Pat" Then
is_ok = TRUE
Else
is_ok = FALSE
End If
swbug_AccessControl = is_ok
End Function
Perl
sub swbug_AccessControl {
my($actioname, $actiontype, $username) = @_;
my $result;
# $actioname string scalar (different name than other action hooks)
# $actiontype as long scalar
# $username as string scalar
# action is Open
# record type name is Defect
#
# To account for the different parameter name, use this:
# my $actionname = $actioname;
# Set $result to 1 if the user has permission to perform
# this action, otherwise set it to 0.
if ($username eq "Pat") {
$result = 1;
} else {
$result = 0;
}
return $result;
}
Note that the parameter name $actioname is spelled differently in the Perl action AccessControl hook script (it uses only one N), than for other Perl action hooks, and for the VBScript version, which uses $actionname (with two N's). Either use the different spelling, or make a new declaration with the other spelling, as described in the comment in the script.
Note that there is little need to use either $actionname or $actiontype in a submit hook because a record type can only have one submit action, so the hook does not need to programatically check which action is being done.