Workspace security example

The following code example illustrates how to use workspace security methods (including methods of the Folder, Folders, Permission, and Permissions objects) to retrieve workspace security permissions applied to Public and Personal folders. This example provides a general idea of how you might use the ClearQuest® API to create a workspace folder security policy and retrieve information on current settings.

Perl

use strict;
require "CQPerlExt.pm";


################################
# Subroutines

sub get_access_description($)
{
    my ($folder) = @_;

    my $perm  = $folder->GetPermission();
    my $kind  = $perm->GetKindName();
    my $group = $perm->GetGroup($CQPerlExt::CQ_NAME_EXTEND_WHEN_NEEDED);

    return "$kind for $group";
}

sub show_subfolders($$);
sub show_subfolders($$)
{
    my ($folder, $indent) = @_;

    my $name = $folder->GetName();
    my $access = get_access_description($folder);

    my $folders = $folder->GetSubfolders();
    my $count = $folders->Count();

    print $indent . "$name: $access\n";
    for (my $i = 0; $i < $count; $i++) {
        my $folder = $folders->Item($i);
        show_subfolders($folder, $indent . "|  ");
    }
}


################################
# Main

my $session;
my $workspace;
my $PublicFolder;
my $PersonalFolder;
my $PublicFolderName;
my $PersonalFolderName;

if (scalar(@ARGV) != 4) {
    die "ERROR: insufficient arguments; need username, password, database, dbset\n";
}

my ($username, $password, $database, $dbset) = @ARGV;

$session = CQSession::Build();
$session->UserLogon($username, $password, $database, $dbset);

$workspace = $session->GetWorkSpace();

$PublicFolder = $workspace->GetPublicFolder(); 
$PublicFolderName = $workspace->GetPublicFolderName();
show_subfolders($PublicFolder, "");

$PersonalFolder = $workspace->GetPersonalFolder(); 
$PersonalFolderName = $workspace->GetPersonalFolderName();
show_subfolders($PersonalFolder, "");

$session->Unbuild();
$session = undef;

# end Main

Feedback