Incomplete Change Packages : Sample server_preop_trig rules

Sample server_preop_trig rules
You can use AccuRev triggers to help prevent some of the actions that can lead to incomplete change packages. For general information about these triggers, see the discussion of server_preop_trig in the Administrator’s Guide, and the sample server_preop_trig.pl file in the AccuRev installation examples folder. The Perl snippets below take the examples provided in the sample server_preop_trig.pl file one step further and show how you can prevent non-administrators from purging files from higher-level streams, and how to enforce promote-by-issue in non-workspace streams.
 
###################################################### CUSTOMIZE ME
#### Add to (or replace) the example code below to
#### implement validation for the PROMOTE command.
######################################################
 
# EXAMPLE VALIDATION:
# only a user listed as an administrator can promote versions
# to a stream in the "admin_stream" list
 
#if ( defined($admin_stream{$stream2}) and `$::AccuRev ismember $principal "$admingrp"` == 0 ) {
# print TIO "Promoting to a stream identified as an 'admin stream' disallowed:\n";
# print TIO "server_preop_trig: You are not in the $admingrp group.\n";
# close TIO;
# exit(1);
#}
# EXAMPLE VALIDATION:
# only a user listed as an administrator can run the Promote
# command without entering a comment
if ( $comment eq "" and `$::AccuRev ismember $principal "$admingrp"` == 0 ) {
print TIO "Empty comments for 'promote' command disallowed:\n";
print TIO "server_preop_trig: You are not in the $admingrp group.\n";
close TIO;
exit(1);
}
# end of EXAMPLE VALIDATION
#This will prevent users from promoting or cross promoting individual files.
#Only users defined in the $admingrp group will be allowed to promote by file.
#This will prevent issues from becoming incomplete which can cause coalescing problems.
#foreach my $changepackage (keys(%{$$xmlinput{'changePackagePromote'}})){
#my @issues = (@{$$xmlinput{'changePackagePromote'}[0]{'changePackageID'}});
my @noissue = (@{$$xmlinput{'changePackagePromote'}});
foreach my $issue (@noissue) {
#foreach my $issue (@issues) {
#print "Array Issue num = $issue\n";
if ($issue == 0 and `$::AccuRev ismember $principal "$admingrp"` == 0 ){
print TIO "Promotion by file is disallowed.\n";
print TIO "You need to promote by issue, please select the issue which needs promotion and
promote\n";
print TIO "Only users in the $admingrp group are able to promote by file as this can cause
incomplete issues.\n";
close TIO;
exit(1);
}
}
# end of EXAMPLE VALIDATION
 
# no problems, allow command to proceed
close TIO;
exit(0);
}
 
#### end of validation for PROMOTE command
 
####
#### Validation for PURGE command
####
 
if ($command eq "purge") {
# at this point, the following variables will have meaningful values:
# $hook Trigger name
# $command AccuRev command being run
# $principal Username of person invoking command
# $ip IP address of AccuRev client machine
# $stream1 Stream from which versions are being purged
# $depot Depot name
# $fromClientPromote Data passed from pre-promote-trig script
# @elems Element list
 
###################################################### CUSTOMIZE ME
#### Add to (or replace) the example code below to
#### implement validation for the PURGE command.
######################################################
 
# EXAMPLE VALIDATION:
# only a user listed as an administrator can promote versions
# to a stream in the "admin_stream" list
 
#if ( defined($admin_stream{$stream1}) and `$::AccuRev ismember $principal "$admingrp"` == 0 ) {
# print TIO "Purging from a stream identified as an 'admin stream' disallowed:\n";
# print TIO "server_preop_trig: You are not in the $admingrp group.\n";
# close TIO;
# exit(1);
#}
# end of EXAMPLE VALIDATION
#Prevent users from purging elements so AccuWork issue will not become incomplete in streams.
unless ( $stream1=~/_$principal/ or `$::AccuRev ismember $principal "$admingrp"` == 1 ) {
print TIO "You can not perform \"Revert to Backed\" or purge operations in streams.\n";
print TIO "This will prevent CR's from disappearing in streams due to them becoming
incomplete issues.\n";
print TIO "Only users in the $admingrp group will be authorized to preform this
operation.\n";
close TIO;
exit(1);
}
 
# no problems, allow command to proceed
close TIO;
exit(0);
}
 
#### end of validation for PURGE command

AccuRev, Inc.
Phone: 781-861-8700
Fax: 781-861-8704
support@accurev.com