Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Instance option to disable voting #648

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/adhocracy/controllers/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class InstanceVotingEditForm(formencode.Schema):
allow_extra_fields = True
allow_delegate = validators.StringBool(not_empty=False, if_empty=False,
if_missing=False)

voting_disabled = validators.StringBool(not_empty=False, if_empty=False,
if_missing=False)
if not config.get_bool('adhocracy.hide_final_adoption_votings'):
allow_adopt = validators.StringBool(not_empty=False, if_empty=False,
if_missing=False)
Expand Down Expand Up @@ -664,6 +667,7 @@ def settings_voting(self, id):
'activation_delay': c.page_instance.activation_delay,
'allow_adopt': c.page_instance.allow_adopt,
'allow_delegate': c.page_instance.allow_delegate,
'voting_disabled': c.page_instance.voting_disabled,
'_tok': csrf.token_id()}
if votedetail.is_enabled():
defaults['votedetail_badges'] = [
Expand All @@ -681,13 +685,19 @@ def settings_voting_update(self, id, format='html'):
c.page_instance = self._get_current_instance(id)
require.instance.edit(c.page_instance)

updated_attributes = ['allow_delegate']
old_voting_disabled = getattr(c.page_instance, 'voting_disabled')

updated_attributes = ['allow_delegate', 'voting_disabled']
if not config.get_bool('adhocracy.hide_final_adoption_votings'):
updated_attributes.extend(
['required_majority', 'activation_delay', 'allow_adopt'])
updated = update_attributes(
c.page_instance, self.form_result, updated_attributes)


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove all trailing whitespace

if old_voting_disabled != getattr(c.page_instance, 'voting_disabled'):
from adhocracy.lib.cache import invalidate_instance_polls
invalidate_instance_polls(c.page_instance)

if votedetail.is_enabled():
new_badges = self.form_result['votedetail_badges']
updated_vd = c.page_instance.votedetail_userbadges != new_badges
Expand Down
3 changes: 3 additions & 0 deletions src/adhocracy/controllers/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def rate(self, id, format):
# rating is like polling but steps via abstention, i.e. if you have
# first voted "for", rating will first go to "abstain" and only
# then produce "against"-
if c.instance.voting_disabled:
abort(403, _("Voting disabled."))

c.poll = self._get_open_poll(id)
if c.poll.action not in [model.Poll.RATE, model.Poll.SELECT]:
abort(400, _("This is not a rating poll."))
Expand Down
3 changes: 2 additions & 1 deletion src/adhocracy/lib/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from invalidate import (invalidate_user, invalidate_vote, invalidate_page,
invalidate_delegateable, invalidate_delegation,
invalidate_revision, invalidate_comment,
invalidate_poll, invalidate_tagging, invalidate_text,
invalidate_poll, invalidate_instance_polls,
invalidate_tagging, invalidate_text,
invalidate_selection, invalidate_badge,
invalidate_userbadges, invalidate_delegateablebadges,
invalidate_instance)
Expand Down
7 changes: 7 additions & 0 deletions src/adhocracy/lib/cache/invalidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def invalidate_poll(poll):
invalidate_comment(poll.subject)


def invalidate_instance_polls(instance):
# invalidates all polls of an instance
for deleg in instance.delegateables:
for poll in deleg.polls:
invalidate_poll(poll)


def invalidate_instance(instance):
# muharhar cache epic fail
clear_tag(instance)
Expand Down
13 changes: 13 additions & 0 deletions src/adhocracy/migration/versions/079_add_voting_disabled_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from sqlalchemy import MetaData, Table, Boolean, Column

from sqlalchemy import Integer


def upgrade(migrate_engine):
meta = MetaData(bind=migrate_engine)

instance_table = Table('instance', meta, autoload=True)
col = Column('voting_disabled', Boolean, nullable=False, default=False,
server_default="0")
col.create(instance_table)

1 change: 1 addition & 0 deletions src/adhocracy/model/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
Column('editable_comments_default', Boolean, nullable=True, default=True),
Column('editable_proposals_default', Boolean, nullable=True, default=True),
Column('require_valid_email', Boolean, nullable=True, default=True),
Column('voting_disabled', Boolean, nullable=True, default=False),
Column('allow_thumbnailbadges', Boolean, default=False),
Column('thumbnailbadges_height', Integer, nullable=True),
Column('thumbnailbadges_width', Integer, nullable=True),
Expand Down
2 changes: 2 additions & 0 deletions src/adhocracy/templates/comment/tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ <h5>${_("(deleted)")}</h5>
</span>
</h5>

%if not c.instance.voting_disabled:
<div class="vote_comment">
${tiles.poll.widget(comment.poll)}
</div>
%endif
</div>

## comment text
Expand Down
2 changes: 2 additions & 0 deletions src/adhocracy/templates/instance/settings_voting.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ <h2>${c.settings_menu.current['label']}</h2>
%endif

${forms.checkbox(_("Enable vote delegation"), 'allow_delegate', 15)}

${forms.checkbox(_("Disable voting"), 'voting_disabled', 20)}

%if c.votedetail_all_userbadges is not None:
<h4>${_('Break down Voting Result by Badge')}</h4>
Expand Down
3 changes: 3 additions & 0 deletions src/adhocracy/templates/poll/tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
con = tile.widget_action_attrs(model.Vote.NO)
%>
<div class="vote_wrapper">

%if not c.instance.voting_disabled:
<div id="${tile.html_id}" class="${tile.widget_class}">
%if tile.can_show:
<a href="${tile.votes_listing_url}" rel="#overlay-url" class="vote_count ${tile.count_class}"
Expand All @@ -32,6 +34,7 @@
%endif
>
</div>
%endif

%if delegate_url:
<span class="or">${_('or:')}</span>
Expand Down
2 changes: 2 additions & 0 deletions src/adhocracy/templates/proposal/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ <h6>${_('Last Activity')}</h6>

<% tally = c.proposal.rate_poll.tally %>

%if not c.instance.voting_disabled:
${sidebar_defs.votes(c.proposal.rate_poll)}
${sidebar_defs.votedetail(c.votedetail)}
%endif

<h6>${_('Category')}</h6>
<p>
Expand Down
4 changes: 4 additions & 0 deletions src/adhocracy/templates/proposal/tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ <h3><a class="link" href="${h.entity_url(proposal)}">${proposal.title}</a>
%endif
%endif
</h3>

%if not c.instance.voting_disabled:
<div class="meta">
%if proposal.is_adopt_polling():
${_("%s%% approval") % int(proposal.adopt_poll.tally.rel_for * 100)|n}
Expand All @@ -46,6 +48,8 @@ <h3><a class="link" href="${h.entity_url(proposal)}">${proposal.title}</a>
·
%endif
</div>
%endif

</div>
</li>
</%def>
Expand Down