--- smeserver-trac-0.4/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/trac.pm.newlines 2007-04-27 00:54:46.000000000 -0600 +++ smeserver-trac-0.4/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/trac.pm 2008-04-26 09:16:34.000000000 -0600 @@ -1,954 +1,954 @@ -#!/usr/bin/perl -w -#---------------------------------------------------------------------- -# $Id: trac.pm 69 2007-03-25 13:20:24Z marco $ -# vim: ft=perl ts=4 sw=4 et: -#---------------------------------------------------------------------- -# Copyright (C) 2007 Marco Hess -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -#---------------------------------------------------------------------- - -package esmith::FormMagick::Panel::trac; - -use strict; -use warnings; - -use esmith::FormMagick; -use esmith::AccountsDB; -use esmith::ConfigDB; -use esmith::DomainsDB; -use esmith::cgi; -use esmith::util; -use File::Basename; -use Exporter; -use Carp; -use Sys::Syslog; - -use constant TRUE => 1; -use constant FALSE => 0; - -our @ISA = qw(esmith::FormMagick Exporter); - -our @EXPORT = qw( - show_trac_projects - print_trac_field_name - repositories_list - group_list - user_list - max_trac_project_name_length - handle_trac_projects - create_trac_project - remove_trac_project - getExtraParams - print_save_or_add_button - validate_name - validate_radio - wherenext - maxLength -); - -our $ConfigDB = esmith::ConfigDB->open - or die "Can't open the Config database : $!\n" ; - -our $AccountsDB = esmith::AccountsDB->open - or die "Can't open the Account database : $!\n" ; - -our $DomainsDB = esmith::DomainsDB->open - or die "Can't open the Domains database : $!\n" ; - - -# fields and records separator for sub records -use constant FS => "," ; -use constant RS => ";" ; - -=pod - -=head1 NAME - -esmith::FormMagick::Panels::trac - Trac - -=head1 SYNOPSIS - -use esmith::FormMagick::Panels::trac - -my $panel = esmith::FormMagick::Panel::trac->new(); -$panel->display(); - -=head1 DESCRIPTION - -This module is the backend to the Trac panel, responsible -for supplying all functions used by that panel. It is a subclass -of esmith::FormMagick itself, so it inherits the functionality -of a FormMagick object. - -=cut - -=head2 new() - -Exactly as for esmith::FormMagick - -=cut - -sub new -{ - my $proto = shift; - my $class = ref($proto) || $proto; - my $self = esmith::FormMagick::new($class); - $self->{calling_package} = (caller)[0]; - - return $self; -} - -=head1 HTML GENERATION ROUTINES - -Routines for generating chunks of HTML needed by the panel. - -=cut - -=head2 show_trac_projects() - -This function displays a table of trac project environments on the system -including the links to modify and remove the trac project environment. - -=cut - -sub show_trac_projects { - my $fm = shift; - my $q = $fm->{cgi}; - - # Setup the various localised text field for the trac project table - my $name = $fm->localise('TRAC_TABLE_HEADER_NAME'); - my $description = $fm->localise('TRAC_TABLE_HEADER_DESCRIPTION'); - my $domains = $fm->localise('TRAC_TABLE_HEADER_DOMAINS'); - my $repository = $fm->localise('TRAC_TABLE_HEADER_REPOSITORY'); - my $path = $fm->localise('TRAC_TABLE_HEADER_PATH'); - my $access = $fm->localise('TRAC_TABLE_HEADER_ACCESS'); - my $action_h = $fm->localise('TRAC_TABLE_HEADER_ACTION'); - my $view = $fm->localise('TRAC_ACTION_VIEW'); - my $modify = $fm->localise('TRAC_ACTION_MODIFY'); - my $remove = $fm->localise('TRAC_ACTION_REMOVE'); - my $backup = $fm->localise('TRAC_ACTION_BACKUP'); - my $restore = $fm->localise('TRAC_ACTION_RESTORE'); - - print $q->start_table({-class => 'sme-noborder'}), "\n"; - - # Check if any repositories exist - my @repositories = $AccountsDB->get_all_by_prop('type' => 'repository'); - unless ( scalar @repositories ) - { - print $q->Tr($q->td($q->h2($fm->localise('NO_REPOSITORIES')))); - return ""; - } - - # TODO what about the case that all repositories have been deleted - # but the Trac project environments are still there? Can we remove the - # trac projects or do we need to reassign the projects to - # another repository? The code above prevents us from accessing the - # trac projects when there are no more repositories. - - print $q->Tr($q->td($q->a({-class => "button-like", - href => "trac?page=0&page_stack=&Next=Next&wherenext=Create"}, - $fm->localise('TRAC_ADD_BUTTON')))); - - # Check if any trac projects exist - my @TracProjects = $AccountsDB->get_all_by_prop('type' => 'trac'); - unless ( scalar @TracProjects ) - { - print $q->Tr($q->td($q->h2($fm->localise('NO_TRAC_PROJECTS')))); - return ""; - } - - # Show the list of configures trac projects - print $q->Tr($q->td($q->h2($fm->localise('CURRENT_TRAC_PROJECTS')))); - - print $q->Tr($q->td($fm->localise('TRAC_MODIFY_REMOVE_BUTTON_DESCRIPTION'))); - - print $q->start_table({-CLASS => "sme-border"}),"\n"; - print $q->Tr ( - esmith::cgi::genSmallCell($q, $name, "header"), - esmith::cgi::genSmallCell($q, $description,"header"), - esmith::cgi::genSmallCell($q, $domains, "header"), - esmith::cgi::genSmallCell($q, $repository, "header"), - esmith::cgi::genSmallCell($q, $path, "header"), - esmith::cgi::genSmallCell($q, $access, "header"), - esmith::cgi::genSmallCell($q, $action_h, "header", 3)),"\n"; - - my $scriptname = basename($0); - - foreach my $TracProject (@TracProjects) - { - my $trac_name = $TracProject->key(); - my $trac_desc = $TracProject->prop('Description'); - my $trac_domains = join("
", split(FS, $TracProject->prop('Domains'))); - my $trac_repo = $TracProject->prop('Repository'); - my $trac_path = $TracProject->prop('RepositoryPath'); - my $trac_access = $TracProject->prop('Access') || 'local'; - my $modifiable = $TracProject->prop('Modifiable') || 'yes'; - my $removable = $TracProject->prop('Removable') || 'yes'; - - my $params = $fm->build_trac_project_cgi_params($trac_name, $TracProject->props()); - - my $href = "$scriptname?$params&action=modify&wherenext="; - - my $actionView = ' '; - $actionView .= $q->a({href => '/' . $TracProject->key(), - target => '_blank'}, $view ) . ' '; - - my $actionModify = ' '; - if ($modifiable eq 'yes') - { - $actionModify .= $q->a({href => "${href}Modify"}, $modify) . ' '; - } - - my $actionRemove = ' '; - if ($removable eq 'yes') - { - $actionRemove .= $q->a({href => "${href}Remove"}, $remove) . ' '; - } - - my $actionBackup = ' '; - $actionBackup .= $q->a({href => "${href}Backup"}, $backup) . ' '; - - my $actionRestore = ' '; - $actionRestore .= $q->a({href => "${href}Restore"}, $restore) . ' '; - - print $q->Tr( - esmith::cgi::genSmallCell($q, $trac_name, "normal"), - esmith::cgi::genSmallCell($q, $trac_desc, "normal"), - esmith::cgi::genSmallCell($q, $trac_domains, "normal"), - esmith::cgi::genSmallCell($q, $trac_repo, "normal"), - esmith::cgi::genSmallCell($q, $trac_path, "normal"), - esmith::cgi::genSmallCell($q, $trac_access, "normal"), - esmith::cgi::genSmallCell($q, $actionView, "normal"), - esmith::cgi::genSmallCell($q, $actionModify, "normal"), - esmith::cgi::genSmallCell($q, $actionRemove, "normal") - ); - } - - print $q->end_table,"\n"; - - print $q->end_table,"\n"; - - return ""; -} - -=cut - -=head2 print_save_or_add_button() - -Prints the ADD button when a new trac project environment is addded and the SAVE buttom -whem modifications are made. - -=cut - -sub print_save_or_add_button { - - my ($fm) = @_; - - my $cgi = $fm->{cgi}; - - if (($cgi->param("action") || '') eq "modify") { - $fm->print_button("SAVE"); - } else { - $fm->print_button("ADD"); - } -} - -=head1 HELPER FUNCTIONS FOR THE PANEL - -Routines for modifying the database and signaling events -from the server-manager panel - -=cut - -=head2 build_trac_project_cgi_params($fm, $tracprojectname, %oldprops) - -Constructs the parameters for the links in the trac project environments table - -=cut - -sub build_trac_project_cgi_params { - my ($self, $tracprojectname, %oldprops) = @_; - - my %props = ( - page => 0, - page_stack => "", - tracName => $tracprojectname, - ); - - return $self->props_to_query_string(\%props); -} - -*wherenext = \&CGI::FormMagick::wherenext; - -=head2 print_trac_field_name() - -Helper function to print the field NAME so that it becomes -an edit field upon ADD and a fixed field upon MODIFY. - -Also read all the account db values so the other fields -can show the existing values. - -=cut - -sub print_trac_field_name { - my $fm = shift; - my $in = $fm->{cgi}->param('tracName') || ''; - my $action = $fm->{cgi}->param('action') || ''; - - print qq() . - $fm->localise('TRAC_FIELD_PROJECT_NAME') . qq(\n); - - if ($action eq 'modify' and $in) { - #------------------------------------------------------- - # Updating an existing record. - #-------------------------------------------------------- - - my $rec = $AccountsDB->get($in); - my $modifiable = $rec->prop('Modifiable') || 'yes'; - my $removable = $rec->prop('Removable') || 'yes'; - - print qq( - $in - - - - ); - - # Read the values for each field from the accounts db and store - # them in the cgi object so our form will have the correct - # info displayed. - my $q = $fm->{cgi}; - if ($rec) - { - $q->param(-name=>'tracDescription',-value=> - $rec->prop('Description')); - - $q->param(-name=>'tracRepository',-value=> - $rec->prop('Repository')); - - $q->param(-name=>'tracRepositoryPath',-value=> - $rec->prop('RepositoryPath')); - - # domain list is handled separately - - $q->param(-name=>'tracGroups',-value=> - join(FS, split(FS, $rec->prop('Groups')))); - - $q->param(-name=>'tracUsers',-value=> - join(FS, split(FS, $rec->prop('Users')))); - - $q->param(-name=>'tracAccess',-value=> - $rec->prop('Access')), - } - } else { - #------------------------------------------------------- - # Adding a new record so allow an entry field for the - # name. - #-------------------------------------------------------- - print qq( - - - - ); - } - - print qq(\n); - return undef; -} - - -=head2 print_trac_domains() - -When this server has more than one domain this function takes -the list of domains and returns a string of html checkboxes -for all these domains. - -Those domains that are listed with this Trac environment -will have their checkbox checked. - -=cut - -sub print_trac_domains() { - - # Retrieve the Trac account name from the CGI parameters - my $fm = shift; - my $name = $fm->{'cgi'}->param('tracName'); - my $action = $fm->{'cgi'}->param("action") || ''; - my $out = ""; - - # Get a full list of all the domains on this server. - my @domains = $DomainsDB->get_all_by_prop( type => 'domain' ); - my $numdomains = @domains; - - # If there is more than one domain, we generate a list - # of checkboxes. Otherwise we just show the primary domain. - if ($numdomains > 1) { - - # With the Trac account name, get the list of the Domains for which - # this Trac account is active. - my $trac_domains_list = ""; - if ($AccountsDB->get($name)) { - $trac_domains_list = $AccountsDB->get($name)->prop('Domains'); - } - - # Split the comma separated list into the individual bits. - my %trac_domains; - foreach my $trac_domain ( split ( /,/, $trac_domains_list ) ) { - $trac_domains{$trac_domain} = 1; - } - - # Now generate the table of domains with a checkbox in front of it. - # If the domain is in our listed domains for the Trac environment, the - # checkbox will show checked. - $out = " \n"; - $out .= " " . $fm->localise('TRAC_FIELD_DOMAINS_DESCRIPTION') . ""; - $out .= " \n"; - $out .= " \n"; - $out .= " " . $fm->localise('TRAC_FIELD_DOMAINS') . "\n"; - $out .= " \n"; - $out .= " \n"; - $out .= " \n"; - - foreach my $domain (sort @domains) { - - # If this is a ADD form, we default check all domains, otherwise only - # those that are in our Trac project list. - my $checked = ""; - if ( $action eq 'modify' ) { - if ( $trac_domains{ $domain->key() } ) { - $checked = "checked"; - } - } else { - $checked = "checked"; - } - - $out .= " \n"; - $out .= " \n"; - $out .= " \n"; - $out .= " \n"; - } - - $out .= "
key . "\">" . $domain->key . "
\n"; - $out .= " \n"; - $out .= " \n"; - } - else - { - # We only have a single domain, so we just show this domain but without the - # checkbox (so it can't be unchecked). - my $domainname = $ConfigDB->get('DomainName')->value(); - $out = " \n"; - $out .= " " . $fm->localise('TRAC_FIELD_DOMAIN_DESCRIPTION') . ""; - $out .= " \n"; - $out .= " \n"; - $out .= " " . $fm->localise('TRAC_FIELD_DOMAIN') . "\n"; - $out .= " "; - $out .= $domainname . "\n"; - $out .= " \n"; - } - - return $out; -} - - -=pod - -=head2 repositories_list() - -Returns a hash of repositories for the Create/Modify screen's repository -field's drop down list. - -=cut - -sub repositories_list -{ - my @repositories = $AccountsDB->get_all_by_prop('type' => 'repository'); - my %repositories = (); - foreach my $repository (@repositories) { - $repositories{$repository->key()} = $repository->prop('Description') . " (" . $repository->key . ")"; - } - return \%repositories; -} - -=head2 group_list() - -Returns a hash of groups for the Create/Modify screen's group -field's drop down list. - -=cut - -sub group_list -{ - my @groups = $AccountsDB->groups(); - my %groups = (); - foreach my $group (@groups) { - $groups{$group->key()} = $group->prop('Description')." (".$group->key.")"; - } - return \%groups; -} - -=head2 user_list() - -Returns a hash of users for the Create/Modify screen's user field's -drop down list. - -=cut - -sub user_list -{ - my @users = $AccountsDB->users(); - my %users = (); - foreach my $user (@users) { - $users{$user->key()} = $user->prop('LastName').", ". $user->prop('FirstName')." (". $user->key.")"; - } - return \%users; -} - -=head1 THE ROUTINES THAT ACTUALLY DO THE WORK - -=cut - -=head2 handle_trac_projects() - -Determine whether to modify or add the trac project environment - -=cut - -sub handle_trac_projects { - - my ($fm) = @_; - - if ($fm->cgi->param("action") eq "create") { - $fm->create_trac_project(); - } else { - $fm->modify_trac_project(); - } - -} - -=head2 create_trac_project() - -Handle the create event for the trac project environment - -=cut - -sub create_trac_project { - - my ($fm) = @_; - - # Validate Name - # ============= - - my $name = $fm->cgi->param('tracName'); - my $msg; - - $msg = $fm->validate_name($name); - unless ($msg eq "OK") - { - return $fm->error($msg); - } - - $msg = $fm->max_trac_project_name_length($name); - unless ($msg eq "OK") - { - return $fm->error($msg); - } - - $msg = $fm->conflict_check($name); - unless ($msg eq "OK") - { - return $fm->error($msg); - } - - # Validate & Setup Domain List - # ============================ - - my @active_trac_domains = $fm->cgi->param('tracDomains'); - - $msg = $fm->validate_trac_has_domains(@active_trac_domains); - unless ($msg eq "OK") - { - return $fm->error($msg); - } - - my $domain_list = ""; - foreach my $domain (@active_trac_domains) { - if ($domain_list) { - $domain_list .= "," . $domain; - } else { - $domain_list = $domain; - } - } - - # Setup Group List - # ================ - - my @groups = $fm->cgi->param('tracGroups'); - - my $group_list = ""; - foreach my $group (@groups) { - if ($group_list) { - $group_list .= "," . $group; - } else { - $group_list = $group; - } - } - - # Setup User List - # =============== - - my @users = $fm->cgi->param('tracUsers'); - - my $user_list = ""; - foreach my $user (@users) { - if ($user_list) { - $user_list .= "," . $user; - } else { - $user_list = $user; - } - } - - # Update Database - # =============== - - my $uid = $AccountsDB->get_next_uid(); - if (my $acct = $AccountsDB->new_record($name, { - Description => $fm->cgi->param('tracDescription'), - Repository => $fm->cgi->param('tracRepository'), - RepositoryPath => $fm->cgi->param('tracRepositoryPath'), - Domains => "$domain_list", - Groups => "$group_list", - Users => "$user_list", - Modifiable => 'yes', - Removable => 'yes', - Access => $fm->cgi->param('tracAccess'), - type => 'trac', - }) ) - { - # Untaint $name before use in system() - $name =~ /(.+)/; $name = $1; - - $fm->clear_params(); - - if (system ("/sbin/e-smith/signal-event", "trac-project-create", $name) == 0) { - $fm->success("SUCCESSFULLY_CREATED_TRAC_PROJECT"); - } else { - $fm->error("ERROR_WHILE_CREATING_TRAC_PROJECT"); - } - } else { - $fm->error('CANT_CREATE_TRAC_PROJECT'); - } -} - -=head2 modify_trac_project() - -Handle the modify event for the trac project environment - -=cut - -sub modify_trac_project { - - my ($fm) = @_; - my $name = $fm->cgi->param('tracName'); - - # Validate Name - # ============= - - my $msg = $fm->validate_name($name); - unless ($msg eq "OK") - { - return $fm->error($msg); - } - - # Validate & Setup Domain List - # ============================ - - my @active_trac_domains = $fm->cgi->param('tracDomains'); - - $msg = $fm->validate_trac_has_domains(@active_trac_domains); - unless ($msg eq "OK") - { - return $fm->error($msg); - } - - my $domain_list; - foreach my $domain (@active_trac_domains) { - if ($domain_list) { - $domain_list .= "," . $domain; - } else { - $domain_list = $domain; - } - } - - # Setup Group List - # ================ - - my @groups = $fm->cgi->param('tracGroups'); - - my $group_list; - foreach my $group (@groups) { - if ($group_list) { - $group_list .= "," . $group; - } else { - $group_list = $group; - } - } - - # Setup User List - # =============== - - my @users = $fm->cgi->param('tracUsers'); - - my $user_list; - foreach my $user (@users) { - if ($user_list) { - $user_list .= "," . $user; - } else { - $user_list = $user; - } - } - - # Update Database - # =============== - - if (my $acct = $AccountsDB->get($name)) { - if ($acct->prop('type') eq 'trac') { - - $acct->merge_props( - Description => $fm->cgi->param('tracDescription'), - Repository => $fm->cgi->param('tracRepository'), - RepositoryPath => $fm->cgi->param('tracRepositoryPath'), - Domains => $domain_list, - Groups => $group_list, - Users => $user_list, - Access => $fm->cgi->param('tracAccess'), - type => 'trac', - ); - - # Untaint $name before use in system() - $name =~ /(.+)/; $name = $1; - - $fm->clear_params(); - - if (system ("/sbin/e-smith/signal-event", "trac-project-modify", $name) == 0) - { - $fm->success("SUCCESSFULLY_MODIFIED_TRAC_PROJECT"); - } else { - $fm->error("ERROR_WHILE_MODIFYING_TRAC_PROJECT"); - } - } else { - $fm->error('CANT_FIND_TRAC_PROJECT'); - } - } else { - $fm->error('CANT_FIND_TRAC_PROJECT'); - } -} - -=head2 remove_trac_project() - -Handle the remove event for the trac project environment - -=cut - -sub remove_trac_project { - - my $fm = shift; - - my $name = $fm->cgi->param('tracName'); - if (my $acct = $AccountsDB->get($name)) { - if ($acct->prop('type') eq 'trac') { - $acct->set_prop('type', 'trac-deleted'); - - # Untaint $name before use in system() - $name =~ /(.+)/; $name = $1; - if (system ("/sbin/e-smith/signal-event", "trac-project-delete", $name) == 0) { - $fm ->success("SUCCESSFULLY_DELETED_TRAC_PROJECT"); - $acct->delete(); - } else { - $fm ->error("ERROR_WHILE_DELETING_TRAC_PROJECT"); - } - } else { - $fm->error('CANT_FIND_TRAC_PROJECT'); - } - - } else { - $fm->error('CANT_FIND_TRAC_PROJECT'); - } - $fm->wherenext('First'); -} - -=head1 VALIDATION ROUTINES - -=head2 max_trac_project_name_length() - -Checks the length of a given trac project environment name against the -maximum set in the maxTracNameLength record of the configuration database. -Defaults to a maximum length of $self->{defaultMaxLength} if nothing is -set in the config db. - -=cut - -sub max_trac_project_name_length { - my ($fm, $data) = @_; - - $ConfigDB->reload(); - my $max; - if (my $max_record = $ConfigDB->get('maxTracNameLength')) { - $max = $max_record->value(); - } - - if (length($data) <= $max) { - return "OK"; - } else { - return $fm->localise("MAX_TRAC_NAME_LENGTH_ERROR", - {acctName => $data, - maxRepositoryNameLength => $max, - maxLength => $max}); - } -} - -=head2 getExtraParams() - -Sets variables used in the lexicon to their required values. - -=cut - -sub getExtraParams { - - my $fm = shift; - my $TracProjectName = $fm->cgi->param('tracName'); - my $TracProjectDescription = ''; - my $maxLength = $ConfigDB->get('maxTracNameLength'); - - if ($TracProjectName) - { - my $TracAccount = $AccountsDB->get($TracProjectName); - if ($TracAccount) - { - $TracProjectDescription = $TracAccount->prop('Description'); - } - } - - return (name => $TracProjectName, - description => $TracProjectDescription, - maxLength => $maxLength); -} - -=head2 validate_name() - -Checks that the name supplied does not contain any unacceptable chars. -Returns OK on success or a localised error message otherwise. - -=cut - -sub validate_name { - - my ($fm, $tracName) = @_; - - unless ($tracName =~ /^([a-z][\_\.\-a-z0-9]*)$/) - { - return $fm->localise('TRAC_PROJECT_NAME_HAS_INVALID_CHARS', {tracName => $tracName}); - } - - return "OK"; -} - -=head2 conflict_check() - -Check the proposed name for clashes with existing pseudonyms or other -accounts of any type. - -=cut - -sub conflict_check { - - my ($fm, $name) = @_; - my $rec = $AccountsDB->get($name); - - my $type; - if (defined $rec) - { - my $type = $rec->prop('type'); - if ($type eq "pseudonym") - { - my $acct = $rec->prop("Account"); - my $acct_type = $AccountsDB->get($acct)->prop('type'); - - return $fm->localise('ACCT_CLASHES_WITH_PSEUDONYM', - {acctName => $name, acctType => $acct_type, acct => $acct}); - } - } - elsif (defined getpwnam($name) || defined getgrnam($name)) - { - $type = 'system'; - } - else - { - # No account record and no account - return 'OK'; - } - return $fm->localise('ACCOUNT_EXISTS', - {acctName => $name, acctType => $type}); -} - -=head2 validate_trac_has_domains() - -Validates that the cgi parameter DOMAINS is an array with at least one entry -Returns OK if true. Otherwise, returns NO_DOMAINS - -=cut - -sub validate_trac_has_domains { - - my $fm = shift; - my @domains = @_; - - my $count = @domains; - - if ( $count == 0 ) { - return ('NO_DOMAINS'); - } - else { - return ('OK'); - } -} - -=head2 clear_params() - -This method clears-out the parameters used in form submission so that they are -not inadvertenly picked-up where they should not be. - -=cut - -sub clear_params { - - my $fm = shift; - my $q = $fm->{cgi}; - - # Don't delete tracName here as we need in the next page for - # status messages. - - $q->delete('tracDescription'); - $q->delete('tracRepository'); - $q->delete('tracRepositoryPath'); - $q->delete('tracDomains'); - $q->delete('tracGroups'); - $q->delete('tracUsers'); - $q->delete('tracAccess'); - -} - -1; +#!/usr/bin/perl -w +#---------------------------------------------------------------------- +# $Id: trac.pm 69 2007-03-25 13:20:24Z marco $ +# vim: ft=perl ts=4 sw=4 et: +#---------------------------------------------------------------------- +# Copyright (C) 2007 Marco Hess +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#---------------------------------------------------------------------- + +package esmith::FormMagick::Panel::trac; + +use strict; +use warnings; + +use esmith::FormMagick; +use esmith::AccountsDB; +use esmith::ConfigDB; +use esmith::DomainsDB; +use esmith::cgi; +use esmith::util; +use File::Basename; +use Exporter; +use Carp; +use Sys::Syslog; + +use constant TRUE => 1; +use constant FALSE => 0; + +our @ISA = qw(esmith::FormMagick Exporter); + +our @EXPORT = qw( + show_trac_projects + print_trac_field_name + repositories_list + group_list + user_list + max_trac_project_name_length + handle_trac_projects + create_trac_project + remove_trac_project + getExtraParams + print_save_or_add_button + validate_name + validate_radio + wherenext + maxLength +); + +our $ConfigDB = esmith::ConfigDB->open + or die "Can't open the Config database : $!\n" ; + +our $AccountsDB = esmith::AccountsDB->open + or die "Can't open the Account database : $!\n" ; + +our $DomainsDB = esmith::DomainsDB->open + or die "Can't open the Domains database : $!\n" ; + + +# fields and records separator for sub records +use constant FS => "," ; +use constant RS => ";" ; + +=pod + +=head1 NAME + +esmith::FormMagick::Panels::trac - Trac + +=head1 SYNOPSIS + +use esmith::FormMagick::Panels::trac + +my $panel = esmith::FormMagick::Panel::trac->new(); +$panel->display(); + +=head1 DESCRIPTION + +This module is the backend to the Trac panel, responsible +for supplying all functions used by that panel. It is a subclass +of esmith::FormMagick itself, so it inherits the functionality +of a FormMagick object. + +=cut + +=head2 new() + +Exactly as for esmith::FormMagick + +=cut + +sub new +{ + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = esmith::FormMagick::new($class); + $self->{calling_package} = (caller)[0]; + + return $self; +} + +=head1 HTML GENERATION ROUTINES + +Routines for generating chunks of HTML needed by the panel. + +=cut + +=head2 show_trac_projects() + +This function displays a table of trac project environments on the system +including the links to modify and remove the trac project environment. + +=cut + +sub show_trac_projects { + my $fm = shift; + my $q = $fm->{cgi}; + + # Setup the various localised text field for the trac project table + my $name = $fm->localise('TRAC_TABLE_HEADER_NAME'); + my $description = $fm->localise('TRAC_TABLE_HEADER_DESCRIPTION'); + my $domains = $fm->localise('TRAC_TABLE_HEADER_DOMAINS'); + my $repository = $fm->localise('TRAC_TABLE_HEADER_REPOSITORY'); + my $path = $fm->localise('TRAC_TABLE_HEADER_PATH'); + my $access = $fm->localise('TRAC_TABLE_HEADER_ACCESS'); + my $action_h = $fm->localise('TRAC_TABLE_HEADER_ACTION'); + my $view = $fm->localise('TRAC_ACTION_VIEW'); + my $modify = $fm->localise('TRAC_ACTION_MODIFY'); + my $remove = $fm->localise('TRAC_ACTION_REMOVE'); + my $backup = $fm->localise('TRAC_ACTION_BACKUP'); + my $restore = $fm->localise('TRAC_ACTION_RESTORE'); + + print $q->start_table({-class => 'sme-noborder'}), "\n"; + + # Check if any repositories exist + my @repositories = $AccountsDB->get_all_by_prop('type' => 'repository'); + unless ( scalar @repositories ) + { + print $q->Tr($q->td($q->h2($fm->localise('NO_REPOSITORIES')))); + return ""; + } + + # TODO what about the case that all repositories have been deleted + # but the Trac project environments are still there? Can we remove the + # trac projects or do we need to reassign the projects to + # another repository? The code above prevents us from accessing the + # trac projects when there are no more repositories. + + print $q->Tr($q->td($q->a({-class => "button-like", + href => "trac?page=0&page_stack=&Next=Next&wherenext=Create"}, + $fm->localise('TRAC_ADD_BUTTON')))); + + # Check if any trac projects exist + my @TracProjects = $AccountsDB->get_all_by_prop('type' => 'trac'); + unless ( scalar @TracProjects ) + { + print $q->Tr($q->td($q->h2($fm->localise('NO_TRAC_PROJECTS')))); + return ""; + } + + # Show the list of configures trac projects + print $q->Tr($q->td($q->h2($fm->localise('CURRENT_TRAC_PROJECTS')))); + + print $q->Tr($q->td($fm->localise('TRAC_MODIFY_REMOVE_BUTTON_DESCRIPTION'))); + + print $q->start_table({-CLASS => "sme-border"}),"\n"; + print $q->Tr ( + esmith::cgi::genSmallCell($q, $name, "header"), + esmith::cgi::genSmallCell($q, $description,"header"), + esmith::cgi::genSmallCell($q, $domains, "header"), + esmith::cgi::genSmallCell($q, $repository, "header"), + esmith::cgi::genSmallCell($q, $path, "header"), + esmith::cgi::genSmallCell($q, $access, "header"), + esmith::cgi::genSmallCell($q, $action_h, "header", 3)),"\n"; + + my $scriptname = basename($0); + + foreach my $TracProject (@TracProjects) + { + my $trac_name = $TracProject->key(); + my $trac_desc = $TracProject->prop('Description'); + my $trac_domains = join("
", split(FS, $TracProject->prop('Domains'))); + my $trac_repo = $TracProject->prop('Repository'); + my $trac_path = $TracProject->prop('RepositoryPath'); + my $trac_access = $TracProject->prop('Access') || 'local'; + my $modifiable = $TracProject->prop('Modifiable') || 'yes'; + my $removable = $TracProject->prop('Removable') || 'yes'; + + my $params = $fm->build_trac_project_cgi_params($trac_name, $TracProject->props()); + + my $href = "$scriptname?$params&action=modify&wherenext="; + + my $actionView = ' '; + $actionView .= $q->a({href => '/' . $TracProject->key(), + target => '_blank'}, $view ) . ' '; + + my $actionModify = ' '; + if ($modifiable eq 'yes') + { + $actionModify .= $q->a({href => "${href}Modify"}, $modify) . ' '; + } + + my $actionRemove = ' '; + if ($removable eq 'yes') + { + $actionRemove .= $q->a({href => "${href}Remove"}, $remove) . ' '; + } + + my $actionBackup = ' '; + $actionBackup .= $q->a({href => "${href}Backup"}, $backup) . ' '; + + my $actionRestore = ' '; + $actionRestore .= $q->a({href => "${href}Restore"}, $restore) . ' '; + + print $q->Tr( + esmith::cgi::genSmallCell($q, $trac_name, "normal"), + esmith::cgi::genSmallCell($q, $trac_desc, "normal"), + esmith::cgi::genSmallCell($q, $trac_domains, "normal"), + esmith::cgi::genSmallCell($q, $trac_repo, "normal"), + esmith::cgi::genSmallCell($q, $trac_path, "normal"), + esmith::cgi::genSmallCell($q, $trac_access, "normal"), + esmith::cgi::genSmallCell($q, $actionView, "normal"), + esmith::cgi::genSmallCell($q, $actionModify, "normal"), + esmith::cgi::genSmallCell($q, $actionRemove, "normal") + ); + } + + print $q->end_table,"\n"; + + print $q->end_table,"\n"; + + return ""; +} + +=cut + +=head2 print_save_or_add_button() + +Prints the ADD button when a new trac project environment is addded and the SAVE buttom +whem modifications are made. + +=cut + +sub print_save_or_add_button { + + my ($fm) = @_; + + my $cgi = $fm->{cgi}; + + if (($cgi->param("action") || '') eq "modify") { + $fm->print_button("SAVE"); + } else { + $fm->print_button("ADD"); + } +} + +=head1 HELPER FUNCTIONS FOR THE PANEL + +Routines for modifying the database and signaling events +from the server-manager panel + +=cut + +=head2 build_trac_project_cgi_params($fm, $tracprojectname, %oldprops) + +Constructs the parameters for the links in the trac project environments table + +=cut + +sub build_trac_project_cgi_params { + my ($self, $tracprojectname, %oldprops) = @_; + + my %props = ( + page => 0, + page_stack => "", + tracName => $tracprojectname, + ); + + return $self->props_to_query_string(\%props); +} + +*wherenext = \&CGI::FormMagick::wherenext; + +=head2 print_trac_field_name() + +Helper function to print the field NAME so that it becomes +an edit field upon ADD and a fixed field upon MODIFY. + +Also read all the account db values so the other fields +can show the existing values. + +=cut + +sub print_trac_field_name { + my $fm = shift; + my $in = $fm->{cgi}->param('tracName') || ''; + my $action = $fm->{cgi}->param('action') || ''; + + print qq() . + $fm->localise('TRAC_FIELD_PROJECT_NAME') . qq(\n); + + if ($action eq 'modify' and $in) { + #------------------------------------------------------- + # Updating an existing record. + #-------------------------------------------------------- + + my $rec = $AccountsDB->get($in); + my $modifiable = $rec->prop('Modifiable') || 'yes'; + my $removable = $rec->prop('Removable') || 'yes'; + + print qq( + $in + + + + ); + + # Read the values for each field from the accounts db and store + # them in the cgi object so our form will have the correct + # info displayed. + my $q = $fm->{cgi}; + if ($rec) + { + $q->param(-name=>'tracDescription',-value=> + $rec->prop('Description')); + + $q->param(-name=>'tracRepository',-value=> + $rec->prop('Repository')); + + $q->param(-name=>'tracRepositoryPath',-value=> + $rec->prop('RepositoryPath')); + + # domain list is handled separately + + $q->param(-name=>'tracGroups',-value=> + join(FS, split(FS, $rec->prop('Groups')))); + + $q->param(-name=>'tracUsers',-value=> + join(FS, split(FS, $rec->prop('Users')))); + + $q->param(-name=>'tracAccess',-value=> + $rec->prop('Access')), + } + } else { + #------------------------------------------------------- + # Adding a new record so allow an entry field for the + # name. + #-------------------------------------------------------- + print qq( + + + + ); + } + + print qq(\n); + return undef; +} + + +=head2 print_trac_domains() + +When this server has more than one domain this function takes +the list of domains and returns a string of html checkboxes +for all these domains. + +Those domains that are listed with this Trac environment +will have their checkbox checked. + +=cut + +sub print_trac_domains() { + + # Retrieve the Trac account name from the CGI parameters + my $fm = shift; + my $name = $fm->{'cgi'}->param('tracName'); + my $action = $fm->{'cgi'}->param("action") || ''; + my $out = ""; + + # Get a full list of all the domains on this server. + my @domains = $DomainsDB->get_all_by_prop( type => 'domain' ); + my $numdomains = @domains; + + # If there is more than one domain, we generate a list + # of checkboxes. Otherwise we just show the primary domain. + if ($numdomains > 1) { + + # With the Trac account name, get the list of the Domains for which + # this Trac account is active. + my $trac_domains_list = ""; + if ($AccountsDB->get($name)) { + $trac_domains_list = $AccountsDB->get($name)->prop('Domains'); + } + + # Split the comma separated list into the individual bits. + my %trac_domains; + foreach my $trac_domain ( split ( /,/, $trac_domains_list ) ) { + $trac_domains{$trac_domain} = 1; + } + + # Now generate the table of domains with a checkbox in front of it. + # If the domain is in our listed domains for the Trac environment, the + # checkbox will show checked. + $out = " \n"; + $out .= " " . $fm->localise('TRAC_FIELD_DOMAINS_DESCRIPTION') . ""; + $out .= " \n"; + $out .= " \n"; + $out .= " " . $fm->localise('TRAC_FIELD_DOMAINS') . "\n"; + $out .= " \n"; + $out .= " \n"; + $out .= " \n"; + + foreach my $domain (sort @domains) { + + # If this is a ADD form, we default check all domains, otherwise only + # those that are in our Trac project list. + my $checked = ""; + if ( $action eq 'modify' ) { + if ( $trac_domains{ $domain->key() } ) { + $checked = "checked"; + } + } else { + $checked = "checked"; + } + + $out .= " \n"; + $out .= " \n"; + $out .= " \n"; + $out .= " \n"; + } + + $out .= "
key . "\">" . $domain->key . "
\n"; + $out .= " \n"; + $out .= " \n"; + } + else + { + # We only have a single domain, so we just show this domain but without the + # checkbox (so it can't be unchecked). + my $domainname = $ConfigDB->get('DomainName')->value(); + $out = " \n"; + $out .= " " . $fm->localise('TRAC_FIELD_DOMAIN_DESCRIPTION') . ""; + $out .= " \n"; + $out .= " \n"; + $out .= " " . $fm->localise('TRAC_FIELD_DOMAIN') . "\n"; + $out .= " "; + $out .= $domainname . "\n"; + $out .= " \n"; + } + + return $out; +} + + +=pod + +=head2 repositories_list() + +Returns a hash of repositories for the Create/Modify screen's repository +field's drop down list. + +=cut + +sub repositories_list +{ + my @repositories = $AccountsDB->get_all_by_prop('type' => 'repository'); + my %repositories = (); + foreach my $repository (@repositories) { + $repositories{$repository->key()} = $repository->prop('Description') . " (" . $repository->key . ")"; + } + return \%repositories; +} + +=head2 group_list() + +Returns a hash of groups for the Create/Modify screen's group +field's drop down list. + +=cut + +sub group_list +{ + my @groups = $AccountsDB->groups(); + my %groups = (); + foreach my $group (@groups) { + $groups{$group->key()} = $group->prop('Description')." (".$group->key.")"; + } + return \%groups; +} + +=head2 user_list() + +Returns a hash of users for the Create/Modify screen's user field's +drop down list. + +=cut + +sub user_list +{ + my @users = $AccountsDB->users(); + my %users = (); + foreach my $user (@users) { + $users{$user->key()} = $user->prop('LastName').", ". $user->prop('FirstName')." (". $user->key.")"; + } + return \%users; +} + +=head1 THE ROUTINES THAT ACTUALLY DO THE WORK + +=cut + +=head2 handle_trac_projects() + +Determine whether to modify or add the trac project environment + +=cut + +sub handle_trac_projects { + + my ($fm) = @_; + + if ($fm->cgi->param("action") eq "create") { + $fm->create_trac_project(); + } else { + $fm->modify_trac_project(); + } + +} + +=head2 create_trac_project() + +Handle the create event for the trac project environment + +=cut + +sub create_trac_project { + + my ($fm) = @_; + + # Validate Name + # ============= + + my $name = $fm->cgi->param('tracName'); + my $msg; + + $msg = $fm->validate_name($name); + unless ($msg eq "OK") + { + return $fm->error($msg); + } + + $msg = $fm->max_trac_project_name_length($name); + unless ($msg eq "OK") + { + return $fm->error($msg); + } + + $msg = $fm->conflict_check($name); + unless ($msg eq "OK") + { + return $fm->error($msg); + } + + # Validate & Setup Domain List + # ============================ + + my @active_trac_domains = $fm->cgi->param('tracDomains'); + + $msg = $fm->validate_trac_has_domains(@active_trac_domains); + unless ($msg eq "OK") + { + return $fm->error($msg); + } + + my $domain_list = ""; + foreach my $domain (@active_trac_domains) { + if ($domain_list) { + $domain_list .= "," . $domain; + } else { + $domain_list = $domain; + } + } + + # Setup Group List + # ================ + + my @groups = $fm->cgi->param('tracGroups'); + + my $group_list = ""; + foreach my $group (@groups) { + if ($group_list) { + $group_list .= "," . $group; + } else { + $group_list = $group; + } + } + + # Setup User List + # =============== + + my @users = $fm->cgi->param('tracUsers'); + + my $user_list = ""; + foreach my $user (@users) { + if ($user_list) { + $user_list .= "," . $user; + } else { + $user_list = $user; + } + } + + # Update Database + # =============== + + my $uid = $AccountsDB->get_next_uid(); + if (my $acct = $AccountsDB->new_record($name, { + Description => $fm->cgi->param('tracDescription'), + Repository => $fm->cgi->param('tracRepository'), + RepositoryPath => $fm->cgi->param('tracRepositoryPath'), + Domains => "$domain_list", + Groups => "$group_list", + Users => "$user_list", + Modifiable => 'yes', + Removable => 'yes', + Access => $fm->cgi->param('tracAccess'), + type => 'trac', + }) ) + { + # Untaint $name before use in system() + $name =~ /(.+)/; $name = $1; + + $fm->clear_params(); + + if (system ("/sbin/e-smith/signal-event", "trac-project-create", $name) == 0) { + $fm->success("SUCCESSFULLY_CREATED_TRAC_PROJECT"); + } else { + $fm->error("ERROR_WHILE_CREATING_TRAC_PROJECT"); + } + } else { + $fm->error('CANT_CREATE_TRAC_PROJECT'); + } +} + +=head2 modify_trac_project() + +Handle the modify event for the trac project environment + +=cut + +sub modify_trac_project { + + my ($fm) = @_; + my $name = $fm->cgi->param('tracName'); + + # Validate Name + # ============= + + my $msg = $fm->validate_name($name); + unless ($msg eq "OK") + { + return $fm->error($msg); + } + + # Validate & Setup Domain List + # ============================ + + my @active_trac_domains = $fm->cgi->param('tracDomains'); + + $msg = $fm->validate_trac_has_domains(@active_trac_domains); + unless ($msg eq "OK") + { + return $fm->error($msg); + } + + my $domain_list; + foreach my $domain (@active_trac_domains) { + if ($domain_list) { + $domain_list .= "," . $domain; + } else { + $domain_list = $domain; + } + } + + # Setup Group List + # ================ + + my @groups = $fm->cgi->param('tracGroups'); + + my $group_list; + foreach my $group (@groups) { + if ($group_list) { + $group_list .= "," . $group; + } else { + $group_list = $group; + } + } + + # Setup User List + # =============== + + my @users = $fm->cgi->param('tracUsers'); + + my $user_list; + foreach my $user (@users) { + if ($user_list) { + $user_list .= "," . $user; + } else { + $user_list = $user; + } + } + + # Update Database + # =============== + + if (my $acct = $AccountsDB->get($name)) { + if ($acct->prop('type') eq 'trac') { + + $acct->merge_props( + Description => $fm->cgi->param('tracDescription'), + Repository => $fm->cgi->param('tracRepository'), + RepositoryPath => $fm->cgi->param('tracRepositoryPath'), + Domains => $domain_list, + Groups => $group_list, + Users => $user_list, + Access => $fm->cgi->param('tracAccess'), + type => 'trac', + ); + + # Untaint $name before use in system() + $name =~ /(.+)/; $name = $1; + + $fm->clear_params(); + + if (system ("/sbin/e-smith/signal-event", "trac-project-modify", $name) == 0) + { + $fm->success("SUCCESSFULLY_MODIFIED_TRAC_PROJECT"); + } else { + $fm->error("ERROR_WHILE_MODIFYING_TRAC_PROJECT"); + } + } else { + $fm->error('CANT_FIND_TRAC_PROJECT'); + } + } else { + $fm->error('CANT_FIND_TRAC_PROJECT'); + } +} + +=head2 remove_trac_project() + +Handle the remove event for the trac project environment + +=cut + +sub remove_trac_project { + + my $fm = shift; + + my $name = $fm->cgi->param('tracName'); + if (my $acct = $AccountsDB->get($name)) { + if ($acct->prop('type') eq 'trac') { + $acct->set_prop('type', 'trac-deleted'); + + # Untaint $name before use in system() + $name =~ /(.+)/; $name = $1; + if (system ("/sbin/e-smith/signal-event", "trac-project-delete", $name) == 0) { + $fm ->success("SUCCESSFULLY_DELETED_TRAC_PROJECT"); + $acct->delete(); + } else { + $fm ->error("ERROR_WHILE_DELETING_TRAC_PROJECT"); + } + } else { + $fm->error('CANT_FIND_TRAC_PROJECT'); + } + + } else { + $fm->error('CANT_FIND_TRAC_PROJECT'); + } + $fm->wherenext('First'); +} + +=head1 VALIDATION ROUTINES + +=head2 max_trac_project_name_length() + +Checks the length of a given trac project environment name against the +maximum set in the maxTracNameLength record of the configuration database. +Defaults to a maximum length of $self->{defaultMaxLength} if nothing is +set in the config db. + +=cut + +sub max_trac_project_name_length { + my ($fm, $data) = @_; + + $ConfigDB->reload(); + my $max; + if (my $max_record = $ConfigDB->get('maxTracNameLength')) { + $max = $max_record->value(); + } + + if (length($data) <= $max) { + return "OK"; + } else { + return $fm->localise("MAX_TRAC_NAME_LENGTH_ERROR", + {acctName => $data, + maxRepositoryNameLength => $max, + maxLength => $max}); + } +} + +=head2 getExtraParams() + +Sets variables used in the lexicon to their required values. + +=cut + +sub getExtraParams { + + my $fm = shift; + my $TracProjectName = $fm->cgi->param('tracName'); + my $TracProjectDescription = ''; + my $maxLength = $ConfigDB->get('maxTracNameLength'); + + if ($TracProjectName) + { + my $TracAccount = $AccountsDB->get($TracProjectName); + if ($TracAccount) + { + $TracProjectDescription = $TracAccount->prop('Description'); + } + } + + return (name => $TracProjectName, + description => $TracProjectDescription, + maxLength => $maxLength); +} + +=head2 validate_name() + +Checks that the name supplied does not contain any unacceptable chars. +Returns OK on success or a localised error message otherwise. + +=cut + +sub validate_name { + + my ($fm, $tracName) = @_; + + unless ($tracName =~ /^([a-z][\_\.\-a-z0-9]*)$/) + { + return $fm->localise('TRAC_PROJECT_NAME_HAS_INVALID_CHARS', {tracName => $tracName}); + } + + return "OK"; +} + +=head2 conflict_check() + +Check the proposed name for clashes with existing pseudonyms or other +accounts of any type. + +=cut + +sub conflict_check { + + my ($fm, $name) = @_; + my $rec = $AccountsDB->get($name); + + my $type; + if (defined $rec) + { + my $type = $rec->prop('type'); + if ($type eq "pseudonym") + { + my $acct = $rec->prop("Account"); + my $acct_type = $AccountsDB->get($acct)->prop('type'); + + return $fm->localise('ACCT_CLASHES_WITH_PSEUDONYM', + {acctName => $name, acctType => $acct_type, acct => $acct}); + } + } + elsif (defined getpwnam($name) || defined getgrnam($name)) + { + $type = 'system'; + } + else + { + # No account record and no account + return 'OK'; + } + return $fm->localise('ACCOUNT_EXISTS', + {acctName => $name, acctType => $type}); +} + +=head2 validate_trac_has_domains() + +Validates that the cgi parameter DOMAINS is an array with at least one entry +Returns OK if true. Otherwise, returns NO_DOMAINS + +=cut + +sub validate_trac_has_domains { + + my $fm = shift; + my @domains = @_; + + my $count = @domains; + + if ( $count == 0 ) { + return ('NO_DOMAINS'); + } + else { + return ('OK'); + } +} + +=head2 clear_params() + +This method clears-out the parameters used in form submission so that they are +not inadvertenly picked-up where they should not be. + +=cut + +sub clear_params { + + my $fm = shift; + my $q = $fm->{cgi}; + + # Don't delete tracName here as we need in the next page for + # status messages. + + $q->delete('tracDescription'); + $q->delete('tracRepository'); + $q->delete('tracRepositoryPath'); + $q->delete('tracDomains'); + $q->delete('tracGroups'); + $q->delete('tracUsers'); + $q->delete('tracAccess'); + +} + +1; --- smeserver-trac-0.4/root/etc/e-smith/web/functions/trac.newlines 2007-04-26 20:42:10.000000000 -0600 +++ smeserver-trac-0.4/root/etc/e-smith/web/functions/trac 2008-04-26 09:16:53.000000000 -0600 @@ -1,235 +1,235 @@ -#!/usr/bin/perl -wT -# vim: ft=xml: -# $Id: trac 69 2007-03-25 13:20:24Z marco $ - -#---------------------------------------------------------------------- -# heading : Collaboration -# description : TRAC_NAVIGATION_DESCRIPTION -# navigation : 2650 2650 -#---------------------------------------------------------------------- - -use strict; -use warnings; -use esmith::FormMagick::Panel::trac; -my $f = esmith::FormMagick::Panel::trac->new(); -$f->display(); - -=pod - -=head1 NAME - -Trac project environment -- add/remove/manage trac project environments - -=head2 DESCRIPTION - -This screen allows the administrator to manage Trac environments for the subversion repositories. - -=begin testing - -use esmith::FormMagick::Tester; -use esmith::TestUtils; -use esmith::TestUtils; -use esmith::ConfigDB; -use esmith::AccountsDB; -my $panel = $Original_File; -my $ua = esmith::FormMagick::Tester->new(); - -my $c = esmith::ConfigDB->open(); -my $a = esmith::AccountsDB->open(); - -is (mode($panel), '4750', "Check permissions on script"); -ok ($ua->get_panel($panel), "ABOUT TO RUN L10N TESTS"); -is ($ua->{status}, 200, "200 OK"); -like($ua->{content}, qr/FORM_TITLE/, "Saw untranslated form title"); -ok ($ua->set_language("en"), "Set language to English"); -ok ($ua->get_panel($panel), "Get panel"); -is ($ua->{status}, 200, "200 OK"); - -ok ($ua->get_panel($panel), "ABOUT TO TEST CREATING TRAC ENVIRONMENT"); -ok ($ua->follow("Click here"), "Follow 'create repository' link"); -is ($ua->{status}, 200, "200 OK"); -like($ua->{content}, qr/Create a new Trac environment/, "Saw page title"); -like($ua->{content}, qr/Brief description/, "Saw description field"); -like($ua->{content}, qr/Add/, "Saw add button"); - -SKIP: { - - skip 10, "Unsafe!" unless destruction_ok(); - - ok ($ua->follow("Click here"), "ACTUALLY ADDING A TRAC ENVIRONMENT"); - $ua->field(); - $ua->click("Add"); - like($ua->{content}, qr/Successfully added Trac environment/, "Saw success message"); - - ok ($ua->follow("Remove"), "REMOVING TRAC ENVIRONMENT"); - like($ua->{content}, qr/Are you sure/, "Saw confirmation message"); - $ua->click("Remove"); - like($ua->{content}, qr/Successfully deleted/, "Saw success message"); -} - -=end testing - -=cut - -__DATA__ -
- - - - - TRAC_FORM_DESCRIPTION - - - - - - - - TRAC_FORM_ADD_TITLE - - TRAC_FORM_ADD_DESCRIPTION - - - - - - - - - TRAC_FIELD_REPOSITORY_NAME_DESCRIPTION - - - - - TRAC_FIELD_REPOSITORY_PATH_DESCRIPTION - - - - - - - TRAC_FIELD_ACCESS_TYPE_DESCRIPTION - - - - - TRAC_FIELD_GROUPS_DESCRIPTION - - - - - - - - - - - - - - TRAC_FORM_MODIFY_TITLE - TRAC_FORM_MODIFY_DESCRIPTION - - - - - - - - - - TRAC_FIELD_REPOSITORY_NAME_DESCRIPTION - - - - - TRAC_FIELD_REPOSITORY_PATH_DESCRIPTION - - - - - - - TRAC_FIELD_ACCESS_TYPE_DESCRIPTION - - - - - TRAC_FIELD_GROUPS_DESCRIPTION - - - - - - - - - - - - - - - TRAC_FORM_REMOVE_TITLE - TRAC_FORM_REMOVE_DESCRIPTION - - - - - -
+#!/usr/bin/perl -wT +# vim: ft=xml: +# $Id: trac 69 2007-03-25 13:20:24Z marco $ + +#---------------------------------------------------------------------- +# heading : Collaboration +# description : TRAC_NAVIGATION_DESCRIPTION +# navigation : 2650 2650 +#---------------------------------------------------------------------- + +use strict; +use warnings; +use esmith::FormMagick::Panel::trac; +my $f = esmith::FormMagick::Panel::trac->new(); +$f->display(); + +=pod + +=head1 NAME + +Trac project environment -- add/remove/manage trac project environments + +=head2 DESCRIPTION + +This screen allows the administrator to manage Trac environments for the subversion repositories. + +=begin testing + +use esmith::FormMagick::Tester; +use esmith::TestUtils; +use esmith::TestUtils; +use esmith::ConfigDB; +use esmith::AccountsDB; +my $panel = $Original_File; +my $ua = esmith::FormMagick::Tester->new(); + +my $c = esmith::ConfigDB->open(); +my $a = esmith::AccountsDB->open(); + +is (mode($panel), '4750', "Check permissions on script"); +ok ($ua->get_panel($panel), "ABOUT TO RUN L10N TESTS"); +is ($ua->{status}, 200, "200 OK"); +like($ua->{content}, qr/FORM_TITLE/, "Saw untranslated form title"); +ok ($ua->set_language("en"), "Set language to English"); +ok ($ua->get_panel($panel), "Get panel"); +is ($ua->{status}, 200, "200 OK"); + +ok ($ua->get_panel($panel), "ABOUT TO TEST CREATING TRAC ENVIRONMENT"); +ok ($ua->follow("Click here"), "Follow 'create repository' link"); +is ($ua->{status}, 200, "200 OK"); +like($ua->{content}, qr/Create a new Trac environment/, "Saw page title"); +like($ua->{content}, qr/Brief description/, "Saw description field"); +like($ua->{content}, qr/Add/, "Saw add button"); + +SKIP: { + + skip 10, "Unsafe!" unless destruction_ok(); + + ok ($ua->follow("Click here"), "ACTUALLY ADDING A TRAC ENVIRONMENT"); + $ua->field(); + $ua->click("Add"); + like($ua->{content}, qr/Successfully added Trac environment/, "Saw success message"); + + ok ($ua->follow("Remove"), "REMOVING TRAC ENVIRONMENT"); + like($ua->{content}, qr/Are you sure/, "Saw confirmation message"); + $ua->click("Remove"); + like($ua->{content}, qr/Successfully deleted/, "Saw success message"); +} + +=end testing + +=cut + +__DATA__ +
+ + + + + TRAC_FORM_DESCRIPTION + + + + + + + + TRAC_FORM_ADD_TITLE + + TRAC_FORM_ADD_DESCRIPTION + + + + + + + + + TRAC_FIELD_REPOSITORY_NAME_DESCRIPTION + + + + + TRAC_FIELD_REPOSITORY_PATH_DESCRIPTION + + + + + + + TRAC_FIELD_ACCESS_TYPE_DESCRIPTION + + + + + TRAC_FIELD_GROUPS_DESCRIPTION + + + + + + + + + + + + + + TRAC_FORM_MODIFY_TITLE + TRAC_FORM_MODIFY_DESCRIPTION + + + + + + + + + + TRAC_FIELD_REPOSITORY_NAME_DESCRIPTION + + + + + TRAC_FIELD_REPOSITORY_PATH_DESCRIPTION + + + + + + + TRAC_FIELD_ACCESS_TYPE_DESCRIPTION + + + + + TRAC_FIELD_GROUPS_DESCRIPTION + + + + + + + + + + + + + + + TRAC_FORM_REMOVE_TITLE + TRAC_FORM_REMOVE_DESCRIPTION + + + + + +