From: <de...@de...> - 2012-04-20 22:36:55
|
Author: MichaelGulitz Date: 2012-04-20 17:36:49 -0500 (Fri, 20 Apr 2012) New Revision: 22834 Trac url: http://develop.twiki.org/trac/changeset/22834 Modified: twiki/trunk/ConnectByRestPlugin/data/TWiki/ConnectByRestPlugin.txt twiki/trunk/ConnectByRestPlugin/lib/TWiki/Plugins/ConnectByRestPlugin.pm Log: Item6619: Checking in beta release Modified: twiki/trunk/ConnectByRestPlugin/data/TWiki/ConnectByRestPlugin.txt =================================================================== --- twiki/trunk/ConnectByRestPlugin/data/TWiki/ConnectByRestPlugin.txt 2012-04-18 23:02:47 UTC (rev 22833) +++ twiki/trunk/ConnectByRestPlugin/data/TWiki/ConnectByRestPlugin.txt 2012-04-20 22:36:49 UTC (rev 22834) @@ -1,17 +1,38 @@ -%META:TOPICINFO{author="MichaelGulitz" date="1315256734" format="1.1" reprev="1.4" version="1.4"}% +%META:TOPICINFO{author="MichaelGulitz" date="1334959730" format="1.1" version="1.4"}% ---+!! <nop>%TOPIC% -This plugin wraps function from the TWiki API in REST functions. The intention is to offer external applications access to TWiki by implementing a REST interface. +This plugin wraps functions from the TWiki API in REST functions. The intention is to offer external applications access to TWiki by implementing a REST interface. -These functions of this plugin include: - * create new topics - * update existing topics +The functions of this plugin include: + * create and update topics * read topics and meta data * read and update form fields of a topic %TOC% ---++ REST Functions + +---+++ Function Readtopic + +*Description* + +This function returns the content of a topic as a string. +It reads the topic that was specified in the parameter _topic_ and returns the topic text as a string. + +*Parameters* + +| *Parameter* | *Direction* | *Type* | *Description* | +| username | in | string | | +| password | in | string | | +| topic | in | string | use full topic name: _web.topic_ | +| text | out | string | topic text | + +*Security* + + * The function checks if the given user has read access to the topic. + + + ---+++ Function Getmetastring *Description* @@ -50,15 +71,11 @@ * The functions checks if the given user has write access to the topic. ----+++ Function Readtopic +---+++ Function Savetopic ----+++ Function Updatetopic - ----+++ Function Createtopic - *Description* -The function creates a new topic in the specified web. An existing topic cannot be changed using this function! +The function creates a new topic or updates an existing topic in the specified web. *Parameters* @@ -71,7 +88,7 @@ *Security* - * The functions checks if the given user has write access to the web and if a topic with the same name already exists (that would lead to an error) . + * The functions checks if the given user has write access to the web. ---++ Syntax Rules Modified: twiki/trunk/ConnectByRestPlugin/lib/TWiki/Plugins/ConnectByRestPlugin.pm =================================================================== --- twiki/trunk/ConnectByRestPlugin/lib/TWiki/Plugins/ConnectByRestPlugin.pm 2012-04-18 23:02:47 UTC (rev 22833) +++ twiki/trunk/ConnectByRestPlugin/lib/TWiki/Plugins/ConnectByRestPlugin.pm 2012-04-20 22:36:49 UTC (rev 22834) @@ -161,6 +161,7 @@ # Allow a sub to be called from the REST interface # using the provided alias + TWiki::Func::registerRESTHandler('readtopic', \&restReadtopic); TWiki::Func::registerRESTHandler('savetopic', \&restSavetopic); TWiki::Func::registerRESTHandler('getmetastring', \&restGetmetastring); TWiki::Func::registerRESTHandler('updateformfield', \&restUpdateformfield); @@ -794,6 +795,61 @@ =pod +---++ restReadtopic($session) -> $text + + * =$session= - The TWiki object associated to this session. + * =$web= - name of the target web + * =$topic= - Name of the topic file to be saved/created +Return: + * =$text= - Topic content + + + + +The function reads the given topic and returns the topic text and metadata as string. + +=cut + +sub restReadtopic { + + require TWiki::Meta; + + my ($session) = @_; + my $topic = TWiki::Func::getCgiQuery()->param('topic'); + my $web; + my $error; + + ($web, $topic) = TWiki::Func::normalizeWebTopicName(undef, $topic); + + + unless ( TWiki::Func::webExists ( $web )) { + return "Invalid Web $web \n"; + } + +# check if topic exists + if ( TWiki::Func::topicExists( $web, $topic )) { + # check accessrights in topic + unless (TWiki::Func::checkAccessPermission( + 'VIEW', TWiki::Func::getWikiName(), + undef, $topic, $web)) { + $error = "Access to topic $topic denied"; + print CGI::header(-status => 401); + print $error; + print STDERR $error; + return undef; + } + + my ($meta, $text) = TWiki::Func::readTopic($web, $topic); +# my $metastring = $meta->stringify(); + return $text; + + } + + return undef; + +} + +=pod ---++ restCreatetopic($session) -> $text * =$session= - The TWiki object associated to this session. @@ -854,22 +910,6 @@ $error = TWiki::Func::saveTopic( $web, $topic, $newmeta, $ptext, { forcenewrevision => 1 } ); print STDERR -# save new topic -# $error = TWiki::Func::saveTopic( $web, $topic, $meta, $text, { forcenewrevision => 1 } ); -# unless (TWiki::Func::saveTopic( $web, $topic, $meta, $text, $options )){ -# my $error = "Fehler beim Anlegen von Topic $topic,\n $text \n"; -# print CGI::header(-status => 401); -# print $error; -# print STDERR $error; -# return undef; -# } -# $error = TWiki::Func::saveTopic( $web, $topic, $meta, $textold, { forcenewrevision => 1 } ); -# unless ($error){ -# return $error; -# } -# return undef; -# TWiki::Func::saveTopic( $web, $topic, $meta, $text,{ comment => 'uif save' } ); - return undef; } |