Skip to content

Commit 62fc946

Browse files
committed
feat(pv): implement canVote
1 parent 253104a commit 62fc946

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/posts/PollViewer.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@
132132
</template>
133133
<script>
134134
import humanDate from '@/composables/filters/humanDate'
135-
import { reactive, toRefs, watch } from 'vue'
135+
import { AuthStore } from '@/composables/stores/auth'
136+
import { reactive, toRefs, watch, inject } from 'vue'
136137
import { pollsApi } from '@/api'
137138
import { cloneDeep } from 'lodash'
138139
@@ -158,8 +159,14 @@ export default {
158159
return true
159160
}
160161
const canVote = () => {
161-
console.log('PollViewer canVote')
162-
return true
162+
if (!$auth.loggedIn) { return false }
163+
// TODO(boka): check for banned */
164+
// if ($scope.banned) { return false }
165+
else if (!v.permissionUtils.hasPermission('threads.vote.allow')) { return false }
166+
else if (v.pollCopy.has_voted) { return false }
167+
else if (v.pollCopy.locked) { return false }
168+
else if (v.pollCopy.expired) { return false }
169+
else { return true }
163170
}
164171
const canRemoveVote = () => {
165172
console.log('PollViewer canRemoveVote')
@@ -218,9 +225,12 @@ export default {
218225
v.options.display_mode = 'always';
219226
}
220227
}
228+
/* Internal Data */
229+
const $auth = inject(AuthStore)
221230
222231
/* View Data */
223232
const v = reactive({
233+
permissionUtils: $auth.permissionUtils,
224234
options: {
225235
expiration: props.poll.expiration || undefined,
226236
change_vote: props.poll.change_vote,

0 commit comments

Comments
 (0)