Fixed display of poll participants for guests
authorAlexander Ebert <ebert@woltlab.com>
Wed, 7 Aug 2013 14:28:07 +0000 (16:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 7 Aug 2013 14:28:07 +0000 (16:28 +0200)
com.woltlab.wcf/templates/poll.tpl
wcfsetup/install/files/lib/data/poll/Poll.class.php
wcfsetup/install/files/lib/data/poll/PollAction.class.php

index d33fbf93ea9528b69abf0d83228edec23f88bb0d..ef272e2c2315ecca35eea517762e5ceed473ebcc 100644 (file)
@@ -1,4 +1,4 @@
-{if $__wcf->getUser()->userID && !$__pollLoadedJavaScript|isset}
+{if ($__wcf->getUser()->userID || $poll->canSeeResult() || $poll->canViewParticipants()) && !$__pollLoadedJavaScript|isset}
        {assign var=__pollLoadedJavaScript value=true}
        <script data-relocate="true" src="{@$__wcf->getPath()}js/WCF.Poll{if !ENABLE_DEBUG_MODE}.min{/if}.js?v={@$__wcfVersion}"></script>
        <script data-relocate="true">
@@ -10,7 +10,7 @@
        </script>
 {/if}
 
-<div class="container containerPadding pollContainer" data-poll-id="{@$poll->pollID}" data-can-vote="{if $poll->canVote()}1{else}0{/if}" data-can-view-result="{if $poll->canSeeResult()}1{else}0{/if}" data-can-view-participants="{if $poll->isPublic}true{else}false{/if}" data-in-vote="{if $poll->canVote() && !$poll->isParticipant()}1{else}0{/if}" data-question="{$poll->question}" data-max-votes="{@$poll->maxVotes}">
+<div class="container containerPadding pollContainer" data-poll-id="{@$poll->pollID}" data-can-vote="{if $poll->canVote()}1{else}0{/if}" data-can-view-result="{if $poll->canSeeResult()}1{else}0{/if}" data-can-view-participants="{if $poll->canViewParticipants()}true{else}false{/if}" data-in-vote="{if $poll->canVote() && !$poll->isParticipant()}1{else}0{/if}" data-question="{$poll->question}" data-max-votes="{@$poll->maxVotes}">
        <fieldset>
                <legend>{$poll->question} <span class="badge jsTooltip" title="{lang}wcf.poll.totalVotes{/lang}">{#$poll->votes}</span></legend>
                
                </div>
        </fieldset>
        
-       {if $__wcf->getUser()->userID}
+       {hascontent}
                <div class="formSubmit jsOnly">
-                       <button class="small jsButtonPollVote">{lang}wcf.poll.button.vote{/lang}</button>
-                       <button class="small jsButtonPollShowVote">{lang}wcf.poll.button.showVote{/lang}</button>
-                       <button class="small jsButtonPollShowResult">{lang}wcf.poll.button.showResult{/lang}</button>
-                       <button class="small jsButtonPollShowParticipants">{lang}wcf.poll.button.showParticipants{/lang}</button>
-                       {event name='pollButtons'}
+                       {content}
+                               {if $__wcf->getUser()->userID}
+                                       <button class="small jsButtonPollVote">{lang}wcf.poll.button.vote{/lang}</button>
+                                       <button class="small jsButtonPollShowVote">{lang}wcf.poll.button.showVote{/lang}</button>
+                                       <button class="small jsButtonPollShowResult">{lang}wcf.poll.button.showResult{/lang}</button>
+                               {/if}
+                               {if $poll->canViewParticipants()}
+                                       <button class="small jsButtonPollShowParticipants">{lang}wcf.poll.button.showParticipants{/lang}</button>
+                               {/if}
+                               
+                               {event name='pollButtons'}
+                       {/content}
                </div>
-       {/if}
+       {/hascontent}
 </div>
\ No newline at end of file
index 1f2791a3361f6f4ddfe5b52c1e420861437230be..71a63723a6ffafaa7c1161d9001186512de49378 100644 (file)
@@ -165,6 +165,19 @@ class Poll extends DatabaseObject {
                return false;
        }
        
+       /**
+        * Returns true if current user can view the participant list.
+        * 
+        * @return      boolean
+        */
+       public function canViewParticipants() {
+               if ($this->canSeeResult() && $this->isPublic) {
+                       return true;
+               }
+               
+               return false;
+       }
+       
        /**
         * Sets related object for this poll.
         * 
index 6e7049ed51cc1b52c92b7f019b4f0f576159710a..437a97c02368d89add8959d514cf3f2ed1b6fcac 100644 (file)
@@ -19,6 +19,11 @@ use wcf\system\WCF;
  * @category   Community Framework
  */
 class PollAction extends AbstractDatabaseObjectAction implements IGroupedUserListAction {
+       /**
+        * @see wcf\data\AbstractDatabaseObjectAction::$allowGuestAccess
+        */
+       protected $allowGuestAccess = array('getGroupedUserList');
+       
        /**
         * @see wcf\data\AbstractDatabaseObjectAction::$className
         */
@@ -245,7 +250,7 @@ class PollAction extends AbstractDatabaseObjectAction implements IGroupedUserLis
                if (!$this->poll->pollID) {
                        throw new UserInputException('pollID');
                }
-               else if (!$this->poll->isPublic || !$this->poll->canSeeResult()) {
+               else if (!$this->poll->canViewParticipants()) {
                        throw new PermissionDeniedException();
                }
        }