updates for page management security, labels

This commit is contained in:
hudajkhan 2013-10-02 14:58:01 -04:00
parent 8d520895ac
commit 3e5c770506
10 changed files with 60 additions and 17 deletions

View file

@ -14,7 +14,7 @@ display:pageListPage
display:urlMapping "/pageList" ; display:urlMapping "/pageList" ;
display:requiresBodyTemplate "pageList.ftl" ; display:requiresBodyTemplate "pageList.ftl" ;
display:hasDataGetter display:pageListData; display:hasDataGetter display:pageListData;
display:requiredAction <java:edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission#ManageMenus> ; display:requiresAction <java:edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission#ManageMenus> ;
display:cannotDeletePage "true" . display:cannotDeletePage "true" .
display:pageListData display:pageListData

View file

@ -54,7 +54,8 @@
<owl:Class rdf:about="&display;IndividualsForClassesPage"/> <owl:Class rdf:about="&display;IndividualsForClassesPage"/>
<owl:Class rdf:about="&display;InternalClassesPage"/> <owl:Class rdf:about="&display;InternalClassesPage"/>
<!-- For permissions -->
<owl:Class rdf:about="&display;RequiredAction"/>
<!-- Annotation Properties --> <!-- Annotation Properties -->
<owl:AnnotationProperty rdf:about="&rdfs;comment"/> <owl:AnnotationProperty rdf:about="&rdfs;comment"/>
<owl:AnnotationProperty rdf:about="&rdfs;label"/> <owl:AnnotationProperty rdf:about="&rdfs;label"/>
@ -127,7 +128,9 @@
<owl:ObjectProperty rdf:about="&display;restrictResultsByClass"/> <owl:ObjectProperty rdf:about="&display;restrictResultsByClass"/>
<owl:ObjectProperty rdf:about="&display;getIndividualsForClass"/> <owl:ObjectProperty rdf:about="&display;getIndividualsForClass"/>
<owl:ObjectProperty rdf:about="&display;hasDataGetter"/> <owl:ObjectProperty rdf:about="&display;hasDataGetter"/>
<owl:ObjectProperty rdf:about="&display;requiresAction">
</owl:ObjectProperty>
<!--Custom properties--> <!--Custom properties-->

View file

