From: John Graham-C. <jgr...@us...> - 2005-02-13 02:16:43
|
Update of /cvsroot/popfile/engine/UI In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25558/UI Modified Files: HTML.pm Log Message: More work on v0.23.0 (Multi-user Support) Add the 'Users' tab that is available only to administrators and allows them to create, remove and edit users. Users can be created as a clone of an existing user and the complete list of user parameters can be edited by the administrator. There is currently no way to use this information in POPFile (that's for my next commit); POPFile is still hard-wired to use any information related to user 1 (admin). ---- Classifier/Bayes.pm: Make the cache of user parameter values have entries for whether the value is default or not and also keep track of the last time that the cache entry was read or written so that later we can implementing culling of the cache to save space. New APIs added that are accessible by authenticated administrators: create_user (with optional cloning of another user), remove_user, get_user_list (returns a list of all users), get_user_parameter_list (returns the list of all parameters a user can have), get_user_id (returns the database ID for a named user). Add get_user_parameter as way to get a user parameter for the authenticated user. Change signature of get_user_parameter_from_id so that it returns both the value and whether the value is the default or not. POPFile/Module.pm: Update user_module_config_ because of the change in the signature of get_user_parameter_from_id. UI/HTML.pm: Add support for the users_page (using the users-page.thtml template) and handle create, remove and edit of users. New functions status_message__ and error_message__ are used to set a status or error message using the common-middle.thtml bars at the top of the UI. The intention is that all status and error messages are displayed in a standard place. languages/English.msg: Add strings needed by the new Users page. skins/default/style.css: New styles shellStatusMessage and shellErrorMessage for styling the display of status and error messages. The HTML for this is in common-middle.thtml. Remove DOS-style line endings. skins/default/common-middle.thtml: Add bars at the top of the screen above the tabs that can be used to display status and error messages. skins/default/advanced-page.thtml: Left justify the column headers on the list of user parameters because it looks better. skins/default/history-bar.thtml: Remove error messages that are now handled in HTML.pm by calling error_message__ with the appropriate error string. skins/default/users-page.thtml: Add HTML to handle the Users page. ---- TODO: Go through code and make all errors and status message use the new status_message__ and error_message__ functions in HTML. TODO: Cache flushing of user parameters in Bayes. TODO: New Bayes API functions need tests Index: HTML.pm =================================================================== RCS file: /cvsroot/popfile/engine/UI/HTML.pm,v retrieving revision 1.336 retrieving revision 1.337 diff -C2 -d -r1.336 -r1.337 *** HTML.pm 10 Feb 2005 10:12:43 -0000 1.336 --- HTML.pm 13 Feb 2005 02:16:34 -0000 1.337 *************** *** 500,503 **** --- 500,504 ---- 'magnets' => [ \&magnet_page, 'magnet-page.thtml' ], 'advanced' => [ \&advanced_page, 'advanced-page.thtml' ], + 'users' => [ \&users_page, 'users-page.thtml' ], 'history' => [ \&history_page, 'history-page.thtml' ], 'view' => [ \&view_page, 'view-page.thtml' ] ); # PROFILE BLOCK STOP *************** *** 507,510 **** --- 508,512 ---- '/magnets' => 'magnets', '/advanced' => 'advanced', + '/users' => 'users', '/view' => 'view', '/history' => 'history', *************** *** 517,520 **** --- 519,523 ---- delete $url_table{administration}; delete $url_table{advanced}; + delete $url_table{users}; } *************** *** 608,612 **** $selected = -1 if ( !defined( $selected ) ); ! my @tab = ( 'menuStandard', 'menuStandard', 'menuStandard', 'menuStandard', 'menuStandard', 'menuStandard' ); $tab[$selected] = 'menuSelected' if ( ( $selected <= $#tab ) && ( $selected >= 0 ) ); --- 611,615 ---- $selected = -1 if ( !defined( $selected ) ); ! my @tab = ( 'menuStandard', 'menuStandard', 'menuStandard', 'menuStandard', 'menuStandard', 'menuStandard', 'menuStandard' ); $tab[$selected] = 'menuSelected' if ( ( $selected <= $#tab ) && ( $selected >= 0 ) ); *************** *** 685,689 **** $self->user_config_( 1, 'page_size', $self->{form_}{page_size} ); } else { ! $templ->param( 'Configuration_If_Page_Size_Error' => 1 ); delete $self->{form_}{page_size}; } --- 688,693 ---- $self->user_config_( 1, 'page_size', $self->{form_}{page_size} ); } else { ! $self->error_message__( $templ, ! $self->{language__}{Configuration_Error4} ); delete $self->{form_}{page_size}; } *************** *** 699,702 **** --- 703,708 ---- $self->{form_}{history_days} ); } else { + $self->error_message__( $templ, + $self->{language__}{Configuration_Error5} ); $templ->param( 'Configuration_If_History_Days_Error' => 1 ); delete $self->{form_}{history_days}; *************** *** 1070,1073 **** --- 1076,1190 ---- #---------------------------------------------------------------------------- # + # users_page - Handle user creation, deletion, etc. + # + # $client The web browser to send the results to + # + #---------------------------------------------------------------------------- + sub users_page + { + my ( $self, $client, $templ, $template, $page ) = @_; + + $templ = $self->handle_configuration_bar__( $client, $templ, $template, + $page ); + + # Handle user creation + + if ( exists( $self->{form_}{create} ) && ( $self->{form_}{newuser} ne '' ) ) { + my $result = $self->classifier_()->create_user( $self->{api_session__}, $self->{form_}{newuser}, $self->{form_}{clone} ); + if ( $result == 0 ) { + if ( $self->{form_}{clone} ne '' ) { + $self->status_message__( $templ, sprintf( $self->{language__}{Users_Created_And_Cloned}, $self->{form_}{newuser}, $self->{form_}{clone} ) ); + } else { + $self->status_message__( $templ, sprintf( $self->{language__}{Users_Created}, $self->{form_}{newuser} ) ); + } + } + if ( $result == 1 ) { + $self->error_message__( $templ, sprintf( $self->{language__}{Users_Not_Created_Exists}, $self->{form_}{newuser} ) ); + } + if ( $result == 2 ) { + $self->error_message__( $templ, sprintf( $self->{language__}{Users_Not_Created}, $self->{form_}{newuser} ) ); + } + if ( $result == 3 ) { + $self->error_message__( $templ, sprintf( $self->{language__}{Users_Created_Not_Cloned}, $self->{form_}{newuser}, $self->{form_}{clone} ) ); + } + } + + # Handle user removal + + if ( exists( $self->{form_}{remove} ) && ( $self->{form_}{toremove} ne '' ) ) { + my $result = $self->classifier_()->remove_user( $self->{api_session__}, $self->{form_}{toremove} ); + if ( $result == 0 ) { + $self->status_message__( $templ, sprintf( $self->{language__}{Users_Removed}, $self->{form_}{toremove} ) ); + } + if ( $result == 1 ) { + $self->error_message__( $templ, sprintf( $self->{language__}{Users_Removed_Failed}, $self->{form_}{toremove} ) ); + } + if ( $result == 2 ) { + $self->error_message__( $templ, sprintf( $self->{language__}{Users_Removed_Failed_Admin}, $self->{form_}{toremove} ) ); + } + } + + # Handle editing the parameters of a user + + if ( defined( $self->{form_}{update_params} ) ) { + my $id = $self->classifier_()->get_user_id( $self->{api_session__}, $self->{form_}{editname} ); + foreach my $param (sort keys %{$self->{form_}}) { + if ( $param =~ /parameter_(.*)/ ) { + $self->classifier_()->set_user_parameter_from_id( $id, + $1, $self->{form_}{$param} ); + } + } + } + + my $users = $self->classifier_()->get_user_list( $self->{api_session__} ); + + my @user_loop; + my @remove_user_loop; + foreach my $user (@$users) { + my %row_data; + $row_data{Users_Name} = $user; + push ( @user_loop, \%row_data); + if ( $user ne 'admin' ) { + push ( @remove_user_loop, \%row_data); + } + } + if ( $#remove_user_loop != -1 ) { + $templ->param( 'Users_Loop_Remove' => \@remove_user_loop ); + $templ->param( 'Users_If_Remove' => 1 ); + } + $templ->param( 'Users_Loop_Edit' => \@user_loop ); + $templ->param( 'Users_Loop_Copy' => \@user_loop ); + + if ( exists( $self->{form_}{edituser} ) ) { + my $id = $self->classifier_()->get_user_id( $self->{api_session__}, $self->{form_}{editname} ); + my @parameters = $self->classifier_()->get_user_parameter_list( $self->{api_session__} ); + + my @parameter_list; + my $last = ''; + foreach my $param (sort @parameters) { + my %row_data; + $param =~ /^([^_]+)_/; + if ( ( $last ne '' ) && ( $last ne $1 ) ) { + $row_data{Users_If_New_Module} = 1; + } else { + $row_data{Users_If_New_Module} = 0; + } + $last = $1; + $row_data{Users_Parameter} = $param; + my ( $val, $default ) = $self->classifier_()->get_user_parameter_from_id( $id, $param ); + $row_data{Users_Value} = $val; + $row_data{Users_If_Changed} = !$default; + push ( @parameter_list, \%row_data ); + } + $templ->param( 'Users_Loop_Parameter' => \@parameter_list ); + $templ->param( 'Users_If_Editing_User' => 1 ); + $templ->param( 'Users_Edit_User_Name' => $self->{form_}{editname} ); + } + + $self->http_ok( $client, $templ, 5 ); + } + + #---------------------------------------------------------------------------- + # # advanced_page - very advanced configuration options # *************** *** 1208,1212 **** $templ->param( 'Advanced_Loop_Parameter' => \@param_loop ); ! $self->http_ok( $client, $templ, 5 ); } --- 1325,1329 ---- $templ->param( 'Advanced_Loop_Parameter' => \@param_loop ); ! $self->http_ok( $client, $templ, 6 ); } *************** *** 2834,2837 **** --- 2951,2994 ---- #---------------------------------------------------------------------------- # + # status_message__ + # + # Called to cause the next page generated to show a status message + # (typically at the top) + # + # $templ The current page template + # $message The message to display + # + #---------------------------------------------------------------------------- + sub status_message__ + { + my ( $self, $templ, $message ) = @_; + + my $old = $templ->param( 'Header_Message' ) || ''; + $templ->param( 'Header_If_Message' => 1 ); + $templ->param( 'Header_Message' =>($old ne '')?("$message<br />$old" ):$message); + } + + #---------------------------------------------------------------------------- + # + # error_message__ + # + # Called to cause the next page generated to show a error message + # (typically at the top) + # + # $templ The current page template + # $message The message to display + # + #---------------------------------------------------------------------------- + sub error_message__ + { + my ( $self, $templ, $message ) = @_; + + my $old = $templ->param( 'Header_Error' ) || ''; + $templ->param( 'Header_If_Error' => 1 ); + $templ->param( 'Header_Error' => ($old ne '')?("$message<br />$old" ):$message); + } + + #---------------------------------------------------------------------------- + # # load_template__ # |