Skip to content

Commit

Permalink
Merge pull request #210 from ciudadanointeligente/master
Browse files Browse the repository at this point in the history
Merge 'master' to 'testing' branch
  • Loading branch information
rezzo committed Apr 21, 2014
2 parents 1b2e0ca + 67dc17a commit c1cd622
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 114 deletions.
7 changes: 4 additions & 3 deletions Gemfile
Expand Up @@ -50,8 +50,9 @@ gem 'route_translator'
gem 'actionpack-page_caching'
gem 'actionpack-action_caching'

# Clean ruby syntax for writing and deploying cron jobs
gem 'whenever', :require => false
# Clean ruby syntax for writing and deploying cron jobs (for rvm)
gem 'whenever', :git => 'https://github.com/Insomniware/whenever.git', :require => false
#gem 'whenever', :require => false #for non rvm

group :production do
gem 'mysql'
Expand Down Expand Up @@ -82,7 +83,7 @@ end
gem 'roar', '0.11.19'
gem 'roar-rails', '0.1.0'
gem 'faraday', '0.8.1'
gem 'billit_representers', '0.9.0'
gem 'billit_representers', '0.9.3'
gem 'popit_representers', '0.0.15'
gem 'writeit-rails', :git => 'git://github.com/ciudadanointeligente/writeit-rails.git'

Expand Down
21 changes: 12 additions & 9 deletions Gemfile.lock
Expand Up @@ -16,6 +16,14 @@ GIT
railties (>= 3.2.6, < 5)
warden (~> 1.2.1)

GIT
remote: https://github.com/Insomniware/whenever.git
revision: 957a332fba539c5128fda08777d772e1060cfb3c
specs:
whenever (0.8.4)
activesupport (>= 2.3.4)
chronic (>= 0.6.3)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -49,14 +57,13 @@ GEM
tzinfo (~> 0.3.37)
addressable (2.3.6)
arel (4.0.2)
atomic (1.1.16)
bcrypt (3.1.7)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
billit_representers (0.9.0)
billit_representers (0.9.3)
activemodel
roar (= 0.11.19)
roar-rails (= 0.1.0)
Expand Down Expand Up @@ -261,8 +268,7 @@ GEM
eventmachine (>= 1.0.0)
rack (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.1)
atomic (>= 1.1.7, < 2)
thread_safe (0.3.3)
tilt (1.4.1)
timers (1.1.0)
tins (1.0.1)
Expand All @@ -281,9 +287,6 @@ GEM
webmock (1.17.4)
addressable (>= 2.2.7)
crack (>= 0.3.2)
whenever (0.9.2)
activesupport (>= 2.3.4)
chronic (>= 0.6.3)

