Index: lib/Foswiki/Plugins/WorkflowPlugin/Workflow.pm =================================================================== --- lib/Foswiki/Plugins/WorkflowPlugin/Workflow.pm (revision 7192) +++ lib/Foswiki/Plugins/WorkflowPlugin/Workflow.pm (working copy) @@ -48,23 +48,16 @@ $class ); my $inBlock = 0; - my @fields; # | *Current state* | *Action* | *Next state* | *Allowed* | foreach ( split( /\n/, $text ) ) { if (/^\s*\|[\s*]*State[\s*]*\|[\s*]*Action[\s*]*\|.*\|$/i) { - @fields = map { _cleanField( lc($_) ) } split(/\s*\|\s*/); - shift @fields; - # from now on, we are in the TRANSITION table $inBlock = 1; } elsif (/^\s*\|[\s*]*State[\s*]*\|[\s*]*Allow Edit[\s*]*\|.*\|$/i) { - @fields = map { _cleanField( lc($_) ) } split(/\s*\|\s*/); - shift @fields; - # from now on, we are in the STATE table $inBlock = 2; @@ -74,20 +67,34 @@ # store preferences $this->{preferences}->{$1} = $2; } - elsif ( $inBlock == 1 && s/^\s*\|\s*// ) { + elsif ( $inBlock == 1 && s/^\s*\|//o ) { - # read row in TRANSITION table - my %data; - @data{@fields} = split(/\s*\|\s*/); - push( @{ $this->{transitions} }, \%data ); + my ( $state, $action, $next, $allowed, $form ) = + split(/\s*\|\s*/); + $state = _cleanField($state); + push( + @{ $this->{transitions} }, + { + state => $state, + action => $action, + nextstate => $next, + allowed => $allowed, + form => $form + } + ); + } - elsif ( $inBlock == 2 && s/^\s*\|\s*//o ) { + elsif ( $inBlock == 2 && s/^\s*\|//o ) { - # read row in STATE table - my %data; - @data{@fields} = split(/\s*\|\s*/); - $this->{defaultState} ||= $data{state}; - $this->{states}->{ $data{state} } = \%data; + my ( $state, $allowedit, $message ) = split(/\s*\|\s*/); + $state = _cleanField($state); + $this->{defaultState} ||= $state; + $this->{states}->{$state} = { + name => $state, + allowedit => $allowedit, + message => $message + }; + } else { $inBlock = 0; @@ -102,12 +109,12 @@ my @actions = (); my $currentState = $topic->getState(); foreach ( @{ $this->{transitions} } ) { - my $allowed = $topic->expandMacros( $_->{allowed} ); - my $nextState = $topic->expandMacros( $_->{nextstate} ); - if ( $_->{state} eq $currentState + my $allowed = $topic->expandMacros( $_{allowed} ); + my $nextState = $topic->expandMacros( $_{nextstate} ); + if ( $_{state} eq $currentState && _isAllowed($allowed) && $nextState ) { - push( @actions, $_->{action} ); + push( @actions, $_{action} ); } } return @actions; @@ -120,10 +127,10 @@ my ( $this, $topic, $action ) = @_; my $currentState = $topic->getState(); foreach ( @{ $this->{transitions} } ) { - my $allowed = $topic->expandMacros( $_->{allowed} ); - my $nextState = $topic->expandMacros( $_->{nextstate} ); - if ( $_->{state} eq $currentState - && $_->{action} eq $action + my $allowed = $topic->expandMacros( $_{allowed} ); + my $nextState = $topic->expandMacros( $_{nextstate} ); + if ( $_{state} eq $currentState + && $_{action} eq $action && _isAllowed($allowed) && $nextState ) { return $nextState; @@ -139,12 +146,12 @@ my ( $this, $topic, $action ) = @_; my $currentState = $topic->getState(); foreach ( @{ $this->{transitions} } ) { - my $allowed = $topic->expandMacros( $_->{allowed} ); - if ( $_->{state} eq $currentState - && $_->{action} eq $action + my $allowed = $topic->expandMacros( $_{allowed} ); + if ( $_{state} eq $currentState + && $_{action} eq $action && _isAllowed($allowed) ) { - return $_->{form}; + return $_{form}; } } return undef; @@ -157,12 +164,12 @@ my ( $this, $topic, $action ) = @_; my $currentState = $topic->getState(); foreach ( @{ $this->{transitions} } ) { - my $allowed = $topic->expandMacros( $_->{allowed} ); - if ( $_->{state} eq $currentState - && $_->{action} eq $action + my $allowed = $topic->expandMacros( $_{allowed} ); + if ( $_{state} eq $currentState + && $_{action} eq $action && _isAllowed( $allowed ) ) { - return $_->{notify}; + return $_{notify}; } } return undef;