Skip to content

Commit

Permalink
Item12865: fully specify all security switches for rest handlers
Browse files Browse the repository at this point in the history
also:
- added options to disable some parts of a category view template
- added tool to list uncategorized topics



git-svn-id: http://svn.foswiki.org/trunk/ClassificationPlugin@17760 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Jun 10, 2014
1 parent dd72430 commit 4db3147
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 78 deletions.
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1397121183" format="1.1" reprev="9" version="11"}%
%META:TOPICINFO{author="micha" comment="reprev" date="1402084278" format="1.1" reprev="13" version="13"}%
%META:TOPICPARENT{name="TopicFunction"}%
%TOC{depth="2"}%

Expand All @@ -10,13 +10,16 @@ a summary for an object of type ClassifiedTopic.
---+++++ Parameters
* OBJECT
* TITLE
* THEWEB

%ENDSECTION{name="documentation" type="section"}%

---++ Implementation
<verbatim class="tml">
%STARTINCLUDE%<!-- --><noautolink>
%CATINFO{cat="%DBQUERY{topic="%OBJECT%" format="$topic"}%"
%CATINFO{
cat="%DBQUERY{topic="%OBJECT%" format="$topic"}%"
web="%THEWEB{default="%DBQUERY{topic="%OBJECT%" format="$web"}%"}%"
maxchildren="6"
sortchildren="on"
morechildren="<a href='$url' title='%MAKETEXT{"more"}%'>...</a>"
Expand Down
45 changes: 19 additions & 26 deletions data/Applications/ClassificationApp/CategoryViewTemplate.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1380204072" format="1.1" reprev="15" version="15"}%
%META:TOPICINFO{author="micha" comment="reprev" date="1402086950" format="1.1" reprev="16" version="16"}%
%META:TOPICPARENT{name="TopicView"}%
%{<verbatim class="tml">}%
%TMPL:INCLUDE{"Applications.WikiTopicView"}%
Expand All @@ -14,36 +14,29 @@

%{<verbatim class="tml">}%
%TMPL:DEF{"beforetext"}%<!-- -->
%IF{"defined catname"
then="$percntTMPL:P{\"virtualcategory\"}$percnt"
else="$percntTMPL:P{\"normalcategory\"}$percnt"
}%
<!-- -->%TMPL:END%
%{</verbatim>}%

%{<verbatim class="tml">}%
%TMPL:DEF{"normalcategory"}%<!-- -->
<div class="foswikiTopicInfo">
%DBCALL{"Applications.ClassificationApp.RenderClassifiedTopicView" TITLE_EXTRA="%TMPL:P{"titleextra"}%" }%
</div>
<!-- -->%TMPL:END%
%{</verbatim>}%

%{<verbatim class="tml">}%
%TMPL:DEF{"virtualcategory"}%<!-- -->
<div class="foswikiTopicInfo">
%CATINFO{
cat="%URLPARAM{"catname"}%"
cat="%URLPARAM{"catname" default="%BASETOPIC%"}%"
format="<h1>$link
$percntIF{\"'$percntENCODE{\"$summary\" type=\"entity\"}$percnt'!=''\"
then=\"<br /><span class='foswikiTopicSummary'>$summary</span>\"
}$percnt</h1>
$percntMAKETEXT{\"Filed in [_1]\"
args=\"$percntFORMATLIST{\"$parentlinks\" split=\"\s*,\s*\" separator=\"&#44; \"}$percnt\"
}$percnt"
}$percnt</h1>"
}%
</div>
<!-- -->%TMPL:END%
%IF{"'%DISPLAYREVISIONINFO{default="on"}%'='on'"
then="$percntTMPL:P{\"catrevinfo\"}$percnt"
}%<!-- -->%TMPL:END%
%{</verbatim>}%

%{<verbatim class="tml">}%
%TMPL:DEF{"catrevinfo"}%<!-- -->
%CATINFO{
cat="%URLPARAM{"catname" default="%BASETOPIC%"}%"
format="$percntFORMATLIST{\"$parentlinks\"
split=\"\s*,\s*\"
separator=\"&#44; \"
header=\"<div class='foswikiTopicInfo'>%JQICON{"fa-folder"}% \"
footer=\"</div>\"
}$percnt"
}%<!-- -->%TMPL:END%
%{</verbatim>}%

