[Bio] / SubsystemEditor / WebPage / ShowSubsystem.pm Repository:
ViewVC logotype

Diff of /SubsystemEditor/WebPage/ShowSubsystem.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21, Tue Oct 7 09:37:32 2008 UTC revision 1.26, Wed Apr 8 15:39:04 2009 UTC
# Line 37  Line 37 
37  sub output {  sub output {
38    my ( $self ) = @_;    my ( $self ) = @_;
39    
40    my $fig = new FIG;    my $fig = $self->application->data_handle( 'FIG' );
41    my $cgi = $self->application->cgi;    my $cgi = $self->application->cgi;
42    
43    # subsystem name and 'nice name' #    # subsystem name and 'nice name' #
# Line 49  Line 49 
49    my $can_alter = 0;    my $can_alter = 0;
50    my $user = $self->application->session->user;    my $user = $self->application->session->user;
51    
52    my $dbmaster = DBMaster->new( -database => 'WebAppBackend' );    my $dbmaster = $self->application->dbmaster;
53    my $ppoapplication = $dbmaster->Backend->init( { name => 'SubsystemEditor' } );    my $ppoapplication = $self->application->backend;
54    
55    # get a seeduser #    # get a seeduser #
56    my $seeduser = '';    my $seeduser = '';
# Line 170  Line 170 
170      $subsystem->set_classification( [ $class1, $class2 ] );      $subsystem->set_classification( [ $class1, $class2 ] );
171    
172      my $litstoset = $cgi->param( 'SUBSYSLIT' );      my $litstoset = $cgi->param( 'SUBSYSLIT' );
173        $litstoset =~ s/ //g;
174      my @lits = split( ', ', $litstoset );      my @lits = split( ', ', $litstoset );
175      setLiteratures( $fig, $name, \@lits );      setLiteratures( $fig, $name, \@lits );
176    
# Line 184  Line 185 
185      $subsystem->db_sync();      $subsystem->db_sync();
186      $subsystem->write_subsystem();      $subsystem->write_subsystem();
187    }    }
188      elsif ( defined( $cgi->param( 'GrantRightButton' ) ) ) {
189        if ( $can_alter && $user->has_right( undef, 'edit', 'subsystem', $name, 1 ) ) {
190          my $newAnno = $cgi->param( 'ANNOBOX' );
191          my $newScope;
192          if ($newAnno =~ /group\:(.*)/) {
193            $newScope = $dbmaster->Scope->init( { application => undef, name => $1 } );
194          } else {
195            my $thisUsers = $dbmaster->User->get_objects( { login => $newAnno } );
196            if ( defined( $thisUsers->[0] ) ) {
197              $newScope = $thisUsers->[0]->get_user_scope();
198            }
199          }
200          if (defined($newScope)) {
201            my $rights = $dbmaster->Rights->get_objects( { name => 'edit',
202                                                           data_type => 'subsystem',
203                                                           data_id => $name,
204                                                           scope => $newScope } );
205            if ( defined( $rights->[0] ) ) {
206              $self->application->add_message( 'warning', "User $newAnno already has the right to edit this subsystem." );
207            }
208            else {
209              my $right = $dbmaster->Rights->create( { granted => 1,
210                                                       delegated => 1,
211                                                       name => 'edit',
212                                                       data_type => 'subsystem',
213                                                       data_id => $name,
214                                                       scope => $newScope } );
215              if ( $right ) {
216                $self->application->add_message( 'info', "$newAnno can now edit this subsystem" );
217              }
218              else {
219                $self->application->add_message( 'warning', "Could not create right to edit the subsystem for user $newAnno" );
220              }
221            }
222          }
223        }
224        else {
225          $self->application->add_message( 'warning', "You do not have the right to share the subsystem." );
226        }
227      }
228      elsif ( defined( $cgi->param( 'RevokeRightButton' ) ) ) {
229        if ( $can_alter && $user->has_right( undef, 'edit', 'subsystem', $name, 1 ) ) {
230          my $newAnno = $cgi->param( 'ALANNOBOX' );
231          my $newScope;
232          if ($newAnno =~ /group\:(.*)/) {
233            $newScope = $dbmaster->Scope->init( { application => undef, name => $1 } );
234          } else {
235            my $thisUsers = $dbmaster->User->get_objects( { login => $newAnno } );
236            if ( defined( $thisUsers->[0] ) ) {
237              $newScope = $thisUsers->[0]->get_user_scope();
238            }
239          }
240          my $rights = $dbmaster->Rights->get_objects( { name => 'edit',
241                                                         data_type => 'subsystem',
242                                                         data_id => $name,
243                                                         scope => $newScope } );
244    
245          my $thisRight = $rights->[0];
246          if ( defined( $thisRight ) && $thisRight->delegated ) {
247            $thisRight->delete();
248    
249            $self->application->add_message( 'info', "$newAnno cannot edit this subsystem any more." );
250          }
251          else {
252            $self->application->add_message( 'warning', "You can't revoke the right of $newAnno to edit this subsystem." );
253          }
254        }
255        else {
256          $self->application->add_message( 'warning', "You do not have the right to revoke rights for this subsystem." );
257        }
258      }
259    
260    $subsystem = new Subsystem( $name, $fig, 0 );    $subsystem = new Subsystem( $name, $fig, 0 );
261    
# Line 221  Line 293 
293    
294    my $infotable = "<TABLE><TR><TH>Name:</TH><TD>$ssname</TD></TR>";    my $infotable = "<TABLE><TR><TH>Name:</TH><TD>$ssname</TD></TR>";
295    $infotable .= "<TR><TH>Author:</TH><TD>$sscurator</TD></TR>";    $infotable .= "<TR><TH>Author:</TH><TD>$sscurator</TD></TR>";
296      if ( $can_alter && $user->has_right( undef, 'edit', 'subsystem', $name, 1 ) ) {
297    
298        my $annoGrp = $dbmaster->Scope->get_objects( { name => 'Annotators' } );
299        my $annoScope = $dbmaster->UserHasScope->get_objects( { scope => $annoGrp->[0] } );
300        my $annoMems = [];
301        foreach my $aS ( @$annoScope ) {
302          push @$annoMems, $aS->user();
303        }
304        @$annoMems = sort { $a->lastname cmp $b->lastname || $a->firstname cmp $b->firstname } @$annoMems;
305    
306        my $editRightButton = "<INPUT TYPE=SUBMIT ID='GrantRightButton' NAME='GrantRightButton' VALUE='Grant Right'>";
307        my $revokeRightButton = "<INPUT TYPE=SUBMIT ID='RevokeRightButton' NAME='RevokeRightButton' VALUE='Revoke Right'>";
308    
309        my $annotatorsBox = "<SELECT NAME='ANNOBOX' ID='ANNOBOX'>";
310        my $alreadyAnnotatorsBox = "<SELECT NAME='ALANNOBOX' ID='ALANNOBOX'>";
311        foreach my $a ( @$annoMems ) {
312          unless ( $a->has_right( undef, 'edit', 'subsystem', $name ) ) {
313            $annotatorsBox .= "<OPTION VALUE='".$a->login."'>".$a->firstname.' '.$a->lastname.' ( '.$a->login." )</OPTION>";
314          }
315          else {
316            if ( $a->login() ne $user->login() && ( ! $a->has_right( undef, 'edit', 'subsystem', '*' ) ) ) {
317              $alreadyAnnotatorsBox .= "<OPTION VALUE='".$a->login."'>".$a->firstname.' '.$a->lastname.' ( '.$a->login." )</OPTION>";
318            }
319          }
320        }
321    
322        # check for groups
323        my $user_groups = $user->scopes();
324        foreach my $scope (@$user_groups) {
325          next if ($scope->name =~ /^user\:/);
326          next if ($scope->name eq "Annotators");
327          next if ($scope->name eq "Public");
328          if (scalar(@{$dbmaster->Rights->get_objects( { name => 'edit',
329                                                         data_type => 'subsystem',
330                                                         data_id => $name,
331                                                         scope => $scope,
332                                                         granted => 1 } )})) {
333            $alreadyAnnotatorsBox .= "<OPTION VALUE='group:".$scope->name()."'>group: ".$scope->name()."</OPTION>";
334          } else {
335            $annotatorsBox .= "<OPTION VALUE='group:".$scope->name()."'>group: ".$scope->name()."</OPTION>";
336          }
337        }
338    
339        $annotatorsBox .= "</SELECT>";
340        $alreadyAnnotatorsBox .= "</SELECT>";
341    
342        $infotable .= "<TR><TH>Grant Right To Edit To:</TH><TD>$annotatorsBox $editRightButton</TD></TR>";
343        $infotable .= "<TR><TH>Revoke Right To Edit From:</TH><TD>$alreadyAnnotatorsBox $revokeRightButton</TD></TR>";
344      }
345    $infotable .= "<TR><TH>Version:</TH><TD>$ssversion $versionlink</TD></TR>";    $infotable .= "<TR><TH>Version:</TH><TD>$ssversion $versionlink</TD></TR>";
346    $infotable .= "<TR><TH>Last Modified:</TH><TD>$mod_time</TD></TR>";    $infotable .= "<TR><TH>Last Modified:</TH><TD>$mod_time</TD></TR>";
347    
# Line 369  Line 490 
490    my @ssclassifications = $fig->all_subsystem_classifications();    my @ssclassifications = $fig->all_subsystem_classifications();
491    my $ssclass;    my $ssclass;
492    foreach my $ssc ( @ssclassifications ) {    foreach my $ssc ( @ssclassifications ) {
493      next if ( ( !defined( $ssc->[0] ) ) || ( !defined( $ssc->[1] ) ) );      if ( !defined( $ssc->[1] ) ) {
494      next if ( ( $ssc->[0] eq '' ) || ( $ssc->[1] eq '' ) );        $ssc->[1] = '';
495        }
496    #    next if ( ( !defined( $ssc->[0] ) ) || ( !defined( $ssc->[1] ) ) );
497        next if ( !defined( $ssc->[0] ) );
498        next if ( $ssc->[0] eq '' );
499    #    next if ( ( $ssc->[0] eq '' ) || ( $ssc->[1] eq '' ) );
500      next if ( ( $ssc->[0] =~ /^\s+$/ ) || ( $ssc->[1] =~ /^\s+$/ ) );      next if ( ( $ssc->[0] =~ /^\s+$/ ) || ( $ssc->[1] =~ /^\s+$/ ) );
501      push @{ $ssclass->{ $ssc->[0] } }, $ssc->[1];      push @{ $ssclass->{ $ssc->[0] } }, $ssc->[1];
502    }    }

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.26

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3