Civically Petition

Civically Petition



Description: Adds additional functionality to Discourse Voting, so it can be used to run petitions.

Status: Currently live on

The main change that the Civically Petitions Plugin makes to Discourse Voting is to add ‘Petition Controls’ and a ‘Petition Status’, which allows voting to be orientated around a threshold and for it to be finally ‘resolved’.

Adding controls and a threshold also allows other plugins to set up programmatic logic that run on the resolution of a petition.

For example the Civically Place Plugin sets up a ‘resolution’ for a petitions with the id ‘place’.

CivicallyPetition::Petition.add_resolution('place') do |topic, forced|
  status = topic.custom_fields['petition_status']
  result = {}

  if status === 'accepted'
    result = CivicallyPlace::Place.create(, forced)

    if result[:error]
      result[:message] = result[:error]

    if result[:category_id]
      category = Category.find(result[:category_id])
      result[:route_to] = category.url

  if status === 'rejected'
    topic.closed = true

This resolution automatically creates a new place if the petition is accepted, or closes the topic if it is rejected.

Generalisation Notes

This plugin is basically generalised in its current form. The main change that would need to be made would be removing the name ‘civically’ from various functions.