From 5e31a9f3384e796878a6cffa8fee2c43953b64a7 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 24 Aug 2015 14:34:58 +0200 Subject: [PATCH 01/49] adds a new "organization sigup success" view. Related with #226 --- .../organizations/registrations_controller.rb | 8 ++++++++ app/views/organizations/registrations/success.html.erb | 8 ++++++++ config/locales/devise_views.en.yml | 9 +++++++++ config/locales/devise_views.es.yml | 8 ++++++++ config/routes.rb | 9 +++++++-- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 app/views/organizations/registrations/success.html.erb diff --git a/app/controllers/organizations/registrations_controller.rb b/app/controllers/organizations/registrations_controller.rb index 8602ba4ba..630cc64e4 100644 --- a/app/controllers/organizations/registrations_controller.rb +++ b/app/controllers/organizations/registrations_controller.rb @@ -5,6 +5,9 @@ class Organizations::RegistrationsController < Devise::RegistrationsController end end + def success + end + def create build_resource(sign_up_params) if resource.valid_with_captcha? @@ -17,6 +20,11 @@ class Organizations::RegistrationsController < Devise::RegistrationsController end end + protected + def after_inactive_sign_up_path_for(resource) + organizations_sign_up_success_path + end + private def sign_up_params diff --git a/app/views/organizations/registrations/success.html.erb b/app/views/organizations/registrations/success.html.erb new file mode 100644 index 000000000..91c377102 --- /dev/null +++ b/app/views/organizations/registrations/success.html.erb @@ -0,0 +1,8 @@ +

<%= t('devise_views.organizations.registrations.success.title') %>

+ +

<%= t('devise_views.organizations.registrations.success.thank_you') %>

+ +

<%= t('devise_views.organizations.registrations.success.instructions') %>

+ +

<%= link_to t('devise_views.organizations.registrations.success.back_to_index'), root_path %>

+ diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index e1b2a571d..394c3611c 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -66,6 +66,15 @@ en: phone_number_label: "Phone number" password_confirmation_label: "Confirm password" submit: "Sign up" + success: + title: "Registration of organization / collective pending verification" + thank_you: "Thank you for registering your organization or collective in the website." + instructions: + We will contact you soon in order to verify that you represent your collective. + Meanwhile, please review your email. We have sent you a confirmation link which you + will have to click in order to activate your account. You will then be able to participate + as a non-verified organization. + back_to_index: "Ok, go back to index" sessions: new: title: "Log in" diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index 7ed5298de..e27065038 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -66,6 +66,14 @@ es: phone_number_label: "Teléfono" password_confirmation_label: "Confirmar contraseña" submit: "Registrarse" + success: + title: "Registro de organización / colectivo pendiente de verificación" + thank_you: "Gracias por registrar tu colectivo en la web." + instructions: + En breve nos pondremos en contacto contigo para verificar que realmente representas a un colectivo. + Entretanto, por favor revisa tu correo electrónico. Te hemos enviado un enlace que debes pulsar para confirmar + tu correo. Una vez confirmado, podrás empezar a participar como colectivo no verificado. + back_to_index: "Entendido, volver a la página principal" sessions: new: title: "Entrar" diff --git a/config/routes.rb b/config/routes.rb index f224609b9..d55068aab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,15 @@ Rails.application.routes.draw do devise_for :users, controllers: { registrations: 'users/registrations' } - devise_for :organizations, class_name: 'User', + devise_for(:organizations, class_name: 'User', controllers: { registrations: 'organizations/registrations', sessions: 'devise/sessions' - } + }) + + devise_scope :organization do + get "organizations/sign_up/success", to: "organizations/registrations#success" + end + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From 88eb8a6cc463879b02efc57a281264afe878590e Mon Sep 17 00:00:00 2001 From: David Gil Date: Mon, 24 Aug 2015 17:14:45 +0200 Subject: [PATCH 02/49] adds omniauth and omniauth-twitter gems and initializer with references to secrets --- Gemfile | 5 +++++ Gemfile.lock | 13 +++++++++++++ config/deploy/shared/secrets.yml.erb | 5 ++++- config/initializers/omniauth.rb | 4 ++++ config/secrets.yml.example | 8 +++++++- 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 config/initializers/omniauth.rb diff --git a/Gemfile b/Gemfile index f1b251db4..95ce82135 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,11 @@ gem 'turbolinks' gem 'devise' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' +gem 'omniauth' +gem 'omniauth-twitter' +# gem 'omniauth-facebook' +# gem 'omniauth-google-oauth2' + gem 'kaminari' gem 'acts_as_commentable_with_threading' gem 'acts-as-taggable-on' diff --git a/Gemfile.lock b/Gemfile.lock index deed6bc4f..d1a5ece7b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -150,6 +150,7 @@ GEM activesupport (>= 4.1.0) groupdate (2.4.0) activesupport (>= 3) + hashie (3.4.2) highline (1.7.3) http-cookie (1.0.2) domain_name (~> 0.5) @@ -195,6 +196,16 @@ GEM netrc (0.10.3) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) + oauth (0.4.7) + omniauth (1.2.2) + hashie (>= 1.2, < 4) + rack (~> 1.0) + omniauth-oauth (1.1.0) + oauth + omniauth (~> 1.0) + omniauth-twitter (1.2.1) + json (~> 1.3) + omniauth-oauth (~> 1.1) orm_adapter (0.5.0) paranoia (2.1.3) activerecord (~> 4.0) @@ -362,6 +373,8 @@ DEPENDENCIES kaminari launchy letter_opener_web (~> 1.3.0) + omniauth + omniauth-twitter paranoia pg poltergeist diff --git a/config/deploy/shared/secrets.yml.erb b/config/deploy/shared/secrets.yml.erb index a1cc29fb8..9a6582afb 100644 --- a/config/deploy/shared/secrets.yml.erb +++ b/config/deploy/shared/secrets.yml.erb @@ -2,4 +2,7 @@ recaptcha_public_key: <%= ENV["MADRID_RECAPTCHA_PUBLIC_KEY"] %> recaptcha_private_key: <%= ENV["MADRID_RECAPTCHA_PRIVATE_KEY"] %> secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> - server_name: <%= fetch(:server_name) %> \ No newline at end of file + twitter_key: <%= ENV["TWITTER_KEY"] %> + twitter_secret: <%= ENV["TWITTER_SECRET"] %> + server_name: <%= fetch(:server_name) %> + diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 000000000..42e97b02f --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,4 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :developer unless Rails.env.production? + provider :twitter, Rails.application.secrets.twitter_key, Rails.application.secrets.twitter_secret +end diff --git a/config/secrets.yml.example b/config/secrets.yml.example index f4ad98027..72c7a6d64 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -14,12 +14,18 @@ default: &default development: secret_key_base: 56792feef405a59b18ea7db57b4777e855103882b926413d4afdfb8c0ea8aa86ea6649da4e729c5f5ae324c0ab9338f789174cf48c544173bc18fdc3b14262e4 + twitter_key: AAAA + twitter_secret: BBBB <<: *default test: secret_key_base: 4d5adf961ddd27aef19622d6c0b3234d555f9ee003f022b1f829c92bbe33aaee907be7feb67bd54c14a1a32512fa968565ad405971fbc41bd0797af73c26a796 + twitter_key: AAAA + twitter_secret: BBBB <<: *default production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> - <<: *default \ No newline at end of file + twitter_key: <%= ENV["TWITTER_KEY"] %> + twitter_secret: <%= ENV["TWITTER_SECRET"] %> + <<: *default From f0e47ee78779128abb8afc4d9c48579ceb520827 Mon Sep 17 00:00:00 2001 From: David Gil Date: Mon, 24 Aug 2015 19:42:51 +0200 Subject: [PATCH 03/49] adds Identity model and migration --- app/models/identity.rb | 10 ++++++++++ .../20150824144524_create_identities.rb | 11 ++++++++++ db/schema.rb | 17 +++++++++++++--- spec/factories.rb | 7 ++++++- spec/models/identity_spec.rb | 9 +++++++++ spec/models/user_spec.rb | 20 +++++++++++++++++++ 6 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 app/models/identity.rb create mode 100644 db/migrate/20150824144524_create_identities.rb create mode 100644 spec/models/identity_spec.rb diff --git a/app/models/identity.rb b/app/models/identity.rb new file mode 100644 index 000000000..e0778dfae --- /dev/null +++ b/app/models/identity.rb @@ -0,0 +1,10 @@ +class Identity < ActiveRecord::Base + belongs_to :user + + validates :provider, presence: true + validates :uid, presence: true, uniqueness: { scope: :provider } + + def self.find_for_oauth(auth) + where(uid: auth.uid, provider: auth.provider).first_or_create + end +end diff --git a/db/migrate/20150824144524_create_identities.rb b/db/migrate/20150824144524_create_identities.rb new file mode 100644 index 000000000..38a5e603a --- /dev/null +++ b/db/migrate/20150824144524_create_identities.rb @@ -0,0 +1,11 @@ +class CreateIdentities < ActiveRecord::Migration + def change + create_table :identities do |t| + t.references :user, index: true, foreign_key: true + t.string :provider + t.string :uid + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 12e457a1c..d21459719 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150824113326) do +ActiveRecord::Schema.define(version: 20150824144524) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -66,8 +66,8 @@ ActiveRecord::Schema.define(version: 20150824113326) do t.integer "author_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.datetime "hidden_at" t.string "visit_id" + t.datetime "hidden_at" t.datetime "flagged_as_inappropiate_at" t.integer "inappropiate_flags_count", default: 0 t.datetime "reviewed_at" @@ -75,6 +75,16 @@ ActiveRecord::Schema.define(version: 20150824113326) do add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree + create_table "identities", force: :cascade do |t| + t.integer "user_id" + t.string "provider" + t.string "uid" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree + create_table "inappropiate_flags", force: :cascade do |t| t.integer "user_id" t.string "flaggable_type" @@ -156,10 +166,10 @@ ActiveRecord::Schema.define(version: 20150824113326) do t.string "unconfirmed_email" t.boolean "email_on_debate_comment", default: false t.boolean "email_on_comment_reply", default: false + t.string "phone_number", limit: 30 t.string "official_position" t.integer "official_level", default: 0 t.datetime "hidden_at" - t.string "phone_number", limit: 30 t.string "username" end @@ -214,6 +224,7 @@ ActiveRecord::Schema.define(version: 20150824113326) do add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree add_foreign_key "administrators", "users" + add_foreign_key "identities", "users" add_foreign_key "inappropiate_flags", "users" add_foreign_key "moderators", "users" add_foreign_key "organizations", "users" diff --git a/spec/factories.rb b/spec/factories.rb index 038a0102e..4fa2a70e3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,5 +1,4 @@ FactoryGirl.define do - factory :user do username 'Manuela' sequence(:email) { |n| "manuela#{n}@madrid.es" } @@ -7,6 +6,12 @@ FactoryGirl.define do confirmed_at { Time.now } end + factory :identity do + user nil + provider "Twitter" + uid "MyString" + end + factory :debate do sequence(:title) { |n| "Debate #{n} title" } description 'Debate description' diff --git a/spec/models/identity_spec.rb b/spec/models/identity_spec.rb new file mode 100644 index 000000000..82d5c4be3 --- /dev/null +++ b/spec/models/identity_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Identity, type: :model do + let(:identity) { build(:identity) } + + it "should be valid" do + expect(identity).to be_valid + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5a4bbdf88..e0260285a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -50,6 +50,26 @@ describe User do end end + describe 'OmniAuth' do + describe '#email_provided?' do + it "is false if the email matchs was temporarely assigned by the OmniAuth process" do + subject.email = 'omniauth@participacion-ABCD-twitter.com' + expect(subject.email_provided?).to eq(false) + end + + it "is true if the email is not omniauth-like" do + subject.email = 'manuelacarmena@example.com' + expect(subject.email_provided?).to eq(true) + end + + it "is true if the user's real email is pending to be confirmed" do + subject.email = 'omniauth@participacion-ABCD-twitter.com' + subject.unconfirmed_email = 'manuelacarmena@example.com' + expect(subject.email_provided?).to eq(true) + end + end + end + describe "administrator?" do it "is false when the user is not an admin" do expect(subject.administrator?).to be false From 158e20393692bd2726794c83a95206a3cf7f02a3 Mon Sep 17 00:00:00 2001 From: David Gil Date: Mon, 24 Aug 2015 19:44:46 +0200 Subject: [PATCH 04/49] adds omniauth basic authentication process with Twitter, including an intermediate step to ask the user for her email if not provided by the OAuth provider - Twitter, for instance --- app/controllers/application_controller.rb | 11 ++++ .../users/omniauth_callbacks_controller.rb | 30 ++++++++++ .../users/registrations_controller.rb | 15 +++++ app/models/user.rb | 55 ++++++++++++++++++- app/views/devise/_omniauth_form.html.erb | 5 ++ app/views/devise/menu/_login_items.html.erb | 14 ++--- app/views/devise/passwords/new.html.erb | 2 +- app/views/devise/sessions/new.html.erb | 4 +- .../registrations/finish_signup.html.erb | 13 +++++ app/views/users/registrations/new.html.erb | 3 + config/initializers/devise.rb | 1 + config/initializers/omniauth.rb | 4 -- config/locales/devise.es.yml | 2 +- config/locales/en.yml | 6 ++ config/locales/es.yml | 6 ++ config/routes.rb | 15 ++++- 16 files changed, 167 insertions(+), 19 deletions(-) create mode 100644 app/controllers/users/omniauth_callbacks_controller.rb create mode 100644 app/views/devise/_omniauth_form.html.erb create mode 100644 app/views/users/registrations/finish_signup.html.erb delete mode 100644 config/initializers/omniauth.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b879a4a8d..802dda3bc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,6 +13,8 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + before_action :ensure_signup_complete + rescue_from CanCan::AccessDenied do |exception| redirect_to main_app.root_url, alert: exception.message end @@ -40,4 +42,13 @@ class ApplicationController < ActionController::Base def set_debate_votes(debates) @voted_values = current_user ? current_user.debate_votes(debates) : {} end + + def ensure_signup_complete + # Ensure we don't go into an infinite loop + return if action_name.in? %w(finish_signup do_finish_signup) + + if user_signed_in? && !current_user.email_provided? + redirect_to finish_signup_path + end + end end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb new file mode 100644 index 000000000..aac6583d1 --- /dev/null +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -0,0 +1,30 @@ +class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController + def self.provides_callback_for(provider) + class_eval %Q{ + def #{provider} + @user = User.find_for_oauth(env["omniauth.auth"], current_user) + + if @user.persisted? + sign_in_and_redirect @user, event: :authentication + set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format? + else + session["devise.#{provider}_data"] = env["omniauth.auth"] + redirect_to new_user_registration_url + end + end + } + end + + # [:twitter, :facebook, :google_oauth2].each do |provider| + [:twitter].each do |provider| + provides_callback_for provider + end + + def after_sign_in_path_for(resource) + if resource.email_provided? + super(resource) + else + finish_signup_path + end + end +end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 0ef0ba638..d1fc54aab 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,4 +1,5 @@ class Users::RegistrationsController < Devise::RegistrationsController + prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy, :finish_signup, :do_finish_signup] def create build_resource(sign_up_params) @@ -9,6 +10,20 @@ class Users::RegistrationsController < Devise::RegistrationsController end end + def finish_signup + end + + def do_finish_signup + if current_user.update(sign_up_params) + current_user.skip_reconfirmation! + sign_in(current_user, bypass: true) + redirect_to root_url, notice: I18n.t('devise.registrations.updated') + else + @show_errors = true + render :finish_signup + end + end + private def sign_up_params diff --git a/app/models/user.rb b/app/models/user.rb index 544142c2f..4a1839b34 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,8 +1,12 @@ class User < ActiveRecord::Base include ActsAsParanoidAliases + + OMNIAUTH_EMAIL_PREFIX = 'omniauth@participacion' + OMNIAUTH_EMAIL_REGEX = /\A#{OMNIAUTH_EMAIL_PREFIX}/ + apply_simple_captcha devise :database_authenticatable, :registerable, :confirmable, - :recoverable, :rememberable, :trackable, :validatable + :recoverable, :rememberable, :trackable, :validatable, :omniauthable acts_as_voter acts_as_paranoid column: :hidden_at @@ -11,9 +15,11 @@ class User < ActiveRecord::Base has_one :moderator has_one :organization has_many :inappropiate_flags + has_many :identities, dependent: :destroy - validates :username, presence: true, unless: :organization? + validates :username, presence: true, unless: :organization? validates :official_level, inclusion: {in: 0..5} + validates_format_of :email, without: OMNIAUTH_EMAIL_REGEX, on: :update validates_associated :organization, message: false @@ -25,6 +31,47 @@ class User < ActiveRecord::Base scope :organizations, -> { joins(:organization) } scope :officials, -> { where("official_level > 0") } + def self.find_for_oauth(auth, signed_in_resource = nil) + # Get the identity and user if they exist + identity = Identity.find_for_oauth(auth) + + # If a signed_in_resource is provided it always overrides the existing user + # to prevent the identity being locked with accidentally created accounts. + # Note that this may leave zombie accounts (with no associated identity) which + # can be cleaned up at a later date. + user = signed_in_resource ? signed_in_resource : identity.user + + # Create the user if needed + if user.nil? + + # Get the existing user by email if the provider gives us a verified email. + # If no verified email was provided we assign a temporary email and ask the + # user to verify it on the next step via RegistrationsController.finish_signup + email_is_verified = auth.info.email && (auth.info.verified || auth.info.verified_email) + email = auth.info.email if email_is_verified + user = User.where(email: email).first if email + + # Create the user if it's a new registration + if user.nil? + user = User.new( + username: auth.info.nickname || auth.extra.raw_info.name.parameterize('-') || auth.uid, + email: email ? email : "#{OMNIAUTH_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com", + password: Devise.friendly_token[0,20] + ) + user.skip_confirmation! + user.save! + end + end + + # Associate the identity with the user if needed + if identity.user != user + identity.user = user + identity.save! + end + + user + end + def name organization? ? organization.name : username end @@ -67,4 +114,8 @@ class User < ActiveRecord::Base e.present? ? where(email: e) : none end + def email_provided? + !!(email && email !~ OMNIAUTH_EMAIL_REGEX) || + !!(unconfirmed_email && unconfirmed_email !~ OMNIAUTH_EMAIL_REGEX) + end end diff --git a/app/views/devise/_omniauth_form.html.erb b/app/views/devise/_omniauth_form.html.erb new file mode 100644 index 000000000..888a3ba2f --- /dev/null +++ b/app/views/devise/_omniauth_form.html.erb @@ -0,0 +1,5 @@ +
+ +<%= link_to t("omniauth.twitter.sign_in"), user_omniauth_authorize_path(:twitter), class: 'button radius expand' %> + +
diff --git a/app/views/devise/menu/_login_items.html.erb b/app/views/devise/menu/_login_items.html.erb index 4959553f9..6cd27160d 100644 --- a/app/views/devise/menu/_login_items.html.erb +++ b/app/views/devise/menu/_login_items.html.erb @@ -7,11 +7,11 @@ <%= link_to(t("devise_views.menu.login_items.logout"), destroy_user_session_path, method: :delete) %> <% else %> -
  • - <%= link_to(t("devise_views.menu.login_items.login"), new_user_session_path) %> -
  • -
  • - <%= link_to(t("devise_views.menu.login_items.signup"), new_user_registration_path, class: "button radius small") %> -
  • +
  • + <%= link_to(t("devise_views.menu.login_items.login"), new_user_session_path) %> +
  • +
  • + <%= link_to(t("devise_views.menu.login_items.signup"), new_user_registration_path, class: "button radius small") %> +
  • <% end %> - \ No newline at end of file + diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 78a8b8b4c..1219c393d 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -19,4 +19,4 @@ <%= render "devise/shared/links" %> - \ No newline at end of file + diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 391ef186c..ab0b22426 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -3,6 +3,8 @@

    <%= t("devise_views.sessions.new.title") %>

    + <%= render 'devise/omniauth_form' %> + <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
    @@ -28,4 +30,4 @@ <%= render "devise/shared/links" %>
    -
    \ No newline at end of file + diff --git a/app/views/users/registrations/finish_signup.html.erb b/app/views/users/registrations/finish_signup.html.erb new file mode 100644 index 000000000..c57f01a8e --- /dev/null +++ b/app/views/users/registrations/finish_signup.html.erb @@ -0,0 +1,13 @@ +
    +
    +
    +

    <%= t('omniauth.finish_signup.title') %>

    + + <%= form_for current_user, as: :user, url: do_finish_signup_path, html: { role: 'form'} do |f| %> + <%= render 'shared/errors', resource: current_user %> + <%= f.email_field :email, placeholder: t("devise_views.users.registrations.new.email_label"), value: nil %> + <%= f.submit t("devise_views.users.registrations.new.submit"), class: 'button radius' %> + <% end %> +
    +
    +
    diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 92344b76f..2ac5b7af6 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -2,6 +2,9 @@

    <%= t("devise_views.users.registrations.new.title") %>

    + + <%= render 'devise/omniauth_form' %> + <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render 'shared/errors', resource: resource %> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index f7cdfb292..06c4740ba 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -239,6 +239,7 @@ Devise.setup do |config| # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + config.omniauth :twitter, Rails.application.secrets.twitter_key, Rails.application.secrets.twitter_secret # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb deleted file mode 100644 index 42e97b02f..000000000 --- a/config/initializers/omniauth.rb +++ /dev/null @@ -1,4 +0,0 @@ -Rails.application.config.middleware.use OmniAuth::Builder do - provider :developer unless Rails.env.production? - provider :twitter, Rails.application.secrets.twitter_key, Rails.application.secrets.twitter_secret -end diff --git a/config/locales/devise.es.yml b/config/locales/devise.es.yml index f39099f57..c2bc246e9 100644 --- a/config/locales/devise.es.yml +++ b/config/locales/devise.es.yml @@ -55,4 +55,4 @@ es: not_locked: "no estaba bloqueado." not_saved: one: "1 error impidió que este %{resource} fuera guardado:" - other: "%{count} errores impidieron que este %{resource} fuera guardado:" \ No newline at end of file + other: "%{count} errores impidieron que este %{resource} fuera guardado:" diff --git a/config/locales/en.yml b/config/locales/en.yml index ce3339b25..725955c30 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -148,3 +148,9 @@ en: all: "You are not authorized to %{action} %{subject}." welcome: last_debates: Last debates + omniauth: + finish_signup: + title: Add Email + twitter: + sign_in: Sign in with Twitter + or: or diff --git a/config/locales/es.yml b/config/locales/es.yml index 1e2cca785..efd0fd88e 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -148,3 +148,9 @@ es: all: "No tienes permiso para realizar la acción '%{action}' sobre %{subject}." welcome: last_debates: Últimos debates + omniauth: + finish_signup: + title: Añade tu email + twitter: + sign_in: Inicia sessión con Twitter + or: o diff --git a/config/routes.rb b/config/routes.rb index f224609b9..a51c75c39 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,19 @@ Rails.application.routes.draw do - devise_for :users, controllers: { registrations: 'users/registrations' } + devise_for :users, controllers: { + registrations: 'users/registrations', + omniauth_callbacks: 'users/omniauth_callbacks' + } devise_for :organizations, class_name: 'User', controllers: { registrations: 'organizations/registrations', - sessions: 'devise/sessions' - } + sessions: 'devise/sessions', + }, + skip: [:omniauth_callbacks] + + devise_scope :user do + get :finish_signup, to: 'users/registrations#finish_signup' + patch :do_finish_signup, to: 'users/registrations#do_finish_signup' + end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From ddcef1a0f22fd061f987bbfc01a10dd49afc9d2f Mon Sep 17 00:00:00 2001 From: David Gil Date: Mon, 24 Aug 2015 19:49:10 +0200 Subject: [PATCH 05/49] remove unused and locales --- app/controllers/users/registrations_controller.rb | 2 +- config/locales/en.yml | 1 - config/locales/es.yml | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index d1fc54aab..989badc76 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -17,7 +17,7 @@ class Users::RegistrationsController < Devise::RegistrationsController if current_user.update(sign_up_params) current_user.skip_reconfirmation! sign_in(current_user, bypass: true) - redirect_to root_url, notice: I18n.t('devise.registrations.updated') + redirect_to root_url else @show_errors = true render :finish_signup diff --git a/config/locales/en.yml b/config/locales/en.yml index 725955c30..11f012080 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -153,4 +153,3 @@ en: title: Add Email twitter: sign_in: Sign in with Twitter - or: or diff --git a/config/locales/es.yml b/config/locales/es.yml index efd0fd88e..2a5ee2ec5 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -153,4 +153,3 @@ es: title: Añade tu email twitter: sign_in: Inicia sessión con Twitter - or: o From af7396757f9df4965ff20742344c9dc0702121d4 Mon Sep 17 00:00:00 2001 From: David Gil Date: Mon, 24 Aug 2015 19:53:46 +0200 Subject: [PATCH 06/49] removes omniauth link from organizations --- app/views/devise/shared/_links.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index 0fd80f429..7f8142144 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -25,7 +25,7 @@ <%= link_to t("devise_views.shared.links.new_unlock"), new_unlock_path(resource_name) %>
    <% end -%> - <%- if devise_mapping.omniauthable? %> + <%- if devise_mapping.omniauthable? && devise_mapping.name == 'user' %> <%- resource_class.omniauth_providers.each do |provider| %> <%= link_to t("devise_views.shared.links.signin_with_provider", provider: provider.to_s.titleize), omniauth_authorize_path(resource_name, provider) %>
    <% end -%> From 86dccac9c6e0cb1a6603815d83cb03d424e07657 Mon Sep 17 00:00:00 2001 From: David Gil Date: Mon, 24 Aug 2015 20:21:45 +0200 Subject: [PATCH 07/49] adds support for Facebook OAuth --- Gemfile | 2 +- Gemfile.lock | 17 +++++++++++++++++ .../users/omniauth_callbacks_controller.rb | 2 +- app/views/devise/_omniauth_form.html.erb | 1 + config/deploy/shared/secrets.yml.erb | 3 ++- config/initializers/devise.rb | 1 + config/locales/en.yml | 2 ++ config/locales/es.yml | 4 +++- config/secrets.yml.example | 6 ++++++ 9 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 95ce82135..6365cc67f 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ gem 'devise' # gem 'bcrypt', '~> 3.1.7' gem 'omniauth' gem 'omniauth-twitter' -# gem 'omniauth-facebook' +gem 'omniauth-facebook' # gem 'omniauth-google-oauth2' gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock index d1a5ece7b..0023fb231 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,6 +133,8 @@ GEM factory_girl_rails (4.5.0) factory_girl (~> 4.5.0) railties (>= 3.0.0) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) foundation-rails (5.5.2.1) railties (>= 3.1.0) sass (>= 3.3.0, < 3.5) @@ -170,6 +172,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) + jwt (1.5.1) kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -190,6 +193,8 @@ GEM mini_portile (0.6.2) minitest (5.8.0) multi_json (1.11.2) + multi_xml (0.5.5) + multipart-post (2.0.0) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.2) @@ -197,12 +202,23 @@ GEM nokogiri (1.6.6.2) mini_portile (~> 0.6.0) oauth (0.4.7) + oauth2 (1.0.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (~> 1.2) omniauth (1.2.2) hashie (>= 1.2, < 4) rack (~> 1.0) + omniauth-facebook (2.0.1) + omniauth-oauth2 (~> 1.2) omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) + omniauth-oauth2 (1.3.1) + oauth2 (~> 1.0) + omniauth (~> 1.2) omniauth-twitter (1.2.1) json (~> 1.3) omniauth-oauth (~> 1.1) @@ -374,6 +390,7 @@ DEPENDENCIES launchy letter_opener_web (~> 1.3.0) omniauth + omniauth-facebook omniauth-twitter paranoia pg diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index aac6583d1..a0a90c400 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -16,7 +16,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController end # [:twitter, :facebook, :google_oauth2].each do |provider| - [:twitter].each do |provider| + [:twitter, :facebook].each do |provider| provides_callback_for provider end diff --git a/app/views/devise/_omniauth_form.html.erb b/app/views/devise/_omniauth_form.html.erb index 888a3ba2f..cf06d359f 100644 --- a/app/views/devise/_omniauth_form.html.erb +++ b/app/views/devise/_omniauth_form.html.erb @@ -1,5 +1,6 @@
    <%= link_to t("omniauth.twitter.sign_in"), user_omniauth_authorize_path(:twitter), class: 'button radius expand' %> +<%= link_to t("omniauth.facebook.sign_in"), user_omniauth_authorize_path(:facebook), class: 'button radius expand' %>
    diff --git a/config/deploy/shared/secrets.yml.erb b/config/deploy/shared/secrets.yml.erb index 9a6582afb..b4fa2634f 100644 --- a/config/deploy/shared/secrets.yml.erb +++ b/config/deploy/shared/secrets.yml.erb @@ -4,5 +4,6 @@ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> twitter_key: <%= ENV["TWITTER_KEY"] %> twitter_secret: <%= ENV["TWITTER_SECRET"] %> + facebook_key: <%= ENV["FACEBOOK_KEY"] %> + facebook_secret: <%= ENV["FACEBOOK_SECRET"] %> server_name: <%= fetch(:server_name) %> - diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 06c4740ba..eb7ec1970 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -240,6 +240,7 @@ Devise.setup do |config| # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' config.omniauth :twitter, Rails.application.secrets.twitter_key, Rails.application.secrets.twitter_secret + config.omniauth :facebook, Rails.application.secrets.facebook_key, Rails.application.secrets.facebook_secret # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/locales/en.yml b/config/locales/en.yml index 11f012080..15275eb82 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -153,3 +153,5 @@ en: title: Add Email twitter: sign_in: Sign in with Twitter + facebook: + sign_in: Sign in with Facebook diff --git a/config/locales/es.yml b/config/locales/es.yml index 2a5ee2ec5..74fd1d2d1 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -152,4 +152,6 @@ es: finish_signup: title: Añade tu email twitter: - sign_in: Inicia sessión con Twitter + sign_in: Entra con Twitter + facebook: + sign_in: Entra con Facebook diff --git a/config/secrets.yml.example b/config/secrets.yml.example index 72c7a6d64..fc872bdaa 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -16,16 +16,22 @@ development: secret_key_base: 56792feef405a59b18ea7db57b4777e855103882b926413d4afdfb8c0ea8aa86ea6649da4e729c5f5ae324c0ab9338f789174cf48c544173bc18fdc3b14262e4 twitter_key: AAAA twitter_secret: BBBB + facebook_key: AAAA + facebook_secret: BBBB <<: *default test: secret_key_base: 4d5adf961ddd27aef19622d6c0b3234d555f9ee003f022b1f829c92bbe33aaee907be7feb67bd54c14a1a32512fa968565ad405971fbc41bd0797af73c26a796 twitter_key: AAAA twitter_secret: BBBB + facebook_key: AAAA + facebook_secret: BBBB <<: *default production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> twitter_key: <%= ENV["TWITTER_KEY"] %> twitter_secret: <%= ENV["TWITTER_SECRET"] %> + facebook_key: <%= ENV["FACEBOOK_KEY"] %> + facebook_secret: <%= ENV["FACEBOOK_SECRET"] %> <<: *default From fe78837dfc2256ac2d90ad0e1b8ed6b44ed048ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 25 Aug 2015 09:28:43 +0200 Subject: [PATCH 08/49] updates Rails version --- Gemfile | 2 +- Gemfile.lock | 66 ++++++++++++++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index f1b251db4..f6b4f0e33 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.2.3' +gem 'rails', '4.2.4' # Use PostgreSQL gem 'pg' # Use SCSS for stylesheets diff --git a/Gemfile.lock b/Gemfile.lock index deed6bc4f..ae1930e1d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,36 +1,36 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.3) - actionpack (= 4.2.3) - actionview (= 4.2.3) - activejob (= 4.2.3) + actionmailer (4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.3) - actionview (= 4.2.3) - activesupport (= 4.2.3) + actionpack (4.2.4) + actionview (= 4.2.4) + activesupport (= 4.2.4) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.3) - activesupport (= 4.2.3) + actionview (4.2.4) + activesupport (= 4.2.4) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.3) - activesupport (= 4.2.3) + activejob (4.2.4) + activesupport (= 4.2.4) globalid (>= 0.3.0) - activemodel (4.2.3) - activesupport (= 4.2.3) + activemodel (4.2.4) + activesupport (= 4.2.4) builder (~> 3.1) - activerecord (4.2.3) - activemodel (= 4.2.3) - activesupport (= 4.2.3) + activerecord (4.2.4) + activemodel (= 4.2.4) + activesupport (= 4.2.4) arel (~> 6.0) - activesupport (4.2.3) + activesupport (4.2.4) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -181,7 +181,7 @@ GEM actionmailer (>= 3.2) letter_opener (~> 1.0) railties (>= 3.2) - loofah (2.0.2) + loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) @@ -209,28 +209,28 @@ GEM rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.3) - actionmailer (= 4.2.3) - actionpack (= 4.2.3) - actionview (= 4.2.3) - activejob (= 4.2.3) - activemodel (= 4.2.3) - activerecord (= 4.2.3) - activesupport (= 4.2.3) + rails (4.2.4) + actionmailer (= 4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) + activemodel (= 4.2.4) + activerecord (= 4.2.4) + activesupport (= 4.2.4) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.3) + railties (= 4.2.4) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.6) + rails-dom-testing (1.0.7) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.2) loofah (~> 2.0) - railties (4.2.3) - actionpack (= 4.2.3) - activesupport (= 4.2.3) + railties (4.2.4) + actionpack (= 4.2.4) + activesupport (= 4.2.4) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.15.0) @@ -283,7 +283,7 @@ GEM coffee-rails sass-rails spring (1.3.6) - sprockets (3.2.0) + sprockets (3.3.3) rack (~> 1.0) sprockets-rails (2.3.2) actionpack (>= 3.0) @@ -366,7 +366,7 @@ DEPENDENCIES pg poltergeist quiet_assets - rails (= 4.2.3) + rails (= 4.2.4) responders rspec-rails (~> 3.0) sass-rails (~> 5.0) From 8233aa6a3ebabe250113388364ee9ee12f1ea566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 25 Aug 2015 13:03:30 +0200 Subject: [PATCH 09/49] adds different avatar for same initial name users --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/views/account/show.html.erb | 2 +- app/views/comments/_comment.html.erb | 2 +- app/views/debates/show.html.erb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index f6b4f0e33..e2b104de0 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,7 @@ gem 'simple_captcha2', require: 'simple_captcha' gem 'ckeditor' gem 'cancancan' gem 'social-share-button' -gem 'initialjs-rails' +gem 'initialjs-rails', '0.2.0' gem 'unicorn' gem 'paranoia' diff --git a/Gemfile.lock b/Gemfile.lock index ae1930e1d..67d007883 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -162,7 +162,7 @@ GEM i18n term-ansicolor (>= 1.3.2) terminal-table (>= 1.5.1) - initialjs-rails (0.1.0) + initialjs-rails (0.2.0) railties (>= 3.1, < 5.0) jquery-rails (4.0.4) rails-dom-testing (~> 1.0) @@ -357,7 +357,7 @@ DEPENDENCIES fuubar groupdate i18n-tasks - initialjs-rails + initialjs-rails (= 0.2.0) jquery-rails kaminari launchy diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index d24343ea5..fa9ccdd04 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -26,7 +26,7 @@

    <%= t("account.show.avatar")%>

    - <%= avatar_image(@account, size: 100) %> + <%= avatar_image(@account, seed: @account.id, size: 100) %>

    <%= t("account.show.notifications")%>

    diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index ca7474ebd..0a1fd19a3 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -14,7 +14,7 @@ <% if comment.user.organization? %> <%= image_tag("collective_avatar.png", size: 32, class: "avatar left") %> <% else %> - <%= avatar_image(comment.user, size: 32, class: "left") %> + <%= avatar_image(comment.user, seed: comment.user_id, size: 32, class: "left") %> <% end %> <% if comment.user.hidden? %> diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 47ff9e34f..8dcc334b8 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -13,7 +13,7 @@

    <%= @debate.title %>

    - <%= avatar_image(@debate.author, size: 32, class: 'author-photo') %> + <%= avatar_image(@debate.author, seed: @debate.author_id, size: 32, class: 'author-photo') %> <% if @debate.author.hidden? %> From 026db24b2ae5e55f59812c4eb6e9d7476ab746c5 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 25 Aug 2015 13:10:39 +0200 Subject: [PATCH 10/49] split long method into shorter, SRPer ones --- app/models/identity.rb | 7 +++++++ app/models/user.rb | 46 +++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/models/identity.rb b/app/models/identity.rb index e0778dfae..3ba19e3fa 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -7,4 +7,11 @@ class Identity < ActiveRecord::Base def self.find_for_oauth(auth) where(uid: auth.uid, provider: auth.provider).first_or_create end + + def update_user(new_user) + return unless user != new_user + + self.user = new_user + save! + end end diff --git a/app/models/user.rb b/app/models/user.rb index 4a1839b34..7cff8d732 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,33 +40,29 @@ class User < ActiveRecord::Base # Note that this may leave zombie accounts (with no associated identity) which # can be cleaned up at a later date. user = signed_in_resource ? signed_in_resource : identity.user - - # Create the user if needed - if user.nil? - - # Get the existing user by email if the provider gives us a verified email. - # If no verified email was provided we assign a temporary email and ask the - # user to verify it on the next step via RegistrationsController.finish_signup - email_is_verified = auth.info.email && (auth.info.verified || auth.info.verified_email) - email = auth.info.email if email_is_verified - user = User.where(email: email).first if email - - # Create the user if it's a new registration - if user.nil? - user = User.new( - username: auth.info.nickname || auth.extra.raw_info.name.parameterize('-') || auth.uid, - email: email ? email : "#{OMNIAUTH_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com", - password: Devise.friendly_token[0,20] - ) - user.skip_confirmation! - user.save! - end - end + user ||= first_or_create_for_oauth(auth) # Associate the identity with the user if needed - if identity.user != user - identity.user = user - identity.save! + identity.update_user(user) + user + end + + # Get the existing user by email if the provider gives us a verified email. + # If no verified email was provided we assign a temporary email and ask the + # user to verify it on the next step via RegistrationsController.finish_signup + def self.first_or_create_for_oauth(auth) + email = auth.info.email if auth.info.verified || auth.info.verified_email + user = User.where(email: email).first if email + + # Create the user if it's a new registration + if user.nil? + user = User.new( + username: auth.info.nickname || auth.extra.raw_info.name.parameterize('-') || auth.uid, + email: email ? email : "#{OMNIAUTH_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com", + password: Devise.friendly_token[0,20] + ) + user.skip_confirmation! + user.save! end user From 6643f971959529963d91aca6898218d5c5b627d4 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 25 Aug 2015 13:51:25 +0200 Subject: [PATCH 11/49] Updates custom icons font --- app/assets/fonts/icons.eot | Bin 5716 -> 5824 bytes app/assets/fonts/icons.svg | 1 + app/assets/fonts/icons.ttf | Bin 5560 -> 5668 bytes app/assets/fonts/icons.woff | Bin 4380 -> 4464 bytes app/assets/stylesheets/icons.scss | 4 ++++ 5 files changed, 5 insertions(+) diff --git a/app/assets/fonts/icons.eot b/app/assets/fonts/icons.eot index 2c00f1f5b9cb03572d4edc47b957eb166f49e9e1..a1cc83d43d12151ca8a386601a45b4974e3b0142 100644 GIT binary patch delta 501 zcmcbjb3m8vfEWXVir7RpGnP5elNu&EH_J_|C}2oom;jWw z0P+>`5_41etvYWrFo;M1#qtXBi%XbKG8X`C=>W=yF)#v2AZ|!{J|~{v<|_j?6HtJG z;S%FBMP!ZUnDWWnn4B3UC;woo1(J=-9g_{1IVW?nXtQwGF)(a4VUZL_W@K<HgWi&H35*ITzG6ynE7&kFXDcC40>1ivm3vvqx zhzUr_TdOMR8YwX|w({x9%km3w|Jw(Y;GW2C}l1xyjLy@eB;2a~K#HWZYd`-5A^$*ns>RAYZ{h zSl`J1cg$`E2F3^=KP)*nu^@0`*gqiu4G@>5Cl(j{|Ife-R9^y==Sa_~OtY_aS72aZ zp25H%Ad!)pn8GS`IdQT8qkKIRP{#(KDyy9QP(Fl#5l8}Ysy>c5Y+^dmqd$!mbi%- SPp%b{VU(CWOH7If* + diff --git a/app/assets/fonts/icons.ttf b/app/assets/fonts/icons.ttf index 808c75487bf0422da6e512d3c1049bc9e25a6f6d..aa9c63faae88382db31d66dded442022c23bbae3 100644 GIT binary patch delta 554 zcmYL`KWGzS7{;IPzDs%#(p>QpO^hVDR7GM8Txt|eD)=XHkrb6sq$<}WHbbvHOra5! zb`caDs^{R4v5Q;LMMOjp1Q!KY9qbYv+{8f(thFY5Co#%$?5u~f>qy|c?F1Ra--?kZe#Oefc%5eo3p#_ z&JLXr{YqV%o4<7<`&;e>WFOFPciMIPGH6`FVGN)>j!1E_Et~Uj$sEC*1EqJTQ2D9eD16gx~5sZ!* zF{@M&rJ}VvRG9Ob{bt@WrMNqqPwk87q3zccLJ!0F z)VP#SHFz7leu|^sx^am4gVE(gr=!K%6?Vug`BRi(|Dz;sijU6{ab|T$e$Af{AFsXp LYI65+(fkAW*P*ld<#np|$je!lwuL1HE{Dbw4 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 Date: Tue, 25 Aug 2015 14:09:04 +0200 Subject: [PATCH 12/49] Adds styles for flag as inappropriate --- app/assets/stylesheets/admin.scss | 4 ++-- app/assets/stylesheets/debates.scss | 19 +++++++++++++++ app/assets/stylesheets/participacion.scss | 23 +++++++++++++++++-- app/assets/stylesheets/variables.scss | 1 + app/views/comments/_actions.html.erb | 8 +++++-- app/views/comments/_comment.html.erb | 10 +++----- .../_flag_as_inappropiate_actions.html.erb | 21 +++++++++++++++-- .../_flag_as_inappropiate_actions.html.erb | 19 +++++++++++++-- app/views/debates/show.html.erb | 4 ++-- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 11 files changed, 92 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 7e6096bc3..f62b5efd6 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -140,7 +140,7 @@ body.admin { .delete { border-bottom: 1px dotted #CF2A0E; - color: #F04124; + color: $delete; font-size: rem-calc(12); &:hover, &:active, &:focus { @@ -160,7 +160,7 @@ body.admin { } .rejected { - color: #F04124; + color: $delete; } .level { diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss index 66ea491af..641e7ccff 100644 --- a/app/assets/stylesheets/debates.scss +++ b/app/assets/stylesheets/debates.scss @@ -5,6 +5,7 @@ // 03. Show // 04. New // 05. Comments +// 06. Flags // // 01. Debates @@ -541,6 +542,10 @@ font-size: rem-calc(12); margin: rem-calc(6) 0; padding: rem-calc(6); + + .divider { + color: $text-light; + } } .comment-user { @@ -608,3 +613,17 @@ .faded { opacity: 0.4; } + +// 06. Flags +// - - - - - - - - - - - - - - - - - - - - - - - - - + +.flag-disable { + color: $text-medium; + line-height: rem-calc(24); + vertical-align: middle; +} + +.flag-active { + @extend .flag-disable; + color: $delete; +} diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 485dbfd60..b3ee7046a 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -150,6 +150,25 @@ h1, h2, h3, h4, h5, h6 { } } +.f-dropdown { + + li a { + font-size: rem-calc(12); + + &:hover { + color: $link-hover; + } + } + + li:hover, .f-dropdown li:focus { + background: white; + } + + &.open { + outline: none; + } +} + // 04. Header // - - - - - - - - - - - - - - - - - - - - - - - - - @@ -692,13 +711,13 @@ form { } } -img.admin-avatar, img.moderator-avatar { +img.avatar, img.admin-avatar, img.moderator-avatar { border-radius: rem-calc(1000); position: relative; } img.initialjs-avatar { - @extend .moderator-avatar; + @extend .avatar; } .author-deleted { diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss index 4be7028e3..64861e215 100644 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -38,6 +38,7 @@ $votes-like-act: #5D9E7F; $votes-unlike: #EF8585; $votes-unlike-act: #BD6A6A; +$delete: #F04124; $check: #46DB91; // 03. Forms diff --git a/app/views/comments/_actions.html.erb b/app/views/comments/_actions.html.erb index 5454179f0..51a6743e0 100644 --- a/app/views/comments/_actions.html.erb +++ b/app/views/comments/_actions.html.erb @@ -1,12 +1,16 @@ + + <%= render 'comments/flag_as_inappropiate_actions', comment: comment %> + + <% if can? :hide, comment %> -  |  +  •  <%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment), method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> <% end %> <% if can? :hide, comment.user %> -  |  +  •  <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(comment.user_id, debate_id: @debate.id), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index ca7474ebd..6f93bdde4 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -58,10 +58,6 @@ <% end %>  • <%= time_ago_in_words(comment.created_at) %> - - - <%= render 'comments/flag_as_inappropiate_actions', comment: comment %> -
    <% if comment.as_administrator? %> @@ -81,11 +77,11 @@ <%= render 'comments/votes', comment: comment %> -

    +

    <%= t("debates.comment.responses", count: comment.children_count) %> <% if user_signed_in? %> -  |  +  |  <%= link_to(comment_link_text(comment), "", class: "js-add-comment-link", data: {'id': dom_id(comment)}) %> @@ -93,7 +89,7 @@ <%= render 'comments/form', {parent: comment, toggeable: true} %> <% end %> -

    +
    <% end %> diff --git a/app/views/comments/_flag_as_inappropiate_actions.html.erb b/app/views/comments/_flag_as_inappropiate_actions.html.erb index fad83d4d6..0b62715e3 100644 --- a/app/views/comments/_flag_as_inappropiate_actions.html.erb +++ b/app/views/comments/_flag_as_inappropiate_actions.html.erb @@ -1,6 +1,23 @@ <% if can? :flag_as_inappropiate, comment %> - <%= link_to t('shared.flag_as_inappropiate'), flag_as_inappropiate_comment_path(comment), method: :put, remote: true %> +  |  + + <% end %> + <% if can? :undo_flag_as_inappropiate, comment %> - <%= link_to t('shared.undo_flag_as_inappropiate'), undo_flag_as_inappropiate_comment_path(comment), method: :put, remote: true %> +  |  + + <% end %> diff --git a/app/views/debates/_flag_as_inappropiate_actions.html.erb b/app/views/debates/_flag_as_inappropiate_actions.html.erb index 8003600e0..6db9bc5f4 100644 --- a/app/views/debates/_flag_as_inappropiate_actions.html.erb +++ b/app/views/debates/_flag_as_inappropiate_actions.html.erb @@ -1,6 +1,21 @@ <% if can? :flag_as_inappropiate, debate %> - <%= link_to t('shared.flag_as_inappropiate'), flag_as_inappropiate_debate_path(debate), method: :put, remote: true %> + + <% end %> + <% if can? :undo_flag_as_inappropiate, debate %> - <%= link_to t('shared.undo_flag_as_inappropiate'), undo_flag_as_inappropiate_debate_path(debate), method: :put, remote: true %> + + <% end %> diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 47ff9e34f..a6765e1b0 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -41,8 +41,8 @@  •    <%= link_to t("debates.show.comments", count: @debate.comment_threads.count), "#comments" %> - - +  •  + <%= render 'debates/flag_as_inappropiate_actions', debate: @debate %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index ce3339b25..55e06af4e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -135,7 +135,7 @@ en: tags_cloud: tags: Topics flag_as_inappropiate: Flag as inappropiate - undo_flag_as_inappropiate: Undo flag as inappropiate + undo_flag_as_inappropiate: Undo flag collective: Collective mailer: comment: diff --git a/config/locales/es.yml b/config/locales/es.yml index 1e2cca785..d548f2334 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -135,7 +135,7 @@ es: tags_cloud: tags: Temas flag_as_inappropiate: Denunciar como inapropiado - undo_flag_as_inappropiate: Deshacer denunciar como inapropiado + undo_flag_as_inappropiate: Deshacer denuncia collective: Colectivo mailer: comment: From de15bbe911beb61a43188bcd40638595a9bd9be1 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 25 Aug 2015 14:15:04 +0200 Subject: [PATCH 13/49] adds feature tests for sign up and sign using OAuth --- spec/features/users_spec.rb | 170 +++++++++++++++++++++++++++------ spec/rails_helper.rb | 2 + spec/support/common_actions.rb | 3 + 3 files changed, 147 insertions(+), 28 deletions(-) diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 42511f28c..1fa30bcbe 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -2,44 +2,159 @@ require 'rails_helper' feature 'Users' do - scenario 'Sign up' do - visit '/' - click_link 'Sign up' + context 'Regular authentication' do + scenario 'Sign up' do + visit '/' + click_link 'Sign up' - fill_in 'user_username', with: 'Manuela Carmena' - fill_in 'user_email', with: 'manuela@madrid.es' - fill_in 'user_password', with: 'judgementday' - fill_in 'user_password_confirmation', with: 'judgementday' - fill_in 'user_captcha', with: correct_captcha_text + fill_in 'user_username', with: 'Manuela Carmena' + fill_in 'user_email', with: 'manuela@madrid.es' + fill_in 'user_password', with: 'judgementday' + fill_in 'user_password_confirmation', with: 'judgementday' + fill_in 'user_captcha', with: correct_captcha_text - click_button 'Sign up' + click_button 'Sign up' - expect(page).to have_content "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + expect(page).to have_content "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." - sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] - visit user_confirmation_path(confirmation_token: sent_token) + sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + visit user_confirmation_path(confirmation_token: sent_token) - expect(page).to have_content "Your email address has been successfully confirmed" + expect(page).to have_content "Your email address has been successfully confirmed" + end + + scenario 'Errors on sign up' do + visit '/' + click_link 'Sign up' + click_button 'Sign up' + + expect(page).to have_content error_message + end + + scenario 'Sign in' do + create(:user, email: 'manuela@madrid.es', password: 'judgementday') + + visit '/' + click_link 'Log in' + fill_in 'user_email', with: 'manuela@madrid.es' + fill_in 'user_password', with: 'judgementday' + click_button 'Log in' + + expect(page).to have_content 'Signed in successfully.' + end end - scenario 'Errors on sign up' do - visit '/' - click_link 'Sign up' - click_button 'Sign up' + context 'OAuth authentication' do + context 'Twitter' do + background do + #request.env["devise.mapping"] = Devise.mappings[:user] + end - expect(page).to have_content error_message - end + scenario 'Sign up, when email was provided by OAuth provider' do + omniauth_twitter_hash = { 'provider' => 'twitter', + 'uid' => '12345', + 'info' => { + 'name' => 'manuela', + 'email' => 'manuelacarmena@example.com', + 'nickname' => 'ManuelaRocks', + 'verified' => '1' + }, + 'extra' => { 'raw_info' => + { 'location' => 'Madrid', + 'name' => 'Manuela de las Carmenas' + } + } + } - scenario 'Sign in' do - create(:user, email: 'manuela@madrid.es', password: 'judgementday') + OmniAuth.config.add_mock(:twitter, omniauth_twitter_hash) - visit '/' - click_link 'Log in' - fill_in 'user_email', with: 'manuela@madrid.es' - fill_in 'user_password', with: 'judgementday' - click_button 'Log in' + visit '/' + click_link 'Sign up' - expect(page).to have_content 'Signed in successfully.' + expect do + expect do + expect do + click_link 'Sign in with Twitter' + end.not_to change { ActionMailer::Base.deliveries.size } + end.to change { Identity.count }.by(1) + end.to change { User.count }.by(1) + + expect(current_path).to eq(root_path) + expect_to_be_signed_in + + user = User.last + expect(user.username).to eq('ManuelaRocks') + expect(user.email).to eq('manuelacarmena@example.com') + expect(user.confirmed?).to eq(true) + end + + scenario 'Sign up, when neither email nor nickname were provided by OAuth provider' do + omniauth_twitter_hash = { 'provider' => 'twitter', + 'uid' => '12345', + 'info' => { + 'name' => 'manuela' + }, + 'extra' => { 'raw_info' => + { 'location' => 'Madrid', + 'name' => 'Manuela de las Carmenas' + } + } + } + + OmniAuth.config.add_mock(:twitter, omniauth_twitter_hash) + + visit '/' + click_link 'Sign up' + + expect do + expect do + expect do + click_link 'Sign in with Twitter' + end.not_to change { ActionMailer::Base.deliveries.size } + end.to change { Identity.count }.by(1) + end.to change { User.count }.by(1) + + expect(current_path).to eq(finish_signup_path) + + user = User.last + expect(user.username).to eq('manuela-de-las-carmenas') + expect(user.email).to eq("omniauth@participacion-12345-twitter.com") + + fill_in 'user_email', with: 'manueladelascarmenas@example.com' + click_button 'Sign up' + + sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + visit user_confirmation_path(confirmation_token: sent_token) + + expect(page).to have_content "Your email address has been successfully confirmed" + + expect(user.reload.email).to eq('manueladelascarmenas@example.com') + end + + scenario 'Sign in, user was already signed up with OAuth' do + user = create(:user, email: 'manuela@madrid.es', password: 'judgementday') + identity = create(:identity, uid: '12345', provider: 'twitter', user: user) + omniauth_twitter_hash = { 'provider' => 'twitter', + 'uid' => '12345', + 'info' => { + 'name' => 'manuela' + } + } + + OmniAuth.config.add_mock(:twitter, omniauth_twitter_hash) + + visit '/' + click_link 'Log in' + + expect do + expect do + click_link 'Sign in with Twitter' + end.not_to change { Identity.count } + end.not_to change { User.count } + + expect_to_be_signed_in + end + end end scenario 'Sign out' do @@ -73,5 +188,4 @@ feature 'Users' do expect(page).to have_content "Your password has been changed successfully. You are now signed in." end - end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d073cc173..c2f5db0fe 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -22,3 +22,5 @@ RSpec.configure do |config| end Capybara.javascript_driver = :poltergeist + +OmniAuth.config.test_mode = true diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 21a98f56f..12d6affd3 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -77,4 +77,7 @@ module CommonActions /\d errors? prohibited this (.*) from being saved:/ end + def expect_to_be_signed_in + expect(find('.top-bar')).to have_content 'My account' + end end From 59aede5b006d5a11ebe3ec1beab634b05f2a6905 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 25 Aug 2015 14:15:24 +0200 Subject: [PATCH 14/49] adds Google OAuth2 support --- Gemfile | 2 +- Gemfile.lock | 4 ++++ app/controllers/users/omniauth_callbacks_controller.rb | 3 +-- app/views/devise/_omniauth_form.html.erb | 1 + config/deploy/shared/secrets.yml.erb | 2 ++ config/initializers/devise.rb | 1 + config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/secrets.yml.example | 6 ++++++ 9 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 6365cc67f..e997090f4 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ gem 'devise' gem 'omniauth' gem 'omniauth-twitter' gem 'omniauth-facebook' -# gem 'omniauth-google-oauth2' +gem 'omniauth-google-oauth2' gem 'kaminari' gem 'acts_as_commentable_with_threading' diff --git a/Gemfile.lock b/Gemfile.lock index 0023fb231..b3f89ec62 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,6 +213,9 @@ GEM rack (~> 1.0) omniauth-facebook (2.0.1) omniauth-oauth2 (~> 1.2) + omniauth-google-oauth2 (0.2.6) + omniauth (> 1.0) + omniauth-oauth2 (~> 1.1) omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) @@ -391,6 +394,7 @@ DEPENDENCIES letter_opener_web (~> 1.3.0) omniauth omniauth-facebook + omniauth-google-oauth2 omniauth-twitter paranoia pg diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index a0a90c400..8588ba243 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -15,8 +15,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController } end - # [:twitter, :facebook, :google_oauth2].each do |provider| - [:twitter, :facebook].each do |provider| + [:twitter, :facebook, :google_oauth2].each do |provider| provides_callback_for provider end diff --git a/app/views/devise/_omniauth_form.html.erb b/app/views/devise/_omniauth_form.html.erb index cf06d359f..fdd812b4f 100644 --- a/app/views/devise/_omniauth_form.html.erb +++ b/app/views/devise/_omniauth_form.html.erb @@ -2,5 +2,6 @@ <%= link_to t("omniauth.twitter.sign_in"), user_omniauth_authorize_path(:twitter), class: 'button radius expand' %> <%= link_to t("omniauth.facebook.sign_in"), user_omniauth_authorize_path(:facebook), class: 'button radius expand' %> +<%= link_to t("omniauth.google_oauth2.sign_in"), user_omniauth_authorize_path(:google_oauth2), class: 'button radius expand' %>
    diff --git a/config/deploy/shared/secrets.yml.erb b/config/deploy/shared/secrets.yml.erb index b4fa2634f..42a8c48a6 100644 --- a/config/deploy/shared/secrets.yml.erb +++ b/config/deploy/shared/secrets.yml.erb @@ -6,4 +6,6 @@ twitter_secret: <%= ENV["TWITTER_SECRET"] %> facebook_key: <%= ENV["FACEBOOK_KEY"] %> facebook_secret: <%= ENV["FACEBOOK_SECRET"] %> + google_oauth2_key: <%= ENV["GOOGLE_KEY"] %> + google_oauth2_secret: <%= ENV["GOOGLE_SECRET"] %> server_name: <%= fetch(:server_name) %> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index eb7ec1970..40f3e50b3 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -241,6 +241,7 @@ Devise.setup do |config| # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' config.omniauth :twitter, Rails.application.secrets.twitter_key, Rails.application.secrets.twitter_secret config.omniauth :facebook, Rails.application.secrets.facebook_key, Rails.application.secrets.facebook_secret + config.omniauth :google_oauth2, Rails.application.secrets.google_oauth2_key, Rails.application.secrets.google_oauth2_secret # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/locales/en.yml b/config/locales/en.yml index 15275eb82..279b2a00e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -155,3 +155,5 @@ en: sign_in: Sign in with Twitter facebook: sign_in: Sign in with Facebook + google_oauth2: + sign_in: Sign in with Google diff --git a/config/locales/es.yml b/config/locales/es.yml index 74fd1d2d1..98c463b1e 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -155,3 +155,5 @@ es: sign_in: Entra con Twitter facebook: sign_in: Entra con Facebook + google_oauth2: + sign_in: Entra con Google diff --git a/config/secrets.yml.example b/config/secrets.yml.example index fc872bdaa..1d1312ea6 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -18,6 +18,8 @@ development: twitter_secret: BBBB facebook_key: AAAA facebook_secret: BBBB + google_oauth2_key: AAAA + google_oauth2_secret: BBBB <<: *default test: @@ -26,6 +28,8 @@ test: twitter_secret: BBBB facebook_key: AAAA facebook_secret: BBBB + google_oauth2_key: AAAA + google_oauth2_secret: BBBB <<: *default production: @@ -34,4 +38,6 @@ production: twitter_secret: <%= ENV["TWITTER_SECRET"] %> facebook_key: <%= ENV["FACEBOOK_KEY"] %> facebook_secret: <%= ENV["FACEBOOK_SECRET"] %> + google_oauth2_key: <%= ENV["GOOGLE_KEY"] %> + google_oauth2_secret: <%= ENV["GOOGLE_SECRET"] %> <<: *default From ff636f7e2a4d0ee3ac8013a823d741baa62b37b5 Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 25 Aug 2015 14:15:43 +0200 Subject: [PATCH 15/49] adds instructions for local configuration to README --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c8bbb453..87e0d1ab9 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Para ejecutar la aplicación en local: bundle exec bin/rails s ``` -Prerequisitos para los tests: tener instalado PhantomJS >= 2.0 +Prerequisitos para los tests: tener instalado PhantomJS >= 2.0 Para ejecutar los tests: @@ -44,6 +44,12 @@ Para ejecutar los tests: bundle exec bin/rspec ``` +### OAuth + +Para probar los servicios de autenticación mediante proveedores externos OAuth — en este momento Twitter, Facebook y Google —, necesitas crear una "aplicación" en cada una de las plataformas soportadas y configurar la *key* y el *secret* proporcionados en tu *secrets.yml* + +En el caso de Google, comprueba que las APIs *Contacts API* y *Google+ API* están habilitadas para la aplicación. + ## Licencia El código de este proyecto está publicado bajo la licencia AFFERO GPL v3 (ver [LICENSE-AGPLv3.txt](LICENSE-AGPLv3.txt)) From 8d0ba2fe334b5165c553ffe8139c0eb7672a918a Mon Sep 17 00:00:00 2001 From: David Gil Date: Tue, 25 Aug 2015 15:07:36 +0200 Subject: [PATCH 16/49] cleans up unused variable --- app/controllers/users/registrations_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 989badc76..4ce5998c8 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -19,7 +19,6 @@ class Users::RegistrationsController < Devise::RegistrationsController sign_in(current_user, bypass: true) redirect_to root_url else - @show_errors = true render :finish_signup end end From 8037a82fef911661fe769b8b3e0ce51d8c8e71ad Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 25 Aug 2015 15:19:34 +0200 Subject: [PATCH 17/49] Adds styles to moderation admin --- app/assets/stylesheets/admin.scss | 17 +++++-- app/assets/stylesheets/participacion.scss | 3 +- .../moderation/comments_controller.rb | 2 +- .../moderation/debates_controller.rb | 2 +- app/models/comment.rb | 2 +- app/models/debate.rb | 2 +- app/views/moderation/_menu.html.erb | 12 ++--- app/views/moderation/comments/index.html.erb | 50 +++++++++++-------- app/views/moderation/debates/index.html.erb | 47 +++++++++-------- config/locales/moderation.en.yml | 18 +++---- config/locales/moderation.es.yml | 19 ++++--- 11 files changed, 99 insertions(+), 75 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index f62b5efd6..5afa088d1 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -151,11 +151,16 @@ body.admin { .verified { color: $check; + + a { + border-bottom: 1px dotted $check; + color: $check; + font-size: rem-calc(12); + } } -.verified a { - border-bottom: 1px dotted $check; - color: $check; +.archived { + color: $text-medium; font-size: rem-calc(12); } @@ -163,6 +168,12 @@ body.admin { color: $delete; } +.date { + color: $text-medium; + font-size: rem-calc(12); + font-style: italic; +} + .level { font-size: rem-calc(12); } diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index b3ee7046a..619f25d48 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -135,6 +135,7 @@ h1, h2, h3, h4, h5, h6 { } .sub-nav dt, .sub-nav dd, .sub-nav li { + padding: rem-calc(3) 0; &.active { background: #008CBA; @@ -142,7 +143,7 @@ h1, h2, h3, h4, h5, h6 { color: white; cursor: default; font-weight: normal; - padding: 0.16667rem 0.88889rem; + padding: rem-calc(3) rem-calc(14); a:hover { color: #737373; diff --git a/app/controllers/moderation/comments_controller.rb b/app/controllers/moderation/comments_controller.rb index 03667e286..6434c708e 100644 --- a/app/controllers/moderation/comments_controller.rb +++ b/app/controllers/moderation/comments_controller.rb @@ -31,7 +31,7 @@ class Moderation::CommentsController < Moderation::BaseController end def set_valid_filters - @valid_filters = %w{all pending_review reviewed} + @valid_filters = %w{all pending_review archived} end def parse_filter diff --git a/app/controllers/moderation/debates_controller.rb b/app/controllers/moderation/debates_controller.rb index 22e4eac6b..89360ddaa 100644 --- a/app/controllers/moderation/debates_controller.rb +++ b/app/controllers/moderation/debates_controller.rb @@ -31,7 +31,7 @@ class Moderation::DebatesController < Moderation::BaseController end def set_valid_filters - @valid_filters = %w{all pending_review reviewed} + @valid_filters = %w{all pending_review archived} end def parse_filter diff --git a/app/models/comment.rb b/app/models/comment.rb index 824f1dbf0..0fa84dc6e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -19,7 +19,7 @@ class Comment < ActiveRecord::Base scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) } scope :pending_review, -> { where(reviewed_at: nil, hidden_at: nil) } - scope :reviewed, -> { where("reviewed_at IS NOT NULL AND hidden_at IS NULL") } + scope :archived, -> { where("reviewed_at IS NOT NULL AND hidden_at IS NULL") } scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") } def self.build(commentable, user, body) diff --git a/app/models/debate.rb b/app/models/debate.rb index c16048f70..e31a82a85 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -25,7 +25,7 @@ class Debate < ActiveRecord::Base scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) } scope :pending_review, -> { where(reviewed_at: nil, hidden_at: nil) } - scope :reviewed, -> { where("reviewed_at IS NOT NULL AND hidden_at IS NULL") } + scope :archived, -> { where("reviewed_at IS NOT NULL AND hidden_at IS NULL") } scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") } # Ahoy setup diff --git a/app/views/moderation/_menu.html.erb b/app/views/moderation/_menu.html.erb index 41e84287a..d7c76b31a 100644 --- a/app/views/moderation/_menu.html.erb +++ b/app/views/moderation/_menu.html.erb @@ -4,17 +4,17 @@ <%= t("moderation.dashboard.index.title") %> -
  • > +
  • > <%= link_to moderation_debates_path do %> - - <%= t('moderation.menu.flagged_debates') %> + + <%= t("moderation.menu.flagged_debates") %> <% end %>
  • -
  • > +
  • > <%= link_to moderation_comments_path do %> - - <%= t('moderation.menu.flagged_comments') %> + + <%= t("moderation.menu.flagged_comments") %> <% end %>
  • diff --git a/app/views/moderation/comments/index.html.erb b/app/views/moderation/comments/index.html.erb index 0d89114f1..02b503497 100644 --- a/app/views/moderation/comments/index.html.erb +++ b/app/views/moderation/comments/index.html.erb @@ -1,45 +1,52 @@ -

    <%= t('moderation.comments.index.title') %>

    +

    <%= t("moderation.comments.index.title") %>

    + +

    <%= page_entries_info @comments %>

    - - - - - + + + + <% @comments.each do |comment| %> - - - - - + + + <% if can? :mark_as_reviewed, comment %> <% end %> <% if comment.reviewed? %> - <% end %> @@ -47,4 +54,3 @@
    <%= t('moderation.comments.index.headers.flags') %><%= t('moderation.comments.index.headers.updated_at') %><%= t('moderation.comments.index.headers.commentable_type') %><%= t('moderation.comments.index.headers.commentable') %><%= t('moderation.comments.index.headers.comment') %> + <%= t("moderation.comments.index.headers.commentable") %> |  + <%= t("moderation.comments.index.headers.commentable_type") %> |  + <%= t("moderation.comments.index.headers.updated_at") %> + <%= t("moderation.comments.index.headers.comment") %><%= t("moderation.comments.index.headers.flags") %><%= t("moderation.debates.index.headers.actions") %>
    <%= comment.inappropiate_flags_count %><%= l comment.updated_at.to_date %><%= comment.commentable_type.constantize.model_name.human %><%= link_to comment.commentable.title, comment.commentable %><%= comment.body %> - <%= link_to t('moderation.comments.index.hide'), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put %> + <%= link_to comment.commentable.title, comment.commentable %> +
    + <%= comment.commentable_type.constantize.model_name.human %> + <%= l comment.updated_at.to_date %> +
    <%= comment.body %><%= comment.inappropiate_flags_count %> + <%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %> - <%= link_to t('moderation.comments.index.mark_as_reviewed'), mark_as_reviewed_moderation_comment_path(comment, request.query_parameters), method: :put %> + <%= link_to t("moderation.comments.index.archive"), mark_as_reviewed_moderation_comment_path(comment, request.query_parameters), method: :put, class: "button radius tiny warning" %> - <%= t('moderation.comments.index.reviewed') %> + + <%= t("moderation.comments.index.archived") %>
    <%= paginate @comments %> - diff --git a/app/views/moderation/debates/index.html.erb b/app/views/moderation/debates/index.html.erb index 611f68e16..68de5807d 100644 --- a/app/views/moderation/debates/index.html.erb +++ b/app/views/moderation/debates/index.html.erb @@ -1,43 +1,51 @@ -

    <%= t('moderation.debates.index.title') %>

    +

    <%= t("moderation.debates.index.title") %>

    + +

    <%= page_entries_info @debates %>

    - - - - + + + <% @debates.each do |debate| %> - - - - + + <% if can? :mark_as_reviewed, debate %> <% end %> <% if debate.reviewed? %> - <% end %> @@ -45,4 +53,3 @@
    <%= t('moderation.debates.index.headers.flags') %><%= t('moderation.debates.index.headers.updated_at') %><%= t('moderation.debates.index.headers.title') %><%= t('moderation.debates.index.headers.description') %> + <%= t("moderation.debates.index.headers.title") %> |  + <%= t("moderation.debates.index.headers.updated_at") %> |  + <%= t("moderation.debates.index.headers.description") %> + <%= t("moderation.debates.index.headers.flags") %><%= t("moderation.debates.index.headers.actions") %>
    <%= debate.inappropiate_flags_count %><%= l debate.updated_at.to_date %><%= link_to debate.title, debate %><%= debate.description %> - <%= link_to t('moderation.debates.index.hide'), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put %> + <%= link_to debate.title, debate, target: "_blank" %> +
    + <%= l debate.updated_at.to_date %> +
    + <%= debate.description %> +
    <%= debate.inappropiate_flags_count %> + <%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %> - <%= link_to t('moderation.debates.index.mark_as_reviewed'), mark_as_reviewed_moderation_debate_path(debate, request.query_parameters), method: :put %> + <%= link_to t("moderation.debates.index.archive"), mark_as_reviewed_moderation_debate_path(debate, request.query_parameters), method: :put, class: "button radius tiny warning" %> - <%= t('moderation.debates.index.reviewed') %> + + <%= t("moderation.debates.index.archived") %>
    <%= paginate @debates %> - diff --git a/config/locales/moderation.en.yml b/config/locales/moderation.en.yml index 2728f10d9..7688dfa09 100644 --- a/config/locales/moderation.en.yml +++ b/config/locales/moderation.en.yml @@ -8,7 +8,7 @@ en: title: Moderation comments: index: - title: Comments flagged as inappropiate + title: Comments flagged as inappropriate headers: flags: Flags updated_at: Date @@ -16,27 +16,27 @@ en: commentable: Root comment: Comment hide: Hide - mark_as_reviewed: Mark as reviewed - reviewed: Reviewed + archive: Archive + archived: Archived filter: Filter filters: all: All pending_review: Pending - reviewed: Reviewed + archived: Archived debates: index: - title: Debates flagged as inappropiate + title: Debates flagged as inappropriate headers: flags: Flags updated_at: Date title: Title description: Description + actions: Actions hide: Hide - mark_as_reviewed: Mark as reviewed - reviewed: Reviewed + archive: Archive + archived: Archived filter: Filter filters: all: All pending_review: Pending - reviewed: Reviewed - + archived: Archived diff --git a/config/locales/moderation.es.yml b/config/locales/moderation.es.yml index 2afaec7a9..61d6b5f5c 100644 --- a/config/locales/moderation.es.yml +++ b/config/locales/moderation.es.yml @@ -8,7 +8,7 @@ es: title: Moderación comments: index: - title: Comentarios Denunciados como Inapropiados + title: Comentarios denunciados como inapropiados headers: flags: Denuncias updated_at: Fecha @@ -16,28 +16,27 @@ es: commentable: Raíz comment: Comentario hide: Ocultar - mark_as_reviewed: Marcar como revisado - reviewed: Revisado + archive: Archivar + archived: Archivado filter: Filtrar filters: all: Todos pending_review: Pendientes - reviewed: Revisados + archived: Archivados debates: index: - title: Debates Denunciados como Inapropiados + title: Debates denunciados como inapropiados headers: flags: Denuncias updated_at: Fecha title: Título description: Descripción + actions: Acciones hide: Ocultar - mark_as_reviewed: Marcar como revisado - reviewed: Revisado + archive: Archivar + archived: Archivado filter: Filtrar filters: all: Todos pending_review: Pendientes - reviewed: Revisados - - + archived: Archivados From 65a91ae821d07b32eb97e97cea864575174d2fc0 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 25 Aug 2015 16:01:43 +0200 Subject: [PATCH 18/49] configures ssl for staging and production environments --- config/environments/production.rb | 2 +- config/environments/staging.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index e84606f73..7a21a1df4 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -42,7 +42,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. diff --git a/config/environments/staging.rb b/config/environments/staging.rb index e84606f73..7a21a1df4 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -42,7 +42,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. From 8bdf03c50d17dd5ad2c9ee19a7b7cbff87fe4ef0 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 25 Aug 2015 16:02:36 +0200 Subject: [PATCH 19/49] Changes some test for moderation --- .../_flag_as_inappropiate_actions.html.erb | 4 +-- config/locales/en.yml | 2 +- spec/features/comments_spec.rb | 14 +++++----- spec/features/moderation/comments_spec.rb | 28 +++++++++---------- spec/features/moderation/debates_spec.rb | 28 +++++++++---------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/app/views/comments/_flag_as_inappropiate_actions.html.erb b/app/views/comments/_flag_as_inappropiate_actions.html.erb index 0b62715e3..07440f600 100644 --- a/app/views/comments/_flag_as_inappropiate_actions.html.erb +++ b/app/views/comments/_flag_as_inappropiate_actions.html.erb @@ -5,7 +5,7 @@ <% end %> @@ -17,7 +17,7 @@ <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 55e06af4e..98ac387fc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -134,7 +134,7 @@ en: shared: tags_cloud: tags: Topics - flag_as_inappropiate: Flag as inappropiate + flag_as_inappropiate: Flag as inappropriate undo_flag_as_inappropiate: Undo flag collective: Collective mailer: diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 4ed16d915..b1b09a777 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -133,7 +133,7 @@ feature 'Comments' do expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") end - scenario "Flagging as inappropiate", :js do + scenario "Flagging as inappropriate", :js do user = create(:user) debate = create(:debate) comment = create(:comment, commentable: debate) @@ -142,15 +142,15 @@ feature 'Comments' do visit debate_path(debate) within "#comment_#{comment.id}" do - expect(page).to_not have_link "Undo flag as inappropiate" - click_on 'Flag as inappropiate' - expect(page).to have_link "Undo flag as inappropiate" + expect(page).to_not have_link "Undo flag as inappropriate" + click_on 'Flag as inappropriate' + expect(page).to have_link "Undo flag as inappropriate" end expect(InappropiateFlag.flagged?(user, comment)).to be end - scenario "Undoing flagging as inappropiate", :js do + scenario "Undoing flagging as inappropriate", :js do user = create(:user) debate = create(:debate) comment = create(:comment, commentable: debate) @@ -160,9 +160,9 @@ feature 'Comments' do visit debate_path(debate) within "#comment_#{comment.id}" do - expect(page).to_not have_link("Flag as inappropiate", exact: true) + expect(page).to_not have_link("Flag as inappropriate", exact: true) click_on 'Undo flag as inappropiate' - expect(page).to have_link("Flag as inappropiate", exact: true) + expect(page).to have_link("Flag as inappropriate", exact: true) end expect(InappropiateFlag.flagged?(user, comment)).to_not be diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb index 5a4100f77..91ed0b083 100644 --- a/spec/features/moderation/comments_spec.rb +++ b/spec/features/moderation/comments_spec.rb @@ -104,43 +104,43 @@ feature 'Moderate Comments' do visit moderation_comments_path expect(page).to_not have_link('All') expect(page).to have_link('Pending') - expect(page).to have_link('Reviewed') + expect(page).to have_link('Archived') visit moderation_comments_path(filter: 'all') expect(page).to_not have_link('All') expect(page).to have_link('Pending') - expect(page).to have_link('Reviewed') + expect(page).to have_link('Archived') visit moderation_comments_path(filter: 'pending_review') expect(page).to have_link('All') expect(page).to_not have_link('Pending') - expect(page).to have_link('Reviewed') + expect(page).to have_link('Archived') - visit moderation_comments_path(filter: 'reviewed') + visit moderation_comments_path(filter: 'archived') expect(page).to have_link('All') expect(page).to have_link('Pending') - expect(page).to_not have_link('Reviewed') + expect(page).to_not have_link('Archived') end scenario "Filtering comments" do create(:comment, :flagged_as_inappropiate, body: "Pending comment") create(:comment, :flagged_as_inappropiate, :hidden, body: "Hidden comment") - create(:comment, :flagged_as_inappropiate, :reviewed, body: "Reviewed comment") + create(:comment, :flagged_as_inappropiate, :reviewed, body: "Archived comment") visit moderation_comments_path(filter: 'all') expect(page).to have_content('Pending comment') expect(page).to_not have_content('Hidden comment') - expect(page).to have_content('Reviewed comment') + expect(page).to have_content('Archived comment') visit moderation_comments_path(filter: 'pending_review') expect(page).to have_content('Pending comment') expect(page).to_not have_content('Hidden comment') - expect(page).to_not have_content('Reviewed comment') + expect(page).to_not have_content('Archived comment') - visit moderation_comments_path(filter: 'reviewed') + visit moderation_comments_path(filter: 'archived') expect(page).to_not have_content('Pending comment') expect(page).to_not have_content('Hidden comment') - expect(page).to have_content('Reviewed comment') + expect(page).to have_content('Archived comment') end scenario "Reviewing links remember the pagination setting and the filter" do @@ -149,7 +149,7 @@ feature 'Moderate Comments' do visit moderation_comments_path(filter: 'pending_review', page: 2) - click_link('Mark as reviewed', match: :first) + click_link('Archive', match: :first) uri = URI.parse(current_url) query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys @@ -172,7 +172,7 @@ feature 'Moderate Comments' do expect(page).to have_content('spammy spam') expect(page).to have_content('1') expect(page).to have_link('Hide') - expect(page).to have_link('Mark as reviewed') + expect(page).to have_link('Archive') end end @@ -189,13 +189,13 @@ feature 'Moderate Comments' do scenario 'Marking the comment as reviewed' do within("#comment_#{@comment.id}") do - click_link('Mark as reviewed') + click_link('Archive') end expect(current_path).to eq(moderation_comments_path) within("#comment_#{@comment.id}") do - expect(page).to have_content('Reviewed') + expect(page).to have_content('Archived') end expect(@comment.reload).to be_reviewed diff --git a/spec/features/moderation/debates_spec.rb b/spec/features/moderation/debates_spec.rb index 1ea3101e0..9a2dfbd24 100644 --- a/spec/features/moderation/debates_spec.rb +++ b/spec/features/moderation/debates_spec.rb @@ -47,43 +47,43 @@ feature 'Moderate debates' do visit moderation_debates_path expect(page).to_not have_link('All') expect(page).to have_link('Pending') - expect(page).to have_link('Reviewed') + expect(page).to have_link('Archived') visit moderation_debates_path(filter: 'all') expect(page).to_not have_link('All') expect(page).to have_link('Pending') - expect(page).to have_link('Reviewed') + expect(page).to have_link('Archived') visit moderation_debates_path(filter: 'pending_review') expect(page).to have_link('All') expect(page).to_not have_link('Pending') - expect(page).to have_link('Reviewed') + expect(page).to have_link('Archived') - visit moderation_debates_path(filter: 'reviewed') + visit moderation_debates_path(filter: 'archived') expect(page).to have_link('All') expect(page).to have_link('Pending') - expect(page).to_not have_link('Reviewed') + expect(page).to_not have_link('Archived') end scenario "Filtering debates" do create(:debate, :flagged_as_inappropiate, title: "Pending debate") create(:debate, :flagged_as_inappropiate, :hidden, title: "Hidden debate") - create(:debate, :flagged_as_inappropiate, :reviewed, title: "Reviewed debate") + create(:debate, :flagged_as_inappropiate, :reviewed, title: "Archived debate") visit moderation_debates_path(filter: 'all') expect(page).to have_content('Pending debate') expect(page).to_not have_content('Hidden debate') - expect(page).to have_content('Reviewed debate') + expect(page).to have_content('Archived debate') visit moderation_debates_path(filter: 'pending_review') expect(page).to have_content('Pending debate') expect(page).to_not have_content('Hidden debate') - expect(page).to_not have_content('Reviewed debate') + expect(page).to_not have_content('Archived debate') - visit moderation_debates_path(filter: 'reviewed') + visit moderation_debates_path(filter: 'archived') expect(page).to_not have_content('Pending debate') expect(page).to_not have_content('Hidden debate') - expect(page).to have_content('Reviewed debate') + expect(page).to have_content('Archived debate') end scenario "Reviewing links remember the pagination setting and the filter" do @@ -92,7 +92,7 @@ feature 'Moderate debates' do visit moderation_debates_path(filter: 'pending_review', page: 2) - click_link('Mark as reviewed', match: :first) + click_link('Archive', match: :first) uri = URI.parse(current_url) query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys @@ -114,7 +114,7 @@ feature 'Moderate debates' do expect(page).to have_content('buy buy buy') expect(page).to have_content('1') expect(page).to have_link('Hide') - expect(page).to have_link('Mark as reviewed') + expect(page).to have_link('Archive') end end @@ -131,13 +131,13 @@ feature 'Moderate debates' do scenario 'Marking the debate as reviewed' do within("#debate_#{@debate.id}") do - click_link('Mark as reviewed') + click_link('Archive') end expect(current_path).to eq(moderation_debates_path) within("#debate_#{@debate.id}") do - expect(page).to have_content('Reviewed') + expect(page).to have_content('Archived') end expect(@debate.reload).to be_reviewed From 96dc85d1a5372a3026f2da3bfd7a51819bf2e774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 25 Aug 2015 15:58:23 +0200 Subject: [PATCH 20/49] adds cache columns to acs_as_votable models --- ...21_adds_votable_cache_field_to_comments.rb | 19 +++++++++++ ...827_adds_votable_cache_field_to_debates.rb | 19 +++++++++++ db/schema.rb | 32 +++++++++++++++++-- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150825124821_adds_votable_cache_field_to_comments.rb create mode 100644 db/migrate/20150825124827_adds_votable_cache_field_to_debates.rb diff --git a/db/migrate/20150825124821_adds_votable_cache_field_to_comments.rb b/db/migrate/20150825124821_adds_votable_cache_field_to_comments.rb new file mode 100644 index 000000000..69f4cad30 --- /dev/null +++ b/db/migrate/20150825124821_adds_votable_cache_field_to_comments.rb @@ -0,0 +1,19 @@ +class AddsVotableCacheFieldToComments < ActiveRecord::Migration + def change + add_column :comments, :cached_votes_total, :integer, default: 0 + add_column :comments, :cached_votes_score, :integer, default: 0 + add_column :comments, :cached_votes_up, :integer, default: 0 + add_column :comments, :cached_votes_down, :integer, default: 0 + add_column :comments, :cached_weighted_score, :integer, default: 0 + add_column :comments, :cached_weighted_total, :integer, default: 0 + add_column :comments, :cached_weighted_average, :float, default: 0 + + add_index :comments, :cached_votes_total + add_index :comments, :cached_votes_score + add_index :comments, :cached_votes_up + add_index :comments, :cached_votes_down + add_index :comments, :cached_weighted_score + add_index :comments, :cached_weighted_total + add_index :comments, :cached_weighted_average + end +end diff --git a/db/migrate/20150825124827_adds_votable_cache_field_to_debates.rb b/db/migrate/20150825124827_adds_votable_cache_field_to_debates.rb new file mode 100644 index 000000000..d34993654 --- /dev/null +++ b/db/migrate/20150825124827_adds_votable_cache_field_to_debates.rb @@ -0,0 +1,19 @@ +class AddsVotableCacheFieldToDebates < ActiveRecord::Migration + def change + add_column :debates, :cached_votes_total, :integer, default: 0 + add_column :debates, :cached_votes_score, :integer, default: 0 + add_column :debates, :cached_votes_up, :integer, default: 0 + add_column :debates, :cached_votes_down, :integer, default: 0 + add_column :debates, :cached_weighted_score, :integer, default: 0 + add_column :debates, :cached_weighted_total, :integer, default: 0 + add_column :debates, :cached_weighted_average, :float, default: 0 + + add_index :debates, :cached_votes_total + add_index :debates, :cached_votes_score + add_index :debates, :cached_votes_up + add_index :debates, :cached_votes_down + add_index :debates, :cached_weighted_score + add_index :debates, :cached_weighted_total + add_index :debates, :cached_weighted_average + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index d21459719..b3911bb57 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150824144524) do +ActiveRecord::Schema.define(version: 20150825124827) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(version: 20150824144524) do t.string "title" t.text "body" t.string "subject" - t.integer "user_id", null: false + t.integer "user_id", null: false t.integer "parent_id" t.integer "lft" t.integer "rgt" @@ -54,8 +54,22 @@ ActiveRecord::Schema.define(version: 20150824144524) do t.datetime "reviewed_at" t.integer "moderator_id" t.integer "administrator_id" + t.integer "cached_votes_total", default: 0 + t.integer "cached_votes_score", default: 0 + t.integer "cached_votes_up", default: 0 + t.integer "cached_votes_down", default: 0 + t.integer "cached_weighted_score", default: 0 + t.integer "cached_weighted_total", default: 0 + t.float "cached_weighted_average", default: 0.0 end + add_index "comments", ["cached_votes_down"], name: "index_comments_on_cached_votes_down", using: :btree + add_index "comments", ["cached_votes_score"], name: "index_comments_on_cached_votes_score", using: :btree + add_index "comments", ["cached_votes_total"], name: "index_comments_on_cached_votes_total", using: :btree + add_index "comments", ["cached_votes_up"], name: "index_comments_on_cached_votes_up", using: :btree + add_index "comments", ["cached_weighted_average"], name: "index_comments_on_cached_weighted_average", using: :btree + add_index "comments", ["cached_weighted_score"], name: "index_comments_on_cached_weighted_score", using: :btree + add_index "comments", ["cached_weighted_total"], name: "index_comments_on_cached_weighted_total", using: :btree add_index "comments", ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type", using: :btree add_index "comments", ["hidden_at"], name: "index_comments_on_hidden_at", using: :btree add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree @@ -71,8 +85,22 @@ ActiveRecord::Schema.define(version: 20150824144524) do t.datetime "flagged_as_inappropiate_at" t.integer "inappropiate_flags_count", default: 0 t.datetime "reviewed_at" + t.integer "cached_votes_total", default: 0 + t.integer "cached_votes_score", default: 0 + t.integer "cached_votes_up", default: 0 + t.integer "cached_votes_down", default: 0 + t.integer "cached_weighted_score", default: 0 + t.integer "cached_weighted_total", default: 0 + t.float "cached_weighted_average", default: 0.0 end + add_index "debates", ["cached_votes_down"], name: "index_debates_on_cached_votes_down", using: :btree + add_index "debates", ["cached_votes_score"], name: "index_debates_on_cached_votes_score", using: :btree + add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree + add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree + add_index "debates", ["cached_weighted_average"], name: "index_debates_on_cached_weighted_average", using: :btree + add_index "debates", ["cached_weighted_score"], name: "index_debates_on_cached_weighted_score", using: :btree + add_index "debates", ["cached_weighted_total"], name: "index_debates_on_cached_weighted_total", using: :btree add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree create_table "identities", force: :cascade do |t| From cfe583fbe6619857ae6bbe980305c8ae19a31f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 25 Aug 2015 15:58:49 +0200 Subject: [PATCH 21/49] adds cache to votes on Comments --- app/models/comment.rb | 10 +++++++++- app/views/comments/_votes.html.erb | 5 ++--- config/locales/en.yml | 1 - config/locales/es.yml | 1 - spec/factories.rb | 3 +++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 824f1dbf0..a9dc68505 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -49,7 +49,15 @@ class Comment < ActiveRecord::Base end def total_votes - votes_for.size + cached_votes_total + end + + def total_likes + cached_votes_up + end + + def total_dislikes + cached_votes_down end def not_visible? diff --git a/app/views/comments/_votes.html.erb b/app/views/comments/_votes.html.erb index 73efa56ba..d7af65bff 100644 --- a/app/views/comments/_votes.html.erb +++ b/app/views/comments/_votes.html.erb @@ -1,5 +1,4 @@ - <%= t('debates.comment.votes', count: comment.total_votes) %>  |  @@ -8,7 +7,7 @@ method: "post", remote: true do %> <% end %> - <%= comment.get_likes.size %> + <%= comment.total_likes %> @@ -16,5 +15,5 @@ method: "post", remote: true do %> <% end %> - <%= comment.get_dislikes.size %> + <%= comment.total_dislikes %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 279b2a00e..e3ebf62d6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -61,7 +61,6 @@ en: zero: No votes one: 1 vote other: "%{count} votes" - votes_weighted_score: "Total: %{score}" form: debate_title: Debate title title_instructions: "SBe clear and precise with the title, but make it informative" diff --git a/config/locales/es.yml b/config/locales/es.yml index 98c463b1e..4097c22b9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -61,7 +61,6 @@ es: zero: Sin votos one: 1 voto other: "%{count} votos" - votes_weighted_score: "Total: %{score}" form: debate_title: Título del debate title_instructions: "Sé claro y conciso a la hora de poner un título, pero recuerda que debe explicar bien tu idea, ¡es tu carta de entrada!" diff --git a/spec/factories.rb b/spec/factories.rb index 4fa2a70e3..0a4922411 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -37,6 +37,9 @@ FactoryGirl.define do association :votable, factory: :debate association :voter, factory: :user vote_flag true + after(:create) do |vote, _| + vote.votable.update_cached_votes + end end factory :comment do From 6ead1a2c1d1e82654b3a223e602650824d842b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 25 Aug 2015 16:22:47 +0200 Subject: [PATCH 22/49] adds cache to votes on Debates --- app/models/debate.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/debate.rb b/app/models/debate.rb index c16048f70..2f93dfa2b 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -40,15 +40,15 @@ class Debate < ActiveRecord::Base end def likes - get_likes.size + cached_votes_up end def dislikes - get_dislikes.size + cached_votes_down end def total_votes - votes_for.size + cached_votes_total end def editable? From 7d17209be63e8eaf4c7e18ed1bb10d5ff78e43ab Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 25 Aug 2015 16:47:53 +0200 Subject: [PATCH 23/49] Adds styles for organization success registration [#226] --- app/assets/stylesheets/participacion.scss | 22 ++++++++++++++++-- app/assets/stylesheets/variables.scss | 1 + .../registrations/success.html.erb | 23 ++++++++++++------- config/locales/devise_views.en.yml | 12 ++++------ config/locales/devise_views.es.yml | 11 ++++----- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index e6aea4db2..9d5487ac9 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -150,6 +150,19 @@ h1, h2, h3, h4, h5, h6 { } } +.margin { + margin-top: $line-height; + margin-bottom: $line-height; +} + +.margin-top { + margin-top: $line-height; +} + +.margin-bottom { + margin-bottom: $line-height; +} + // 04. Header // - - - - - - - - - - - - - - - - - - - - - - - - - @@ -494,9 +507,14 @@ footer { h2 { clear: both; - font-size: rem-calc(30); + font-size: rem-calc(18); font-weight: bold; - line-height: $line-height*2; + line-height: $line-height; + + @media (min-width: $small-breakpoint) { + font-size: rem-calc(30); + line-height: $line-height*2; + } } .back, .icon-angle-left { diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss index 93107e3d2..7d4baeff4 100644 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -83,6 +83,7 @@ $comment-level-5: rgba(255,241,204,1); // 06. Responsive // - - - - - - - - - - - - - - - - - - - - - - - - - +$small: em-calc(480); $small-breakpoint: em-calc(640); $medium-breakpoint: em-calc(1024); $large-breakpoint: em-calc(1440); diff --git a/app/views/organizations/registrations/success.html.erb b/app/views/organizations/registrations/success.html.erb index 91c377102..d4c0953f6 100644 --- a/app/views/organizations/registrations/success.html.erb +++ b/app/views/organizations/registrations/success.html.erb @@ -1,8 +1,15 @@ -

    <%= t('devise_views.organizations.registrations.success.title') %>

    - -

    <%= t('devise_views.organizations.registrations.success.thank_you') %>

    - -

    <%= t('devise_views.organizations.registrations.success.instructions') %>

    - -

    <%= link_to t('devise_views.organizations.registrations.success.back_to_index'), root_path %>

    - +
    +
    +
    +

    <%= t("devise_views.organizations.registrations.success.title") %>

    +

    <%= raw t("devise_views.organizations.registrations.success.thank_you") %>

    +

    <%= raw t("devise_views.organizations.registrations.success.instructions_1") %>

    +

    <%= raw t("devise_views.organizations.registrations.success.instructions_2") %>

    +

    <%= raw t("devise_views.organizations.registrations.success.instructions_3") %>

    +

    + <%= link_to t("devise_views.organizations.registrations.success.back_to_index"), + root_path, class: "button radius small margin-top" %> +

    +
    +
    +
    diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index 394c3611c..0a459ffbf 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -67,13 +67,11 @@ en: password_confirmation_label: "Confirm password" submit: "Sign up" success: - title: "Registration of organization / collective pending verification" - thank_you: "Thank you for registering your organization or collective in the website." - instructions: - We will contact you soon in order to verify that you represent your collective. - Meanwhile, please review your email. We have sent you a confirmation link which you - will have to click in order to activate your account. You will then be able to participate - as a non-verified organization. + title: "Registration of organization / collective" + thank_you: "Thank you for registering your organization or collective in the website. Now is pending verification." + instructions_1: "We will contact you soon in order to verify that you represent your collective." + instructions_2: "Meanwhile, review your email. We have sent you a confirmation link to activate your account." + instructions_3: "When you confirm your account will then be able to participate as a non-verified organization." back_to_index: "Ok, go back to index" sessions: new: diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index e27065038..2d582fde9 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -67,12 +67,11 @@ es: password_confirmation_label: "Confirmar contraseña" submit: "Registrarse" success: - title: "Registro de organización / colectivo pendiente de verificación" - thank_you: "Gracias por registrar tu colectivo en la web." - instructions: - En breve nos pondremos en contacto contigo para verificar que realmente representas a un colectivo. - Entretanto, por favor revisa tu correo electrónico. Te hemos enviado un enlace que debes pulsar para confirmar - tu correo. Una vez confirmado, podrás empezar a participar como colectivo no verificado. + title: "Registro de organización / colectivo" + thank_you: "Gracias por registrar tu colectivo en la web. Ahora está pendiente de verificación." + instructions_1: "En breve nos pondremos en contacto contigo para verificar que realmente representas a este colectivo." + instructions_2: "Mientras revisa tu correo electrónico, te hemos enviado un enlace para confirmartu cuenta." + instructions_3: "Una vez confirmado, podrás empezar a participar como colectivo no verificado." back_to_index: "Entendido, volver a la página principal" sessions: new: From f47fbe82d5b0c6b5ade7f3e3f98e4a0b154dba83 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 25 Aug 2015 19:22:57 +0200 Subject: [PATCH 24/49] Uses *_html tags instead of calling raw in the view --- app/views/organizations/registrations/success.html.erb | 8 ++++---- config/locales/devise_views.en.yml | 6 +++--- config/locales/devise_views.es.yml | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/organizations/registrations/success.html.erb b/app/views/organizations/registrations/success.html.erb index d4c0953f6..e246365f5 100644 --- a/app/views/organizations/registrations/success.html.erb +++ b/app/views/organizations/registrations/success.html.erb @@ -2,10 +2,10 @@

    <%= t("devise_views.organizations.registrations.success.title") %>

    -

    <%= raw t("devise_views.organizations.registrations.success.thank_you") %>

    -

    <%= raw t("devise_views.organizations.registrations.success.instructions_1") %>

    -

    <%= raw t("devise_views.organizations.registrations.success.instructions_2") %>

    -

    <%= raw t("devise_views.organizations.registrations.success.instructions_3") %>

    +

    <%= t("devise_views.organizations.registrations.success.thank_you") %>

    +

    <%= t("devise_views.organizations.registrations.success.instructions_1_html") %>

    +

    <%= t("devise_views.organizations.registrations.success.instructions_2_html") %>

    +

    <%= t("devise_views.organizations.registrations.success.instructions_3_html") %>

    <%= link_to t("devise_views.organizations.registrations.success.back_to_index"), root_path, class: "button radius small margin-top" %> diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index 0a459ffbf..f0e1eb33a 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -69,9 +69,9 @@ en: success: title: "Registration of organization / collective" thank_you: "Thank you for registering your organization or collective in the website. Now is pending verification." - instructions_1: "We will contact you soon in order to verify that you represent your collective." - instructions_2: "Meanwhile, review your email. We have sent you a confirmation link to activate your account." - instructions_3: "When you confirm your account will then be able to participate as a non-verified organization." + instructions_1_html: "We will contact you soon in order to verify that you represent your collective." + instructions_2_html: "Meanwhile, review your email. We have sent you a confirmation link to activate your account." + instructions_3_html: "When you confirm your account will then be able to participate as a non-verified organization." back_to_index: "Ok, go back to index" sessions: new: diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index 2d582fde9..49d304748 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -69,9 +69,9 @@ es: success: title: "Registro de organización / colectivo" thank_you: "Gracias por registrar tu colectivo en la web. Ahora está pendiente de verificación." - instructions_1: "En breve nos pondremos en contacto contigo para verificar que realmente representas a este colectivo." - instructions_2: "Mientras revisa tu correo electrónico, te hemos enviado un enlace para confirmartu cuenta." - instructions_3: "Una vez confirmado, podrás empezar a participar como colectivo no verificado." + instructions_1_html: "En breve nos pondremos en contacto contigo para verificar que realmente representas a este colectivo." + instructions_2_html: "Mientras revisa tu correo electrónico, te hemos enviado un enlace para confirmar tu cuenta." + instructions_3_html: "Una vez confirmado, podrás empezar a participar como colectivo no verificado." back_to_index: "Entendido, volver a la página principal" sessions: new: From 70b40b6ce8753db2779cac6349201640e6cebb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 25 Aug 2015 21:58:38 -0300 Subject: [PATCH 25/49] simplifies redundant commands in README Use either `bundle exec` or bundler generated binstubs, but not both. Since you are committing binstubs to source control, I assume you want the latter. --- README.md | 8 ++++---- README_EN.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 87e0d1ab9..a3433df9d 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ cd participacion bundle install cp config/database.yml.example config/database.yml cp config/secrets.yml.example config/secrets.yml -bundle exec bin/rake db:setup -RAILS_ENV=test bundle exec rake db:setup +bin/rake db:setup +RAILS_ENV=test bin/rake db:setup ``` Para ejecutar la aplicación en local: ``` -bundle exec bin/rails s +bin/rails s ``` Prerequisitos para los tests: tener instalado PhantomJS >= 2.0 @@ -41,7 +41,7 @@ Prerequisitos para los tests: tener instalado PhantomJS >= 2.0 Para ejecutar los tests: ``` -bundle exec bin/rspec +bin/rspec ``` ### OAuth diff --git a/README_EN.md b/README_EN.md index 9ebc58731..a3dd63106 100644 --- a/README_EN.md +++ b/README_EN.md @@ -28,13 +28,13 @@ cd participacion bundle install cp config/database.yml.example config/database.yml cp config/secrets.yml.example config/secrets.yml -bundle exec bin/rake db:setup -RAILS_ENV=test bundle exec rake db:setup +bin/rake db:setup +RAILS_ENV=test bin/rake db:setup ``` Run the app locally: ``` -bundle exec bin/rails s +bin/rails s ``` Prerequisites for testing: install PhantomJS >= 2.0 @@ -42,7 +42,7 @@ Prerequisites for testing: install PhantomJS >= 2.0 Run the tests with: ``` -bundle exec bin/rspec +bin/rspec ``` ## Licence From 98c6f6561c9ed85bcb99bac32815f6c3ddcaf469 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 26 Aug 2015 11:37:41 +0200 Subject: [PATCH 26/49] removes force ssl in staging env --- config/environments/staging.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 7a21a1df4..e84606f73 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -42,7 +42,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true + # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. From 1a806db80db7221de657b02edb44fa408bf7703a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 26 Aug 2015 11:46:09 +0200 Subject: [PATCH 27/49] removes ssl from production env --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 7a21a1df4..e84606f73 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -42,7 +42,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true + # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. From 30d996da845c0410b57274c91c00638e87a2e158 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 26 Aug 2015 12:00:34 +0200 Subject: [PATCH 28/49] force ssl in staging --- config/environments/staging.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index e84606f73..7a21a1df4 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -42,7 +42,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. From c13aea5f1d9bedae45dea9fc0899a00d610adde3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 26 Aug 2015 12:03:28 +0200 Subject: [PATCH 29/49] removes force ssl from staging --- config/environments/staging.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 7a21a1df4..e84606f73 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -42,7 +42,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true + # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. From e219e5be4d737de98d8762cfdc08f34c6d140b3c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 26 Aug 2015 12:22:58 +0200 Subject: [PATCH 30/49] adds force ssl to staging --- config/environments/staging.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index e84606f73..7a21a1df4 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -42,7 +42,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. From 46bd0f2c7f9d4cd244da41a4ce80ed325e9cb418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 26 Aug 2015 12:24:37 +0200 Subject: [PATCH 31/49] adds basic style/content to moderation dashboard --- app/views/moderation/_menu.html.erb | 4 ++-- app/views/moderation/dashboard/index.html.erb | 6 +++++- app/views/shared/_tags.html.erb | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/moderation/_menu.html.erb b/app/views/moderation/_menu.html.erb index 41e84287a..3971b3b51 100644 --- a/app/views/moderation/_menu.html.erb +++ b/app/views/moderation/_menu.html.erb @@ -6,14 +6,14 @@

  • > <%= link_to moderation_debates_path do %> - + <%= t('moderation.menu.flagged_debates') %> <% end %>
  • > <%= link_to moderation_comments_path do %> - + <%= t('moderation.menu.flagged_comments') %> <% end %>
  • diff --git a/app/views/moderation/dashboard/index.html.erb b/app/views/moderation/dashboard/index.html.erb index 16eb4508f..df41493e6 100644 --- a/app/views/moderation/dashboard/index.html.erb +++ b/app/views/moderation/dashboard/index.html.erb @@ -1 +1,5 @@ -

    <%= t("moderation.dashboard.index.title") %>

    +

    <%= t("moderation.dashboard.index.title") %>

    + +

    Lorem ipsum moderator sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

    + +

    Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.

    diff --git a/app/views/shared/_tags.html.erb b/app/views/shared/_tags.html.erb index 6a61bd4b4..2b599ec77 100644 --- a/app/views/shared/_tags.html.erb +++ b/app/views/shared/_tags.html.erb @@ -10,4 +10,4 @@ <%= link_to "#{debate.tags_count_out_of_limit(limit)}+", debate_path(debate) %> <% end %> -<% end %> +<% end %> \ No newline at end of file From 5eeb89584b6563a9de58fd1769d7d9328cd19ba2 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 26 Aug 2015 13:14:07 +0200 Subject: [PATCH 32/49] Fixes a couple specs which fail with the new words (ArchiveD vs Archive) --- spec/features/moderation/comments_spec.rb | 2 +- spec/features/moderation/debates_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb index 91ed0b083..ba40598d8 100644 --- a/spec/features/moderation/comments_spec.rb +++ b/spec/features/moderation/comments_spec.rb @@ -149,7 +149,7 @@ feature 'Moderate Comments' do visit moderation_comments_path(filter: 'pending_review', page: 2) - click_link('Archive', match: :first) + click_link('Archive', match: :first, exact: true) uri = URI.parse(current_url) query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys diff --git a/spec/features/moderation/debates_spec.rb b/spec/features/moderation/debates_spec.rb index 9a2dfbd24..d27a5b9fc 100644 --- a/spec/features/moderation/debates_spec.rb +++ b/spec/features/moderation/debates_spec.rb @@ -92,7 +92,7 @@ feature 'Moderate debates' do visit moderation_debates_path(filter: 'pending_review', page: 2) - click_link('Archive', match: :first) + click_link('Archive', match: :first, exact: true) uri = URI.parse(current_url) query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys From 015fe704e4afcaab689e7f07cdb6d5a2ba3e0ff1 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 26 Aug 2015 13:14:42 +0200 Subject: [PATCH 33/49] Fixes flagging specs by making them id-based instead of text-based --- .../_flag_as_inappropiate_actions.html.erb | 12 ++++++------ .../_flag_as_inappropiate_actions.html.erb | 12 ++++++------ spec/features/comments_spec.rb | 16 +++++++++------- spec/features/debates_spec.rb | 14 ++++++++------ 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/views/comments/_flag_as_inappropiate_actions.html.erb b/app/views/comments/_flag_as_inappropiate_actions.html.erb index 07440f600..9fba8b5b2 100644 --- a/app/views/comments/_flag_as_inappropiate_actions.html.erb +++ b/app/views/comments/_flag_as_inappropiate_actions.html.erb @@ -1,23 +1,23 @@ <% if can? :flag_as_inappropiate, comment %>  |  - -