Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
March 2012
- 3 participants
- 68 discussions
r3211 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources/config webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 27 Mar '12
by fdesbois@users.chorem.org 27 Mar '12
27 Mar '12
Author: fdesbois
Date: 2012-03-27 13:28:43 +0200 (Tue, 27 Mar 2012)
New Revision: 3211
Url: http://chorem.org/repositories/revision/pollen/3211
Log:
- use PollUri object in AbstractPollUriIdAction
- rename and implement EditVote action
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java
Removed:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollUriIdAction.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -23,48 +23,39 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.ui.actions.PollenActionSupport;
/**
* Abstract action for all actions with a poll uri id.
*
* @author tchemit <chemit(a)codelutin.com>
+ * @author fdesbois <fdesbois(a)codelutin.com>
* @since 1.2.6
*/
public abstract class AbstractPollUriIdAction extends PollenActionSupport {
private static final long serialVersionUID = 1L;
+
+ private PollUri pollUri;
- /** Poll id (not topiaId but uuid, perharps we should use directly topiaId transformed to something smaller ?). */
- protected String pollId;
-
- /** Account id (not topiaId but uuid, perharps we should use directly topiaId transformed to something smaller ?). */
- protected String accountId;
-
public final String getUriId() {
- String result = pollId;
- if (StringUtils.isNotEmpty(accountId)) {
- result += ":" + accountId;
- }
- return result;
+ return pollUri != null ? pollUri.getUri() : null;
}
public final void setUriId(String uriId) {
- String[] split = uriId.split(":", 2);
- if (split.length > 0) {
- pollId = split[0];
- if (split.length > 1) {
- accountId = split[1];
- }
- }
+ pollUri = PollUri.newPollUri(uriId);
}
+ public void prepareUriId(String pollId, String accountId) {
+ pollUri = PollUri.newPollUri(pollId, accountId);
+ }
+
public final String getPollId() {
- return pollId;
+ return pollUri != null ? pollUri.getPollId() : null;
}
public final String getAccountId() {
- return accountId;
+ return pollUri != null ? pollUri.getAccountId() : null;
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -34,7 +34,6 @@
import org.chorem.pollen.business.persistence.Comment;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.Vote;
import org.chorem.pollen.business.persistence.VoteToChoice;
import org.chorem.pollen.common.ChoiceType;
@@ -56,6 +55,7 @@
* Abstract action for actions on the vote poll page.
*
* @author tchemit <chemit(a)codelutin.com>
+ * @author fdesbois <fdesbois(a)codelutin.com>
* @since 1.2.6
*/
public abstract class AbstractVoteAction extends AbstractPollUriIdAction implements ParameterAware {
@@ -152,12 +152,6 @@
return vote;
}
- public boolean getVoteValueAsBoolean(int index) {
- VoteToChoice voteToChoice = getVote().getChoiceVoteToChoice().get(index);
- Integer value = voteToChoice.getVoteValue();
- return value == 1;
- }
-
public boolean isPollChoiceOrVoteStarted() {
Date now = serviceContext.getCurrentTime();
return poll.isAddChoiceStarted(now) || poll.isStarted(now);
@@ -287,8 +281,16 @@
DateFormat.SHORT,
DateFormat.SHORT, getLocale()));
- loadPollAccount();
- loadVotes();
+ // Current poll account
+ pollAccount = getPollService().getPollAccount(getAccountId(), getPollenUserAccount());
+
+ // All votes
+ // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount
+ votes = poll.getVote();
+
+ // Current vote
+ vote = getVoteService().getVote(poll, votes, pollAccount);
+
loadPollResults();
loadPollComments();
@@ -365,31 +367,7 @@
}
public boolean isModifAllowed(String voteId) {
-
- boolean result = false;
-
- Vote vote = poll.getVoteByTopiaId(voteId);
-
- // can only modify a vote if poll is running.
- if (vote != null && isPollRunning()) {
- PollAccount votePollAccount = vote.getPollAccount();
-
- // si le votant du vote correspond au votant actuel (pollAccountId)
- if (accountId != null
- && accountId.equals(votePollAccount.getAccountId())) {
- result = true;
- }
-
- UserAccount userAccount = getPollenUserAccount();
-
-
- // si l'utilisateur du vote correspond à l'utilisateur actuel (user)
- if (userAccount != null) {
- UserAccount voteUserAccount = votePollAccount.getUserAccount();
- result = voteUserAccount != null && userAccount.getTopiaId().equals(voteUserAccount.getTopiaId());
- }
- }
- return result;
+ return getVoteService().isUpdateAllowed(getPoll(), voteId, getAccountId(), getPollenUserAccount());
}
public String escapeLineBreak(String text) {
@@ -402,6 +380,7 @@
protected void loadPoll() throws PollNotFoundException {
+ String pollId = getPollId();
if (StringUtils.isNotEmpty(pollId)) {
poll = getPollService().getPollByPollId(pollId);
}
@@ -421,76 +400,6 @@
}
}
- protected void loadPollAccount() throws PollNotFoundException {
-
- //// Contrôle et définition du votingId
-// alreadyVoted = false;
-// boolean modifAllowed = false;
-// boolean restrictedListsForbidden = false;
-
- // Suppression des espaces pouvant provoquer un double vote
- // TODO maybe it's better to keep current pollAccount instead of creating one each time
- pollAccount = getPollService().getNewPollAccount(getPollenUserAccount());
-// String votingId = pollAccount.getVotingId().trim();
-// pollAccount.setVotingId(votingId);
-//
-// // The calcul of alreadyVoted will be needed for no double votingId
-// // Carefull, not correct for an anonymous vote
-// alreadyVoted = getVoteService().hasAlreadyVoted(votingId, poll);
-//
-// // Check for restricted poll
-// if (!alreadyVoted && !isFreePoll()) {
-//
-// if (StringUtils.isNotEmpty(getAccountId())) {
-//
-// // The accountUId must be valid for the poll
-// PollAccount restrictedAccount =
-// getPollService().getRestrictedAccount(getPollId(), getAccountId());
-//
-// if (restrictedAccount != null) {
-// // PollAccount is replaced by the good account from db
-// pollAccount = restrictedAccount;
-//
-// // Refresh alreadyVoted value depends on pollAccount
-//// alreadyVoted = pollAccount.isHasVoted();
-//
-// } else {
-// // Existing account is null is forbidden for a restricted poll
-// restrictedListsForbidden = true;
-// }
-//
-// } else {
-// // Not allowed to vote without an accountUId
-// restrictedListsForbidden = true;
-// }
-//
-// if (restrictedListsForbidden) {
-// addActionError(_("pollen.error.user.restrictedListsForbidden"));
-// }
-// }
-//
-// // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
-// if (poll.isAnonymous() && isFreePoll()) {
-// getPollAccount().setVotingId(
-// "anonymous" + serviceContext.createPollenUrlId());
-// }
-//
-// modifAllowed = isModifAllowed(getPollAccount().getVotingId());
-// if (alreadyVoted && !modifAllowed) {
-// addActionError(_("pollen.error.user.alreadyVoted",
-// getPollAccount().getVotingId()));
-// }
- }
-
- protected void loadVotes() {
-
- // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount
- votes = getPoll().getVote();
-
- // Current vote
- vote = getVoteService().getVote(getPoll(), getVotes(), getPollAccount());
- }
-
protected void loadPollComments() {
PollCommentService service = newService(PollCommentService.class);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -50,7 +50,7 @@
PollService service = newService(PollService.class);
- service.closePoll(pollId, getPollenUserAccount(), accountId);
+ service.closePoll(getPollId(), getPollenUserAccount(), getAccountId());
return SUCCESS;
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteChoice.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -53,6 +53,7 @@
@Override
public String execute() throws Exception {
+ String pollId = getPollId();
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(choiceId);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteComment.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -55,6 +55,7 @@
@Override
public String execute() throws Exception {
+ String pollId = getPollId();
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(commentId);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmDeleteVote.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -53,6 +53,7 @@
@Override
public String execute() throws Exception {
+ String pollId = getPollId();
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voteId);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ConfirmPollAction.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -55,6 +55,7 @@
@Override
public String execute() throws Exception {
+ String pollId = getPollId();
Preconditions.checkNotNull(pollId);
poll = newService(PollService.class).getPollByPollId(pollId);
return SUCCESS;
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -45,6 +45,7 @@
@Override
public String execute() throws Exception {
+ String pollId = getPollId();
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(choiceId);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -50,7 +50,7 @@
PollService service = newService(PollService.class);
- service.deletePoll(pollId, getPollenUserAccount(), accountId);
+ service.deletePoll(getPollId(), getPollenUserAccount(), getAccountId());
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -45,7 +45,6 @@
@Override
public String execute() throws Exception {
- Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voteId);
VoteService service = newService(VoteService.class);
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java (from rev 3210, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditVote.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -0,0 +1,57 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+/**
+ * EditVote is a redirection to vote page. This action will simply update the
+ * uri with {@code accountId} and {@code pollId}.
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @since 1.2.6
+ * @see #prepareUriId(String, String)
+ */
+public class EditVote extends AbstractPollUriIdAction {
+
+ private static final long serialVersionUID = 1L;
+
+ private String accountId;
+
+ private String pollId;
+
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ prepareUriId(pollId, accountId);
+
+ return SUCCESS;
+ }
+}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -60,6 +60,7 @@
@Override
public String execute() throws Exception {
+ String pollId = getPollId();
Preconditions.checkNotNull(pollId);
PollResultsService service = newService(PollResultsService.class);
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -1,44 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since TODO
- */
-public class ModifyVote extends AbstractVoteAction {
-
- private static final long serialVersionUID = 1L;
-
-
- @Override
- public String execute() throws Exception {
-
- loadPoll();
-
- return SUCCESS;
- }
-}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -151,6 +151,7 @@
@Override
public String execute() throws Exception {
+ String pollId = getPollId();
Preconditions.checkNotNull(pollId);
PollService service = newService(PollService.class);
@@ -171,6 +172,7 @@
DateFormat.SHORT,
DateFormat.SHORT, getLocale()));
+ String accountId = getAccountId();
if (poll.isPublicResults()) {
userAllowed = true;
} else if (StringUtils.isNotEmpty(accountId)) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-27 11:28:43 UTC (rev 3211)
@@ -26,23 +26,22 @@
import com.opensymphony.xwork2.Preparable;
import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Vote;
-import org.chorem.pollen.business.persistence.VoteToChoice;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Votes to a poll.
*
* @author tchemit <chemit(a)codelutin.com>
+ * @author fdesbois <fdesbois(a)codelutin.com>
* @since 1.2.6
*/
public class VoteForPoll extends AbstractVoteAction implements Preparable {
+
+ private static final Logger log = LoggerFactory.getLogger(VoteForPoll.class);
private static final long serialVersionUID = 1L;
- public void setVoteValueAsBoolean(int index, boolean value) {
- VoteToChoice voteToChoice = getVote().getChoiceVoteToChoice().get(index);
- voteToChoice.setVoteValue(value ? 1 : 0);
- }
-
@Override
public String input() throws Exception {
@@ -52,6 +51,11 @@
@Override
public String execute() throws Exception {
+
+ // VALIDATION ::
+ // - votingId/name not empty
+ // - account not exists (matching userAccount) > check on all votes (EXISTS userAccount FROM poll.votes)
+ // - votingId/name is unique > check on all votes (EXISTS votingId FROM poll.votes)
if (getVote().getTopiaId() != null) {
getVoteService().updateVote(getVote());
@@ -69,6 +73,9 @@
PollUri pollUri = PollUri.newPollUri(pollId, accountId);
String updateUrl = getVoteService().getUpdateVoteUrl(pollUri);
+
+ log.debug("UpdateURL for poll '{}' and account '{}' = {}", new Object[]{pollId, accountId, updateUrl});
+
addActionMessage(_("pollen.information.vote.createdWithUpdateUrl", updateUrl));
} else{
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-27 11:28:43 UTC (rev 3211)
@@ -225,9 +225,9 @@
<result type="redirectToVote"/>
</action>
- <!-- modify poll vote -->
- <action name="modifyVote"
- class="org.chorem.pollen.ui.actions.poll.ModifyVote">
+ <!-- edit poll vote -->
+ <action name="editVote"
+ class="org.chorem.pollen.ui.actions.poll.EditVote">
<result type="redirectToVote"/>
</action>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-27 11:28:36 UTC (rev 3210)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-27 11:28:43 UTC (rev 3211)
@@ -312,8 +312,8 @@
<s:if test="!poll.anonymous">
<s:if test="isModifAllowed(#vote.topiaId)">
<s:a action="editVote" namespace="/poll">
- <s:param name="uriId" value="%{uriId}"/>
- <s:param name="voteId" value="%{#vote.topiaId}"/>
+ <s:param name="pollId" value="%{pollId}"/>
+ <s:param name="accountId" value="%{#vote.pollAccount.accountId}"/>
<img src="<s:url value="/img/editSmall.png"/>"
title="<s:text name="pollen.action.editVote"/>"
alt="<s:text name="pollen.action.editVote"/>"/>
1
0
r3210 - branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl
by fdesbois@users.chorem.org 27 Mar '12
by fdesbois@users.chorem.org 27 Mar '12
27 Mar '12
Author: fdesbois
Date: 2012-03-27 13:28:36 +0200 (Tue, 27 Mar 2012)
New Revision: 3210
Url: http://chorem.org/repositories/revision/pollen/3210
Log:
- Move isUpdateVoteAllowed to VoteService
- Add getPollAccount method in PollService
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-26 17:02:58 UTC (rev 3209)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-27 11:28:36 UTC (rev 3210)
@@ -25,6 +25,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenConfiguration;
@@ -381,24 +382,66 @@
}
}
+ /**
+ * Retrieve a pollAccount with {@code accountId}. This pollAccount will be
+ * attached to the given {@code userAccount} (only if not already attached).
+ * If the {@code accountId} is undefined, a new instance of PollAccount will
+ * be retrieved, otherwise the existing PollAccount is used. No create or
+ * update is done here.
+ *
+ * @param accountId Id of the existing account (optional)
+ * @param userAccount UserAccount where account will be attached (optional)
+ * @return the existing PollAccount or a new instance
+ * @throws PollAccountNotFound if accountId is defined and doesn't match any
+ * existing PollAccount
+ */
+ public PollAccount getPollAccount(String accountId, UserAccount userAccount) throws PollAccountNotFound {
+ PollAccount result;
+ if (StringUtils.isNotEmpty(accountId)) {
+ result = getPollAccountByAccountId(accountId);
+
+ // REMARQUES :
+ // - pas le droit de modif si le pollAccount est rattaché a un userAccount et qu'on est pas loggé ?!?
+ // - Ce serait plus simple que l'Admin ne puisse jamais voter, il ne peut que modérer les votes
+
+ // Don't remove or update userAccount link if already set
+ if (userAccount != null && result.getUserAccount() == null) {
+ result.setUserAccount(userAccount);
+
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Attach User '%s' [%s] to the existing Account [%s]",
+ userAccount.getDisplayName(),
+ userAccount.getTopiaId(),
+ accountId
+ ));
+ }
+ }
+
+ } else {
+ result = getNewPollAccount(userAccount);
+ }
+ return result;
+ }
+
public PollAccount getNewPollAccount(UserAccount userAccount) {
PollAccountDAO dao = getDAO(PollAccount.class);
PollAccount result = newInstance(dao);
result.setAccountId(serviceContext.createPollenUrlId());
- if (userAccount != null) {
- String displayName = userAccount.getDisplayName();
- result.setVotingId(displayName);
- } else {
- result.setVotingId("");
- }
+ String votingId = userAccount != null ? userAccount.getDisplayName() : "";
+ result.setVotingId(votingId);
result.setUserAccount(userAccount);
return result;
}
- public PollAccount getPollAccountByAccountId(String accountId) {
+ public PollAccount getPollAccountByAccountId(String accountId) throws PollAccountNotFound {
try {
PollAccountDAO dao = getDAO(PollAccount.class);
PollAccount result = dao.findByAccountId(accountId);
+
+ if (result == null) {
+ throw new PollAccountNotFound();
+ }
+
return result;
} catch (TopiaException e) {
throw new PollenTechnicalException("Could not botain account with this id", e);
@@ -424,10 +467,6 @@
PollAccount account = getPollAccountByAccountId(accountId);
- if (account == null) {
- throw new PollAccountNotFound();
- }
-
if (!account.getAccountId().equals(poll.getCreator().getAccountId())) {
throw new UnauthorizedPollAccessException();
}
@@ -458,10 +497,6 @@
PollAccount account = getPollAccountByAccountId(accountId);
- if (account == null) {
- throw new PollAccountNotFound();
- }
-
if (!account.getAccountId().equals(poll.getCreator().getAccountId())) {
throw new UnauthorizedPollAccessException();
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-26 17:02:58 UTC (rev 3209)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-27 11:28:36 UTC (rev 3210)
@@ -50,6 +50,7 @@
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
import java.net.URL;
+import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -303,7 +304,34 @@
throw new PollenTechnicalException("Could not obtain votes", e);
}
}
+
+ public boolean isUpdateAllowed(Poll poll, String voteId, String accountId, UserAccount userConnected) {
+
+ Date now = serviceContext.getCurrentTime();
+
+ boolean result = false;
+ Vote vote = poll.getVoteByTopiaId(voteId);
+
+ // can only modify a vote if poll is running.
+ if (vote != null && poll.isRunning(now)) {
+ PollAccount votePollAccount = vote.getPollAccount();
+
+ // si le votant du vote correspond au votant actuel (pollAccountId)
+ if (accountId != null
+ && accountId.equals(votePollAccount.getAccountId())) {
+ result = true;
+ }
+
+ // si l'utilisateur du vote correspond à l'utilisateur actuel (user)
+ if (userConnected != null) {
+ UserAccount voteUserAccount = votePollAccount.getUserAccount();
+ result = userConnected.equals(voteUserAccount);
+ }
+ }
+ return result;
+ }
+
public boolean hasAlreadyVoted(String votingId, Poll poll) {
try {
VoteDAO dao = getDAO(Vote.class);
1
0
r3209 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui java/org/chorem/pollen/ui/actions java/org/chorem/pollen/ui/actions/poll resources resources/i18n webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 26 Mar '12
by fdesbois@users.chorem.org 26 Mar '12
26 Mar '12
Author: fdesbois
Date: 2012-03-26 19:02:58 +0200 (Mon, 26 Mar 2012)
New Revision: 3209
Url: http://chorem.org/repositories/revision/pollen/3209
Log:
- Resolve issue with VoteToChoice save
- Add message support in session (not working yet)
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-26 17:02:58 UTC (rev 3209)
@@ -48,6 +48,10 @@
/** Key to store the {@link PollenSession} instance in the session's map. */
protected static final String SESSION_PARAMETER = "pollenSession";
+ public static final String SESSION_TOKEN_MESSAGES = "messages";
+
+ public static final String SESSION_TOKEN_ERRORS = "errors";
+
public static PollenSession get(ServletRequest servletRequest) {
HttpSession httpSession = ((HttpServletRequest) servletRequest).getSession(true);
PollenSession pollenSession = (PollenSession) httpSession.getAttribute(SESSION_PARAMETER);
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-26 17:02:58 UTC (rev 3209)
@@ -44,6 +44,8 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -229,4 +231,48 @@
String result = getDateTimeFormat().format(date);
return result;
}
+
+ @Override
+ public void addActionMessage(String message) {
+ List<String> messages = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
+ if (messages == null) {
+ messages = Lists.newArrayList(message);
+ getPollenSession().putDynamicData(PollenSession.SESSION_TOKEN_MESSAGES, messages);
+ } else {
+ messages.add(message);
+ }
+ }
+
+ @Override
+ public void addActionError(String message) {
+ List<String> messages = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
+ if (messages == null) {
+ messages = Lists.newArrayList(message);
+ getPollenSession().putDynamicData(PollenSession.SESSION_TOKEN_ERRORS, messages);
+ } else {
+ messages.add(message);
+ }
+ }
+
+ @Override
+ public Collection<String> getActionErrors() {
+ List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
+ if (result != null) {
+ getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_ERRORS);
+ } else {
+ result = Collections.emptyList();
+ }
+ return result;
+ }
+
+ @Override
+ public Collection<String> getActionMessages() {
+ List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
+ if (result != null) {
+ getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_MESSAGES);
+ } else {
+ result = Collections.emptyList();
+ }
+ return result;
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-26 17:02:58 UTC (rev 3209)
@@ -152,12 +152,9 @@
return vote;
}
- public VoteToChoice getVoteToChoice(int index) {
- return getVote().getChoiceVoteToChoice().get(index);
- }
-
public boolean getVoteValueAsBoolean(int index) {
- Integer value = getVoteToChoice(index).getVoteValue();
+ VoteToChoice voteToChoice = getVote().getChoiceVoteToChoice().get(index);
+ Integer value = voteToChoice.getVoteValue();
return value == 1;
}
@@ -488,7 +485,7 @@
protected void loadVotes() {
// TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount
- votes = getPoll().getVote();
+ votes = getPoll().getVote();
// Current vote
vote = getVoteService().getVote(getPoll(), getVotes(), getPollAccount());
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-26 17:02:58 UTC (rev 3209)
@@ -24,7 +24,9 @@
package org.chorem.pollen.ui.actions.poll;
import com.opensymphony.xwork2.Preparable;
+import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Vote;
+import org.chorem.pollen.business.persistence.VoteToChoice;
/**
* Votes to a poll.
@@ -37,7 +39,8 @@
private static final long serialVersionUID = 1L;
public void setVoteValueAsBoolean(int index, boolean value) {
- getVoteToChoice(index).setVoteValue(value ? 1 : 0);
+ VoteToChoice voteToChoice = getVote().getChoiceVoteToChoice().get(index);
+ voteToChoice.setVoteValue(value ? 1 : 0);
}
@Override
@@ -58,6 +61,20 @@
getPollService().addVoteToPoll(getPoll(), voteCreated);
}
+ // Display updateUrl if user is not logged
+ if (!isUserLoggued()) {
+
+ String pollId = getPoll().getPollId();
+ String accountId = getPollAccount().getAccountId();
+ PollUri pollUri = PollUri.newPollUri(pollId, accountId);
+
+ String updateUrl = getVoteService().getUpdateVoteUrl(pollUri);
+ addActionMessage(_("pollen.information.vote.createdWithUpdateUrl", updateUrl));
+
+ } else{
+
+ addActionMessage(_("pollen.information.vote.created"));
+ }
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-26 17:02:58 UTC (rev 3209)
@@ -193,6 +193,8 @@
pollen.information.user.created=User %s created.
pollen.information.user.deleted=User %s deleted.
pollen.information.user.updated=User %s updated.
+pollen.information.vote.created=
+pollen.information.vote.createdWithUpdateUrl=
pollen.information.your.are.loggued=You are logged.
pollen.label.contact.administrator=Send an email to an administrator
pollen.label.pollEditPage=The link below leads to the page to modify your poll. Save it to be able to modify your poll later if you need it or to close it \:
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-26 17:02:58 UTC (rev 3209)
@@ -200,6 +200,8 @@
pollen.information.user.created=L'utilisateur %s a été créé.
pollen.information.user.deleted=L'utilisateur %s a été supprimé.
pollen.information.user.updated=L'utilisateur %s a été mis à jour.
+pollen.information.vote.created=Vote enregistré
+pollen.information.vote.createdWithUpdateUrl=Vote enregistré, vous pourrez le modifier à l'adresse suivante <a href\="%1$s">%1$s</a>
pollen.information.your.are.loggued=Vous êtes connecté.
pollen.label.contact.administrator=Contacter un administrateur
pollen.label.pollEditPage=Le lien ci-dessous mène à la page de modification du sondage. Enregistrez-le pour pouvoir modifier votre sondage au besoin ou le clore \:
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-26 17:02:58 UTC (rev 3209)
@@ -39,7 +39,7 @@
<constant name="struts.action.extension" value=",,"/>
<constant name="struts.locale" value="fr_FR"/>
<constant name="struts.i18n.reload" value="false"/>
- <constant name="struts.configuration.xml.reload" value="false"/>
+ <constant name="struts.configuration.xml.reload" value="true"/>
<constant name="struts.ui.theme" value="css_xhtml"/>
<constant name="struts.multipart.maxSize" value="209715200"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
@@ -71,9 +71,9 @@
<interceptor-stack name="pollenBasicStack">
<interceptor-ref name="i18n"/>
<interceptor-ref name="basicStack"/>
- <interceptor-ref name="store">
+<!-- <interceptor-ref name="store">
<param name="operationMode">STORE</param>
- </interceptor-ref>
+ </interceptor-ref>-->
</interceptor-stack>
<!-- params stack with params-->
@@ -107,9 +107,9 @@
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
- <interceptor-ref name="store">
+<!-- <interceptor-ref name="store">
<param name="operationMode">STORE</param>
- </interceptor-ref>
+ </interceptor-ref>-->
</interceptor-stack>
</interceptors>
@@ -137,9 +137,9 @@
<result>/WEB-INF/jsp/home.jsp</result>
<interceptor-ref name="i18n"/>
<interceptor-ref name="basicStack"/>
- <interceptor-ref name="store">
+<!-- <interceptor-ref name="store">
<param name="operationMode">RETRIEVE</param>
- </interceptor-ref>
+ </interceptor-ref>-->
</action>
<!-- change lang-->
@@ -153,9 +153,9 @@
<interceptor-ref name="paramRemover">
<param name="paramNames">request_locale</param>
</interceptor-ref>
- <interceptor-ref name="store">
+<!-- <interceptor-ref name="store">
<param name="operationMode">STORE</param>
- </interceptor-ref>
+ </interceptor-ref>-->
</action>
</package>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-26 17:02:51 UTC (rev 3208)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-26 17:02:58 UTC (rev 3209)
@@ -270,24 +270,24 @@
<s:if test="!isChoiceHidden(#choice)">
<th>
<s:if test="normalVoteCounting">
- <s:checkbox name="voteValueAsBoolean[%{#status.index}]"
- value="%{voteValueAsBoolean[#status.index]}" theme="simple"/>
+ <s:checkbox name="vote.choiceVoteToChoice[%{#status.index}].voteValue"
+ value="%{vote.choiceVoteToChoice[#status.index].voteValue}" theme="simple"/>
</s:if>
<s:if test="percentageVoteCounting">
- <s:textfield name="voteToChoice[%{#status.index}].voteValue"
- value="%{voteToChoice[#status.index].voteValue}"
+ <s:textfield name="vote.choiceVoteToChoice[%{#status.index}].voteValue"
+ value="%{vote.choiceVoteToChoice[#status.index].voteValue}"
required="true" size="3" theme="simple"/>
<%--t:validate="required, min=0, max=100"/>%--%>
</s:if>
<s:if test="condorcetVoteCounting">
- <s:textfield name="voteToChoice[%{#status.index}].voteValue"
- value="%{voteToChoice[#status.index].voteValue}"
+ <s:textfield name="vote.choiceVoteToChoice[%{#status.index}].voteValue"
+ value="%{vote.choiceVoteToChoice[#status.index].voteValue}"
id="condorcetInput" size="3" theme="simple"/>
<%--t:nulls="zero" t:validate="min=0, max=99"/>--%>
</s:if>
<s:if test="numberVoteCounting">
- <s:textfield name="voteToChoice[%{#status.index}].voteValue"
- value="%{voteToChoice[#status.index].voteValue}"
+ <s:textfield name="vote.choiceVoteToChoice[%{#status.index}].voteValue"
+ value="%{vote.choiceVoteToChoice[#status.index].voteValue}"
size="3" theme="simple"/>
</s:if>
</th>
1
0
r3208 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/bean pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 26 Mar '12
by fdesbois@users.chorem.org 26 Mar '12
26 Mar '12
Author: fdesbois
Date: 2012-03-26 19:02:51 +0200 (Mon, 26 Mar 2012)
New Revision: 3208
Url: http://chorem.org/repositories/revision/pollen/3208
Log:
- Delete vote
- Add method for updateVoteUrl
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java 2012-03-23 21:32:36 UTC (rev 3207)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java 2012-03-26 17:02:51 UTC (rev 3208)
@@ -23,6 +23,7 @@
*/
package org.chorem.pollen.bean;
+import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
/**
@@ -47,10 +48,22 @@
return result;
}
+ public static PollUri newPollUri(String pollId, String accountId) {
+ Preconditions.checkNotNull(pollId);
+
+ PollUri result = new PollUri();
+
+ result.pollId = pollId;
+ result.accountId = accountId;
+ return result;
+ }
+
protected String pollId;
protected String accountId;
+ private PollUri() { }
+
public String getPollId() {
return pollId;
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-23 21:32:36 UTC (rev 3207)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-26 17:02:51 UTC (rev 3208)
@@ -44,7 +44,6 @@
import org.chorem.pollen.business.persistence.PreventRuleDAO;
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.Vote;
-import org.chorem.pollen.business.persistence.VoteDAO;
import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.common.ChoiceType;
@@ -53,7 +52,6 @@
import org.chorem.pollen.services.exceptions.PollAccountNotFound;
import org.chorem.pollen.services.exceptions.PollChoiceNotFoundException;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
-import org.chorem.pollen.services.exceptions.PollVoteNotFoundException;
import org.chorem.pollen.services.exceptions.UnauthorizedPollAccessException;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
@@ -483,26 +481,6 @@
commitTransaction("Could not close poll " + poll.getTitle());
}
- public void deleteVote(String pollId, String voteId)
- throws PollNotFoundException, PollVoteNotFoundException {
-
- Poll poll = getPollByPollId(pollId);
-
- if (poll == null) {
- throw new PollNotFoundException();
- }
- Vote vote = poll.getVoteByTopiaId(voteId);
-
- if (vote == null) {
- throw new PollVoteNotFoundException();
- }
-
- VoteDAO dao = getDAO(Vote.class);
- delete(dao, vote);
-
- commitTransaction("Could not delete vote " + vote);
- }
-
public void deleteChoice(String pollId, String choiceId)
throws PollNotFoundException, PollChoiceNotFoundException {
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-23 21:32:36 UTC (rev 3207)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-26 17:02:51 UTC (rev 3208)
@@ -25,11 +25,13 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenTechnicalException;
+import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
@@ -39,6 +41,7 @@
import org.chorem.pollen.business.persistence.VoteDAO;
import org.chorem.pollen.business.persistence.VoteToChoice;
import org.chorem.pollen.business.persistence.VoteToChoiceDAO;
+import org.chorem.pollen.common.PollType;
import org.chorem.pollen.entities.PollenDAOHelper;
import org.chorem.pollen.services.PollenServiceSupport;
import org.chorem.pollen.services.exceptions.VoteNotFoundException;
@@ -46,6 +49,7 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import java.net.URL;
import java.util.List;
import java.util.Map;
@@ -117,6 +121,20 @@
}
return result;
}
+
+ /**
+ * Retrieve the URL to update a vote based on {@link PollUri}.
+ *
+ * @param pollUri Uri with pollId and accountId
+ * @return the URL that allow the voting person to update his vote
+ */
+ public String getUpdateVoteUrl(PollUri pollUri) {
+ Preconditions.checkNotNull(pollUri.getAccountId());
+ URL baseUrl = serviceContext.getApplicationURL();
+ String result =
+ String.format("%s/poll/votefor/%s", baseUrl, pollUri.getUri());
+ return result;
+ }
public Vote createVote(Vote vote) {
@@ -172,6 +190,7 @@
String choiceId = input.getChoice().getTopiaId();
Choice choiceLoaded = getEntityById(Choice.class, choiceId);
voteToChoiceCreated.setChoice(choiceLoaded);
+ voteToChoiceCreated.setVote(result);
result.addChoiceVoteToChoice(voteToChoiceCreated);
}
@@ -225,6 +244,16 @@
commitTransaction("Could not update vote");
}
+ /**
+ * Delete vote referenced by {@code voteId}. This will also delete all
+ * associated {@link VoteToChoice}. The {@link PollAccount} could also be
+ * deleted for a {@link PollType#FREE} poll where vote will be removed. This
+ * remove implied an new execution of poll vote counting if continuous results
+ * is activated.
+ *
+ * @param voteId TopiaId of the vote
+ * @throws VoteNotFoundException if vote doesn't exist
+ */
public void deleteVote(String voteId) throws VoteNotFoundException {
Vote entityToDelete = getEntityById(Vote.class, voteId);
@@ -234,8 +263,28 @@
}
VoteDAO dao = getDAO(Vote.class);
+ VoteToChoiceDAO voteToChoiceDao = getDAO(VoteToChoice.class);
+
+ // Delete all VoteToChoice
+ List<VoteToChoice> voteToChoices = ImmutableList.copyOf(entityToDelete.getChoiceVoteToChoice());
+ for (VoteToChoice voteToChoice : voteToChoices) {
+ entityToDelete.removeChoiceVoteToChoice(voteToChoice);
+ delete(voteToChoiceDao, voteToChoice);
+ }
+
+ // Delete vote PollAccount if the Poll is free and account is not the creator
+ Poll poll = entityToDelete.getPoll();
+ PollAccount voteAccount = entityToDelete.getPollAccount();
+ if (PollType.FREE.equals(poll.getPollType()) && !voteAccount.equals(poll.getCreator())) {
+ PollAccountDAO accountDAO = getDAO(PollAccount.class);
+ delete(accountDAO, voteAccount);
+ }
+
+ poll.removeVote(entityToDelete);
delete(dao, entityToDelete);
+ // TODO calculate results if continuous
+
if (log.isDebugEnabled()) {
log.debug("Entity deleted: " + voteId);
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-23 21:32:36 UTC (rev 3207)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-26 17:02:51 UTC (rev 3208)
@@ -24,7 +24,7 @@
package org.chorem.pollen.ui.actions.poll;
import com.google.common.base.Preconditions;
-import org.chorem.pollen.services.impl.PollService;
+import org.chorem.pollen.services.impl.VoteService;
/**
* To delete a poll vote.
@@ -48,9 +48,9 @@
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voteId);
- PollService service = newService(PollService.class);
+ VoteService service = newService(VoteService.class);
- service.deleteVote(pollId, voteId);
+ service.deleteVote(voteId);
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp 2012-03-23 21:32:36 UTC (rev 3207)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmDeletePollVote.jsp 2012-03-26 17:02:51 UTC (rev 3208)
@@ -27,7 +27,7 @@
<s:form method="POST" namespace="/poll" action="deleteVote">
<s:hidden key="uriId" label=''/>
- <s:hidden key="voteId" label=''/>
+ <s:hidden key="voteId" value="%{vote.topiaId}" label=''/>
<s:text name="pollen.information.confirmDeletePollVote">
<s:param>
1
0
23 Mar '12
Author: tchemit
Date: 2012-03-23 22:32:36 +0100 (Fri, 23 Mar 2012)
New Revision: 3207
Url: http://chorem.org/repositories/revision/pollen/3207
Log:
- add shiro filters
- improve access to application context and user session
- usage of javascript files to clean pages
- clean interceptor stacks
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollAccessRequired.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorRequired.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollRequired.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/admin_required.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/connected_required.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_access_required.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_creator_required.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_required.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js
Removed:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsAdmin.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsLogguedInterceptor.java
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-admin.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-user.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -23,22 +23,48 @@
*/
package org.chorem.pollen.ui;
+import com.opensymphony.xwork2.ActionContext;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.services.PollenNotifierWorker;
import org.nuiton.topia.TopiaContext;
+import javax.servlet.ServletContext;
+import java.util.Map;
+
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
public class PollenApplicationContext {
+ /** Key to store the single instance of the application context */
+ public static final String APPLICATION_CONTEXT_PARAMETER =
+ "pollenApplicationContext";
+
protected PollenConfiguration configuration;
protected TopiaContext rootContext;
protected PollenNotifierWorker pollenNotifierWorker;
+ public static PollenApplicationContext get(ActionContext actionContext) {
+ Map<String, Object> application = actionContext.getApplication();
+ PollenApplicationContext applicationContext =
+ (PollenApplicationContext) application.get(APPLICATION_CONTEXT_PARAMETER);
+ return applicationContext;
+ }
+
+ public static PollenApplicationContext get(ServletContext servletContext) {
+ PollenApplicationContext applicationContext =
+ (PollenApplicationContext) servletContext.getAttribute(APPLICATION_CONTEXT_PARAMETER);
+ return applicationContext;
+ }
+
+ public static void set(ServletContext servletContext,
+ PollenApplicationContext context) {
+ servletContext.setAttribute(APPLICATION_CONTEXT_PARAMETER, context);
+ }
+
public PollenConfiguration getConfiguration() {
return configuration;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -34,13 +34,13 @@
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.PollenServiceFactory;
import org.chorem.pollen.services.impl.UserService;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
import org.nuiton.i18n.I18n;
import org.nuiton.i18n.init.DefaultI18nInitializer;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaUtil;
+import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.IOException;
@@ -77,8 +77,10 @@
i18nInitializer.setMissingKeyReturnNull(true);
I18n.init(i18nInitializer, Locale.getDefault());
- PollenApplicationContext applicationContext = new PollenApplicationContext();
- sce.getServletContext().setAttribute(PollenActionSupport.APPLICATION_CONTEXT_PARAMETER, applicationContext);
+ PollenApplicationContext applicationContext =
+ new PollenApplicationContext();
+ PollenApplicationContext.set(sce.getServletContext(),
+ applicationContext);
// initialize configuration
PollenConfiguration configuration = new PollenConfiguration();
@@ -112,8 +114,9 @@
log.info("Application is ending at " + new Date() + "...");
}
+ ServletContext servletContext = sce.getServletContext();
PollenApplicationContext applicationContext =
- (PollenApplicationContext) sce.getServletContext().getAttribute(PollenActionSupport.APPLICATION_CONTEXT_PARAMETER);
+ PollenApplicationContext.get(servletContext);
if (applicationContext != null) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -24,10 +24,14 @@
package org.chorem.pollen.ui;
import com.google.common.collect.Maps;
+import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.persistence.UserAccount;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
import java.util.Map;
/**
@@ -41,6 +45,39 @@
/** Logger. */
private static final Log log = LogFactory.getLog(PollenSession.class);
+ /** Key to store the {@link PollenSession} instance in the session's map. */
+ protected static final String SESSION_PARAMETER = "pollenSession";
+
+ public static PollenSession get(ServletRequest servletRequest) {
+ HttpSession httpSession = ((HttpServletRequest) servletRequest).getSession(true);
+ PollenSession pollenSession = (PollenSession) httpSession.getAttribute(SESSION_PARAMETER);
+ if (pollenSession == null) {
+ pollenSession = new PollenSession();
+ httpSession.setAttribute(SESSION_PARAMETER, pollenSession);
+ }
+ return pollenSession;
+ }
+
+ public static PollenSession get(ActionContext actionContext) {
+
+ // load it from session
+ Map<String, Object> strutsSession =
+ actionContext.getSession();
+ PollenSession session = (PollenSession)
+ strutsSession.get(SESSION_PARAMETER);
+
+ if (session == null) {
+
+ // create an empty session
+ session = new PollenSession();
+
+ // and store it in the struts session
+ strutsSession.put(SESSION_PARAMETER, session);
+ }
+ return session;
+ }
+
+
/** User loggued account (if anonymous, then userAccount is null). */
private UserAccount userAccount;
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -1,37 +0,0 @@
-package org.chorem.pollen.ui;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.shiro.web.filter.authz.AuthorizationFilter;
-import org.chorem.pollen.business.persistence.UserAccount;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-public class PollenShiroFilter extends AuthorizationFilter {
-
- private static final Log log = LogFactory.getLog(PollenShiroFilter.class);
-
- @Override
- protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object mappedValue) {
-
- PollenSession pollenSession = PollenActionSupport.getPollenSession(servletRequest);
-
- UserAccount userAccount = pollenSession.getUserAccount();
-
- boolean isAccessAllowed = userAccount != null && userAccount.isAdministrator();
-
- if (log.isDebugEnabled()) {
- if (isAccessAllowed) {
- log.debug("granting access to an admin-reserved page");
- } else {
- log.debug("illegal access to an admin-reserved page, user will be sent to " + getUnauthorizedUrl());
- }
- }
-
- return isAccessAllowed;
-
- }
-
-}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTopiaTransactionFilter.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -25,7 +25,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaRuntimeException;
@@ -48,7 +47,7 @@
@Override
protected TopiaContext beginTransaction(ServletRequest request) throws TopiaRuntimeException {
PollenApplicationContext applicationContext =
- PollenActionSupport.getPollenApplicationContext();
+ PollenApplicationContext.get(request.getServletContext());
TopiaContext rootContext = applicationContext.getRootContext();
try {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -25,8 +25,6 @@
import com.google.common.collect.Lists;
import com.opensymphony.xwork2.ActionContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.struts2.StrutsStatics;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.business.persistence.UserAccount;
@@ -41,16 +39,13 @@
import org.nuiton.web.filter.TopiaTransactionFilter;
import org.nuiton.web.struts2.BaseAction;
-import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
-import java.util.Map;
/**
* Pollen action support.
@@ -67,24 +62,13 @@
private static final long serialVersionUID = 1L;
- /** Key to store the {@link PollenSession} instance in the session's map. */
- protected static final String SESSION_PARAMETER = "pollenSession";
-
- /** Key to store the single instance of the application context */
- public static final String APPLICATION_CONTEXT_PARAMETER = "pollenApplicationContext";
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(PollenActionSupport.class);
-
private static DateFormat dateTimeFormat;
private DateFormat dateFormat;
public static PollenApplicationContext getPollenApplicationContext() {
- Map<String, Object> application = getActionContext().getApplication();
PollenApplicationContext applicationContext =
- (PollenApplicationContext) application.get(APPLICATION_CONTEXT_PARAMETER);
+ PollenApplicationContext.get(getActionContext());
return applicationContext;
}
@@ -111,34 +95,9 @@
return "Index";
}
- public static PollenSession getPollenSession(ServletRequest servletRequest) {
- HttpSession httpSession = ((HttpServletRequest) servletRequest).getSession(true);
- PollenSession pollenSession = (PollenSession) httpSession.getAttribute(SESSION_PARAMETER);
- if (pollenSession == null) {
- pollenSession = new PollenSession();
- httpSession.setAttribute(SESSION_PARAMETER, pollenSession);
- }
- return pollenSession;
- }
-
public PollenSession getPollenSession() {
if (pollenSession == null) {
-
- // load it from session
- Map<String, Object> strutsSession =
- getActionContext().getSession();
- PollenSession session = (PollenSession)
- strutsSession.get(SESSION_PARAMETER);
-
- if (session == null) {
-
- // create an empty session
- session = new PollenSession();
-
- // and store it in the struts session
- strutsSession.put(SESSION_PARAMETER, session);
- }
- pollenSession = session;
+ pollenSession = PollenSession.get(getActionContext());
}
return pollenSession;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/ManageFavoriteList.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -25,6 +25,7 @@
import com.google.common.base.Preconditions;
import com.opensymphony.xwork2.Preparable;
+import org.apache.struts2.interceptor.ParameterAware;
import org.chorem.pollen.business.persistence.PersonList;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.services.exceptions.FavoriteListNotFoundException;
@@ -33,16 +34,20 @@
import org.chorem.pollen.services.impl.FavoriteService;
import org.chorem.pollen.ui.actions.PollenActionSupport;
+import java.util.Map;
+
/**
* Manage a selected favorite lists of a connected user.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public class ManageFavoriteList extends PollenActionSupport implements Preparable {
+public class ManageFavoriteList extends PollenActionSupport implements Preparable, ParameterAware {
private static final long serialVersionUID = 1L;
+ private Map<String, String[]> parameters;
+
@Override
public String getPageLogo() {
return "Creation";
@@ -50,7 +55,7 @@
protected String action;
- protected String favoriteListId;
+// protected String favoriteListId;
protected PersonList favoriteList;
@@ -73,26 +78,26 @@
}
public String getFavoriteListId() {
- return favoriteListId;
+ return favoriteList.getTopiaId();
}
- public void setFavoriteListId(String favoriteListId) {
- this.favoriteListId = favoriteListId;
- }
-
public String getAction() {
return action;
}
- public void setAction(String action) {
- this.action = action;
- }
-
@Override
public void prepare() throws Exception {
- Preconditions.checkNotNull(favoriteListId);
+ String[] favoriteListIds = parameters.get("favoriteListId");
+ Preconditions.checkNotNull(favoriteListIds);
+ Preconditions.checkArgument(favoriteListIds.length == 1);
+ String favoriteListId = favoriteListIds[0];
+ String[] actions = parameters.get("action");
+ if (actions != null && actions.length == 1) {
+ action = actions[0];
+ }
+
FavoriteService service = newService(FavoriteService.class);
try {
@@ -190,4 +195,8 @@
return pollAccount;
}
+ @Override
+ public void setParameters(Map<String, String[]> parameters) {
+ this.parameters = parameters;
+ }
}
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsAdmin.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsAdmin.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsAdmin.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -1,84 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.interceptors;
-
-import com.google.common.base.Preconditions;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.persistence.UserAccount;
-import org.chorem.pollen.ui.PollenSession;
-import org.chorem.pollen.ui.PollenUIUtils;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-/**
- * To check if logged user is admin.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class CheckUserIsAdmin extends AbstractInterceptor {
-
- private static final long serialVersionUID = 1L;
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(CheckUserIsAdmin.class);
-
- /** Where to redirect where user is loggued */
- protected String redirectAction;
-
- public void setRedirectAction(String redirectAction) {
- this.redirectAction = redirectAction;
- }
-
- @Override
- public String intercept(ActionInvocation invocation) throws Exception {
-
- PollenActionSupport action = (PollenActionSupport) invocation.getAction();
-
- UserAccount user = action.getPollenUserAccount();
- Preconditions.checkNotNull(user, "No user found is session");
-
- boolean check = user.isAdministrator();
-
- String result = null;
-
- if (!check) {
-
- if (log.isInfoEnabled()) {
- log.info("User not admin try to acces admin section...");
- }
-
- if (log.isInfoEnabled()) {
- log.info("Will redirect to " + redirectAction);
- }
- PollenUIUtils.redirect(redirectAction);
-
- } else {
- result = invocation.invoke();
- }
- return result;
- }
-}
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsLogguedInterceptor.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsLogguedInterceptor.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/CheckUserIsLogguedInterceptor.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -1,99 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.interceptors;
-
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.ui.PollenSession;
-import org.chorem.pollen.ui.PollenUIUtils;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-/**
- * To check user is loggued. If not, then redirect to the {@link #loginAction}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class CheckUserIsLogguedInterceptor extends AbstractInterceptor {
-
- private static final long serialVersionUID = 1L;
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(CheckUserIsLogguedInterceptor.class);
-
- /** Where to redirect if user is not authenticated. */
- protected String loginAction;
-
- /** Where to redirect where user is loggued */
- protected String redirectAction;
-
- public void setLoginAction(String loginAction) {
- this.loginAction = loginAction;
- }
-
- public void setRedirectAction(String redirectAction) {
- this.redirectAction = redirectAction;
- }
-
- protected static final String URL_PATTERN = "%s?redirectAction=%s";
-
- @Override
- public String intercept(ActionInvocation invocation) throws Exception {
-
- PollenActionSupport action = (PollenActionSupport) invocation.getAction();
-
- boolean userLoggued = action.getPollenUserAccount() != null;
-
- if (!userLoggued && log.isInfoEnabled()) {
- log.info("No user loggued!");
- }
-
- String result = null;
-
- if (!userLoggued) {
-
- // redirect to login
-
- String url = String.format(URL_PATTERN,
- loginAction,
- redirectAction
- );
- if (log.isInfoEnabled()) {
- log.info("Will redirect to " + url);
- }
- PollenUIUtils.redirect(url);
-
- } else {
-
- result = invocation.invoke();
- }
-
- return result;
- }
-
-
-}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/interceptors/PollenFileUploadInterceptor.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -58,7 +58,6 @@
public class PollenFileUploadInterceptor extends FileUploadInterceptor {
private static final long serialVersionUID = 1L;
-
protected final Pattern FILENAME_PATTERN = Pattern.compile("(.+)\\[(.+)\\]");
@Override
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,115 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.security;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.shiro.util.StringUtils;
+import org.apache.shiro.web.filter.authz.AuthorizationFilter;
+import org.apache.shiro.web.util.WebUtils;
+import org.chorem.pollen.bean.PollUri;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.PollenServiceFactory;
+import org.chorem.pollen.ui.PollenApplicationContext;
+import org.chorem.pollen.ui.PollenSession;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.web.filter.TopiaTransactionFilter;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public abstract class AbstractPollenAuthorization extends AuthorizationFilter {
+
+ public static final Pattern URI_PATTERN =
+ Pattern.compile("/.*/(.[^/]+)/(.+)");
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(AbstractPollenAuthorization.class);
+
+ protected AbstractPollenAuthorization() {
+ if (log.isInfoEnabled()) {
+ log.info("Init - "+this);
+ }
+ }
+
+ protected PollUri getPollUri(ServletRequest request) {
+ String servletPath = ((HttpServletRequest) request).getServletPath();
+ Matcher m = URI_PATTERN.matcher(servletPath);
+
+ PollUri result = null;
+ if (m.find()) {
+
+ String uriId = m.group(2);
+ result = PollUri.newPollUri(uriId);
+
+ }
+ return result;
+ }
+
+ protected UserAccount getPollenUSerAccount(ServletRequest request) {
+ PollenSession pollenSession = PollenSession.get(request);
+
+ return pollenSession.getUserAccount();
+ }
+
+ protected PollenServiceContext getServiceContext(ServletRequest request) {
+ PollenApplicationContext applicationContext =
+ PollenApplicationContext.get(request.getServletContext());
+
+ PollenServiceFactory serviceFactory = new PollenServiceFactory();
+
+ TopiaContext transaction =
+ TopiaTransactionFilter.getTransaction(request);
+
+ Locale locale = Locale.getDefault();
+ return DefaultPollenServiceContext.newContext(
+ locale,
+ transaction,
+ applicationContext.getConfiguration(),
+ serviceFactory
+ );
+ }
+
+ @Override
+ protected final boolean onAccessDenied(ServletRequest request,
+ ServletResponse response) throws IOException {
+ String unauthorizedUrl = getUnauthorizedUrl();
+ //SHIRO-142 - ensure that redirect _or_ error code occurs - both cannot happen due to response commit:
+ if (StringUtils.hasText(unauthorizedUrl)) {
+ WebUtils.issueRedirect(request, response, unauthorizedUrl);
+ } else {
+ WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ }
+ return false;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java (from rev 3202, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,59 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.security;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.persistence.UserAccount;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class AdminUserRequired extends AbstractPollenAuthorization {
+
+ private static final Log log =
+ LogFactory.getLog(AdminUserRequired.class);
+
+ @Override
+ protected boolean isAccessAllowed(ServletRequest request,
+ ServletResponse response,
+ Object mappedValue) {
+
+ UserAccount userAccount = getPollenUSerAccount(request);
+
+ boolean isAccessAllowed = userAccount != null &&
+ userAccount.isAdministrator();
+
+ if (log.isDebugEnabled()) {
+ if (isAccessAllowed) {
+ log.debug("granting access to an admin-reserved page");
+ } else {
+ log.debug("illegal access to an admin-reserved page, user will be sent to " + getUnauthorizedUrl());
+ }
+ }
+
+ return isAccessAllowed;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AdminUserRequired.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,48 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.security;
+
+import org.apache.shiro.web.filter.authc.UserFilter;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.ui.PollenSession;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class ConnectedUserRequired extends UserFilter {
+
+ @Override
+ protected boolean isAccessAllowed(ServletRequest request,
+ ServletResponse response,
+ Object mappedValue) {
+ PollenSession pollenSession =
+ PollenSession.get(request);
+
+ UserAccount userAccount = pollenSession.getUserAccount();
+
+ boolean isAccessAllowed = userAccount != null;
+ return isAccessAllowed;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/ConnectedUserRequired.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollAccessRequired.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollAccessRequired.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollAccessRequired.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,102 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.security;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.bean.PollUri;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
+import org.chorem.pollen.services.exceptions.UnauthorizedPollAccessException;
+import org.chorem.pollen.services.impl.PollService;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class PollAccessRequired extends AbstractPollenAuthorization {
+
+ private static final Log log =
+ LogFactory.getLog(PollAccessRequired.class);
+
+ protected final AdminUserRequired adminFilter;
+
+ public PollAccessRequired() {
+ adminFilter = new AdminUserRequired();
+ }
+
+ @Override
+ protected boolean isAccessAllowed(ServletRequest request,
+ ServletResponse response,
+ Object mappedValue) {
+
+ boolean isAccessAllowed;
+
+ if (adminFilter.isAccessAllowed(request, response, mappedValue)) {
+
+ // user is connected ans admin, so
+ isAccessAllowed = true;
+
+ } else {
+
+ PollUri pollUri = getPollUri(request);
+
+ if (pollUri == null) {
+
+ // no uriId given
+ isAccessAllowed = false;
+
+
+ } else {
+ PollenServiceContext serviceContext =
+ getServiceContext(request);
+
+ PollService pollService =
+ serviceContext.newService(PollService.class);
+
+ try {
+ pollService.checkPollAccount(pollUri);
+ isAccessAllowed = true;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Can access to this poll " + pollUri.getPollId());
+ }
+ } catch (PollNotFoundException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Poll not found!");
+ }
+ isAccessAllowed = false;
+ } catch (UnauthorizedPollAccessException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("User can not access page");
+ }
+ isAccessAllowed = false;
+ }
+
+ }
+ }
+
+ return isAccessAllowed;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollAccessRequired.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorRequired.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorRequired.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorRequired.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,103 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.security;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.bean.PollUri;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
+import org.chorem.pollen.services.exceptions.UnauthorizedPollAccessException;
+import org.chorem.pollen.services.impl.PollService;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class PollCreatorRequired extends AbstractPollenAuthorization {
+
+ private static final Log log = LogFactory.getLog(PollCreatorRequired.class);
+
+ protected final AdminUserRequired adminFilter;
+
+ public PollCreatorRequired() {
+ adminFilter = new AdminUserRequired();
+ }
+
+
+ @Override
+ protected boolean isAccessAllowed(ServletRequest request,
+ ServletResponse response,
+ Object mappedValue) {
+
+ boolean isAccessAllowed;
+
+ if (adminFilter.isAccessAllowed(request, response, mappedValue)) {
+
+ // user is connected ans admin, so
+ isAccessAllowed = true;
+
+ } else {
+
+ PollUri pollUri = getPollUri(request);
+
+ if (pollUri == null) {
+
+ // no uriId given
+ isAccessAllowed = false;
+
+
+ } else {
+ PollenServiceContext serviceContext =
+ getServiceContext(request);
+
+ PollService pollService =
+ serviceContext.newService(PollService.class);
+
+ try {
+ pollService.checkPollCreator(pollUri);
+ isAccessAllowed = true;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Can access to this poll " +
+ pollUri.getPollId());
+ }
+ } catch (PollNotFoundException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Poll not found!");
+ }
+ isAccessAllowed = false;
+ } catch (UnauthorizedPollAccessException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("User can not access page");
+ }
+ isAccessAllowed = false;
+ }
+
+ }
+ }
+
+ return isAccessAllowed;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollCreatorRequired.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollRequired.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollRequired.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollRequired.java 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,80 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.security;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.bean.PollUri;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
+import org.chorem.pollen.services.impl.PollService;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class PollRequired extends AbstractPollenAuthorization {
+
+ private static final Log log =
+ LogFactory.getLog(PollRequired.class);
+
+ @Override
+ protected boolean isAccessAllowed(ServletRequest request,
+ ServletResponse response,
+ Object mappedValue) {
+
+ boolean isAccessAllowed;
+
+ PollUri pollUri = getPollUri(request);
+
+ if (pollUri == null) {
+
+ // no uriId given
+ isAccessAllowed = false;
+
+ } else {
+
+ PollenServiceContext serviceContext = getServiceContext(request);
+
+ PollService pollService =
+ serviceContext.newService(PollService.class);
+
+ try {
+ pollService.checkPoll(pollUri);
+ isAccessAllowed = true;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Can access to this poll " + pollUri.getPollId());
+ }
+ } catch (PollNotFoundException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Poll not found!");
+ }
+ isAccessAllowed = false;
+ }
+ }
+
+ return isAccessAllowed;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/PollRequired.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-admin.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-admin.xml 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-admin.xml 2012-03-23 21:32:36 UTC (rev 3207)
@@ -32,7 +32,7 @@
<package name="admin" extends="default" namespace="/admin">
- <default-interceptor-ref name="pollenBasicAdminStack"/>
+ <default-interceptor-ref name="pollenBasicStack"/>
<!-- manage users -->
<action name="usersList" method="input"
@@ -43,7 +43,7 @@
<!-- create user -->
<action name="create" method="create"
class="org.chorem.pollen.ui.actions.admin.ManageUsers">
- <interceptor-ref name="pollenParamsPrepareParamsAdminStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/admin/usersList.jsp</result>
<result>/WEB-INF/jsp/admin/usersList.jsp</result>
</action>
@@ -51,7 +51,7 @@
<!-- save user -->
<action name="edit" method="edit"
class="org.chorem.pollen.ui.actions.admin.ManageUsers">
- <interceptor-ref name="pollenParamsPrepareParamsAdminStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/admin/usersList.jsp</result>
<result>/WEB-INF/jsp/admin/usersList.jsp</result>
</action>
@@ -59,7 +59,7 @@
<!-- delete user -->
<action name="delete" method="delete"
class="org.chorem.pollen.ui.actions.admin.ManageUsers">
- <interceptor-ref name="pollenParamsPrepareParamsAdminStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/admin/usersList.jsp</result>
<result>/WEB-INF/jsp/admin/usersList.jsp</result>
</action>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-json.xml 2012-03-23 21:32:36 UTC (rev 3207)
@@ -31,83 +31,79 @@
<package name="json" extends="default" namespace="/json">
- <!-- get pagined users -->
- <action name="getUsers"
- class="org.chorem.pollen.ui.actions.json.GetUsers">
- <interceptor-ref name="pollenBasicAdminStack"/>
- <result type="json"/>
- </action>
+ <default-interceptor-ref name="pollenBasicStack"/>
- <!-- get user detail -->
- <action name="getUser"
- class="org.chorem.pollen.ui.actions.json.GetUser">
- <interceptor-ref name="pollenBasicAdminStack"/>
+ <action name="get*"
+ class="org.chorem.pollen.ui.actions.json.Get{1}">
<result type="json"/>
</action>
+ <!---->
+ <!--<!– get pagined users –>-->
+ <!--<action name="getUsers"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetUsers">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get pagined favorite lists of user -->
- <action name="getFavoriteLists"
- class="org.chorem.pollen.ui.actions.json.GetFavoriteLists">
- <interceptor-ref name="pollenBasicLogguedStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get user detail –>-->
+ <!--<action name="getUser"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetUser">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get selected favorite list of user -->
- <action name="getFavoriteList"
- class="org.chorem.pollen.ui.actions.json.GetFavoriteList">
- <interceptor-ref name="pollenBasicLogguedStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get pagined favorite lists of user –>-->
+ <!--<action name="getFavoriteLists"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetFavoriteLists">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get pagined poll accounts of a given favorite list -->
- <action name="getFavoriteListPollAccounts"
- class="org.chorem.pollen.ui.actions.json.GetFavoriteListPollAccounts">
- <interceptor-ref name="pollenBasicLogguedStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get selected favorite list of user –>-->
+ <!--<action name="getFavoriteList"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetFavoriteList">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get selected poll account of a given favorite list -->
- <action name="getFavoriteListPollAccount"
- class="org.chorem.pollen.ui.actions.json.GetFavoriteListPollAccount">
- <interceptor-ref name="pollenBasicLogguedStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get pagined poll accounts of a given favorite list –>-->
+ <!--<action name="getFavoriteListPollAccounts"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetFavoriteListPollAccounts">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get pagined polls -->
- <action name="getPolls"
- class="org.chorem.pollen.ui.actions.json.GetPolls">
- <interceptor-ref name="pollenBasicAdminStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get selected poll account of a given favorite list –>-->
+ <!--<action name="getFavoriteListPollAccount"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetFavoriteListPollAccount">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get pagined created polls -->
- <action name="getCreatedPolls"
- class="org.chorem.pollen.ui.actions.json.GetCreatedPolls">
- <interceptor-ref name="pollenBasicLogguedStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get pagined polls –>-->
+ <!--<action name="getPolls"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetPolls">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get pagined invited polls -->
- <action name="getInvitedPolls"
- class="org.chorem.pollen.ui.actions.json.GetInvitedPolls">
- <interceptor-ref name="pollenBasicLogguedStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get pagined created polls –>-->
+ <!--<action name="getCreatedPolls"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetCreatedPolls">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get pagined created polls -->
- <action name="getParticipatedPolls"
- class="org.chorem.pollen.ui.actions.json.GetParticipatedPolls">
- <interceptor-ref name="pollenBasicLogguedStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get pagined invited polls –>-->
+ <!--<action name="getInvitedPolls"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetInvitedPolls">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
- <!-- get pagined poll comments -->
- <action name="getPollComments"
- class="org.chorem.pollen.ui.actions.json.GetPollComments">
- <interceptor-ref name="pollenBasicStack"/>
- <result type="json"/>
- </action>
+ <!--<!– get pagined created polls –>-->
+ <!--<action name="getParticipatedPolls"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetParticipatedPolls">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
+ <!--<!– get pagined poll comments –>-->
+ <!--<action name="getPollComments"-->
+ <!--class="org.chorem.pollen.ui.actions.json.GetPollComments">-->
+ <!--<result type="json"/>-->
+ <!--</action>-->
+
</package>
</struts>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-23 21:32:36 UTC (rev 3207)
@@ -38,6 +38,12 @@
<param name="namespace">/poll</param>
<param name="actionName">votefor/${uriId}</param>
</result-type>
+
+ <result-type name="redirect2"
+ class="org.apache.struts2.dispatcher.ServletRedirectResult">
+ <param name="location">${redirectUrl}</param>
+ <param name="prependServletContext">false</param>
+ </result-type>
</result-types>
<!-- create poll -->
@@ -110,10 +116,7 @@
<action name="clone/*"
class="org.chorem.pollen.ui.actions.poll.ClonePoll">
<param name="uriId">{1}</param>
- <result type="redirect">
- <param name="location">${redirectUrl}</param>
- <param name="prependServletContext">false</param>
- </result>
+ <result type="redirect2"/>
</action>
<!-- export poll -->
@@ -123,7 +126,8 @@
<result type="stream">
<param name="contentCharSet">UTF-8</param>
<param name="contentType">application/xml</param>
- <param name="contentDisposition">attachment;filename="${filename}"
+ <param name="contentDisposition">
+ attachment;filename="${filename}"
</param>
<param name="encode">true</param>
<param name="bufferSize">4096</param>
@@ -141,10 +145,7 @@
<action name="close/*"
class="org.chorem.pollen.ui.actions.poll.ClosePoll">
<param name="uriId">{1}</param>
- <result type="redirect">
- <param name="location">${redirectUrl}</param>
- <param name="prependServletContext">false</param>
- </result>
+ <result type="redirect2"/>
</action>
<!-- confirm delete poll -->
@@ -158,10 +159,7 @@
<action name="delete/*"
class="org.chorem.pollen.ui.actions.poll.DeletePoll">
<param name="uriId">{1}</param>
- <result type="redirect">
- <param name="location">${redirectUrl}</param>
- <param name="prependServletContext">false</param>
- </result>
+ <result type="redirect2"/>
</action>
<!-- display poll result -->
@@ -174,14 +172,14 @@
<!-- display createds polls -->
<action name="createdList"
class="org.chorem.pollen.ui.actions.poll.CreatedList">
- <interceptor-ref name="pollenBasicLogguedStack"/>
+ <interceptor-ref name="pollenBasicStack"/>
<result>/WEB-INF/jsp/poll/createdList.jsp</result>
</action>
<!-- display participated polls -->
<action name="participatedList"
class="org.chorem.pollen.ui.actions.poll.ParticipatedList">
- <interceptor-ref name="pollenBasicLogguedStack"/>
+ <interceptor-ref name="pollenBasicStack"/>
<result>/WEB-INF/jsp/poll/participatedList.jsp</result>
</action>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-user.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-user.xml 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-user.xml 2012-03-23 21:32:36 UTC (rev 3207)
@@ -66,7 +66,7 @@
<!-- show favorite lists -->
<action name="favoriteLists" method="input"
class="org.chorem.pollen.ui.actions.user.ManageFavoriteLists">
- <interceptor-ref name="pollenBasicLogguedStack"/>
+ <interceptor-ref name="pollenBasicStack"/>
<result name="input">/WEB-INF/jsp/user/favoriteLists.jsp</result>
<result>/WEB-INF/jsp/user/favoriteLists.jsp</result>
</action>
@@ -74,7 +74,7 @@
<!-- create favorite list -->
<action name="createFavoriteList" method="create"
class="org.chorem.pollen.ui.actions.user.ManageFavoriteLists">
- <interceptor-ref name="pollenParamsPrepareParamsLogguedStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/user/favoriteLists.jsp</result>
<result>/WEB-INF/jsp/user/favoriteLists.jsp</result>
</action>
@@ -82,7 +82,7 @@
<!-- delete favorite list -->
<action name="deleteFavoriteList" method="delete"
class="org.chorem.pollen.ui.actions.user.ManageFavoriteLists">
- <interceptor-ref name="pollenParamsPrepareParamsLogguedStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/user/favoriteLists.jsp</result>
<result>/WEB-INF/jsp/user/favoriteLists.jsp</result>
</action>
@@ -90,14 +90,14 @@
<!-- edit favorite list -->
<action name="editFavoriteList" method="input"
class="org.chorem.pollen.ui.actions.user.ManageFavoriteList">
- <interceptor-ref name="pollenParamsPrepareParamsLogguedStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/user/favoriteList.jsp</result>
</action>
<!-- add poll account to favorite list -->
<action name="addPollAccount" method="create"
class="org.chorem.pollen.ui.actions.user.ManageFavoriteList">
- <interceptor-ref name="pollenParamsPrepareParamsAdminStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/user/favoriteList.jsp</result>
<result>/WEB-INF/jsp/user/favoriteList.jsp</result>
</action>
@@ -105,7 +105,7 @@
<!-- edit poll account to favorite list -->
<action name="editPollAccount" method="edit"
class="org.chorem.pollen.ui.actions.user.ManageFavoriteList">
- <interceptor-ref name="pollenParamsPrepareParamsAdminStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/user/favoriteList.jsp</result>
<result>/WEB-INF/jsp/user/favoriteList.jsp</result>
</action>
@@ -113,7 +113,7 @@
<!-- remove poll account from a favorite list -->
<action name="removePollAccount" method="delete"
class="org.chorem.pollen.ui.actions.user.ManageFavoriteList">
- <interceptor-ref name="pollenParamsPrepareParamsAdminStack"/>
+ <interceptor-ref name="pollenParamsPrepareParamsStack"/>
<result name="input">/WEB-INF/jsp/user/favoriteList.jsp</result>
<result>/WEB-INF/jsp/user/favoriteList.jsp</result>
</action>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties 2012-03-23 21:32:36 UTC (rev 3207)
@@ -28,5 +28,5 @@
log4j.appender.console.layout.ConversionPattern=%d [%p] %c %m%n
log4j.logger.org.chorem.pollen=INFO
-log4j.logger.org.chorem.pollen.ui.PollenShiroFilter=DEBUG
+log4j.logger.org.chorem.pollen.ui.PollenShiroIsAdministratorFilter=DEBUG
log4j.logger.org.nuiton=INFO
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini 2012-03-23 21:32:36 UTC (rev 3207)
@@ -1,8 +1,51 @@
[main]
-pollenFilter=org.chorem.pollen.ui.PollenShiroFilter
-pollenFilter.unauthorizedUrl=bordel.jsp
+connected=org.chorem.pollen.ui.security.ConnectedUserRequired
+connected.loginUrl=/security/connected_required
+admin=org.chorem.pollen.ui.security.AdminUserRequired
+admin.unauthorizedUrl=/security/admin_required
+
+poll=org.chorem.pollen.ui.security.PollRequired
+poll.unauthorizedUrl=/security/poll_required
+
+pollAccess=org.chorem.pollen.ui.security.PollAccessRequired
+pollAccess.unauthorizedUrl=/security/poll_access_required
+
+pollCreator=org.chorem.pollen.ui.security.PollCreatorRequired
+pollCreator.unauthorizedUrl=/security/poll_creator_required
+
[urls]
-/admin/**=pollenFilter
+# connected urls
+/poll/createdList=connected
+/poll/participatedList=connected
+/user/favoriteLists=connected
+/user/createFavoriteList=connected
+/user/deleteFavoriteList=connected
+/user/show=connected
+/user/edit=connected
+/user/editFavoriteList=connected
+/json/getFavoriteLists=connected
+/json/getFavoriteList=connected
+/json/getFavoriteListPollAccounts=connected
+/json/getFavoriteListPollAccount=connected
+/json/getCreatedPolls=connected
+/json/getInvitedPolls=connected
+/json/getParticipatedPolls=connected
+
+# connected and admin urls
+/admin/**=connected,admin
+/user/addPollAccount=connected,admin
+/user/editPollAccount=connected,admin
+/user/removePollAccount=connected,admin
+/json/getUsers=connected,admin
+/json/getUser=connected,admin
+/json/getPolls=connected,admin
+
+# is pollAccount (can vote and see result of a poll)
+/poll/votefor/**=poll,pollAccess
+/poll/result/**=poll,pollAccess
+
+# is pollCreator (can admin a poll)
+/poll/modification/**=poll,pollCreator
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-23 21:32:36 UTC (rev 3207)
@@ -67,17 +67,6 @@
<interceptor name="pollenFileUpload"
class="org.chorem.pollen.ui.interceptors.PollenFileUploadInterceptor"/>
- <!--<interceptor name="checkUserLoggued"-->
- <!--class="org.chorem.pollen.ui.interceptors.CheckUserIsLogguedInterceptor">-->
- <!--<param name="loginAction">/notLoggued</param>-->
- <!--<param name="redirectAction">/home</param>-->
- <!--</interceptor>-->
-
- <!--<interceptor name="checkUserAdmin"-->
- <!--class="org.chorem.pollen.ui.interceptors.CheckUserIsAdmin">-->
- <!--<param name="redirectAction">/notAdmin</param>-->
- <!--</interceptor>-->
-
<!-- basic stack -->
<interceptor-stack name="pollenBasicStack">
<interceptor-ref name="i18n"/>
@@ -87,17 +76,6 @@
</interceptor-ref>
</interceptor-stack>
- <interceptor-stack name="pollenBasicLogguedStack">
- <!--<interceptor-ref name="checkUserLoggued"/>-->
- <interceptor-ref name="pollenBasicStack"/>
- </interceptor-stack>
-
- <interceptor-stack name="pollenBasicAdminStack">
- <!-- interceptor-ref name="checkUserLoggued" />
- <interceptor-ref name="checkUserAdmin"/ -->
- <interceptor-ref name="pollenBasicStack"/>
- </interceptor-stack>
-
<!-- params stack with params-->
<interceptor-stack name="pollenParamsPrepareParamsStack">
<interceptor-ref name="i18n"/>
@@ -134,17 +112,6 @@
</interceptor-ref>
</interceptor-stack>
- <interceptor-stack name="pollenParamsPrepareParamsLogguedStack">
- <!--<interceptor-ref name="checkUserLoggued"/>-->
- <interceptor-ref name="pollenParamsPrepareParamsStack"/>
- </interceptor-stack>
-
- <interceptor-stack name="pollenParamsPrepareParamsAdminStack">
- <!--<interceptor-ref name="checkUserLoggued"/>-->
- <!--<interceptor-ref name="checkUserAdmin"/>-->
- <interceptor-ref name="pollenParamsPrepareParamsStack"/>
- </interceptor-stack>
-
</interceptors>
<!-- must be authenticated to perform any actions -->
@@ -193,6 +160,16 @@
</package>
+ <package name="security" extends="default" namespace="/security">
+
+ <default-interceptor-ref name="pollenBasicStack"/>
+
+ <action name="*">
+ <result>/WEB-INF/jsp/security/{1}.jsp</result>
+ </action>
+
+ </package>
+
<include file="config/struts-json.xml"/>
<include file="config/struts-admin.xml"/>
<include file="config/struts-poll.xml"/>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -27,118 +27,23 @@
<script type="text/javascript"
src="<s:url value='/js/gridHelper.js' />"></script>
+<script type="text/javascript"
+ src="<s:url value='/js/usersList.js' />"></script>
+
<title><s:text name="pollen.title.usersList"/></title>
<h1 class="title${pageLogo}"><s:text name="pollen.title.usersList"/></h1>
<s:url id="loadUsers" action="getUsers" namespace="/json" escapeAmp="false"/>
-<s:url id="loadUser" action="getUser" namespace="/json"/>
-
<s:set var="user" value="%{#session.pollenSession.userAccount}"/>
<script type="text/javascript">
-
jQuery(document).ready(function () {
-
- var action='${action}';
-
- if ('${action}' == 'create') {
- $('#createForm').show();
- }
- if ('${action}' == 'edit') {
- $('#editForm').show();
- }
- if ('${action}' == 'delete') {
- $('#deleteForm').show();
- }
-
- // listen row selection
- $.addRowSelectTopic('users');
-
- $.addClearSelectTopic('users', function(){
- if (action !='') {
- // come back from action
- action='';
- return;
- }
- $(".userForm").hide();
- });
-
- // to create a new row
- $.listenRowTopic('users-addRow', function(event) {
-
- $('#createForm .errorMessage').hide();
- $('#createForm [name="createUser.login"]').val("");
- $('#createForm [name="createUser.email"]').val("");
- $('#createForm [name="createUser.firstName"]').val("");
- $('#createForm [name="createUser.lastName"]').val("");
- $('#createForm [name="createUser.administrator"]').prop('checked',false);
- $('#editForm').hide();
- $('#deleteForm').hide();
- $('#createForm').show();
- });
-
- // to edit a selected row
- $.listenRowTopic('users-editRow', function (event) {
- var id = $.getSelectedId('users');
- if(!id) {
-
- // no user selected
- return;
- }
- $('#editForm .errorMessage').hide();
- jQuery.getJSON("${loadUser}", { "userId":id }, function (result) {
-
- var user = result.user;
- $('#editForm [name="editUser.topiaId"]').val(user.id);
- $('#editForm [name="editUser.login"]').val(user.login);
- $('#editForm [name="editUser.email"]').val(user.email);
- $('#editForm [name="editUser.firstName"]').val(user.firstName);
- $('#editForm [name="editUser.lastName"]').val(user.lastName);
- $('#editForm [name="editUser.administrator"]').prop('checked',false);
- $('#editForm [name="editUser.administrator"]').prop('checked',user.administrator);
- $('#editForm').show();
- $('#createForm').hide();
- $('#deleteForm').hide();
- }
- );
- });
-
- // to delete the selected row
- $.listenRowTopic('users-deleteRow', function(event) {
- var id = $.getSelectedId('users');
- if(!id) {
-
- // no user selected
- return;
- }
-
- var userId = '${user.topiaId}';
-
- if (id == userId) {
-
- // can not delete connected user
- return;
- }
- $('#deleteForm .errorMessage').hide();
-
- jQuery.getJSON("${loadUser}", { "userId":id }, function (result) {
-
- var user = result.user;
- $('#deleteForm [name="deleteUser.topiaId"]').val(user.id);
- $('#deleteForm [name="deleteUser.login"]').val(user.login);
- $('#deleteForm [name="deleteUser.email"]').val(user.email);
- $('#deleteForm [name="deleteUser.firstName"]').val(user.firstName);
- $('#deleteForm [name="deleteUser.lastName"]').val(user.lastName);
- $('#deleteForm [name="deleteUser.administrator"]').prop('checked',false);
- $('#deleteForm [name="deleteUser.administrator"]').prop('checked',user.administrator);
- $('#editForm').hide();
- $('#createForm').hide();
- $('#deleteForm').show();
- }
- );
- });
+ initUsersPage(
+ '${action}',
+ '<s:url action="getUser" namespace="/json"/>'
+ );
});
</script>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -2,8 +2,8 @@
#%L
Pollen :: UI (strust2)
- $Id: confirmDeletePoll.jsp 3185 2012-03-14 14:43:26Z tchemit $
- $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-ui-st… $
+ $Id$
+ $HeadURL$
%%
Copyright (C) 2009 - 2012 CodeLutin
%%
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/confirmClonePoll.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/admin_required.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/admin_required.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/admin_required.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,28 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head><title></title></head>
+<body>Vous devez être connecter en administrateur pour accéder à cette page.</body>
+</html>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/admin_required.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/connected_required.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/connected_required.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/connected_required.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,28 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head><title></title></head>
+<body>Vous devez être connecter pour accéder à cette page.</body>
+</html>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/connected_required.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_access_required.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_access_required.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_access_required.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,28 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head><title></title></head>
+<body>Vous n'êtes pas autorisé à accéder à cette page de sondage.</body>
+</html>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_access_required.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_creator_required.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_creator_required.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_creator_required.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,28 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head><title></title></head>
+<body>Seul le créateur du sondage ou un administratuer peut accéder à cette page.</body>
+</html>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_creator_required.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_required.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_required.jsp (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_required.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,28 @@
+<%--
+ #%L
+ Pollen :: UI (strust2)
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ --%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head><title></title></head>
+<body>Aucun sondage à l'url donné.</body>
+</html>
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/security/poll_required.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -27,103 +27,33 @@
<script type="text/javascript"
src="<s:url value='/js/gridHelper.js' />"></script>
+<script type="text/javascript"
+ src="<s:url value='/js/favoriteList.js' />"></script>
+
<s:url id="loadPollAccounts" action="getFavoriteListPollAccounts"
namespace="/json" escapeAmp="false">
- <s:param name="favoriteListId" value="%{favoriteListId}"/>
+ <s:param name="favoriteListId" value="%{favoriteList.topiaId}"/>
</s:url>
-<s:url id="loadPollAccount" action="getFavoriteListPollAccount"
- namespace="/json"/>
-
<script type="text/javascript">
jQuery(document).ready(function () {
- var action = '${action}';
-
- if ('${action}' == 'create') {
- $('#createForm').show();
- } else if ('${action}' == 'edit') {
- $('#editForm').show();
- } else if ('${action}' == 'delete') {
- $('#deleteForm').show();
- }
-
- // listen row selection
- $.addRowSelectTopic('pollAccounts');
-
- $.addClearSelectTopic('pollAccounts', function () {
- if (action != '') {
- // come back from action
- action = '';
- return;
- }
- $(".pollAccountForm").hide();
- });
-
- // to create a new row
- $.listenRowTopic('pollAccounts-addRow', function (event) {
- $('#createForm [name="createPollAccount.votingId"]').val("");
- $('#createForm [name="createPollAccount.email"]').val("");
- $('#deleteForm').hide();
- $('#editForm').hide();
- $('#createForm').show();
- });
-
- // to edit the selected row
- $.listenRowTopic('pollAccounts-editRow', function (event) {
- var id = $.getSelectedId('pollAccounts');
- if (!id) {
-
- // no row selected
- return;
- }
-
- jQuery.getJSON("${loadPollAccount}", { "pollAccountId":id },
- function (result) {
-
- var pollAccount = result.pollAccount;
- $('#editForm [name="editPollAccount.topiaId"]').val(pollAccount.id);
- $('#editForm [name="editPollAccount.votingId"]').val(pollAccount.votingId);
- $('#editForm [name="editPollAccount.email"]').val(pollAccount.email);
- $('#deleteForm').hide();
- $('#createForm').hide();
- $('#editForm').show();
- }
- );
- });
-
- // to delete the selected row
- $.listenRowTopic('pollAccounts-deleteRow', function (event) {
- var id = $.getSelectedId('pollAccounts');
- if (!id) {
-
- // no row selected
- return;
- }
-
- jQuery.getJSON("${loadPollAccount}", { "pollAccountId":id },
- function (result) {
-
- var pollAccount = result.pollAccount;
- $('#deleteForm [name="deletePollAccount.topiaId"]').val(pollAccount.id);
- $('#deleteForm [name="deletePollAccount.votingId"]').val(pollAccount.votingId);
- $('#deleteForm [name="deletePollAccount.email"]').val(pollAccount.email);
- $('#editForm').hide();
- $('#createForm').hide();
- $('#deleteForm').show();
- }
- );
- });
+ initFavoritePage(
+ '${action}',
+ '<s:url action="getFavoriteListPollAccount" namespace="/json"/>'
+ );
});
</script>
<title>
- <s:text name="pollen.title.editFavoriteList"/> ${favoriteList.name}
+ <s:text name="pollen.title.editFavoriteList"/> <s:property
+ value="favoriteList.name"/>
</title>
<h1 class="title${pageLogo}">
- <s:text name="pollen.title.editFavoriteList"/> ${favoriteList.name}
+ <s:text name="pollen.title.editFavoriteList"/> <s:property
+ value="favoriteList.name"/>
</h1>
<sjg:grid id="pollAccounts" dataType="json" href="%{loadPollAccounts}"
@@ -207,7 +137,8 @@
</fieldset>
<br/>
- <s:submit action="removePollAccount" key="pollen.action.delete" align="center"/>
+ <s:submit action="removePollAccount" key="pollen.action.delete"
+ align="center"/>
</s:form>
<br/>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-03-23 21:30:45 UTC (rev 3206)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-03-23 21:32:36 UTC (rev 3207)
@@ -27,81 +27,27 @@
<script type="text/javascript"
src="<s:url value='/js/gridHelper.js' />"></script>
+<script type="text/javascript"
+ src="<s:url value='/js/favoriteLists.js' />"></script>
+
<title><s:text name="pollen.title.favoriteLists"/></title>
<h1 class="title${pageLogo}"><s:text name="pollen.title.favoriteLists"/></h1>
<s:url id="loadFavoriteLists" action="getFavoriteLists" namespace="/json"/>
-<s:url id="loadFavoriteList" action="getFavoriteList" namespace="/json"/>
<script type="text/javascript">
jQuery(document).ready(function () {
- var action = '${action}';
-
- if ('${action}' == 'create') {
- $('#createForm').show();
- } else if ('${action}' == 'delete') {
- $('#deleteForm').show();
- }
-
- // listen row selection
- $.addRowSelectTopic('favoriteLists');
-
- $.addClearSelectTopic('favoriteLists', function () {
- if (action != '') {
- // come back from action
- action = '';
- return;
- }
- $(".userForm").hide();
- });
-
- // to create a new row
- $.listenRowTopic('favoriteLists-addRow', function (event) {
-
- $('#createForm .errorMessage').hide();
- $('#createForm [name="favoriteList.name"]').val("");
- $('#createForm [name="csvImport"]').val("");
- $('#createForm [name="ldapImport"]').val("");
- $('#deleteForm').hide();
- $('#createForm').show();
- });
-
- // to edit a selected row
- $.listenRowTopic('favoriteLists-editRow', function (event) {
- var id = $.getSelectedId('favoriteLists');
- if (!id) {
- // no row selected
- return;
- }
-
- $('#editForm [name="favoriteListId"]').val(id);
- $('#editForm').submit();
- });
-
- // to delete the selected row
- $.listenRowTopic('favoriteLists-deleteRow', function (event) {
- var id = $.getSelectedId('favoriteLists');
- if (!id) {
- // no row selected
- return;
- }
- jQuery.getJSON("${loadFavoriteList}", { favoriteListId:id },
- function (result) {
- var user = result.favoriteList;
- $('#deleteForm [name="deleteFavoriteList.topiaId"]').val(user.id);
- $('#deleteForm [name="deleteFavoriteList.name"]').val(user.name);
- $('#createForm').hide();
- $('#deleteForm').show();
- }
- );
- });
+ initFavoritesPage(
+ '${action}',
+ '<s:url action="getFavoriteList" namespace="/json"/>'
+ );
});
</script>
-<sjg:grid id="favoriteLists" dataType="json" href="%{loadFavoriteLists}"
+<sjg:grid id="favoriteLists" dataType="json" href='%{loadFavoriteLists}'
gridModel="favoriteLists" sortable="true" pager="true"
pagerButtons="true" pagerInput="true" navigator="true"
rownumbers="false" autowidth="true" viewrecords="true"
@@ -153,7 +99,6 @@
</legend>
<s:textfield key="deleteFavoriteList.name" required="true" readonly="true"
size="40" label="%{getText('pollen.common.name')}"/>
-
</fieldset>
<br/>
<s:submit action="deleteFavoriteList" key="pollen.action.delete"
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,99 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+function initFavoritePage(action, loadPollActionUrl) {
+ if (action == 'create') {
+ $('#createForm').show();
+ } else if (action == 'edit') {
+ $('#editForm').show();
+ } else if (action == 'delete') {
+ $('#deleteForm').show();
+ }
+
+ // listen row selection
+ $.addRowSelectTopic('pollAccounts');
+
+ $.addClearSelectTopic('pollAccounts', function () {
+ if (action != '') {
+ // come back from action
+ action = '';
+ return;
+ }
+ $(".pollAccountForm").hide();
+ });
+
+ // to create a new row
+ $.listenRowTopic('pollAccounts-addRow', function (event) {
+ $('#createForm [name="createPollAccount.votingId"]').val("");
+ $('#createForm [name="createPollAccount.email"]').val("");
+ $('#deleteForm').hide();
+ $('#editForm').hide();
+ $('#createForm').show();
+ });
+
+ // to edit the selected row
+ $.listenRowTopic('pollAccounts-editRow', function (event) {
+ var id = $.getSelectedId('pollAccounts');
+ if (!id) {
+
+ // no row selected
+ return;
+ }
+
+ jQuery.getJSON(loadPollActionUrl, { "pollAccountId":id },
+ function (result) {
+
+ var pollAccount = result.pollAccount;
+ $('#editForm [name="editPollAccount.topiaId"]').val(pollAccount.id);
+ $('#editForm [name="editPollAccount.votingId"]').val(pollAccount.votingId);
+ $('#editForm [name="editPollAccount.email"]').val(pollAccount.email);
+ $('#deleteForm').hide();
+ $('#createForm').hide();
+ $('#editForm').show();
+ }
+ );
+ });
+
+ // to delete the selected row
+ $.listenRowTopic('pollAccounts-deleteRow', function (event) {
+ var id = $.getSelectedId('pollAccounts');
+ if (!id) {
+
+ // no row selected
+ return;
+ }
+
+ jQuery.getJSON(loadPollActionUrl, { "pollAccountId":id },
+ function (result) {
+
+ var pollAccount = result.pollAccount;
+ $('#deleteForm [name="deletePollAccount.topiaId"]').val(pollAccount.id);
+ $('#deleteForm [name="deletePollAccount.votingId"]').val(pollAccount.votingId);
+ $('#deleteForm [name="deletePollAccount.email"]').val(pollAccount.email);
+ $('#editForm').hide();
+ $('#createForm').hide();
+ $('#deleteForm').show();
+ }
+ );
+ });
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteList.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,84 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+function initFavoritesPage(action, loadFavoriteList) {
+
+ if (action == 'create') {
+ $('#createForm').show();
+ } else if (action == 'delete') {
+ $('#deleteForm').show();
+ }
+
+ // listen row selection
+ $.addRowSelectTopic('favoriteLists');
+
+ $.addClearSelectTopic('favoriteLists', function () {
+ if (action != '') {
+ // come back from action
+ action = '';
+ return;
+ }
+ $(".userForm").hide();
+ });
+
+ // to create a new row
+ $.listenRowTopic('favoriteLists-addRow', function (event) {
+
+ $('#createForm .errorMessage').hide();
+ $('#createForm [name="favoriteList.name"]').val("");
+ $('#createForm [name="csvImport"]').val("");
+ $('#createForm [name="ldapImport"]').val("");
+ $('#deleteForm').hide();
+ $('#createForm').show();
+ });
+
+ // to edit a selected row
+ $.listenRowTopic('favoriteLists-editRow', function (event) {
+ var id = $.getSelectedId('favoriteLists');
+ if (!id) {
+ // no row selected
+ return;
+ }
+
+ $('#editForm [name="favoriteListId"]').val(id);
+ $('#editForm').submit();
+ });
+
+ // to delete the selected row
+ $.listenRowTopic('favoriteLists-deleteRow', function (event) {
+ var id = $.getSelectedId('favoriteLists');
+ if (!id) {
+ // no row selected
+ return;
+ }
+ jQuery.getJSON(loadFavoriteList, { favoriteListId:id },
+ function (result) {
+ var user = result.favoriteList;
+ $('#deleteForm [name="deleteFavoriteList.topiaId"]').val(user.id);
+ $('#deleteForm [name="deleteFavoriteList.name"]').val(user.name);
+ $('#createForm').hide();
+ $('#deleteForm').show();
+ }
+ );
+ });
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/favoriteLists.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/js/usersList.js 2012-03-23 21:32:36 UTC (rev 3207)
@@ -0,0 +1,122 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+function initUsersPage(action, loadUserUrl) {
+
+ if (action == 'create') {
+ $('#createForm').show();
+ }
+ if (action == 'edit') {
+ $('#editForm').show();
+ }
+ if (action == 'delete') {
+ $('#deleteForm').show();
+ }
+
+ // listen row selection
+ $.addRowSelectTopic('users');
+
+ $.addClearSelectTopic('users', function () {
+ if (action != '') {
+ // come back from action
+ action = '';
+ return;
+ }
+ $(".userForm").hide();
+ });
+
+ // to create a new row
+ $.listenRowTopic('users-addRow', function (event) {
+
+ $('#createForm .errorMessage').hide();
+ $('#createForm [name="createUser.login"]').val("");
+ $('#createForm [name="createUser.email"]').val("");
+ $('#createForm [name="createUser.firstName"]').val("");
+ $('#createForm [name="createUser.lastName"]').val("");
+ $('#createForm [name="createUser.administrator"]').prop('checked', false);
+ $('#editForm').hide();
+ $('#deleteForm').hide();
+ $('#createForm').show();
+ });
+
+ // to edit a selected row
+ $.listenRowTopic('users-editRow', function (event) {
+ var id = $.getSelectedId('users');
+ if (!id) {
+
+ // no user selected
+ return;
+ }
+ $('#editForm .errorMessage').hide();
+ jQuery.getJSON(loadUserUrl, { "userId":id }, function (result) {
+
+ var user = result.user;
+ $('#editForm [name="editUser.topiaId"]').val(user.id);
+ $('#editForm [name="editUser.login"]').val(user.login);
+ $('#editForm [name="editUser.email"]').val(user.email);
+ $('#editForm [name="editUser.firstName"]').val(user.firstName);
+ $('#editForm [name="editUser.lastName"]').val(user.lastName);
+ $('#editForm [name="editUser.administrator"]').prop('checked', false);
+ $('#editForm [name="editUser.administrator"]').prop('checked', user.administrator);
+ $('#editForm').show();
+ $('#createForm').hide();
+ $('#deleteForm').hide();
+ }
+ );
+ });
+
+ // to delete the selected row
+ $.listenRowTopic('users-deleteRow', function (event) {
+ var id = $.getSelectedId('users');
+ if (!id) {
+
+ // no user selected
+ return;
+ }
+
+ var userId = '${user.topiaId}';
+
+ if (id == userId) {
+
+ // can not delete connected user
+ return;
+ }
+ $('#deleteForm .errorMessage').hide();
+
+ jQuery.getJSON(loadUserUrl, { "userId":id }, function (result) {
+
+ var user = result.user;
+ $('#deleteForm [name="deleteUser.topiaId"]').val(user.id);
+ $('#deleteForm [name="deleteUser.login"]').val(user.login);
+ $('#deleteForm [name="deleteUser.email"]').val(user.email);
+ $('#deleteForm [name="deleteUser.firstName"]').val(user.firstName);
+ $('#deleteForm [name="deleteUser.lastName"]').val(user.lastName);
+ $('#deleteForm [name="deleteUser.administrator"]').prop('checked', false);
+ $('#deleteForm [name="deleteUser.administrator"]').prop('checked', user.administrator);
+ $('#editForm').hide();
+ $('#createForm').hide();
+ $('#deleteForm').show();
+ }
+ );
+ });
+}
\ No newline at end of file
1
0
r3206 - in branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen: bean services/impl
by tchemit@users.chorem.org 23 Mar '12
by tchemit@users.chorem.org 23 Mar '12
23 Mar '12
Author: tchemit
Date: 2012-03-23 22:30:45 +0100 (Fri, 23 Mar 2012)
New Revision: 3206
Url: http://chorem.org/repositories/revision/pollen/3206
Log:
add PollUri object + security method in PollService
Added:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
Added: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java 2012-03-23 21:30:45 UTC (rev 3206)
@@ -0,0 +1,77 @@
+/*
+ * #%L
+ * Pollen :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.bean;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollUri {
+
+ public static PollUri newPollUri(String uri) {
+
+ PollUri result = new PollUri();
+
+ String[] split = uri.split(":", 2);
+ if (split.length > 0) {
+ result.setPollId(split[0]);
+ if (split.length > 1) {
+ result.setAccountId(split[1]);
+ }
+ }
+ return result;
+ }
+
+ protected String pollId;
+
+ protected String accountId;
+
+ public String getPollId() {
+ return pollId;
+ }
+
+ public String getAccountId() {
+ return accountId;
+ }
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+
+ public String getUri() {
+ String result = pollId;
+ if (StringUtils.isNotEmpty(accountId)) {
+ result += ":" + accountId;
+ }
+ return result;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollUri.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-23 17:15:58 UTC (rev 3205)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-23 21:30:45 UTC (rev 3206)
@@ -31,6 +31,7 @@
import org.chorem.pollen.PollenTechnicalException;
import org.chorem.pollen.bean.PollDateChoice;
import org.chorem.pollen.bean.PollImageChoice;
+import org.chorem.pollen.bean.PollUri;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.ChoiceDAO;
import org.chorem.pollen.business.persistence.PersonToList;
@@ -47,6 +48,7 @@
import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.common.ChoiceType;
+import org.chorem.pollen.common.PollType;
import org.chorem.pollen.services.PollenServiceSupport;
import org.chorem.pollen.services.exceptions.PollAccountNotFound;
import org.chorem.pollen.services.exceptions.PollChoiceNotFoundException;
@@ -153,7 +155,6 @@
PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class);
for (PreventRule preventRule : poll.getPreventRule()) {
-
PreventRule preventRuleCreated = create(preventRuleDAO);
preventRuleCreated.setActive(preventRule.isActive());
preventRuleCreated.setMethod(preventRule.getMethod());
@@ -522,32 +523,68 @@
commitTransaction("Could not delete choice " + choice.getName());
}
- public PollAccount getRestrictedAccount(String pollId,
- String accountId) throws PollNotFoundException {
+ public void checkPoll(PollUri uri) throws PollNotFoundException {
+
+ String pollId = uri.getPollId();
+
Poll poll = getPollByPollId(pollId);
if (poll == null) {
throw new PollNotFoundException();
}
+ }
- if (log.isInfoEnabled()) {
- log.info("getRestrictedAccount : accountId = " + accountId +
- " _ pollId = " + poll.getPollId());
+ public void checkPollAccount(PollUri uri) throws PollNotFoundException, UnauthorizedPollAccessException {
+
+ String pollId = uri.getPollId();
+ String accountId = uri.getAccountId();
+
+ Poll poll = getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
}
- // Use PersonToList association entity to find coherence between
- // the poll and votingId
- PollAccountDAO dao = getDAO(PollAccount.class);
+ if (poll.getPollType() != PollType.FREE) {
- try {
- PollAccount result = dao.getRestrictedPollAccount(pollId, accountId);
- return result;
- } catch (TopiaException e) {
- throw new PollenTechnicalException(
- "Could not obtain restricted pollAccount", e);
+ // check that uri contains a correct poll account for this
+
+ // Use PersonToList association entity to find coherence between
+ // the poll and votingId
+ PollAccountDAO dao = getDAO(PollAccount.class);
+
+ try {
+ PollAccount result =
+ dao.getRestrictedPollAccount(pollId, accountId);
+
+ if (result == null) {
+ throw new UnauthorizedPollAccessException();
+ }
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException(
+ "Could not obtain restricted pollAccount", e);
+ }
}
}
+ public void checkPollCreator(PollUri uri) throws PollNotFoundException, UnauthorizedPollAccessException {
+
+ String pollId = uri.getPollId();
+ String accountId = uri.getAccountId();
+
+ Poll poll = getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+
+ String creatorId = poll.getCreator().getAccountId();
+
+ if (!creatorId.equals(accountId)) {
+ throw new UnauthorizedPollAccessException();
+ }
+ }
+
public File getPollChoiceImageFile(String pollId,
String choiceId,
boolean thumb) {
@@ -613,8 +650,8 @@
pollToUpdate.addVote(voteToAdd);
commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]");
-
-
+
+
// TopiaContext transaction = null;
// try {
// transaction = rootContext.beginTransaction();
1
0
r3205 - in branches/pollen-1.2.6-struts2: pollen-services/src/main/java/org/chorem/pollen/services pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/resources pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by fdesbois@users.chorem.org 23 Mar '12
by fdesbois@users.chorem.org 23 Mar '12
23 Mar '12
Author: fdesbois
Date: 2012-03-23 18:15:58 +0100 (Fri, 23 Mar 2012)
New Revision: 3205
Url: http://chorem.org/repositories/revision/pollen/3205
Log:
Create/Update Vote with VoteToChoice management
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-03-23 17:15:49 UTC (rev 3204)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-03-23 17:15:58 UTC (rev 3205)
@@ -69,7 +69,7 @@
public <E extends TopiaEntity> E getEntityById(Class<E> entityType, String id) {
Preconditions.checkNotNull(entityType);
- Preconditions.checkArgument(StringUtils.isNotEmpty(id));
+ Preconditions.checkArgument(StringUtils.isNotEmpty(id), "The " + entityType.getSimpleName() + " id is undefined");
try {
TopiaDAO<E> dao = getDAO(entityType);
E result = dao.findByTopiaId(id);
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-23 17:15:49 UTC (rev 3204)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-23 17:15:58 UTC (rev 3205)
@@ -385,12 +385,14 @@
public PollAccount getNewPollAccount(UserAccount userAccount) {
PollAccountDAO dao = getDAO(PollAccount.class);
PollAccount result = newInstance(dao);
+ result.setAccountId(serviceContext.createPollenUrlId());
if (userAccount != null) {
String displayName = userAccount.getDisplayName();
result.setVotingId(displayName);
} else {
result.setVotingId("");
}
+ result.setUserAccount(userAccount);
return result;
}
@@ -600,6 +602,50 @@
return result;
}
+ public void addVoteToPoll(Poll poll, Vote vote) {
+
+ String pollId = poll.getTopiaId();
+ String voteId = vote.getTopiaId();
+
+ Poll pollToUpdate = getEntityById(Poll.class, pollId);
+ Vote voteToAdd = getEntityById(Vote.class, voteId);
+
+ pollToUpdate.addVote(voteToAdd);
+
+ commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]");
+
+
+// TopiaContext transaction = null;
+// try {
+// transaction = rootContext.beginTransaction();
+//
+// pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
+// Poll pollEntity = pollDAO.findByTopiaId(pollId);
+// VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
+// Vote voteEntity = voteDAO.findByTopiaId(voteId);
+//
+// if (log.isDebugEnabled()) {
+// log.debug(pollEntity + " " + voteEntity);
+// }
+//
+// pollEntity.addVote(voteEntity);
+// pollDAO.update(pollEntity);
+//
+// transaction.commitTransaction();
+//
+// if (log.isDebugEnabled()) {
+// log.debug("Entity updated: " + pollId);
+// }
+//
+// return true;
+// } catch (Exception e) {
+// ContextUtil.doCatch(e, transaction);
+// return false;
+// } finally {
+// ContextUtil.doFinally(transaction);
+// }
+ }
+
/**
* Création d'une miniature.
*
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-23 17:15:49 UTC (rev 3204)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-23 17:15:58 UTC (rev 3205)
@@ -23,15 +23,22 @@
*/
package org.chorem.pollen.services.impl;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenTechnicalException;
+import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PollAccountDAO;
+import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.Vote;
import org.chorem.pollen.business.persistence.VoteDAO;
+import org.chorem.pollen.business.persistence.VoteToChoice;
+import org.chorem.pollen.business.persistence.VoteToChoiceDAO;
import org.chorem.pollen.entities.PollenDAOHelper;
import org.chorem.pollen.services.PollenServiceSupport;
import org.chorem.pollen.services.exceptions.VoteNotFoundException;
@@ -46,68 +53,137 @@
/** Logger. */
private static final Log log = LogFactory.getLog(VoteService.class);
+
+ public Vote getNewVote(Poll poll, PollAccount account) {
+
+ Preconditions.checkNotNull(poll);
+
+ VoteDAO voteDAO = getDAO(Vote.class);
+ VoteToChoiceDAO voteToChoiceDAO = getDAO(VoteToChoice.class);
+
+ Vote result = newInstance(voteDAO);
+ result.setPollAccount(account);
+
+ // Prepare the List of VoteToChoice with Poll's choices
+ for (Choice choice : poll.getChoice()) {
+ VoteToChoice element = newInstance(voteToChoiceDAO);
+ element.setChoice(choice);
+ result.addChoiceVoteToChoice(element);
+ }
- public void createVote(Vote vote, PollAccount pollAccount) {
+ // TODO weight ?
+
+ return result;
+ }
+
+ public Vote getVote(Poll poll, List<Vote> votes, final PollAccount account) {
+
+ Preconditions.checkNotNull(poll);
+ Preconditions.checkNotNull(votes);
+ Preconditions.checkNotNull(account);
- // création du compte associé au vote s'il n'existe pas
- // sinon mise à jour du compte
- //ServicePollAccount spa = new ServicePollAccountImpl();
- if (pollAccount == null) {
- vote.setPollAccount(null);
- } else {
-// pollAccount.setHasVoted(true);
- PollAccountDAO pollAccountDAO =
- getDAO(PollAccount.class);
+ Vote result = Iterables.find(votes, new Predicate<Vote>() {
+
+ @Override
+ public boolean apply(Vote input) {
+ return account.equals(input.getPollAccount());
+ }
- PollAccount pollAccountEntity =
- getEntityById(PollAccount.class, pollAccount.getTopiaId());
+ }, getNewVote(poll, account));
-// PollAccountDTO account = spa.findPollAccountById(pollAccountDTO
-// .getId());
- if (pollAccountEntity == null) {
- log.debug("Nouveau compte associé au vote");
- pollAccountEntity = create(pollAccountDAO);
-// voteDTO.setPollAccountId(spa
-// .createPollAccount(pollAccountDTO));
- } else {
- log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId());
- //spa.updatePollAccount(pollAccountDTO);
- //voteDTO.setPollAccountId(account.getId());
+ // For an existing Vote, ensure that there is as many voteToChoice as poll choices
+ if (result.getTopiaId() != null) {
+
+ VoteToChoiceDAO voteToChoiceDAO = getDAO(VoteToChoice.class);
+
+ List<VoteToChoice> voteToChoices = result.getChoiceVoteToChoice();
+
+ // Add all VoteToChoice even they have empty value to match the size of Poll Choice List
+ List<Choice> choices = poll.getChoice();
+ for (int i = 0; i < choices.size(); i++) {
+
+ Choice choice = choices.get(i);
+ VoteToChoice voteToChoice = voteToChoices.get(i);
+
+ // Add new VoteToChoice if choice doesn't match (not exists)
+ if (!voteToChoice.getChoice().equals(choice)) {
+ VoteToChoice element = newInstance(voteToChoiceDAO);
+ element.setChoice(choice);
+ voteToChoices.add(i, element);
+ }
}
- // Fill pollAccountEntity from DTO in argument
-// DataPollAccountConverter pollAccountConverter = new DataPollAccountConverter();
-// pollAccountConverter.setTransaction(transaction);
-// pollAccountConverter.populatePollAccountEntity(pollAccountDTO,
-// pollAccountEntity);
- // Update pollAccountEntity
-// pollAccountDAO.update(pollAccountEntity);
-
- vote.setPollAccount(pollAccountEntity);
-// vote.setVotingListId(pollAccount.getVotingListId());
-// vote.setWeight(pollAccount.getWeight());
- log.debug("Poids du vote : " + vote.getWeight());
+
}
+ return result;
+ }
+
+ public Vote createVote(Vote vote) {
VoteDAO voteDAO = getDAO(Vote.class);
+ VoteToChoiceDAO voteToChoiceDAO = getDAO(VoteToChoice.class);
- Vote voteEntity = create(voteDAO);
-// converter.setTransaction(transaction);
-// converter.populateVoteEntity(vote, voteEntity);
+ Vote result = create(voteDAO);
+ result.setWeight(vote.getWeight());
+ result.setAnonymous(vote.isAnonymous());
-// converter.populateChoiceVote(vote, voteEntity);
+ // -- PollAccount -- //
+ PollAccount pollAccount = vote.getPollAccount();
+ String pollAccountId = pollAccount.getTopiaId();
+ PollAccount pollAccountLoaded = null;
+ // Load existing account only if not anonymous, otherwise a new pollAccount must be created
+ if (pollAccountId != null && !vote.isAnonymous()) {
+ pollAccountLoaded = getEntityById(PollAccount.class, pollAccountId);
+ }
+ // Create the new PollAccount
+ if (pollAccountLoaded == null) {
+
+ PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
+ pollAccountLoaded = create(pollAccountDAO);
+ pollAccountLoaded.setAccountId(pollAccount.getAccountId());
+ }
+
+ // Update user data if not anonymous
+ if (!vote.isAnonymous()) {
+
+ pollAccountLoaded.setVotingId(pollAccount.getVotingId());
+ pollAccountLoaded.setEmail(pollAccount.getEmail());
+
+ UserAccount userAccount = pollAccount.getUserAccount();
+ if (userAccount != null) {
+ UserAccount userAccountLoaded = getEntityById(UserAccount.class, userAccount.getTopiaId());
+ pollAccountLoaded.setUserAccount(userAccountLoaded);
+ }
+ }
+ result.setPollAccount(pollAccountLoaded);
+
+ // -- List of VoteToChoice -- //
+ for (VoteToChoice input : vote.getChoiceVoteToChoice()) {
+
+ Integer value = input.getVoteValue();
+ if (value != null) {
+
+ VoteToChoice voteToChoiceCreated = create(voteToChoiceDAO);
+ voteToChoiceCreated.setVoteValue(value);
+
+ // Bind with existing Choice
+ String choiceId = input.getChoice().getTopiaId();
+ Choice choiceLoaded = getEntityById(Choice.class, choiceId);
+ voteToChoiceCreated.setChoice(choiceLoaded);
+
+ result.addChoiceVoteToChoice(voteToChoiceCreated);
+ }
+ }
+
if (log.isDebugEnabled()) {
- log.debug("Entity created: " + voteEntity.getTopiaId());
+ log.debug("Entity created: " + result.getTopiaId());
}
commitTransaction("Could not create vote");
- // email notification
-
- // feed notification
-
+ return result;
}
public void updateVote(Vote vote) throws VoteNotFoundException {
@@ -117,9 +193,31 @@
if (entityToUpdate == null) {
throw new VoteNotFoundException();
}
-// converter.setTransaction(transaction);
-// converter.populateVoteEntity(voteDTO, voteEntity);
+ VoteToChoiceDAO voteToChoiceDao = getDAO(VoteToChoice.class);
+
+ for (VoteToChoice input : vote.getChoiceVoteToChoice()) {
+
+ Integer value = input.getVoteValue();
+
+ VoteToChoice voteToChoiceEntity = entityToUpdate.getChoiceVoteToChoice(input.getChoice());
+ if (value != null) {
+
+ if (voteToChoiceEntity == null) {
+ voteToChoiceEntity = create(voteToChoiceDao);
+ voteToChoiceEntity.setChoice(input.getChoice()); // very dangerous, bind with id
+ entityToUpdate.addChoiceVoteToChoice(voteToChoiceEntity);
+ }
+ voteToChoiceEntity.setVoteValue(value);
+ // update needed ??
+
+ } else if (voteToChoiceEntity != null) {
+
+ entityToUpdate.removeChoiceVoteToChoice(voteToChoiceEntity);
+ delete(voteToChoiceDao, voteToChoiceEntity);
+ }
+ }
+
if (log.isDebugEnabled()) {
log.debug("Entity updated: " + vote.getTopiaId());
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-23 17:15:49 UTC (rev 3204)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-23 17:15:58 UTC (rev 3205)
@@ -23,9 +23,11 @@
*/
package org.chorem.pollen.ui.actions.poll;
+import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.interceptor.ParameterAware;
import org.chorem.pollen.bean.PollResult;
import org.chorem.pollen.bean.PollResultList;
import org.chorem.pollen.business.persistence.Choice;
@@ -48,6 +50,7 @@
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
+import java.util.Map;
/**
* Abstract action for actions on the vote poll page.
@@ -55,33 +58,35 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
*/
-public abstract class AbstractVoteAction extends AbstractPollUriIdAction {
+public abstract class AbstractVoteAction extends AbstractPollUriIdAction implements ParameterAware {
private static final long serialVersionUID = 1L;
/** Logger. */
private static final Log log = LogFactory.getLog(AbstractVoteAction.class);
- /**
- * Keep this service as property to avoid new instance for each loop in
- * {@link #getResultValue(Choice)}
- */
private transient PollResultsService pollResultsService;
+
+ private transient PollService pollService;
+ private transient VoteService voteService;
+
private Poll poll;
private boolean feedFileExisting;
+ private String voteCountingTypeHelp;
+
private boolean creatorUser;
private PollAccount pollAccount;
private boolean alreadyVoted;
-
- private String voteCountingTypeHelp;
-
- private String accountName;
+ private List<Vote> votes;
+
+ private Vote vote;
+
private String commentName;
private String voteSizeMessage;
@@ -89,19 +94,40 @@
private List<PollResult> results;
private List<Comment> comments;
+
+ private Map<String, String[]> parameters;
@Override
public String getPageLogo() {
return "Vote";
}
- private PollResultsService getPollResultsService() {
+ protected PollResultsService getPollResultsService() {
if (pollResultsService == null) {
pollResultsService = newService(PollResultsService.class);
}
return pollResultsService;
}
+
+ protected PollService getPollService() {
+ if (pollService == null) {
+ pollService = newService(PollService.class);
+ }
+ return pollService;
+ }
+ protected VoteService getVoteService() {
+ if (voteService == null) {
+ voteService = newService(VoteService.class);
+ }
+ return voteService;
+ }
+
+ @Override
+ public void setParameters(Map<String, String[]> parameters) {
+ this.parameters = parameters;
+ }
+
public Poll getPoll() {
return poll;
}
@@ -110,10 +136,31 @@
return feedFileExisting;
}
+ public String getVoteCountingTypeHelp() {
+ return voteCountingTypeHelp;
+ }
+
public PollAccount getPollAccount() {
return pollAccount;
}
+ public List<Vote> getVotes() {
+ return votes;
+ }
+
+ public Vote getVote() {
+ return vote;
+ }
+
+ public VoteToChoice getVoteToChoice(int index) {
+ return getVote().getChoiceVoteToChoice().get(index);
+ }
+
+ public boolean getVoteValueAsBoolean(int index) {
+ Integer value = getVoteToChoice(index).getVoteValue();
+ return value == 1;
+ }
+
public boolean isPollChoiceOrVoteStarted() {
Date now = serviceContext.getCurrentTime();
return poll.isAddChoiceStarted(now) || poll.isStarted(now);
@@ -127,14 +174,6 @@
return poll.isAnonymous();
}
- public String getVoteCountingTypeHelp() {
- return voteCountingTypeHelp;
- }
-
- public String getAccountName() {
- return accountName;
- }
-
public List<PollResult> getResults() {
return results;
}
@@ -232,11 +271,19 @@
}
public void resetCommentName() {
- setCommentName(getAccountName());
+ setCommentName(getPollAccount().getVotingId());
}
public void prepareVotePage() throws Exception {
+ // Ensure pollId for loading
+ if (getPollId() == null) {
+ log.debug("parameters= " + parameters);
+ String uriId = parameters.get("uriId")[0];
+ log.debug("uriId= " + uriId);
+ setUriId(uriId);
+ }
+
loadPoll();
setDateFormat(DateFormat.getDateTimeInstance(
@@ -244,6 +291,7 @@
DateFormat.SHORT, getLocale()));
loadPollAccount();
+ loadVotes();
loadPollResults();
loadPollComments();
@@ -356,14 +404,14 @@
}
protected void loadPoll() throws PollNotFoundException {
-
- PollService service = newService(PollService.class);
-
+
if (StringUtils.isNotEmpty(pollId)) {
- poll = service.getPollByPollId(pollId);
+ poll = getPollService().getPollByPollId(pollId);
}
+ Preconditions.checkNotNull(poll, "Can't load poll with id = [" + pollId + "]");
+
+ log.debug("Poll TopiaId: " + poll.getTopiaId());
-
if (poll.isClosed()) {
addActionMessage(_("pollen.information.pollClosed"));
} else if (!isPollStarted()) {
@@ -378,74 +426,72 @@
protected void loadPollAccount() throws PollNotFoundException {
- PollService service = newService(PollService.class);
-
//// Contrôle et définition du votingId
- alreadyVoted = false;
- boolean modifAllowed = false;
- boolean restrictedListsForbidden = false;
+// alreadyVoted = false;
+// boolean modifAllowed = false;
+// boolean restrictedListsForbidden = false;
- // The calcul of alreadyVoted will be needed for no double votingId
- // Carefull, not correct for an anonymous vote
- VoteService voteService = newService(VoteService.class);
-
// Suppression des espaces pouvant provoquer un double vote
- pollAccount = service.getNewPollAccount(getPollenUserAccount());
- String votingId = pollAccount.getVotingId().trim();
- pollAccount.setVotingId(votingId);
+ // TODO maybe it's better to keep current pollAccount instead of creating one each time
+ pollAccount = getPollService().getNewPollAccount(getPollenUserAccount());
+// String votingId = pollAccount.getVotingId().trim();
+// pollAccount.setVotingId(votingId);
+//
+// // The calcul of alreadyVoted will be needed for no double votingId
+// // Carefull, not correct for an anonymous vote
+// alreadyVoted = getVoteService().hasAlreadyVoted(votingId, poll);
+//
+// // Check for restricted poll
+// if (!alreadyVoted && !isFreePoll()) {
+//
+// if (StringUtils.isNotEmpty(getAccountId())) {
+//
+// // The accountUId must be valid for the poll
+// PollAccount restrictedAccount =
+// getPollService().getRestrictedAccount(getPollId(), getAccountId());
+//
+// if (restrictedAccount != null) {
+// // PollAccount is replaced by the good account from db
+// pollAccount = restrictedAccount;
+//
+// // Refresh alreadyVoted value depends on pollAccount
+//// alreadyVoted = pollAccount.isHasVoted();
+//
+// } else {
+// // Existing account is null is forbidden for a restricted poll
+// restrictedListsForbidden = true;
+// }
+//
+// } else {
+// // Not allowed to vote without an accountUId
+// restrictedListsForbidden = true;
+// }
+//
+// if (restrictedListsForbidden) {
+// addActionError(_("pollen.error.user.restrictedListsForbidden"));
+// }
+// }
+//
+// // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
+// if (poll.isAnonymous() && isFreePoll()) {
+// getPollAccount().setVotingId(
+// "anonymous" + serviceContext.createPollenUrlId());
+// }
+//
+// modifAllowed = isModifAllowed(getPollAccount().getVotingId());
+// if (alreadyVoted && !modifAllowed) {
+// addActionError(_("pollen.error.user.alreadyVoted",
+// getPollAccount().getVotingId()));
+// }
+ }
+
+ protected void loadVotes() {
+
+ // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount
+ votes = getPoll().getVote();
- alreadyVoted = voteService.hasAlreadyVoted(votingId, poll);
-
- // Check for restricted poll
- if (!alreadyVoted && !isFreePoll()) {
-
- if (StringUtils.isNotEmpty(getAccountId())) {
-
- // The accountUId must be valid for the poll
- PollAccount restrictedAccount =
- service.getRestrictedAccount(getPollId(), getAccountId());
-
- if (restrictedAccount != null) {
- // PollAccount is replaced by the good account from db
- pollAccount = restrictedAccount;
-
- // Refresh alreadyVoted value depends on pollAccount
-// alreadyVoted = pollAccount.isHasVoted();
-
- } else {
- // Existing account is null is forbidden for a restricted poll
- restrictedListsForbidden = true;
- }
-
- } else {
- // Not allowed to vote without an accountUId
- restrictedListsForbidden = true;
- }
-
- if (restrictedListsForbidden) {
- addActionError(_("pollen.error.user.restrictedListsForbidden"));
- }
- }
-
- // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
- if (poll.isAnonymous() && isFreePoll()) {
- getPollAccount().setVotingId(
- "anonymous" + serviceContext.createPollenUrlId());
- }
-
- modifAllowed = isModifAllowed(getPollAccount().getVotingId());
- if (alreadyVoted && !modifAllowed) {
- addActionError(_("pollen.error.user.alreadyVoted",
- getPollAccount().getVotingId()));
- }
-
- // Initialize accountName
- UserAccount userAccount = getPollenUserAccount();
- if (userAccount != null) {
- accountName = userAccount.getDisplayName();
- } else {
- accountName = getPollAccount().getAccountId();
- }
+ // Current vote
+ vote = getVoteService().getVote(getPoll(), getVotes(), getPollAccount());
}
protected void loadPollComments() {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-23 17:15:49 UTC (rev 3204)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-23 17:15:58 UTC (rev 3205)
@@ -24,6 +24,7 @@
package org.chorem.pollen.ui.actions.poll;
import com.opensymphony.xwork2.Preparable;
+import org.chorem.pollen.business.persistence.Vote;
/**
* Votes to a poll.
@@ -35,6 +36,10 @@
private static final long serialVersionUID = 1L;
+ public void setVoteValueAsBoolean(int index, boolean value) {
+ getVoteToChoice(index).setVoteValue(value ? 1 : 0);
+ }
+
@Override
public String input() throws Exception {
@@ -44,9 +49,15 @@
@Override
public String execute() throws Exception {
+
+ if (getVote().getTopiaId() != null) {
+ getVoteService().updateVote(getVote());
+
+ } else {
+ Vote voteCreated = getVoteService().createVote(getVote());
+ getPollService().addVoteToPoll(getPoll(), voteCreated);
+ }
- //TODO Do me!
-
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-23 17:15:49 UTC (rev 3204)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-23 17:15:58 UTC (rev 3205)
@@ -108,9 +108,9 @@
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="pollenFileUpload"/>
- <interceptor-ref name="params">
+<!-- <interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
- </interceptor-ref>
+ </interceptor-ref>-->
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="staticParams"/>
@@ -119,9 +119,9 @@
<interceptor-ref name="modelDriven"/>
<!--<interceptor-ref name="staticParams"/>-->
<interceptor-ref name="actionMappingParams"/>
- <!--<interceptor-ref name="params">-->
- <!--<param name="excludeParams">dojo\..*,^struts\..*</param>-->
- <!--</interceptor-ref>-->
+ <interceptor-ref name="params">
+ <param name="excludeParams">dojo\..*,^struts\..*</param>
+ </interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-23 17:15:49 UTC (rev 3204)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-23 17:15:58 UTC (rev 3205)
@@ -161,6 +161,7 @@
autoOpen="false" modal="true" width="800"/>
<s:form id="voteForm">
+<s:hidden key="uriId"/>
<table id="poll">
<thead>
<tr>
@@ -257,32 +258,37 @@
<tr>
<s:if test="accountFieldDisplayed">
<th id="voterName">
- <s:textfield id='pollAccountName' required="true"
+ <s:textfield key='pollAccount.votingId' required="true"
value="%{pollAccount.votingId}" theme="simple"/>
</th>
</s:if>
<s:else>
<th></th>
</s:else>
- <s:iterator value="poll.choice" var="choice">
+ <s:iterator value="poll.choice" var="choice" status="status">
<s:if test="!isChoiceHidden(#choice)">
<th>
<s:if test="normalVoteCounting">
- <s:checkbox name="addChoice" theme="simple"/>
+ <s:checkbox name="voteValueAsBoolean[%{#status.index}]"
+ value="%{voteValueAsBoolean[#status.index]}" theme="simple"/>
</s:if>
<s:if test="percentageVoteCounting">
- <s:textfield value="#choice.value" size="3" required="true"
- theme="simple"/>
+ <s:textfield name="voteToChoice[%{#status.index}].voteValue"
+ value="%{voteToChoice[#status.index].voteValue}"
+ required="true" size="3" theme="simple"/>
<%--t:validate="required, min=0, max=100"/>%--%>
</s:if>
<s:if test="condorcetVoteCounting">
- <s:textfield id="condorcetInput" value="choice.value" size="3"
- theme="simple"/>
+ <s:textfield name="voteToChoice[%{#status.index}].voteValue"
+ value="%{voteToChoice[#status.index].voteValue}"
+ id="condorcetInput" size="3" theme="simple"/>
<%--t:nulls="zero" t:validate="min=0, max=99"/>--%>
</s:if>
<s:if test="numberVoteCounting">
- <s:textfield value="addNumberVote" size="3" theme="simple"/>
+ <s:textfield name="voteToChoice[%{#status.index}].voteValue"
+ value="%{voteToChoice[#status.index].voteValue}"
+ size="3" theme="simple"/>
</s:if>
</th>
</s:if>
@@ -292,7 +298,7 @@
</s:if>
<tbody>
<s:if test="!poll.anonymous">
- <s:iterator value="poll.vote" var="vote">
+ <s:iterator value="votes" var="vote">
<tr>
<td>
<s:if test="accountFieldDisplayed">
1
0
Author: fdesbois
Date: 2012-03-23 18:15:49 +0100 (Fri, 23 Mar 2012)
New Revision: 3204
Url: http://chorem.org/repositories/revision/pollen/3204
Log:
Use last mavenpom
Modified:
branches/pollen-1.2.6-struts2/pom.xml
Modified: branches/pollen-1.2.6-struts2/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pom.xml 2012-03-23 17:15:45 UTC (rev 3203)
+++ branches/pollen-1.2.6-struts2/pom.xml 2012-03-23 17:15:49 UTC (rev 3204)
@@ -12,7 +12,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.1.1</version>
+ <version>3.2.1-SNAPSHOT</version>
</parent>
<groupId>org.chorem</groupId>
@@ -508,12 +508,6 @@
<version>${nuitonI18nVersion}</version>
</plugin>
- <plugin>
- <groupId>org.apache.tomcat.maven</groupId>
- <artifactId>tomcat7-maven-plugin</artifactId>
- <version>2.0-beta-1</version>
- </plugin>
-
</plugins>
</pluginManagement>
1
0
r3203 - branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll
by fdesbois@users.chorem.org 23 Mar '12
by fdesbois@users.chorem.org 23 Mar '12
23 Mar '12
Author: fdesbois
Date: 2012-03-23 18:15:45 +0100 (Fri, 23 Mar 2012)
New Revision: 3203
Url: http://chorem.org/repositories/revision/pollen/3203
Log:
Use new methods for flags in Poll and improve code organization
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-23 08:56:10 UTC (rev 3202)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-23 17:15:45 UTC (rev 3203)
@@ -62,64 +62,61 @@
/** Logger. */
private static final Log log = LogFactory.getLog(AbstractVoteAction.class);
- protected Poll poll;
+ /**
+ * Keep this service as property to avoid new instance for each loop in
+ * {@link #getResultValue(Choice)}
+ */
+ private transient PollResultsService pollResultsService;
- protected boolean feedFileExisting;
+ private Poll poll;
- protected boolean creatorUser;
+ private boolean feedFileExisting;
- protected boolean pollChoiceOrVoteStarted;
+ private boolean creatorUser;
- protected boolean accountFieldDisplayed;
+ private PollAccount pollAccount;
- protected boolean pollChoiceRunning;
+ private boolean alreadyVoted;
- protected boolean pollRunning;
+ private String voteCountingTypeHelp;
- protected boolean alreadyVoted;
+ private String accountName;
+
+ private String commentName;
- private boolean anonymousVote;
+ private String voteSizeMessage;
- protected String voteCountingTypeHelp;
-
- protected String defaultCommentName;
-
- protected String creatorName;
-
- protected String commentName;
-
- protected String voteSizeMessage;
-
- private PollAccount pollAccount;
-
private List<PollResult> results;
private List<Comment> comments;
@Override
- public final String getPageLogo() {
+ public String getPageLogo() {
return "Vote";
}
- public final Poll getPoll() {
- return poll;
+ private PollResultsService getPollResultsService() {
+ if (pollResultsService == null) {
+ pollResultsService = newService(PollResultsService.class);
+ }
+ return pollResultsService;
}
- public PollAccount getPollAccount() {
- if (pollAccount == null) {
- PollService service = newService(PollService.class);
- pollAccount = service.getNewPollAccount(
- getPollenUserAccount());
- }
- return pollAccount;
+ public Poll getPoll() {
+ return poll;
}
- public final boolean isFeedFileExisting() {
+ public boolean isFeedFileExisting() {
return feedFileExisting;
}
+ public PollAccount getPollAccount() {
+ return pollAccount;
+ }
+
public boolean isPollChoiceOrVoteStarted() {
- return pollChoiceOrVoteStarted;
+ Date now = serviceContext.getCurrentTime();
+ return poll.isAddChoiceStarted(now) || poll.isStarted(now);
}
public boolean isAlreadyVoted() {
@@ -127,21 +124,17 @@
}
public boolean isAnonymousVote() {
- return anonymousVote;
+ return poll.isAnonymous();
}
- public final String getVoteCountingTypeHelp() {
+ public String getVoteCountingTypeHelp() {
return voteCountingTypeHelp;
}
- public final String getDefaultCommentName() {
- return defaultCommentName;
+ public String getAccountName() {
+ return accountName;
}
- public final String getCommentName() {
- return commentName;
- }
-
public List<PollResult> getResults() {
return results;
}
@@ -150,194 +143,155 @@
return comments;
}
- public void prepareVotePage() throws Exception {
+ public boolean isCreatorUser() {
+ return creatorUser;
+ }
- loadPoll();
+ public boolean isAccountFieldDisplayed() {
+ return !poll.isAnonymous() || isRestrictedPoll() || isGroupPoll();
+ }
- setDateFormat(DateFormat.getDateTimeInstance(
- DateFormat.SHORT,
- DateFormat.SHORT, getLocale()));
+ public boolean isPollChoiceRunning() {
+ Date now = serviceContext.getCurrentTime();
+ return poll.isAddChoiceRunning(now);
+ }
- if (poll != null) {
+ public boolean isPollRunning() {
+ Date now = serviceContext.getCurrentTime();
+ return poll.isRunning(now);
+ }
- loadPollAccount();
- loadPollResults();
- loadPollComments();
+ public String getCreatorName() {
+ return poll.getCreator().getAccountId();
+ }
- PollFeedService pollFeedService = newService(PollFeedService.class);
+ public String getVoteSizeMessage() {
+ return voteSizeMessage;
+ }
- feedFileExisting = pollFeedService.isFeedExists(poll);
+ public boolean isDescNull(Choice choice) {
+ return StringUtils.isEmpty(choice.getDescription());
+ }
- VoteCountingType voteCountingType = poll.getVoteCountingType();
- switch (voteCountingType) {
+ public boolean isFreePoll() {
+ return poll.getPollType() == PollType.FREE;
+ }
- case NORMAL:
- voteCountingTypeHelp =
- _("pollen.common.voteCountingTypeHelp.normal");
- break;
- case PERCENTAGE:
- voteCountingTypeHelp =
- _("pollen.common.voteCountingTypeHelp.percentage");
- break;
- case CONDORCET:
- voteCountingTypeHelp =
- _("pollen.common.voteCountingTypeHelp.condorcet");
- break;
- case NUMBER:
- voteCountingTypeHelp =
- _("pollen.common.voteCountingTypeHelp.number");
- break;
- }
+ public boolean isRestrictedPoll() {
+ return poll.getPollType() == PollType.RESTRICTED;
+ }
- // set default comment name
- UserAccount userAccount = getPollenUserAccount();
- if (userAccount == null) {
- defaultCommentName = "";
- } else {
- defaultCommentName = userAccount.getDisplayName();
- }
+ public boolean isGroupPoll() {
+ return poll.getPollType() == PollType.GROUP;
+ }
- Date currentTime = serviceContext.getCurrentTime();
+ public boolean isTextType() {
+ return poll.getChoiceType() == ChoiceType.TEXT;
+ }
- accountFieldDisplayed = !poll.isAnonymous() || isRestrictedPoll() || isGroupPoll();
+ public boolean isDateType() {
+ return poll.getChoiceType() == ChoiceType.DATE;
+ }
- boolean choicestarted = poll.getBeginChoiceDate() == null || poll.getBeginChoiceDate().before(currentTime);
- boolean choiceended = poll.getEndChoiceDate() != null && poll.getEndChoiceDate().before(currentTime);
- boolean pollChoiceStarted = choicestarted && !choiceended;
+ public boolean isImageType() {
+ return poll.getChoiceType() == ChoiceType.IMAGE;
+ }
- //TODO Move this is poll entity
- pollChoiceOrVoteStarted = pollChoiceStarted || isPollStarted();
+ public boolean isNormalVoteCounting() {
+ return poll.getVoteCountingType() == VoteCountingType.NORMAL;
+ }
- pollChoiceRunning = poll.isChoiceAddAllowed() && pollChoiceStarted;
+ public boolean isPercentageVoteCounting() {
+ return poll.getVoteCountingType() == VoteCountingType.PERCENTAGE;
+ }
- pollRunning = !poll.isClosed() && isPollStarted() && !isPollFinished();
+ public boolean isCondorcetVoteCounting() {
+ return poll.getVoteCountingType() == VoteCountingType.CONDORCET;
+ }
- //TODO Deal the case of the not loggued poll (using the pollAccountId
- creatorUser = getPollenUserAccount() != null &&
- getPollenUserAccount().equals(poll.getCreator().getUserAccount());
-
- if (log.isInfoEnabled()) {
- log.info("pollChoiceOrVoteStarted = " + pollChoiceOrVoteStarted);
- log.info("pollChoiceRunning = " + pollChoiceRunning);
- log.info("pollRunning = " + pollRunning);
- log.info("accountFieldDisplayed = " + accountFieldDisplayed);
- log.info("creatorUser = " + creatorUser);
- }
- creatorName = poll.getCreator().getVotingId();
-
-// voteSizeMessage=XXX;
- }
+ public boolean isNumberVoteCounting() {
+ return poll.getVoteCountingType() == VoteCountingType.NUMBER;
}
- private transient PollResultsService pollResultsService;
-
- private PollResultsService getPollResultsService() {
- if (pollResultsService == null) {
- pollResultsService = newService(PollResultsService.class);
- }
- return pollResultsService;
+ public boolean isPollStarted() {
+ Date now = serviceContext.getCurrentTime();
+ return poll.getBeginDate() == null || poll.getBeginDate().before(now);
}
- public String getResultValue(Choice choice) {
-
- String val = getPollResultsService().getResultValue(choice, results);
- return val;
+ public boolean isPollFinished() {
+ Date now = serviceContext.getCurrentTime();
+ return poll.getEndDate() != null && poll.getEndDate().before(now);
}
- protected void loadPollComments() {
-
- PollCommentService service = newService(PollCommentService.class);
-
- comments = service.getAllComments(poll.getPollId());
+ public String getCommentName() {
+ return commentName;
}
- protected void loadPollResults() throws PollNotFoundException {
-
- PollResultsService service = getPollResultsService();
-
- PollResultList pollResultList = service.getResults(poll.getPollId());
-
- results = pollResultList.getPollResults();
-
- if (log.isDebugEnabled()) {
- for (PollResult res : results) {
- log.debug(res.getName() + ": " + res.getValue()
- + ", (voteCounting=" + res.getVoteCountingType()
- + ", byGroup=" + res.isByGroup() + ")");
- }
- }
+ public void setCommentName(String commentName) {
+ this.commentName = commentName;
}
+
+ public void resetCommentName() {
+ setCommentName(getAccountName());
+ }
- protected void loadPollAccount() throws PollNotFoundException {
+ public void prepareVotePage() throws Exception {
- PollService service = newService(PollService.class);
+ loadPoll();
- //// Contrôle et définition du votingId
- alreadyVoted = false;
- boolean modifAllowed = false;
- boolean restrictedListsForbidden = false;
+ setDateFormat(DateFormat.getDateTimeInstance(
+ DateFormat.SHORT,
+ DateFormat.SHORT, getLocale()));
- // The calcul of alreadyVoted will be needed for no double votingId
- // Carefull, not correct for an anonymous vote
- VoteService voteService = newService(VoteService.class);
+ loadPollAccount();
+ loadPollResults();
+ loadPollComments();
- // Suppression des espaces pouvant provoquer un double vote
- String votingId = getPollAccount().getVotingId().trim();
- getPollAccount().setVotingId(votingId);
+ PollFeedService pollFeedService = newService(PollFeedService.class);
+ feedFileExisting = pollFeedService.isFeedExists(poll);
- alreadyVoted = voteService.hasAlreadyVoted(votingId, poll);
+ VoteCountingType voteCountingType = poll.getVoteCountingType();
+ switch (voteCountingType) {
- // Check for restricted poll
- if (!alreadyVoted && !isFreePoll()) {
+ case NORMAL:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.normal");
+ break;
+ case PERCENTAGE:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.percentage");
+ break;
+ case CONDORCET:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.condorcet");
+ break;
+ case NUMBER:
+ voteCountingTypeHelp =
+ _("pollen.common.voteCountingTypeHelp.number");
+ break;
+ }
- if (StringUtils.isNotEmpty(getAccountId())) {
+ //TODO Deal the case of the not loggued poll (using the pollAccountId
+ creatorUser = getPollenUserAccount() != null &&
+ getPollenUserAccount().equals(poll.getCreator().getUserAccount());
- // The accountUId must be valid for the poll
- PollAccount restrictedAccount =
- service.getRestrictedAccount(getPollId(), getAccountId());
+ resetCommentName();
- if (restrictedAccount != null) {
- // PollAccount is replaced by the good account from db
- pollAccount = restrictedAccount;
-
- // Refresh alreadyVoted value depends on pollAccount
-// alreadyVoted = pollAccount.isHasVoted();
-
- } else {
- // Existing account is null is forbidden for a restricted poll
- restrictedListsForbidden = true;
- }
-
- } else {
- // Not allowed to vote without an accountUId
- restrictedListsForbidden = true;
- }
-
- if (restrictedListsForbidden) {
- addActionError(_("pollen.error.user.restrictedListsForbidden"));
- }
+ if (log.isInfoEnabled()) {
+ log.info("pollChoiceOrVoteStarted = " + isPollChoiceOrVoteStarted());
+ log.info("pollChoiceRunning = " + isPollChoiceRunning());
+ log.info("pollRunning = " + isPollRunning());
+ log.info("accountFieldDisplayed = " + isAccountFieldDisplayed());
+ log.info("creatorUser = " + creatorUser);
}
+ }
- // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
- if (poll.isAnonymous()) {
- anonymousVote = true;
- if (isFreePoll()) {
- getPollAccount().setVotingId(
- "anonymous" + serviceContext.createPollenUrlId());
- }
- }
+ public String getResultValue(Choice choice) {
- modifAllowed = isModifAllowed(getPollAccount().getVotingId());
- if (alreadyVoted && !modifAllowed) {
- addActionError(_("pollen.error.user.alreadyVoted",
- getPollAccount().getVotingId()));
- }
+ String val = getPollResultsService().getResultValue(choice, results);
+ return val;
}
- public String escapeLineBreak(String text) {
- return text;
- }
-
/**
* Retourne si le choix fait partie du vote (s'il a été renseigné par le
* votant).
@@ -372,7 +326,7 @@
Vote vote = poll.getVoteByTopiaId(voteId);
// can only modify a vote if poll is running.
- if (vote != null && pollRunning) {
+ if (vote != null && isPollRunning()) {
PollAccount votePollAccount = vote.getPollAccount();
// si le votant du vote correspond au votant actuel (pollAccountId)
@@ -393,30 +347,14 @@
return result;
}
- public boolean isCreatorUser() {
- return creatorUser;
+ public String escapeLineBreak(String text) {
+ return text;
}
- public boolean isAccountFieldDisplayed() {
- return accountFieldDisplayed;
+ public String formatChoiceNameAsDate(Choice choice) {
+ return formatDate(new Date(Long.valueOf(choice.getName())));
}
- public boolean isPollChoiceRunning() {
- return pollChoiceRunning;
- }
-
- public boolean isPollRunning() {
- return pollRunning;
- }
-
- public String getCreatorName() {
- return creatorName;
- }
-
- public String getVoteSizeMessage() {
- return voteSizeMessage;
- }
-
protected void loadPoll() throws PollNotFoundException {
PollService service = newService(PollService.class);
@@ -425,77 +363,112 @@
poll = service.getPollByPollId(pollId);
}
- if (poll == null) {
- addActionError(_("pollen.error.poll.notfound"));
- } else {
- if (poll.isClosed()) {
- addActionMessage(_("pollen.information.pollClosed"));
- } else if (!isPollStarted()) {
- addActionMessage(_("pollen.information.pollNotStarted"));
- } else if (isPollFinished()) {
- addActionMessage(_("pollen.information.pollFinished"));
- }
- if (isPollChoiceRunning()) {
- addActionMessage(_("pollen.information.pollChoiceRunning"));
- }
+
+ if (poll.isClosed()) {
+ addActionMessage(_("pollen.information.pollClosed"));
+ } else if (!isPollStarted()) {
+ addActionMessage(_("pollen.information.pollNotStarted"));
+ } else if (isPollFinished()) {
+ addActionMessage(_("pollen.information.pollFinished"));
}
+ if (isPollChoiceRunning()) {
+ addActionMessage(_("pollen.information.pollChoiceRunning"));
+ }
}
- public boolean isDescNull(Choice choice) {
- return StringUtils.isEmpty(choice.getDescription());
- }
+ protected void loadPollAccount() throws PollNotFoundException {
- public boolean isFreePoll() {
- return poll.getPollType() == PollType.FREE;
- }
+ PollService service = newService(PollService.class);
- public boolean isRestrictedPoll() {
- return poll.getPollType() == PollType.RESTRICTED;
- }
+ //// Contrôle et définition du votingId
+ alreadyVoted = false;
+ boolean modifAllowed = false;
+ boolean restrictedListsForbidden = false;
- public boolean isGroupPoll() {
- return poll.getPollType() == PollType.GROUP;
- }
+ // The calcul of alreadyVoted will be needed for no double votingId
+ // Carefull, not correct for an anonymous vote
+ VoteService voteService = newService(VoteService.class);
- public boolean isTextType() {
- return poll.getChoiceType() == ChoiceType.TEXT;
- }
+ // Suppression des espaces pouvant provoquer un double vote
+ pollAccount = service.getNewPollAccount(getPollenUserAccount());
+ String votingId = pollAccount.getVotingId().trim();
+ pollAccount.setVotingId(votingId);
- public boolean isDateType() {
- return poll.getChoiceType() == ChoiceType.DATE;
- }
+ alreadyVoted = voteService.hasAlreadyVoted(votingId, poll);
- public boolean isImageType() {
- return poll.getChoiceType() == ChoiceType.IMAGE;
- }
+ // Check for restricted poll
+ if (!alreadyVoted && !isFreePoll()) {
- public boolean isNormalVoteCounting() {
- return poll.getVoteCountingType() == VoteCountingType.NORMAL;
- }
+ if (StringUtils.isNotEmpty(getAccountId())) {
- public boolean isPercentageVoteCounting() {
- return poll.getVoteCountingType() == VoteCountingType.PERCENTAGE;
- }
+ // The accountUId must be valid for the poll
+ PollAccount restrictedAccount =
+ service.getRestrictedAccount(getPollId(), getAccountId());
- public boolean isCondorcetVoteCounting() {
- return poll.getVoteCountingType() == VoteCountingType.CONDORCET;
- }
+ if (restrictedAccount != null) {
+ // PollAccount is replaced by the good account from db
+ pollAccount = restrictedAccount;
- public boolean isNumberVoteCounting() {
- return poll.getVoteCountingType() == VoteCountingType.NUMBER;
- }
+ // Refresh alreadyVoted value depends on pollAccount
+// alreadyVoted = pollAccount.isHasVoted();
- public boolean isPollStarted() {
- Date now = serviceContext.getCurrentTime();
- return poll.getBeginDate() == null || poll.getBeginDate().before(now);
+ } else {
+ // Existing account is null is forbidden for a restricted poll
+ restrictedListsForbidden = true;
+ }
+
+ } else {
+ // Not allowed to vote without an accountUId
+ restrictedListsForbidden = true;
+ }
+
+ if (restrictedListsForbidden) {
+ addActionError(_("pollen.error.user.restrictedListsForbidden"));
+ }
+ }
+
+ // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
+ if (poll.isAnonymous() && isFreePoll()) {
+ getPollAccount().setVotingId(
+ "anonymous" + serviceContext.createPollenUrlId());
+ }
+
+ modifAllowed = isModifAllowed(getPollAccount().getVotingId());
+ if (alreadyVoted && !modifAllowed) {
+ addActionError(_("pollen.error.user.alreadyVoted",
+ getPollAccount().getVotingId()));
+ }
+
+ // Initialize accountName
+ UserAccount userAccount = getPollenUserAccount();
+ if (userAccount != null) {
+ accountName = userAccount.getDisplayName();
+ } else {
+ accountName = getPollAccount().getAccountId();
+ }
}
- public boolean isPollFinished() {
- Date now = serviceContext.getCurrentTime();
- return poll.getEndDate() != null && poll.getEndDate().before(now);
+ protected void loadPollComments() {
+
+ PollCommentService service = newService(PollCommentService.class);
+
+ comments = service.getAllComments(poll.getPollId());
}
- public String formatChoiceNameAsDate(Choice choice) {
- return formatDate(new Date(Long.valueOf(choice.getName())));
+ protected void loadPollResults() throws PollNotFoundException {
+
+ PollResultsService service = getPollResultsService();
+
+ PollResultList pollResultList = service.getResults(poll.getPollId());
+
+ results = pollResultList.getPollResults();
+
+ if (log.isDebugEnabled()) {
+ for (PollResult res : results) {
+ log.debug(res.getName() + ": " + res.getValue()
+ + ", (voteCounting=" + res.getVoteCountingType()
+ + ", byGroup=" + res.isByGroup() + ")");
+ }
+ }
}
}
\ No newline at end of file
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-03-23 08:56:10 UTC (rev 3202)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-03-23 17:15:45 UTC (rev 3203)
@@ -42,10 +42,6 @@
/** Text of the comment. */
protected String commentText;
- public void setCommentName(String commentName) {
- this.commentName = commentName;
- }
-
public String getCommentText() {
return commentText;
}
@@ -60,23 +56,22 @@
loadPoll();
- Preconditions.checkNotNull(commentName);
- Preconditions.checkNotNull(commentText);
+ Preconditions.checkNotNull(getCommentName());
+ Preconditions.checkNotNull(getCommentText());
PollCommentService service = newService(PollCommentService.class);
// prepare a new poll account for the comment
PollAccount pollAccount = service.getNewPollAccount(
- getPollenUserAccount(), commentName);
+ getPollenUserAccount(), getCommentName());
// prepare a new comment
- Comment comment = service.getNewComment(pollAccount, commentText);
+ Comment comment = service.getNewComment(pollAccount, getCommentText());
// create the comment
- service.createComment(poll, comment);
+ service.createComment(getPoll(), comment);
- // let's use back default comment name
- commentName = getDefaultCommentName();
+ resetCommentName();
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-03-23 08:56:10 UTC (rev 3202)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-03-23 17:15:45 UTC (rev 3203)
@@ -64,8 +64,7 @@
service.deleteComment(commentId);
- commentName = getDefaultCommentName();
-
+ resetCommentName();
return SUCCESS;
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java 2012-03-23 08:56:10 UTC (rev 3202)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ModifyVote.java 2012-03-23 17:15:45 UTC (rev 3203)
@@ -37,14 +37,8 @@
@Override
public String execute() throws Exception {
-
loadPoll();
-
- if (poll == null) {
-
- }
-
return SUCCESS;
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-23 08:56:10 UTC (rev 3202)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-23 17:15:45 UTC (rev 3203)
@@ -54,6 +54,5 @@
public void prepare() throws Exception {
prepareVotePage();
- commentName = getDefaultCommentName();
}
}
1
0
r3202 - in branches/pollen-1.2.6-struts2: . pollen-ui-struts2 pollen-ui-struts2/src/main/java/org/chorem/pollen/ui pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions pollen-ui-struts2/src/main/resources pollen-ui-struts2/src/main/webapp/WEB-INF
by bleny@users.chorem.org 23 Mar '12
by bleny@users.chorem.org 23 Mar '12
23 Mar '12
Author: bleny
Date: 2012-03-23 09:56:10 +0100 (Fri, 23 Mar 2012)
New Revision: 3202
Url: http://chorem.org/repositories/revision/pollen/3202
Log:
mise en place de shiro sur pollen-struts (pom, web.xml, shiro.ini, filtre d'admin) : fonctionne mais on est redirig?\195?\169 vers login.jsp
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/pom.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/web.xml
branches/pollen-1.2.6-struts2/pom.xml
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/pom.xml 2012-03-22 15:13:57 UTC (rev 3201)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/pom.xml 2012-03-23 08:56:10 UTC (rev 3202)
@@ -128,6 +128,11 @@
<artifactId>jetty-runner</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-web</artifactId>
+ </dependency>
+
<!-- Provided dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenShiroFilter.java 2012-03-23 08:56:10 UTC (rev 3202)
@@ -0,0 +1,37 @@
+package org.chorem.pollen.ui;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.shiro.web.filter.authz.AuthorizationFilter;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class PollenShiroFilter extends AuthorizationFilter {
+
+ private static final Log log = LogFactory.getLog(PollenShiroFilter.class);
+
+ @Override
+ protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object mappedValue) {
+
+ PollenSession pollenSession = PollenActionSupport.getPollenSession(servletRequest);
+
+ UserAccount userAccount = pollenSession.getUserAccount();
+
+ boolean isAccessAllowed = userAccount != null && userAccount.isAdministrator();
+
+ if (log.isDebugEnabled()) {
+ if (isAccessAllowed) {
+ log.debug("granting access to an admin-reserved page");
+ } else {
+ log.debug("illegal access to an admin-reserved page, user will be sent to " + getUnauthorizedUrl());
+ }
+ }
+
+ return isAccessAllowed;
+
+ }
+
+}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-22 15:13:57 UTC (rev 3201)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-23 08:56:10 UTC (rev 3202)
@@ -41,7 +41,9 @@
import org.nuiton.web.filter.TopiaTransactionFilter;
import org.nuiton.web.struts2.BaseAction;
+import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
@@ -109,6 +111,16 @@
return "Index";
}
+ public static PollenSession getPollenSession(ServletRequest servletRequest) {
+ HttpSession httpSession = ((HttpServletRequest) servletRequest).getSession(true);
+ PollenSession pollenSession = (PollenSession) httpSession.getAttribute(SESSION_PARAMETER);
+ if (pollenSession == null) {
+ pollenSession = new PollenSession();
+ httpSession.setAttribute(SESSION_PARAMETER, pollenSession);
+ }
+ return pollenSession;
+ }
+
public PollenSession getPollenSession() {
if (pollenSession == null) {
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties 2012-03-22 15:13:57 UTC (rev 3201)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/log4j.properties 2012-03-23 08:56:10 UTC (rev 3202)
@@ -28,4 +28,5 @@
log4j.appender.console.layout.ConversionPattern=%d [%p] %c %m%n
log4j.logger.org.chorem.pollen=INFO
+log4j.logger.org.chorem.pollen.ui.PollenShiroFilter=DEBUG
log4j.logger.org.nuiton=INFO
Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/shiro.ini 2012-03-23 08:56:10 UTC (rev 3202)
@@ -0,0 +1,8 @@
+[main]
+
+pollenFilter=org.chorem.pollen.ui.PollenShiroFilter
+pollenFilter.unauthorizedUrl=bordel.jsp
+
+[urls]
+
+/admin/**=pollenFilter
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-22 15:13:57 UTC (rev 3201)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-23 08:56:10 UTC (rev 3202)
@@ -67,16 +67,16 @@
<interceptor name="pollenFileUpload"
class="org.chorem.pollen.ui.interceptors.PollenFileUploadInterceptor"/>
- <interceptor name="checkUserLoggued"
- class="org.chorem.pollen.ui.interceptors.CheckUserIsLogguedInterceptor">
- <param name="loginAction">/notLoggued</param>
- <param name="redirectAction">/home</param>
- </interceptor>
+ <!--<interceptor name="checkUserLoggued"-->
+ <!--class="org.chorem.pollen.ui.interceptors.CheckUserIsLogguedInterceptor">-->
+ <!--<param name="loginAction">/notLoggued</param>-->
+ <!--<param name="redirectAction">/home</param>-->
+ <!--</interceptor>-->
- <interceptor name="checkUserAdmin"
- class="org.chorem.pollen.ui.interceptors.CheckUserIsAdmin">
- <param name="redirectAction">/notAdmin</param>
- </interceptor>
+ <!--<interceptor name="checkUserAdmin"-->
+ <!--class="org.chorem.pollen.ui.interceptors.CheckUserIsAdmin">-->
+ <!--<param name="redirectAction">/notAdmin</param>-->
+ <!--</interceptor>-->
<!-- basic stack -->
<interceptor-stack name="pollenBasicStack">
@@ -88,13 +88,13 @@
</interceptor-stack>
<interceptor-stack name="pollenBasicLogguedStack">
- <interceptor-ref name="checkUserLoggued"/>
+ <!--<interceptor-ref name="checkUserLoggued"/>-->
<interceptor-ref name="pollenBasicStack"/>
</interceptor-stack>
<interceptor-stack name="pollenBasicAdminStack">
- <interceptor-ref name="checkUserLoggued"/>
- <interceptor-ref name="checkUserAdmin"/>
+ <!-- interceptor-ref name="checkUserLoggued" />
+ <interceptor-ref name="checkUserAdmin"/ -->
<interceptor-ref name="pollenBasicStack"/>
</interceptor-stack>
@@ -135,13 +135,13 @@
</interceptor-stack>
<interceptor-stack name="pollenParamsPrepareParamsLogguedStack">
- <interceptor-ref name="checkUserLoggued"/>
+ <!--<interceptor-ref name="checkUserLoggued"/>-->
<interceptor-ref name="pollenParamsPrepareParamsStack"/>
</interceptor-stack>
<interceptor-stack name="pollenParamsPrepareParamsAdminStack">
- <interceptor-ref name="checkUserLoggued"/>
- <interceptor-ref name="checkUserAdmin"/>
+ <!--<interceptor-ref name="checkUserLoggued"/>-->
+ <!--<interceptor-ref name="checkUserAdmin"/>-->
<interceptor-ref name="pollenParamsPrepareParamsStack"/>
</interceptor-stack>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/web.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/web.xml 2012-03-22 15:13:57 UTC (rev 3201)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/web.xml 2012-03-23 08:56:10 UTC (rev 3202)
@@ -29,6 +29,7 @@
<display-name>Pollen</display-name>
+
<filter>
<filter-name>topiaTransaction</filter-name>
<filter-class>org.chorem.pollen.ui.PollenTopiaTransactionFilter</filter-class>
@@ -40,6 +41,10 @@
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter
</filter-class>
</filter>
+ <filter>
+ <filter-name>ShiroFilter</filter-name>
+ <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
+ </filter>
<filter>
<filter-name>sitemesh</filter-name>
@@ -59,6 +64,15 @@
</filter-mapping>
<filter-mapping>
+ <filter-name>ShiroFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+
+ <filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
@@ -78,6 +92,11 @@
<listener-class>org.chorem.pollen.ui.PollenApplicationListener</listener-class>
</listener>
+ <listener>
+ <description>Shiro security layer</description>
+ <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
+ </listener>
+
<welcome-file-list>
<welcome-file>/</welcome-file>
<welcome-file>index.jsp</welcome-file>
Modified: branches/pollen-1.2.6-struts2/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pom.xml 2012-03-22 15:13:57 UTC (rev 3201)
+++ branches/pollen-1.2.6-struts2/pom.xml 2012-03-23 08:56:10 UTC (rev 3202)
@@ -146,6 +146,18 @@
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-core</artifactId>
+ <version>${shiroVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-web</artifactId>
+ <version>${shiroVersion}</version>
+ </dependency>
+
+
<!-- Tapestry -->
<dependency>
<groupId>org.apache.tapestry</groupId>
@@ -445,6 +457,7 @@
<postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion>
<struts2Version>2.3.1.2</struts2Version>
<jqueryPluginVersion>3.2.1</jqueryPluginVersion>
+ <shiroVersion>1.2.0</shiroVersion>
<slf4jVersion>1.6.4</slf4jVersion>
<jettyVersion>${jettyPluginVersion}</jettyVersion>
1
0