diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-05-26 19:07:37 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-03 19:27:05 +0200 |
commit | 301b1015f99f8e32a4843cf5bf0243409317e53e (patch) | |
tree | 48a2c46f294f424bf256b573e7369f1dd1999f41 /site/app | |
parent | Bot obtains voters, agenda items and voting options lists from webapp (diff) | |
download | council-webapp-301b1015f99f8e32a4843cf5bf0243409317e53e.tar.gz council-webapp-301b1015f99f8e32a4843cf5bf0243409317e53e.tar.bz2 council-webapp-301b1015f99f8e32a4843cf5bf0243409317e53e.zip |
Application receives data from IRC bot
Diffstat (limited to 'site/app')
-rw-r--r-- | site/app/controllers/agendas_controller.rb | 12 | ||||
-rw-r--r-- | site/app/models/agenda.rb | 13 |
2 files changed, 25 insertions, 0 deletions
diff --git a/site/app/controllers/agendas_controller.rb b/site/app/controllers/agendas_controller.rb index 0ee7ae0..ce84f1f 100644 --- a/site/app/controllers/agendas_controller.rb +++ b/site/app/controllers/agendas_controller.rb @@ -2,6 +2,7 @@ class AgendasController < ApplicationController hobo_model_controller + before_filter :authenticate_bot, :only => :results auto_actions :all def index @@ -11,4 +12,15 @@ class AgendasController < ApplicationController def current_items render :json => Agenda.current.voting_array end + + def results + Agenda.process_results JSON.parse(request.env["rack.input"].read) + end + + private + def authenticate_bot + authenticate_or_request_with_http_basic do |user_name, password| + user_name == CustomConfig['Bot']['user'] && password == CustomConfig['Bot']['password'] + end + end end diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index ed8e385..44386e3 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -62,6 +62,19 @@ class Agenda < ActiveRecord::Base false end + def self.process_results(results) + a = Agenda.current + for item_title in results.keys + i = AgendaItem.first :conditions => { :agenda_id => a, :title => item_title } + votes = results[item_title] + for voter in votes.keys + o = VotingOption.first :conditions => { :agenda_item_id => i.id, :description => votes[voter] } + u = ::User.find_by_irc_nick voter + Vote.create! :voting_option => o, :user => u + end + end + end + def possible_transitions transitions = case state when 'open' |