Civically Petition

Civically Petition
0

#1

Repo: https://github.com/CivicallyHQ/civically-petition

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

Status: Currently live on civically.io.

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(topic.id, forced)

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

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

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

  topic.save!
  result
end

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.