%{<verbatim class="tml">}%
Expand Down
2 changes: 1 addition & 1 deletion data/Applications/ClassificationApp/IntranetDirectory.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1400744215" format="1.1" reprev="9" version="10"}%
%META:TOPICINFO{author="micha" comment="reprev" date="1401705411" format="1.1" reprev="11" version="11"}%
%META:TOPICPARENT{name="WebHome"}%
%DBCALL{"Applications.ClassificationApp.RenderCategory"}%

Expand Down
25 changes: 4 additions & 21 deletions data/Applications/ClassificationApp/OrgChart.txt
@@ -1,27 +1,10 @@
%META:TOPICINFO{author="ProjectContributor" comment="autosave" date="1357565280" format="1.1" version="7"}%
%META:TOPICPARENT{name="WebHome"}%
wwwxxx
yyy
zzz
111222
111
222
333
444
555
666
777
888
999
111
222
333
444
555
%META:TOPICINFO{author="micha" comment="reprev" date="1401709243" format="1.1" reprev="8" version="8"}%
%META:TOPICPARENT{name="BusinessStructure"}%


%META:FORM{name="Applications.ClassificationApp.ClassifiedTopic"}%
%META:FIELD{name="TopicType" title="TopicType" value="ClassifiedTopic, CategorizedTopic, TaggedTopic, WikiTopic"}%
%META:FIELD{name="TopicTitle" attributes="" title="<nop>TopicTitle" value="Org.Chart"}%
%META:FIELD{name="Summary" attributes="" title="Summary" value="This is a test topic with a nop in it"}%
%META:FIELD{name="Tag" attributes="" title="Tag" value=""}%
%META:FIELD{name="Category" attributes="" title="Category" value=""}%
%META:FIELD{name="Category" attributes="" title="Category" value="BusinessStructure"}%
35 changes: 25 additions & 10 deletions data/Applications/ClassificationApp/RenderCategory.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1392980602" format="1.1" reprev="17" version="17"}%
%META:TOPICINFO{author="micha" comment="reprev" date="1402086723" format="1.1" reprev="21" version="21"}%
%META:TOPICPARENT{name="TopicFunction"}%
%TOC{depth="2"}%

Expand All @@ -11,8 +11,10 @@ See the CategoryTemplate.
* CAT: category to be rendered, defaults to URLPARM{"catname" default="BASETOPIC"}
* KEYWORDS: keywords to filter for
* TAG: tags to be searching for in this category
* SHOWHEADER: display anchors, defaults to off
* EXCLUDE: categories to be excluded from the list
* SHOWHEADER: switch on/off display anchors, defaults to off
* SHOWTOPICS: switch on/off display of topics in this category; defaults to on
* SHOWGROUPS: switch on/off alphabetic headers; defaults to off

%ENDSECTION{name="documentation" type="section"}%

Expand All @@ -22,8 +24,8 @@ See the CategoryTemplate.
%MAKEINDEX{
"%HIERARCHY{
web="%BASEWEB%"
top="%IF{"defined CAT" then="%CAT%" else="%URLPARAM{"catname" default="%BASETOPIC%"}%"}%"
exclude="%IF{"defined CAT" then="%CAT%" else="%URLPARAM{"catname" default="%BASETOPIC%"}%"}%%IF{"defined EXCLUDE" then="|%EXCLUDE%"}%"
top="%CAT{default="%URLPARAM{"catname" default="%BASETOPIC%"}%"}%"
exclude="%CAT{default="%URLPARAM{"catname" default="%BASETOPIC%"}%"}%%IF{"defined EXCLUDE" then="|%EXCLUDE%"}%"
depth="2"
sort="title"
format="($trunctitle);$topic;$origweb$n"
Expand All @@ -32,8 +34,22 @@ See the CategoryTemplate.
split="\n"
pattern="\((.*)\);(.*);(.*)"
sort="off"
format="$percntDBCALL{\"$3.$2->RenderIndexItem\" TITLE=\"$1\"}$percnt"
}%
%IF{"'%SHOWGROUPS{default="off"}%'!='on'" then="group=\"\""}%
format="$percntDBCALL{\"$3.$2->RenderIndexItem\" TITLE=\"$1\" THEWEB=\"%BASEWEB%\"}$percnt"
}%<!-- -->
%IF{"'%SHOWTOPICS{default="%IF{"'%CAT{default="%URLPARAM{"catname" default="%BASETOPIC%"}%"}%'='TopCategory'" then="off" else="on"}%"}%'='on'"
then="$percntDBCALL{\"%WEB%.%TOPIC%\"
section=\"topicindex\"
TAG=\"%TAG%\"
KEYWORDS=\"%KEYWORDS%\"
}$percnt"
}%<!-- -->
</div></noautolink>
<!-- -->%STOPINCLUDE%
</verbatim>

