Changeset 78 for trunk


Ignore:
Timestamp:
02/23/11 14:53:57 (14 years ago)
Author:
Kris Deugau
Message:

/trunk

Tweak and fix permission update sub; it should now properly add
the permission entry if the permissions being edited were inherited

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r72 r78  
    247247  my $newperms = shift;
    248248
    249 my $failmsg = '';
     249  my $failmsg = '';
    250250
    251251  # see if we're switching from inherited to custom
     
    258258  my ($wasinherited,$permid) = $sth->fetchrow_array;
    259259
     260# hack phtoui
     261# group id 1 is "special" in that it's it's own parent (err...  possibly.)
     262# may make its parent id 0 which doesn't exist, and as a bonus is Perl-false.
     263  $wasinherited = 0 if ($type eq 'group' && $id == 1);
     264
    260265  local $dbh->{AutoCommit} = 0;
    261266  local $dbh->{RaiseError} = 1;
     
    264269  eval {
    265270    if ($wasinherited) {
    266 $failmsg = "wasinherited: '$wasinherited'";
    267 die "don't wanna add perms where we don't need to";
    268271##fixme: need to add semirecursive bit to properly munge inherited permission ID on subgroups and users
    269 ## FIXME:  need to fiddle permissions table to track back to users or groups table
    270       my $sql = "INSERT INTO permissions ($permlist) ".
    271         "SELECT $permlist FROM permissions WHERE permission_id=?";
    272       $sth = $dbh->prepare($sql);
    273       $sth->execute($permid);
     272      $dbh->do("INSERT INTO permissions ($permlist) ".
     273        "SELECT $permlist FROM permissions WHERE permission_id=?", undef, ($permid) );
     274      #$sth = $dbh->prepare($sql);
     275      #$sth->execute($permid);
    274276      $sth = $dbh->prepare("SELECT permission_id FROM ".($type eq 'user' ? 'users' : 'groups').
    275277        " WHERE ".($type eq 'user' ? 'user' : 'group')."_id=?");
    276278      $sth->execute($id);
    277279      ($permid) = $sth->fetchrow_array;
     280      $dbh->do("UPDATE permissions SET ".($type eq 'user' ? 'user' : 'group')."_id=? ".
     281        "WHERE permission_id=?", undef, ($id,$permid) );
     282      $dbh->do("UPDATE ".($type eq 'user' ? 'users' : 'groups')." SET permission_id=? ".
     283        "WHERE ".($type eq 'user' ? 'user' : 'group')."_id=?", undef, ($permid,$id) );
    278284    }
    279285    foreach (@permtypes) {
    280286      if (defined ($newperms->{$_})) {
    281         $sth = $dbh->prepare("UPDATE permissions SET $_=? WHERE permission_id=?");
    282         $sth->execute($newperms->{$_},$permid);
     287        $dbh->do("UPDATE permissions SET $_=? WHERE permission_id=?", undef, ($newperms->{$_},$permid) );
     288        #$sth->execute($newperms->{$_},$permid);
    283289      }
    284290    }
     291
    285292    $dbh->commit;
    286293  }; # end eval
Note: See TracChangeset for help on using the changeset viewer.