[Bio] / FigWebServices / users.cgi Repository:
ViewVC logotype

View of /FigWebServices/users.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Mon Jan 10 22:53:30 2005 UTC (14 years, 10 months ago) by olson
Branch: MAIN
CVS Tags: merge-trunktag-bobdev_news-2, Root-bobdev_news, merge-bobdev_news-1, merge-trunktag-bobdev_news-1, merge-bodev_news-3, caBIG-00-00-00, merge-bobdev_news-2, merge-trunktag-bodev_news-3
Branch point for: Branch-bobdev_news
Add simple interface for user management. Right now it just handles the
'assignmetns accepted' parameter on users.

#
# Simple user management CGI.
#
# This allows one to manage a set of per-user parameters that one might be interested
# in. Currently we support:
#
#     accept_assignments	True if we accept assignments from this user on p2p transfers.
# 				Defaults to true for users that aren't one of the
#				pseudo-users billogix, automated_assignment(s), master, fix, 
#				last_release
#

use strict;

use UserDB;
use FIG;
use HTML;
use CGI;

my @pseudo_users = qw(billogix automated_assignment automated_assignments master fix last_release);
my %pseudo_users;
map { $pseudo_users{$_}++; } @pseudo_users;

my $fig = new FIG;
my $cgi = new CGI;
my $udb = new UserDB($fig);

my @html;

push(@html, $cgi->title("SEED User Management"),
     $cgi->h1("SEED User Management"));


#
# If we're coming in thru a submit button being pressed, need to scan thru
# the old_values and compare to the checked state.
#

if ($cgi->param('submit'))
{
    my $need_write;
    for my $param ($cgi->param)
    {
	if ($param =~ /^aa_old_(\S+)/)
	{
	    my $user = $1;
	    my $form_aa = $cgi->param("aa_$user") ? 1 : 0;
	    my $old_aa = $cgi->param($param);
	    my $udb_aa = $udb->get_user_param($user, 'accept_assignments');

	    if ($old_aa != $form_aa)
	    {
		$udb->set_user_param($user, 'accept_assignments', $form_aa);
		$need_write++;
	    }
	}
    }
    $udb->write() if $need_write;
}
    


push(@html, $cgi->start_form(-action => 'users.cgi'));
build_user_table($fig, $cgi, \@html);

push(@html, $cgi->submit(-name => "submit",
			 -value => 'Submit'));

push(@html, $cgi->end_form);

&HTML::show_page($cgi, \@html);
exit;

sub build_user_table
{
    my($fig, $cgi, $html) = @_;

    my $need_write;

    my(@rows);

    for my $user (sort $udb->get_users())
    {
	my $aa = $udb->get_user_param($user, 'accept_assignments');
	my $aa_cb_name = "aa_$user";
	my $aa_oldval_name = "aa_old_$user";

	#
	# If we've not set a value for aa yet, default it to on unless user is a pseudo-user.
	#

	if (!defined($aa))
	{
	    warn "setting a default\n";
	    $aa = defined($pseudo_users{$user}) ? 0 : 1;
	    $udb->set_user_param($user, 'accept_assignments', $aa);
	    $need_write++;
	}

	my $aa_checkbox = $cgi->checkbox(-name => "aa_$user",
					 -checked => $aa,
					 -override => 1,
					 -label => '');
	push(@rows, [$user, "\@align=center:$aa_checkbox"]);
	push(@$html, $cgi->hidden(-name => $aa_oldval_name,
				  -value => $aa));
    }

    #
    # If we set any defaults, write the user db.
    #
    $udb->write() if $need_write;

    push(@$html, HTML::make_table(["User", "Assignments accepted"], \@rows));
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3