<verbatim class="tml">
%STARTSECTION{"topicindex"}%<!-- -->
%MAKEINDEX{
"%DBQUERY{
"!(TopicType=~'\bCategory\b') AND
Expand All @@ -59,10 +75,9 @@ See the CategoryTemplate.
pattern="(.*);(.*);(.*)"
sort="nocase"
%IF{"'%SHOWHEADER%'='on'" then="header=\"$anchors\""}%
format="$percntDBCALL{\"$3.$2->RenderIndexItem\"}$percnt"
}%<!-- -->
</div></noautolink>
<!-- -->%STOPINCLUDE%
format="$percntDBCALL{\"$3.$2->RenderIndexItem\"}$percnt"
}%<!-- -->
<!-- -->%ENDSECTION{"topicindex"}%%
</verbatim>

---++ Toolbar
Expand Down
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1398678623" format="1.1" reprev="21" version="21"}%
%META:TOPICINFO{author="micha" comment="reprev" date="1402085106" format="1.1" reprev="22" version="22"}%
%META:TOPICPARENT{name="TopicFunction"}%
%TOC{depth="2"}%

Expand Down
40 changes: 40 additions & 0 deletions data/Applications/ClassificationApp/RenderUncategorizedTopics.txt
@@ -0,0 +1,40 @@
%META:TOPICINFO{author="micha" comment="reprev" date="1401709324" format="1.1" reprev="2" version="2"}%
%META:TOPICPARENT{name="TopicFunction"}%
%TOC{depth="2"}%

---++ Documentation
%STARTSECTION{"documentation"}%
%RED%TODO%ENDCOLOR%

---+++++ Parameters
* EXCLUDE: regular expression of topics to be excluded, defaults to =UncategorizedTopics|WebTopicEditTemplate=

%ENDSECTION{"documentation"}%

---++ Implementation
<verbatim class="tml">
%STARTINCLUDE%%DBQUERY{
"TopicType=~'\b(Classified|Categorized)Topic\b' AND TopicType !~ '\bCategory\b' AND ('TopCategory' DISTANCE topic) = 1"
exclude="%EXCLUDE{default="UncategorizedTopics|WebTopicEditTemplat"}%"
web="%BASEWEB%"
format=" 1 [[$web.$topic]]"
}%%STOPINCLUDE%
</verbatim>

---++ Test
%DBCALL{"%TOPIC%"}%

%DBCALL{"Applications.RenderFunctionCallers"}%

---++ Copyright
&copy; 2014 Michael Daum http://michaeldaumconsulting.com

%DBCALL{"Applications.GnuGeneralPublicLicense" section="notice"}%

