Skip to content

Commit

Permalink
Item2321: new implementation of RestPlugin as new UI script
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@10129 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Dec 1, 2010
1 parent 0f1bf3d commit 180536a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
20 changes: 20 additions & 0 deletions UnitTestContrib/test/unit/MetaTests.pm
Expand Up @@ -793,6 +793,26 @@ sub test_getRevisionHistory {
$this->assert(!$revIt->hasNext());
}

sub test_haveAccess {
my $this = shift;

my $topicObject = Foswiki::Meta->new(
$this->{session}, $this->{test_web}, 'WebHome' );
$this->assert($topicObject->haveAccess('VIEW'));
$this->assert($topicObject->haveAccess('CHANGE'));


my $webObject = Foswiki::Meta->new(
$this->{session}, $this->{test_web} );
$this->assert($webObject->haveAccess('VIEW'));
$this->assert($webObject->haveAccess('CHANGE'));

my $rootObject = Foswiki::Meta->new(
$this->{session} );
$this->assert($rootObject->haveAccess('VIEW'));
$this->assert(not $rootObject->haveAccess('CHANGE'));
}

# Disabled as XML functionnality has been removed from the core, see Foswikitask:Item1917
# sub testXML_topic {
# my $this = shift;
Expand Down
68 changes: 67 additions & 1 deletion core/lib/Foswiki/Serialise.pm
Expand Up @@ -5,6 +5,9 @@ use strict;
use warnings;
use Foswiki ();


#NOTE that JSON::XS is essentially so fast its a nop, whereas the non-XS version is slow as a slow thing,

#should this really be a register/request?

#TODO: do we need to use Foswiki, or can we throw a Simple exception instead?
Expand All @@ -31,9 +34,11 @@ sub perl {
return Data::Dumper->Dump( [$result] );
}

#TODO: should really use encode_json / decode_json as those will use utf8,
#but er, that'll cause other issues - as QUERY will blast the json into a topic..
sub json {
my ( $session, $result ) = @_;
eval "require JSON";
eval "require JSON::XS";
if ($@) {
return $session->inlineAlert( 'alerts', 'generic',
'Perl JSON module is not available' );
Expand Down Expand Up @@ -62,6 +67,67 @@ sub default {
}
}

#filter out parts of a meta object that don't make sense serialise (for example, json doesn't really like being sent a blessed object
sub convertMeta {
my $savedMeta = shift;

my $meta = {
_web => $savedMeta->web(),
_topic => $savedMeta->topic()
};

foreach my $key ( keys(%$savedMeta) ) {
next if ( $key eq '_session' );
next if ( $key eq '_indices' );

$meta->{$key} = $savedMeta->{$key};
}

$meta->{_raw_text} = $savedMeta->getEmbeddedStoreForm();

return $meta;
}


#TODO: ok, ugly, and incomplete
sub deserialise {
my $session = shift;
my $result = shift;
my $style = shift;

$style = $style.'_un';
#test to make sure we exist, and other things

no strict 'refs';
my $data = &$style($session, $result);
use strict 'refs';
return $data;
}


sub perl_un {
die 'not implemented';
}

#TODO: should really use encode_json / decode_json as those will use utf8,
#but er, that'll cause other issues - as QUERY will blast the json into a topic..
sub json_un {
my ( $session, $result ) = @_;
eval "require JSON::XS";
if ($@) {
return $session->inlineAlert( 'alerts', 'generic',
'Perl JSON module is not available' );
}
return JSON::from_json( $result );
}

# Default serialiser
sub default_un {
die 'not implemented';
}



1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down

0 comments on commit 180536a

Please sign in to comment.