Commit 4d66e2de authored by Cillian O'Ruanaidh's avatar Cillian O'Ruanaidh

On a multi-stakeholder proposal display a voting forbidden message if they…

On a multi-stakeholder proposal display a voting forbidden message if they haven't been assigned a stakeholder type yet.
parent 95a2fc15
AbilityService = require 'shared/services/ability_service.coffee'
Session = require 'shared/services/session'
AbilityService.canParticipateInPoll = (poll) ->
return false unless poll.isActive()
return false if @cannotParticipateInMultiStakeholderProposal(poll)
poll.anyoneCanParticipate or
@adminOf(poll) or
(@memberOf(poll) and (!poll.group() or poll.group().membersCanVote))
AbilityService.cannotParticipateInMultiStakeholderProposal = (poll) ->
return false if poll.pollType != "multi_stakeholder_proposal"
group = poll.group()
membership = Session.user().membershipFor(group)
count = 0
_.each group.stakeholderTypeMembershipOptions, (stakeholderTypeMembershipOption) ->
if stakeholderTypeMembershipOption.id == membership.id && stakeholderTypeMembershipOption.stakeholder_type_id?
count += 1
count == 0
......@@ -34,6 +34,7 @@ module Plugins
plugin.use_translations("config/locales", :loomio_multi_stakeholder_proposal)
plugin.use_asset_directory 'components/models'
plugin.use_asset_directory 'components/decorators'
plugin.use_component :poll_multi_stakeholder_proposal_form
plugin.use_component :poll_multi_stakeholder_proposal_chart
plugin.use_component :poll_multi_stakeholder_proposal_chart_preview
......@@ -250,22 +251,24 @@ module Plugins
end
plugin.extend_class StanceChoice do
before_validation :set_weighted_score
before_validation :set_multi_stakeholder_proposal_score
private
def membership_stakeholder_type_id
poll.group.memberships.find_by(user_id: stance.participant.id).stakeholder_type.id
poll.group.memberships.find_by(user_id: stance.participant.id).stakeholder_type.try(:id)
end
def set_weighted_score
if poll.multi_stakeholder_proposal?
self.score = weighted_score
def multi_stakeholder_proposal_score
if membership_stakeholder_type_id.present?
poll.stakeholder_types_stance_weights[membership_stakeholder_type_id.to_s] || 1
end
end
def weighted_score
poll.stakeholder_types_stance_weights[membership_stakeholder_type_id.to_s] || 1
def set_multi_stakeholder_proposal_score
if multi_stakeholder_proposal_score.present?
self.score = multi_stakeholder_proposal_score
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment