r3719 - in trunk: 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/java/org/chorem/pollen/ui/actions/poll/vote
Author: tchemit Date: 2012-10-01 13:32:38 +0200 (Mon, 01 Oct 2012) New Revision: 3719 Url: http://chorem.org/repositories/revision/pollen/3719 Log: fixes #805: RSS flux must be disabled or modified with vote visibility Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -91,13 +91,13 @@ commentCreated.setPollAccount(pollAccountLoaded); } - commitTransaction("Could not create comment (" + comment.getAuthor() + ") " + comment.getText()); - // feed notification PollFeedService pollFeedService = newService(PollFeedService.class); pollFeedService.onCommentAdded(poll, commentCreated); + commitTransaction("Could not create comment (" + comment.getAuthor() + ") " + comment.getText()); + return commentCreated; } catch (TopiaException e) { throw new PollenTechnicalException(e); @@ -119,13 +119,13 @@ dao.delete(comment); - commitTransaction("Could not delete comment " + comment.getText()); - // feed notification PollFeedService pollFeedService = newService(PollFeedService.class); pollFeedService.onCommentDeleted(poll, comment, reason); + commitTransaction("Could not delete comment " + comment.getText()); + } catch (TopiaException e) { throw new PollenTechnicalException(e); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -22,6 +22,7 @@ */ package org.chorem.pollen.services.impl; +import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.sun.syndication.feed.synd.SyndContent; @@ -33,6 +34,7 @@ import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.SyndFeedOutput; import com.sun.syndication.io.XmlReader; +import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.PollenTechnicalException; @@ -46,6 +48,8 @@ import java.io.File; import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; import java.io.Writer; import java.util.List; @@ -82,6 +86,25 @@ return result; } + /** + * Obtain the feed file of the given poll. + * + * @param poll poll + * @return the location of the feed of the given poll + */ + public String getFeed(Poll poll) { + + File feedDirectory = getConfiguration().getFeedDirectory(); + String filename = poll.getPollId() + ".xml"; + File feedFile = new File(feedDirectory, filename); + try { + String result = FileUtils.readFileToString(feedFile, Charsets.UTF_8); + return result; + } catch (IOException e) { + throw new PollenTechnicalException("Could not read feed file",e); + } + } + public void onPollCreated(Poll poll) { File file = getFeedLocation(poll); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -344,18 +344,18 @@ throw new PollenTechnicalException("Can't save votingLists", e); } + // feed notification + // XXX-fdesbois-2012-04-12 : if the feed is the same for everybody maybe + // not publish restricted poll that can't be accessed by everybody + PollFeedService pollFeedService = newService(PollFeedService.class); + pollFeedService.onPollCreated(result); + commitTransaction("Could not create poll " + poll.getTitle()); // email notification EmailService emailService = newService(EmailService.class); emailService.onPollCreated(result); - // feed notification - // XXX-fdesbois-2012-04-12 : if the feed is the same for everybody maybe - // not publish restricted poll that can't be accessed by everybody - PollFeedService pollFeedService = newService(PollFeedService.class); - pollFeedService.onPollCreated(result); - return result; } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/SecurityService.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -544,4 +544,25 @@ "from account '" + accountId + "'", e); } } + + public boolean isCanShowFeed(PollenUserSecurityContext userSecurityContext) { + Poll poll = userSecurityContext.getPoll(); + boolean result = newService(PollFeedService.class).isFeedExists(poll); + if (result) { + PollVoteVisibility voteVisibility = poll.getPollVoteVisibility(); + switch (voteVisibility) { + case NOBODY: + case CREATOR_ONLY: + result = userSecurityContext.isAdmin() || userSecurityContext.isCreator(); + break; + case PARTICIPANT_ONLY: + result = userSecurityContext.isVoter() || userSecurityContext.isRestrictedVoter(); + break; + case EVERYBODY: + result = true; + break; + } + } + return result; + } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -199,9 +199,10 @@ personToList.setHasVoted(true); } - // regnenerate poll results + // feed notification -// generatePollResult(pollToUpdate); + PollFeedService pollFeedService = newService(PollFeedService.class); + pollFeedService.onVoteAdded(pollToUpdate, result); commitTransaction("Could not create vote"); @@ -209,11 +210,6 @@ PreventRuleService preventRuleService = newService(PreventRuleService.class); preventRuleService.onVoteAdded(poll); - // feed notification - - PollFeedService pollFeedService = newService(PollFeedService.class); - pollFeedService.onVoteAdded(pollToUpdate, result); - return result; } @@ -263,14 +259,13 @@ log.debug("Entity updated: " + result.getTopiaId()); } -// generatePollResult(poll); - - commitTransaction("Could not update vote"); - // feed notification PollFeedService pollFeedService = newService(PollFeedService.class); pollFeedService.onVoteUpdated(poll, result); + + commitTransaction("Could not update vote"); + return result; } @@ -333,14 +328,12 @@ log.debug("Entity deleted: " + voteId); } -// generatePollResult(poll); - - commitTransaction("Could not delete vote"); - // feed notification - PollFeedService pollFeedService = newService(PollFeedService.class); pollFeedService.onVoteDeleted(poll, entityToDelete, voteAccount, reason); + + commitTransaction("Could not delete vote"); + } public List<Vote> getAllVotes(Poll poll) { Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -23,11 +23,10 @@ package org.chorem.pollen.ui.actions.poll; import com.google.common.base.Preconditions; +import org.apache.commons.io.IOUtils; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.ui.actions.PollenActionSupport; -import java.io.File; -import java.io.FileInputStream; import java.io.InputStream; /** @@ -65,11 +64,11 @@ Poll poll = getPollService().getExistingPollByPollId(pollId); - File feedLocation = getPollFeedService().getFeedLocation(poll); + String content = getPollFeedService().getFeed(poll); - contentLength = feedLocation.length(); + contentLength = content.length(); - inputStream = new FileInputStream(feedLocation); + inputStream = IOUtils.toInputStream(content); return SUCCESS; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -246,7 +246,8 @@ choicesById = Maps.uniqueIndex(poll.getChoice(), TopiaId.GET_TOPIA_ID); - feedFileExisting = getPollFeedService().isFeedExists(poll); + feedFileExisting = + getSecurityService().isCanShowFeed(getUserSecurityContext()); PollVoteCountingService voteCountingService = getService(PollVoteCountingService.class); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java 2012-10-01 10:52:00 UTC (rev 3718) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java 2012-10-01 11:32:38 UTC (rev 3719) @@ -441,7 +441,8 @@ comments = getPollCommentService().getAllComments(poll.getPollId()); } - feedFileExisting = getPollFeedService().isFeedExists(poll); + feedFileExisting = + getSecurityService().isCanShowFeed(getUserSecurityContext()); if (log.isDebugEnabled()) { Date now = serviceContext.getCurrentTime();
participants (1)
-
tchemit@users.chorem.org