%META:FORM{name="Applications.ApplicationTopic"}%
%META:FIELD{name="TopicType" title="TopicType" value="DocuTopic, TopicFunction"}%
%META:FIELD{name="TopicTitle" attributes="" title="<nop>TopicTitle" value=""}%
%META:FIELD{name="Summary" attributes="c" title="Summary" value="list all topics not categorized yet"}%
%META:FIELD{name="WikiApplication" attributes="" title="WikiApplication" value="ClassificationApp"}%
%META:TOPICMOVED{by="micha" date="1401703596" from="Applications/ClassificationApp.RenderUncategorizedTopicsuncat" to="Applications/ClassificationApp.RenderUncategorizedTopics"}%
%META:PREFERENCE{name="EDIT_TEMPLATE" title="EDIT_TEMPLATE" type="Set" value="Applications.WikiTopicEdit"}%
4 changes: 2 additions & 2 deletions data/Applications/ClassificationApp/TestSeoTopic.txt
@@ -1,6 +1,6 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1367829599" format="1.1" reprev="1" version="1"}%
%META:TOPICINFO{author="micha" comment="reprev" date="1401709261" format="1.1" reprev="2" version="2"}%
%META:TOPICPARENT{name="WebHome"}%
* <nop>MetaDescription: %DBQUERY{topic="%TOPIC%" format="$formfield(MetaDescription)"}%


%META:FORM{name="Applications/ClassificationApp.SeoTopic"}%
%META:FIELD{name="TopicType" title="TopicType" value="SeoTopic, ClassifiedTopic, CategorizedTopic, TaggedTopic, WikiTopic"}%
Expand Down
1 change: 1 addition & 0 deletions data/System/ClassificationPlugin.txt
Expand Up @@ -353,6 +353,7 @@ Note however that for now only the =%DBQUERY= language is supported (see [[Foswi
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 10 Jun 2014: | added options to disable some parts of a category view template; added tool to list uncategorized topics; fully specify all security switches for rest handlers |
| 22 May 2014: | fixes to Category factory; initial work on a category-based virtual filesystem for webdav |
| 23 Apr 2014: | improved topic info layout; added <nop>WebTagList; added back Clear button to category editor |
| 04 Apr 2014: | fixed compatibility with foswiki >= 1.2.0; flag rest handlers that don't require authentication |
Expand Down
13 changes: 13 additions & 0 deletions data/_ClassificationTemplate/UncategorizedTopics.txt
@@ -0,0 +1,13 @@
%META:TOPICINFO{author="micha" comment="reprev" date="1401709430" format="1.1" reprev="1" version="1"}%
%META:TOPICPARENT{name="WebHome"}%
%DBCALL{
"Applications.ClassificationApp.RenderUncategorizedTopics"
EXCLUDE="UncategorizedTopics|WebTopicEditTemplate"
}%

%META:FORM{name="Applications.ClassificationApp.ClassifiedTopic"}%
%META:FIELD{name="TopicType" title="TopicType" value="ClassifiedTopic, CategorizedTopic, TaggedTopic, WikiTopic"}%
%META:FIELD{name="TopicTitle" attributes="" title="<nop>TopicTitle" value="Uncategorized Topics"}%
%META:FIELD{name="Summary" attributes="" title="Summary" value=""}%
%META:FIELD{name="Tag" attributes="" title="Tag" value=""}%
%META:FIELD{name="Category" attributes="" title="Category" value=""}%
38 changes: 29 additions & 9 deletions lib/Foswiki/Plugins/ClassificationPlugin.pm
Expand Up @@ -17,8 +17,8 @@ use strict;
use warnings;
use Foswiki::Contrib::DBCacheContrib::Search ();

our $VERSION = '3.22';
our $RELEASE = '3.22';
our $VERSION = '3.30';
our $RELEASE = '3.30';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'A topic classification plugin and application';

Expand Down Expand Up @@ -76,27 +76,47 @@ sub initPlugin {
$jsTreeConnector = Foswiki::Plugins::ClassificationPlugin::JSTreeConnector->new();
}
$jsTreeConnector->dispatchAction(@_);
}, authenticate => 0);
},
authenticate => 0,
validate => 0,
http_allow => 'GET,POST',
);

Foswiki::Func::registerRESTHandler('splitfacet', sub {
initServices();
return Foswiki::Plugins::ClassificationPlugin::Services::splitFacet(@_);
}, authenticate => 0);
},
authenticate => 1,
validate => 0,
http_allow => 'GET,POST',
);

