Skip to content

Commit

Permalink
budgeting/assets//api: remove is_voting_phase from templatetags and a…
Browse files Browse the repository at this point in the history
…dd pass through api
  • Loading branch information
rine committed Nov 2, 2022
1 parent f624a17 commit 704cba6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
4 changes: 4 additions & 0 deletions meinberlin/apps/budgeting/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from adhocracy4.categories.models import Category
from adhocracy4.labels.models import Label
from adhocracy4.modules.predicates import module_is_between_phases
from adhocracy4.phases.predicates import has_feature_active
from meinberlin.apps.contrib.filters import IdeaCategoryFilterBackend
from meinberlin.apps.contrib.filters import OrderingFilterWithDailyRandom
from meinberlin.apps.contrib.templatetags.contrib_tags import \
Expand Down Expand Up @@ -185,6 +186,9 @@ def list(self, request, *args, **kwargs):
permissions['view_comment_count'] = (
self.module.has_feature('comment', Proposal)
)
permissions['view_vote_count'] = has_feature_active(
self.module, Proposal, 'vote'
)

response = super().list(request, args, kwargs)
response.data['permissions'] = permissions
Expand Down
2 changes: 1 addition & 1 deletion meinberlin/apps/budgeting/assets/BudgetingProposalList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const BudgetingProposalList = (props) => {

return (
<>
{(props.is_voting_phase && meta?.token_info) &&
{(meta?.permissions.view_vote_count && meta?.token_info) &&
<div className="module-content--light">
<div className="container">
<div className="offset-lg-3 col-lg-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { BrowserRouter } from 'react-router-dom'
const permissions = {
view_support_count: false,
view_rate_count: true,
view_comment_count: true
view_comment_count: true,
view_vote_count: true
}

test('Budgeting Proposal List without list item (empty)', async () => {
// mimicking fetch response with empty list
const mockedFetchEmpty = Promise.resolve({
json: () => Promise.resolve({ results: [] })
json: () => Promise.resolve({ results: [], permissions })
})

// overwrite global.fetch with mock function
Expand Down
6 changes: 0 additions & 6 deletions meinberlin/apps/budgeting/templatetags/react_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from django.urls import reverse
from django.utils.html import format_html

from adhocracy4.phases.predicates import has_feature_active
from meinberlin.apps.budgeting.models import Proposal

register = template.Library()


Expand All @@ -25,9 +22,6 @@ def react_proposals(context, module):

attributes = {'proposals_api_url': proposals_api_url,
'tokenvote_api_url': tokenvote_api_url,
'is_voting_phase': has_feature_active(module,
Proposal,
'vote')
}

return format_html(
Expand Down
10 changes: 1 addition & 9 deletions meinberlin/apps/budgeting/templatetags/react_proposals_vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from django.urls import reverse
from django.utils.html import format_html

from adhocracy4.phases.predicates import has_feature_active
from meinberlin.apps.budgeting.models import Proposal
from meinberlin.apps.votes.models import TokenVote
from meinberlin.apps.votes.models import VotingToken
from meinberlin.apps.votes.serializers import VotingTokenSerializer
Expand All @@ -16,8 +14,6 @@

@register.simple_tag(takes_context=True)
def react_proposals_vote(context, module, proposal):
proposals_api_url = reverse('proposals-list',
kwargs={'module_pk': module.pk})
proposal_ct = ContentType.objects.get(app_label='meinberlin_budgeting',
model='proposal')
tokenvote_api_url = reverse('tokenvotes-list',
Expand Down Expand Up @@ -45,11 +41,7 @@ def react_proposals_vote(context, module, proposal):
except VotingToken.DoesNotExist:
pass

attributes = {'proposals_api_url': proposals_api_url,
'tokenvote_api_url': tokenvote_api_url,
'is_voting_phase': has_feature_active(module,
Proposal,
'vote'),
attributes = {'tokenvote_api_url': tokenvote_api_url,
'objectID': proposal.pk,
'session_token_voted': session_token_voted,
'token_info': token_info
Expand Down

0 comments on commit 704cba6

Please sign in to comment.