PLATFORMS
ruby
Expand All @@ -293,7 +296,7 @@ DEPENDENCIES
actionpack-page_caching
bcrypt-ruby
better_errors
billit_representers (= 0.9.0)
billit_representers (= 0.9.3)
binding_of_caller
coffee-rails (~> 4.0.0)
coveralls
Expand Down Expand Up @@ -329,5 +332,5 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
webmock
whenever
whenever!
writeit-rails!
117 changes: 71 additions & 46 deletions README.md
@@ -1,4 +1,4 @@
# Legislative
# Legislative: A Monitoring Platform
[![Build Status](https://travis-ci.org/ciudadanointeligente/legislative.png?branch=master)](https://travis-ci.org/ciudadanointeligente/legislative)
[![Coverage Status](https://coveralls.io/repos/ciudadanointeligente/legislative/badge.png)](https://coveralls.io/r/ciudadanointeligente/legislative)
[![Code Climate](https://codeclimate.com/github/ciudadanointeligente/legislative.png)](https://codeclimate.com/github/ciudadanointeligente/legislative)
Expand All @@ -7,73 +7,98 @@

Legislative is a channel of participation and seeks to bring information to the public what is happening to our Congress. Built using POPLUS environment.

## Dependencies

Make sure you're using ruby 2.0 or above (we highly recommend using [rvm](http://rvm.io/)), and that [bundler](http://bundler.io/) is installed.

## System requirements

The following system requirements are also needed, for image manipulation:

Red Hat / Fedora / CentOS

yum install ImageMagick-devel

Debian / Ubuntu (for 13.04 also install `libmagickwand-dev`)

apt-get install imagemagick

OS X

brew update
brew install ImageMagick
gem install rmagick

## Quick start

Clone the git repo - `git clone https://github.com/ciudadanointeligente/legislative.git` - or [download it](https://github.com/ciudadanointeligente/legislative/zipball/master)

Go to your legislative folder and run install
<pre>
sh setup.sh
</pre>

sh setup.sh

Create the config files

cp config/database.yml.example config/database.yml

Then run your server
<pre>
rails s
</pre>

rails s

Check at [http://localhost:3000](http://localhost:3000)

You can try loggin in with `admin@ciudadanointeligente.org / benito`

## System requirements

The following system requirements are also needed, for image manipulation:
### Deploying to production

Red Hat / Fedora
<pre>
yum install ImageMagick-devel
</pre>
This section will not be relevant to most people. It will however be relevant if you're deploying to a production server.

Debian / Ubuntu
<pre>
apt-get install imagemagick
</pre>
#### Production environment

for Ubuntu 13.04 also install
<pre>
apt-get install libmagickwand-dev
</pre>
Create the follow config files.

for OSX
<pre>
brew update
</pre>
<pre>
brew uninstall ImageMagick
</pre>
<pre>
brew install ImageMagick
</pre>
<pre>
gem uninstall rmagick
</pre>
<pre>
gem install rmagick
</pre>
cp config/newrelic.yml.example config/newrelic.yml
cp config/schedule.rb.example config/schedule.rb
cp config/private_legislative.yml.example config/private_legislative.yml

#### Deploy

We recommend the follow commands in the job for automatic deploy and the use of [phusion passenger](https://www.phusionpassenger.com/) as web server and application server with apache or nginx in production.

bundle install
rake db:migrate
rake tmp:cache:clear
rake assets:clean
rake assets:precompile

#### Tasks using cron

The following system requirements are also needed, for database
To run tasks like send notifications emails of changes in bills the project use [whenever](https://github.com/javan/whenever), this tool generate cron jobs from the `config/schedule.rb` file.

Add the jobs to crontab:

bundle exec whenever --update-crontab legislative

Clear the jobs associated with a app name:

bundle exec whenever --clear-crontab legislative

#### MariaDB

For improve the performance in production is a good idea change the db engine from sqlite3 to mariaDB or postgreSQL. To use mariaDB you need edit `config/database.yml` config file.

Red Hat / Fedora / CentOS
<pre>
sudo yum install mariadb-server mariadb-devel
</pre>

Debian / Ubuntu / Mint
<pre>
sudo apt-get install mariadb-server libmariadbd-dev
</pre>
yum install mariadb-server mariadb-devel

Debian / Ubuntu

apt-get install mariadb-server libmariadbd-dev

OS X

and then, you need config your config/database.yml file
brew install mariadb

## Features

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bills_controller.rb
Expand Up @@ -3,7 +3,7 @@
require 'billit_representers/models/bill_basic'
require './app/models/bill'
require './app/models/bill_basic'
require './app/models/paperwork'
require './app/models/billit_paperwork'

class BillsController < ApplicationController
include Roar::Rails::ControllerAdditions
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/mains_controller.rb
Expand Up @@ -14,7 +14,7 @@ def index
@high_chamber_agenda[0] = get_current_chamber_agenda ENV['high_chamber_name']
@high_chamber_agenda[1] = get_bills_per_agenda JSON.parse(@high_chamber_agenda[0]['bill_list']).uniq

@hot_bills = Billit::BillPage.get(ENV['billit_url'] + "search?current_urgency=Simple&per_page=8", 'application/json').bills
@hot_bills = Billit::BillPage.get(ENV['billit_url'] + URI::escape("search?current_priority=Discusión%20inmediata|Suma|Simple&per_page=8"), 'application/json').bills

@answers = LegislativeAnswerCollection.get()
if @answers.objects.length > 2
Expand Down
21 changes: 1 addition & 20 deletions app/controllers/notifiers_controller.rb
Expand Up @@ -7,29 +7,15 @@ def index
render json: Notifier.all
end

def run_tasks
# It runs all the tasks according to notify users with updates on bills
last_notification = params[:date]
@bills = bills_updated(last_notification)
@bills.each do |bill|
@user_id_subscriptions = get_user_id_subscriptions(bill)
build(bill, @user_id_subscriptions)
end
send_notifies
end

private

def bills_updated(last_notification)
# Returns a list of bills updated since last_notification
@paperworks_updated_collection = Billit::PaperworkCollection.get(ENV['paperworks_url'] + 'search.json?date_min=' + last_notification, 'application/json')
@paperworks_updated_collection = BillitPaperworkCollection.get(ENV['paperworks_url'] + 'search.json?date_min=' + last_notification, 'application/json')
@paperworks_updated = @paperworks_updated_collection.paperworks
@bills_updated = @paperworks_updated.map { |paperwork| paperwork.bill_uid }
@bills_updated.uniq!
@bills_updated
end


def get_user_id_subscriptions(bill)
# Given a bill, returns all the user_id_subscriptions subscribed to that bill that have confirmed.
@bill = bill
Expand All @@ -38,7 +24,6 @@ def get_user_id_subscriptions(bill)
@users_id_subscribed
end


def build(bill, users_id_subscribed)
# It creates or updates notifiers
@bill = bill
Expand Down Expand Up @@ -71,9 +56,5 @@ def send_notifies
# Remove notify from database
Notifier.delete_all(["user_id = ?", notify.user_id])
end

flash[:notice] = 'Notificaciones Enviadas!'
redirect_to ""
end

end
20 changes: 14 additions & 6 deletions app/controllers/user_subscriptions_controller.rb
Expand Up @@ -80,8 +80,12 @@ def confirmed
@user_subscription = UserSubscription.find_by_email_token(params[:email_token])
@user_subscription.confirmed = true
@user_subscription.save
flash[:notice] = t('user_subscriptions.verified_mail')
redirect_to bill_path(@user_subscription.bill)
if params[:ajax] == false
flash[:notice] = t('user_subscriptions.verified_mail')
redirect_to bill_path(@user_subscription.bill)
else
render :nothing => true, :status => 200, :content_type => 'text/html'
end
end

# PATCH/PUT /user_subscriptions/1
Expand All @@ -94,10 +98,14 @@ def update
end

# DELETE /user_subscriptions/1
# def destroy
# @user_subscription.destroy
# redirect_to user_subscriptions_url, notice: 'User subscription was successfully destroyed.'
# end
def destroy
@user_subscription.destroy
if params[:ajax] == false
redirect_to user_subscriptions_url, notice: 'User subscription was successfully destroyed.'
else
render :nothing => true, :status => 200, :content_type => 'text/html'
end
end

# # DELETE /user_subscription?user_id=1
# def unsubscribe_all
Expand Down
17 changes: 10 additions & 7 deletions app/controllers/users_controller.rb
Expand Up @@ -5,21 +5,24 @@ def new
end

def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
format.json{ render :json => @users }
end
#@users = User.all
#respond_to do |format|
# format.html # index.html.erb
# format.xml { render :xml => @users }
# format.json{ render :json => @users }
#end
redirect_to root_url
end

def show
@user = User.find_by_id(params[:id])
email = Base64.decode64(params[:id])
@user = User.find_by_email(email)

# If user not found
if @user.nil?
redirect_to users_path , :notice => t('users.user_not_found')
else
@bills_subscriptions = UserSubscription.where('user = ' + @user.id.to_s)
respond_to do |format|
format.html
format.xml { render :xml => @user }
Expand Down
2 changes: 1 addition & 1 deletion app/models/paperwork.rb → app/models/billit_paperwork.rb
@@ -1,4 +1,4 @@
class Billit::Paperwork
class BillitPaperwork
def icon_event
case self.timeline_status
when "Ingreso"
Expand Down

0 comments on commit c1cd622

Please sign in to comment.