Foswiki::Func::registerRESTHandler('renametag', sub {
initServices();
return Foswiki::Plugins::ClassificationPlugin::Services::renameTag(@_);
}, authenticate => 0);
initServices();
return Foswiki::Plugins::ClassificationPlugin::Services::renameTag(@_);
},
authenticate => 1,
validate => 0,
http_allow => 'POST',
);

Foswiki::Func::registerRESTHandler('normalizetags', sub {
initServices();
return Foswiki::Plugins::ClassificationPlugin::Services::normalizeTags(@_);
}, authenticate => 0);
},
authenticate => 1,
validate => 0,
http_allow => 'POST',
);

Foswiki::Func::registerRESTHandler('deployTopicType', sub {
initServices();
return Foswiki::Plugins::ClassificationPlugin::Services::deployTopicType(@_);
}, authenticate => 0);
},
authenticate => 1,
validate => 0,
http_allow => 'POST',
);

Foswiki::Contrib::DBCacheContrib::Search::addOperator(
name=>'SUBSUMES',
Expand Down
3 changes: 1 addition & 2 deletions lib/Foswiki/Plugins/ClassificationPlugin/Category.pm
Expand Up @@ -100,7 +100,7 @@ sub init {
if ($parent) {
$this->{parents}{$name} = $parent;
} else {
print STDERR "parent $name of $this->{name} NOT found in $this->{hierarchy}->{web}\n";
writeDebug("parent $name of $this->{name} NOT found in $this->{hierarchy}->{web}");
delete $this->{parents}{$name};
}
}
Expand Down Expand Up @@ -183,7 +183,6 @@ sub computeDistance {
my $thisId = $this->{id};
return if $ancestors->{$thisId};


# become an ancestor
$ancestors->{$thisId} = $this;
$$distance[$thisId][$thisId] = 0;
Expand Down
3 changes: 2 additions & 1 deletion lib/Foswiki/Plugins/ClassificationPlugin/Core.pm
Expand Up @@ -112,6 +112,7 @@ sub OP_distance {
my $web = $Foswiki::Plugins::DBCachePlugin::Core::dbQueryCurrentWeb || $baseWeb;
my $hierarchy = getHierarchy($web);
my $dist = $hierarchy->distance($lval, $rval);

return $dist || 0;
}

Expand Down Expand Up @@ -344,7 +345,7 @@ sub handleCATINFO {
my $parentSubsumesCat = $hierarchy->getCategory($theParentSubsumes);

foreach my $catName (sort @$categories) {
next if $catName =~ /BottomCategory|TopCategory/;
next if $theCat && $theCat ne 'TopCategory' && $catName =~ /BottomCategory|TopCategory/;
my $category = $hierarchy->getCategory($catName);
next unless $category;

Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/ClassificationPlugin/Hierarchy.pm
Expand Up @@ -425,7 +425,7 @@ sub distance {
return undef unless $cats; # no categories, no distance
foreach my $name (@$cats) {
$catObj = $this->getCategory($name);
$catSet2{$name} = $catObj->{id} if $catObj
$catSet2{$name} = $catObj->{id} if $catObj;
}
}
return 0 if
Expand All @@ -451,7 +451,7 @@ sub distance {
}

# both sets aren't connected
return undef unless defined($min);
return undef if !defined($min) && $topic1 ne 'TopCategory' && $topic2 ne 'TopCategory';

$min = abs($min) + 2 if $firstIsTopic && $secondIsTopic;
$min-- if $firstIsTopic;
Expand Down
Expand Up @@ -296,7 +296,7 @@ sub handle_move_node {
$a->{order} <=> $b->{order} || $a->{title} cmp $b->{title};
} grep {$_->{name} !~ /^BottomCategory$/} values %{$newParent->{children}};

print STDERR "sortedCats=".join(", ", map {$_->{name}} @sortedCats)."\n";
#print STDERR "sortedCats=".join(", ", map {$_->{name}} @sortedCats)."\n";

my $index = 10;
foreach my $item (@sortedCats) {
Expand Down

0 comments on commit 4db3147

Please sign in to comment.