Author: christian.bauer(a)jboss.com
Date: 2009-12-09 04:40:45 -0500 (Wed, 09 Dec 2009)
New Revision: 11801
Modified:
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java
branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml
Log:
JBSEAM-4501, wiki registration protection
Modified:
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java
===================================================================
---
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java 2009-12-09
08:55:44 UTC (rev 11800)
+++
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/action/UserHome.java 2009-12-09
09:40:45 UTC (rev 11801)
@@ -72,6 +72,7 @@
private List<Role> roles;
private org.jboss.seam.wiki.core.model.Role defaultRole;
private Uploader uploader;
+ private Long createdWikiNodeCount;
private String requestedUsername;
private WikiTextEditor bioTextEditor;
private WikiTextEditor signatureTextEditor;
@@ -109,6 +110,8 @@
if (roles == null) roles = getInstance().getRoles();
if (oldUsername == null) oldUsername = getInstance().getUsername();
+ createdWikiNodeCount = userDAO.countNodesCreatedBy(getInstance().getId());
+
uploader = (Uploader)Component.getInstance(Uploader.class);
} else {
@@ -216,6 +219,7 @@
"Activiate account:
/confirmRegistration.seam?activationCode=" + getInstance().getActivationCode());
*/
+
org.jboss.seam.core.Events.instance().raiseEvent("User.registered",
getInstance());
org.jboss.seam.core.Events.instance().raiseEvent("User.persisted",
getInstance());
}
return outcome;
@@ -226,12 +230,13 @@
@Restrict("#{s:hasPermission('User', 'edit',
userHome.instance)}")
public String update() {
- if (!validateWikiTextEditors()) {
- return null;
+ if (isManaged() && getCreatedWikiNodeCount() != null &&
getCreatedWikiNodeCount() > 0) {
+ if (!validateWikiTextEditors()) {
+ return null;
+ }
+ syncWikiTextEditorsToInstance();
}
- syncWikiTextEditorsToInstance();
-
if (uploader.hasData()) {
uploader.uploadNewInstance();
if (WikiUploadImage.class.isAssignableFrom(uploader.getUpload().getClass()))
{
@@ -508,6 +513,10 @@
return userDAO.findRatingPoints(getInstance().getId());
}
+ public Long getCreatedWikiNodeCount() {
+ return createdWikiNodeCount;
+ }
+
public WikiTextEditor getBioTextEditor() {
return bioTextEditor;
}
Modified:
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java
===================================================================
---
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java 2009-12-09
08:55:44 UTC (rev 11800)
+++
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java 2009-12-09
09:40:45 UTC (rev 11801)
@@ -100,6 +100,12 @@
return ratingPoints != null ? (Long)ratingPoints : 0;
}
+ public Long countNodesCreatedBy(Long userId) {
+ return (Long)entityManager.createQuery("select count(n) from WikiNode n
where n.createdBy.id = :userId")
+ .setParameter("userId", userId)
+ .getSingleResult();
+ }
+
public void resetNodeCreatorToAdmin(User user) {
User adminUser = (User) Component.getInstance("adminUser");
@@ -149,7 +155,7 @@
if (orderByProperty != null)
crit.addOrder( orderDescending ? Order.desc(orderByProperty) :
Order.asc(orderByProperty) );
- return crit.setResultTransformer(new DistinctRootEntityResultTransformer());
+ return crit.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
}
}
Modified: branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml
===================================================================
--- branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml 2009-12-09 08:55:44
UTC (rev 11800)
+++ branches/community/Seam_2_2/examples/wiki/view/userHome_d.xhtml 2009-12-09 09:40:45
UTC (rev 11801)
@@ -215,29 +215,31 @@
</s:span>
</s:div>
- <s:div styleClass="entry">
- <div class="label"><h:outputText
value="#{messages['lacewiki.label.userHome.Bio']}:"/></div>
- <div class="output"> </div>
- </s:div>
- <ui:include
src="includes/wikitext/editor/editor.xhtml">
- <ui:param name="textEditor"
value="#{userHome.bioTextEditor}"/>
- <ui:param name="namingContainer"
value="userHomeForm"/>
- <ui:param name="tabId"
value="userProfileTab"/>
- </ui:include>
- <ui:include
src="includes/wikitext/editor/preview.xhtml">
- <ui:param name="textEditor"
value="#{userHome.bioTextEditor}"/>
- <ui:param name="baseDocument"
value="#{wikiStart}"/>
- <ui:param name="baseDirectory"
value="#{wikiStart.parent}"/>
- </ui:include>
+ <s:fragment rendered="#{userHome.createdWikiNodeCount >
0}">
+ <s:div styleClass="entry">
+ <div class="label"><h:outputText
value="#{messages['lacewiki.label.userHome.Bio']}:"/></div>
+ <div class="output"> </div>
+ </s:div>
+ <ui:include
src="includes/wikitext/editor/editor.xhtml">
+ <ui:param name="textEditor"
value="#{userHome.bioTextEditor}"/>
+ <ui:param name="namingContainer"
value="userHomeForm"/>
+ <ui:param name="tabId"
value="userProfileTab"/>
+ </ui:include>
+ <ui:include
src="includes/wikitext/editor/preview.xhtml">
+ <ui:param name="textEditor"
value="#{userHome.bioTextEditor}"/>
+ <ui:param name="baseDocument"
value="#{wikiStart}"/>
+ <ui:param name="baseDirectory"
value="#{wikiStart.parent}"/>
+ </ui:include>
- <s:decorate id="websiteDecorate"
template="includes/formFieldDecorate.xhtml">
- <ui:param name="tabId"
value="userProfileTab"/>
- <ui:param name="fieldId"
value="website"/>
- <ui:define
name="label">#{messages['lacewiki.label.userHome.Website']}</ui:define>
- <h:inputText styleClass="ajaxSupport"
tabindex="1" size="55" maxlength="1000"
value="#{userHome.instance.profile.website}">
- <a:support status="globalStatus"
event="onchange" reRender="websiteDecorate"
oncomplete="onAjaxRequestComplete()"/>
- </h:inputText>
- </s:decorate>
+ <s:decorate id="websiteDecorate"
template="includes/formFieldDecorate.xhtml">
+ <ui:param name="tabId"
value="userProfileTab"/>
+ <ui:param name="fieldId"
value="website"/>
+ <ui:define
name="label">#{messages['lacewiki.label.userHome.Website']}</ui:define>
+ <h:inputText styleClass="ajaxSupport"
tabindex="1" size="55" maxlength="1000"
value="#{userHome.instance.profile.website}">
+ <a:support status="globalStatus"
event="onchange" reRender="websiteDecorate"
oncomplete="onAjaxRequestComplete()"/>
+ </h:inputText>
+ </s:decorate>
+ </s:fragment>
<s:decorate id="locationDecorate"
template="includes/formFieldDecorate.xhtml">
<ui:param name="tabId"
value="userProfileTab"/>
@@ -257,20 +259,22 @@
</h:inputText>
</s:decorate>
- <s:div styleClass="entry">
- <div class="label"><h:outputText
value="#{messages['lacewiki.label.userHome.Signature']}:"/></div>
- <div class="output"> </div>
- </s:div>
- <ui:include
src="includes/wikitext/editor/editor.xhtml">
- <ui:param name="textEditor"
value="#{userHome.signatureTextEditor}"/>
- <ui:param name="namingContainer"
value="userHomeForm"/>
- <ui:param name="tabId"
value="userProfileTab"/>
- </ui:include>
- <ui:include
src="includes/wikitext/editor/preview.xhtml">
- <ui:param name="textEditor"
value="#{userHome.signatureTextEditor}"/>
- <ui:param name="baseDocument"
value="#{wikiStart}"/>
- <ui:param name="baseDirectory"
value="#{wikiStart.parent}"/>
- </ui:include>
+ <s:fragment rendered="#{userHome.createdWikiNodeCount >
0}">
+ <s:div styleClass="entry">
+ <div class="label"><h:outputText
value="#{messages['lacewiki.label.userHome.Signature']}:"/></div>
+ <div class="output"> </div>
+ </s:div>
+ <ui:include
src="includes/wikitext/editor/editor.xhtml">
+ <ui:param name="textEditor"
value="#{userHome.signatureTextEditor}"/>
+ <ui:param name="namingContainer"
value="userHomeForm"/>
+ <ui:param name="tabId"
value="userProfileTab"/>
+ </ui:include>
+ <ui:include
src="includes/wikitext/editor/preview.xhtml">
+ <ui:param name="textEditor"
value="#{userHome.signatureTextEditor}"/>
+ <ui:param name="baseDocument"
value="#{wikiStart}"/>
+ <ui:param name="baseDirectory"
value="#{wikiStart.parent}"/>
+ </ui:include>
+ </s:fragment>
</s:validateAll>
</div>