Changeset 112 for trunk


Ignore:
Timestamp:
08/02/11 18:54:07 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Mostly complete functionality of bulk group move

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r111 r112  
    2727        &initGlobals
    2828        &initPermissions &getPermissions &changePermissions &comparePermissions
     29        &changeGroup
    2930        &connectDB &finish
    3031        &addDomain &delDomain &domainName &domainID
     
    4344                &initGlobals
    4445                &initPermissions &getPermissions &changePermissions &comparePermissions
     46                &changeGroup
    4547                &connectDB &finish
    4648                &addDomain &delDomain &domainName &domainID
     
    348350  return $retval;
    349351} # end comparePermissions()
     352
     353
     354## DNSDB::changeGroup()
     355# Change group ID of an entity
     356# Takes a database handle, entity type, entity ID, and new group ID
     357sub changeGroup {
     358  my $dbh = shift;
     359  my $type = shift;
     360  my $id = shift;
     361  my $newgrp = shift;
     362
     363##fixme:  fail on not enough args
     364  #return ('FAIL', "Missing
     365
     366  if ($type eq 'domain') {
     367    $dbh->do("UPDATE domains SET group_id=? WHERE domain_id=?", undef, ($newgrp, $id))
     368        or return ('FAIL','Group change failed: '.$dbh->errstr);
     369  } elsif ($type eq 'user') {
     370    $dbh->do("UPDATE users SET group_id=? WHERE user_id=?", undef, ($newgrp, $id))
     371        or return ('FAIL','Group change failed: '.$dbh->errstr);
     372  } elsif ($type eq 'group') {
     373    $dbh->do("UPDATE groups SET parent_group_id=? WHERE group_id=?", undef, ($newgrp, $id))
     374        or return ('FAIL','Group change failed: '.$dbh->errstr);
     375  }
     376  return ('OK','OK');
     377} # end changeGroup()
    350378
    351379
  • trunk/dns.cgi

    r111 r112  
    3737
    3838my @debugbits;  # temp, to be spit out near the end of processing
    39 my $debugenv = 0;
     39my $debugenv = 1;
    4040
    4141# Let's do these templates right...
     
    108108my $sortorder = "ASC";
    109109
    110 my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret","newdbhost");
     110#my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret","newdbhost");
     111# dbname, user, pass, host (optional)
     112my ($dbh,$msg) = connectDB("dnsdb", "dnsdb", "secret", "dnsdbhost");
    111113#my $dbh = DBI->connect("DBI:mysql:database=vegadns","vegadns","secret",
    112114#       { AutoCommit => 0 }) or die $DBI::errstr;
     
    587589    if ($code ne 'OK') {
    588590# need to find failure mode
     591      logaction(0, $session->param("username"), $webvar{curgroup}, "Failure deleting group $deleteme: $msg");
    589592      changepage(page => "grpman", del_failed => 1, errmsg => $msg);
    590 ##fixme: log
    591593    } else {
    592594##fixme: need to clean up log when deleting a major container
     
    642644
    643645##fixme: un-hardcode the limit?
    644   $perpage = 50;
     646#  $perpage = 50;
    645647
    646648  my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
     
    651653  fill_pgcount($count,'domains',groupName($dbh,$curgroup));
    652654  fill_fpnla($count);
     655  $page->param(offset => $offset);      # since apparently this isn't set explicitly elsewhere.  Who knew?
     656  $page->param(perpage => $perpage);
    653657
    654658  my @domlist;
     
    669673  }
    670674  $page->param(domtable => \@domlist);
    671 # ACLs
     675  # ACLs
    672676  $page->param(maymove => ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete})));
    673677  $page->param(maystatus => $permissions{admin} || $permissions{domain_edit});
    674678  $page->param(maydelete => $permissions{admin} || $permissions{domain_delete});
    675679
    676 ##fixme:  need to clean up status indicator/usage/inversion
     680} elsif ($webvar{page} eq 'bulkchange') {
     681
     682  if ($webvar{action} eq 'move') {
     683    changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains")
     684        unless ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete}));
     685$page->param(action => $webvar{action});
     686my $tmpstr = 'tmpstr: ';
     687my @bulkresults;
     688# nngh.  due to alpha-sorting on the previous page, we can't use domid-numeric
     689# order here, and since we don't have the domain names until we go around this
     690# loop, we can't alpha-sort them here.  :(
     691foreach (keys %webvar) {
     692  my %row;
     693  next unless $_ =~ /^dom_\d+$/;
     694  $row{domain} = domainName($dbh,$webvar{$_});
     695  my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup});
     696  $row{domok} = ($code eq 'OK');
     697  $row{domerr} = $msg;
     698  push @bulkresults, \%row;
     699}
     700$page->param(bulkresults => \@bulkresults);
     701
     702  } elsif ($webvar{action} eq 'deactivate') {
     703    changepage(page => "domlist", errmsg => "You are not permitted to bulk-deactivate domains")
     704        unless ($permissions{admin} || $permissions{domain_edit});
     705  } elsif ($webvar{action} eq 'activate') {
     706    changepage(page => "domlist", errmsg => "You are not permitted to bulk-activate domains")
     707        unless ($permissions{admin} || $permissions{domain_edit});
     708  } elsif ($webvar{action} eq 'delete') {
     709    changepage(page => "domlist", errmsg => "You are not permitted to bulk-delete domains")
     710        unless ($permissions{admin} || $permissions{domain_delete});
     711  }
     712  # not going to handle the unknown $webvar{action} else;  it should not be possible in normal
     713  # operations, and anyone who meddles with the URL gets what they deserve.
    677714
    678715} elsif ($webvar{page} eq 'useradmin') {
  • trunk/templates/bulkdomain.tmpl

    r110 r112  
    99
    1010<input type="hidden" name="sid" value="<TMPL_VAR NAME=sid>" />
    11 <input type="hidden" name="page" value="bulkdomain" />
     11<input type="hidden" name="page" value="bulkchange" />
     12<input type="hidden" name="offset" value="<TMPL_VAR NAME=offset>" />
     13<input type="hidden" name="perpage" value="<TMPL_VAR NAME=perpage>" />
    1214
    1315<table class="container">
    1416<tr><td>
    1517    <table border="0" cellspacing="2" cellpadding="2" width="100%">
    16 <TMPL_IF add_failed>    <tr><td class="errhead" colspan="2">Error adding domain <TMPL_VAR NAME=domain>: <TMPL_VAR NAME=errmsg></td></tr></TMPL_IF>
    1718        <tr class="darkrowheader"><td colspan="2" align="center">Bulk Domain Changes</td></tr>
    1819
     
    2021                <td>Action:</td>
    2122                <td align="left">
    22 <TMPL_IF maymove><input type="radio" name="action" value="move" /> Move to group: <select name="group">
     23<TMPL_IF maymove>               <input type="radio" name="action" value="move" checked="checked" /> Move to group: <select name="destgroup">
    2324<TMPL_LOOP name=grouplist>              <option value="<TMPL_VAR NAME=groupval>"<TMPL_IF groupactive> selected="selected"</TMPL_IF>><TMPL_VAR name=groupname></option>
    2425</TMPL_LOOP>
    2526                </select><br /></TMPL_IF>
    26 <TMPL_IF maystatus><input type="radio" name="action" value="deactivate" /> Deactivate<br />
    27 <input type="radio" name="action" value="activate" /> Activate<br /></TMPL_IF>
    28 <TMPL_IF maydelete><input type="radio" name="action" value="delete" /> Delete<br /></TMPL_IF>
    29 </td>
     27<TMPL_IF maystatus>             <input type="radio" name="action" value="deactivate" /> Deactivate<br />
     28                <input type="radio" name="action" value="activate" /> Activate<br /></TMPL_IF>
     29<TMPL_IF maydelete>             <input type="radio" name="action" value="delete" /> Delete<br /></TMPL_IF>
     30                </td>
    3031        </tr>
    3132        <tr class="darkrowheader">
     
    4647</table>
    4748                </td>
    48         </tr>
     49</td>
     50</tr>
     51<tr class="darkrowheader"><td colspan="2" align="center"><input type="submit" value="Make changes" /></td></tr>
    4952    </table>
    5053    </td>
Note: See TracChangeset for help on using the changeset viewer.