@ -111,6 +111,7 @@ class IndividualResponseBuilder {
*/ */
// body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE)); // body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE));
body.put("labelCount", getLabelCount(itm.getUri(), vreq)); body.put("labelCount", getLabelCount(itm.getUri(), vreq));
body.put("languageCount", getLanguagesRepresentedCount(itm.getUri(), vreq));
//We also need to know the number of available locales //We also need to know the number of available locales
body.put("localesCount", SelectedLocale.getSelectableLocales(vreq).size()); body.put("localesCount", SelectedLocale.getSelectableLocales(vreq).size());
body.put("profileType", getProfileType(itm.getUri(), vreq)); body.put("profileType", getProfileType(itm.getUri(), vreq));
@ -279,6 +280,13 @@ class IndividualResponseBuilder {
+ " FILTER isLiteral(?label) \n" + " FILTER isLiteral(?label) \n"
+ "}" ; + "}" ;
private static String DISTINCT_LANGUAGE_QUERY = ""
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "SELECT ( str(COUNT(DISTINCT lang(?label))) AS ?languageCount ) WHERE { \n"
+ " ?subject rdfs:label ?label \n"
+ " FILTER isLiteral(?label) \n"
+ "}" ;
private static Integer getLabelCount(String subjectUri, VitroRequest vreq) { private static Integer getLabelCount(String subjectUri, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(LABEL_COUNT_QUERY, "subject", subjectUri); String queryStr = QueryUtils.subUriForQueryVar(LABEL_COUNT_QUERY, "subject", subjectUri);
log.debug("queryStr = " + queryStr); log.debug("queryStr = " + queryStr);
@ -297,6 +305,25 @@ class IndividualResponseBuilder {
} }
return theCount; return theCount;
} }
//what is the number of languages represented across the labels
private static Integer getLanguagesRepresentedCount(String subjectUri, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(DISTINCT_LANGUAGE_QUERY, "subject", subjectUri);
log.debug("queryStr = " + queryStr);
int theCount = 0;
try {
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
if (results.hasNext()) {
QuerySolution soln = results.nextSolution();
String countStr = soln.get("languageCount").toString();
theCount = Integer.parseInt(countStr);
}
} catch (Exception e) {
log.error(e, e);
}
return theCount;
}
private static String PROFILE_TYPE_QUERY = "" private static String PROFILE_TYPE_QUERY = ""
+ "PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> \n" + "PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> \n"

View file

@ -48,7 +48,7 @@ public class DisplayVocabulary {
public static final String ITEM_TO_PAGE = NS + "toPage"; public static final String ITEM_TO_PAGE = NS + "toPage";
public static final String HAS_ELEMENT = NS + "hasElement"; public static final String HAS_ELEMENT = NS + "hasElement";
public static final String USES_DATAGETTER_CLASS = NS + "usesDataGetterClass"; public static final String USES_DATAGETTER_CLASS = NS + "usesDataGetterClass";
public static final String REQUIRED_ACTIONS = NS + "requiredAction"; public static final String REQUIRES_ACTIONS = NS + "requiresAction";
/**Data Getter object properties **/ /**Data Getter object properties **/
public static final String HAS_DATA_GETTER = NS + "hasDataGetter"; public static final String HAS_DATA_GETTER = NS + "hasDataGetter";

View file

@ -83,7 +83,7 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
static final protected String requiredActionsQuery = static final protected String requiredActionsQuery =
prefixes + "\n" + prefixes + "\n" +
"SELECT ?requiredAction WHERE{\n" + "SELECT ?requiredAction WHERE{\n" +
" ?pageUri <" + DisplayVocabulary.REQUIRED_ACTIONS + "> ?requiredAction .\n"+ " ?pageUri <" + DisplayVocabulary.REQUIRES_ACTIONS + "> ?requiredAction .\n"+
"}"; "}";
//Get data getter URIs //Get data getter URIs

View file

@ -1,10 +1,16 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#--Number of labels present-->
<#if !labelCount??> <#if !labelCount??>
<#assign labelCount = 0 > <#assign labelCount = 0 >
</#if> </#if>
<#--Number of available locales-->
<#if !localesCount??> <#if !localesCount??>
<#assign localesCount = 1> <#assign localesCount = 1>
</#if> </#if>
<#--Number of distinct languages represented, with no language tag counting as a language, across labels-->
<#if !languageCount??>
<#assign languageCount = 1>
</#if>
<#-- Default individual profile page template --> <#-- Default individual profile page template -->
<#--@dumpAll /--> <#--@dumpAll /-->
@ -35,7 +41,7 @@
<#else> <#else>
<h1 class="fn"> <h1 class="fn">
<#-- Label --> <#-- Label -->
<@p.label individual editable labelCount localesCount/> <@p.label individual editable labelCount localesCount languageCount/>
<#-- Most-specific types --> <#-- Most-specific types -->
<@p.mostSpecificTypes individual /> <@p.mostSpecificTypes individual />

View file

@ -14,7 +14,11 @@
<#assign label = labelLiteral /> <#assign label = labelLiteral />
<#assign labelLang = labelObject.languageName /> <#assign labelLang = labelObject.languageName />
<#assign languageCode = labelObject.languageCode /> <#assign languageCode = labelObject.languageCode />
<#assign labelEditLink = labelObject.editLinkURL /> <#assign labelEditLink = ""/>
<#if labelObject.editLinkURL?has_content>
<#assign labelEditLink = labelObject.editLinkURL/>
</#if>
<#if label?? && ( label?index_of("@") > -1 ) > <#if label?? && ( label?index_of("@") > -1 ) >
<#assign labelStr = label?substring(0, label?index_of("@")) > <#assign labelStr = label?substring(0, label?index_of("@")) >
<#assign tagOrTypeStr = label?substring(label?index_of("@")) > <#assign tagOrTypeStr = label?substring(label?index_of("@")) >
@ -52,7 +56,10 @@
<#assign label = labelLiteral /> <#assign label = labelLiteral />
<#assign labelLang = labelObject.languageName /> <#assign labelLang = labelObject.languageName />
<#assign languageCode = labelObject.languageCode /> <#assign languageCode = labelObject.languageCode />
<#assign labelEditLink = labelObject.editLinkURL /> <#assign labelEditLink = ""/>
<#if labelObject.editLinkURL?has_content>
<#assign labelEditLink = labelObject.editLinkURL/>
</#if>
<#if label?? && ( label?index_of("@") > -1 ) > <#if label?? && ( label?index_of("@") > -1 ) >
<#assign labelStr = label?substring(0, label?index_of("@")) > <#assign labelStr = label?substring(0, label?index_of("@")) >
<#assign tagOrTypeStr = label?substring(label?index_of("@")) > <#assign tagOrTypeStr = label?substring(label?index_of("@")) >
@ -75,7 +82,7 @@
<#macro displayLabel labelSeq labelStr languageCode labelEditLink tagOrTypeStr editGenerator editable displayRemoveLink> <#macro displayLabel labelSeq labelStr languageCode labelEditLink tagOrTypeStr editGenerator editable displayRemoveLink>
<li>${labelStr} <#if labelSeq?seq_contains(labelStr)> (duplicate value) </#if> <li>${labelStr} <#if labelSeq?seq_contains(labelStr)> (duplicate value) </#if>
<#if editable> <#if labelEditLink?has_content> <a href="${labelEditLink}&${editGenerator}">Edit</a></#if> <#if editable> <#if labelEditLink?has_content> <a href="${labelEditLink}&${editGenerator}">Edit</a></#if>
<#if displayRemoveLink = true> <#if displayRemoveLink>
<a href="${urls.base}/edit/primitiveRdfEdit" languageName="${labelLang}" languageCode="${languageCode}" <a href="${urls.base}/edit/primitiveRdfEdit" languageName="${labelLang}" languageCode="${languageCode}"
labelValue="${labelStr}" tagOrType="${tagOrTypeStr!}" class="remove" title="${i18n().remove_capitalized}">${i18n().remove_capitalized}</a> labelValue="${labelStr}" tagOrType="${tagOrTypeStr!}" class="remove" title="${i18n().remove_capitalized}">${i18n().remove_capitalized}</a>
</#if> </#if>

View file

@ -8,11 +8,11 @@
<#assign labelStr = "" > <#assign labelStr = "" >
<#assign languageTag = "" > <#assign languageTag = "" >
<#assign labelSeq = [] > <#assign labelSeq = [] >
<#assign editable = "false"/> <#assign editable = false/>
<#assign displayRemoveLink = "false"/> <#assign displayRemoveLink = false/>
<#if subjectName?? > <#if subjectName?? >
<h2>${i18n().view_labels_for} ${editConfiguration.pageData.subjectName}</h2> <h2>${i18n().view_labels_for} ${subjectName}</h2>
<#else> <#else>
<h2>${i18n().view_labels_capitalized}</h2> <h2>${i18n().view_labels_capitalized}</h2>
</#if> </#if>
@ -21,9 +21,9 @@
<section id="rdfsLabels" role="container"> <section id="rdfsLabels" role="container">
<ul id="existingLabelsList" name="existingLabelsList"> <ul id="existingLabelsList" name="existingLabelsList">
<#if editConfiguration.pageData.labelsSortedByLanguageName?has_content> <#if labelsSortedByLanguageName?has_content>
<#--List of labelInformation objects as value where key = language name --> <#--List of labelInformation objects as value where key = language name -->
<#assign labelsSorted = editConfiguration.pageData.labelsSortedByLanguageName /> <#assign labelsSorted = labelsSortedByLanguageName />
<#--Keys would be the actual names of languages--> <#--Keys would be the actual names of languages-->
<#assign labelLanguages = labelsSorted?keys?sort /> <#assign labelLanguages = labelsSorted?keys?sort />

View file

@ -238,7 +238,7 @@ name will be used as the label. -->
</#macro> </#macro>
<#-- Label --> <#-- Label -->
<#macro label individual editable labelCount localesCount=1> <#macro label individual editable labelCount localesCount=1 languageCount=1>
<#assign labelPropertyUri = ("http://www.w3.org/2000/01/rdf-schema#label"?url) /> <#assign labelPropertyUri = ("http://www.w3.org/2000/01/rdf-schema#label"?url) />
<#assign useEditLink = false /> <#assign useEditLink = false />
<#--edit link used if in edit mode and only one label and one language--> <#--edit link used if in edit mode and only one label and one language-->
@ -249,8 +249,8 @@ name will be used as the label. -->
${label.value} ${label.value}
<#if useEditLink> <#if useEditLink>
<@editingLinks "label" "" label editable /> <@editingLinks "label" "" label editable />
<#elseif editable || (labelCount > 1)> <#elseif editable || (languageCount > 1)>
<#--We display the link even when the user is not logged in case of multiple labels--> <#--We display the link even when the user is not logged in case of multiple labels with different languages-->
<#assign labelLink = ""/> <#assign labelLink = ""/>
<#-- Manage labels now goes to generator --> <#-- Manage labels now goes to generator -->
<#assign individualUri = individual.uri!""/> <#assign individualUri = individual.uri!""/>