Merge pull request #479 from AyuntamientoMadrid/orgs-responsible
Orgs responsible
This commit is contained in:
@@ -23,7 +23,7 @@ class AccountController < ApplicationController
|
|||||||
|
|
||||||
def account_params
|
def account_params
|
||||||
if @account.organization?
|
if @account.organization?
|
||||||
params.require(:account).permit(:phone_number, :email_on_debate_comment, :email_on_comment_reply, organization_attributes: [:name])
|
params.require(:account).permit(:phone_number, :email_on_debate_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name])
|
||||||
else
|
else
|
||||||
params.require(:account).permit(:username, :email_on_debate_comment, :email_on_comment_reply)
|
params.require(:account).permit(:username, :email_on_debate_comment, :email_on_comment_reply)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class Organizations::RegistrationsController < Devise::RegistrationsController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def sign_up_params
|
def sign_up_params
|
||||||
params.require(:user).permit(:email, :password, :phone_number, :password_confirmation, :captcha, :captcha_key, :terms_of_service, organization_attributes: [:name])
|
params.require(:user).permit(:email, :password, :phone_number, :password_confirmation, :captcha, :captcha_key, :terms_of_service, organization_attributes: [:name, :responsible_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ class VerificationController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def next_step_path(user = current_user)
|
def next_step_path(user = current_user)
|
||||||
if user.level_three_verified?
|
if user.organization?
|
||||||
|
{ path: account_path }
|
||||||
|
elsif user.level_three_verified?
|
||||||
{ path: account_path, notice: t('verification.redirect_notices.already_verified') }
|
{ path: account_path, notice: t('verification.redirect_notices.already_verified') }
|
||||||
elsif user.verification_letter_sent?
|
elsif user.verification_letter_sent?
|
||||||
{ path: edit_letter_path }
|
{ path: edit_letter_path }
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ class Organization < ActiveRecord::Base
|
|||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :name, uniqueness: true
|
validates :name, uniqueness: true
|
||||||
validate :validate_name_length
|
validate :validate_name_length
|
||||||
|
validates :responsible_name, presence: true
|
||||||
|
validate :validate_responsible_name_length
|
||||||
|
|
||||||
delegate :email, :phone_number, to: :user
|
delegate :email, :phone_number, to: :user
|
||||||
|
|
||||||
@@ -37,6 +39,10 @@ class Organization < ActiveRecord::Base
|
|||||||
@@name_max_length ||= self.columns.find { |c| c.name == 'name' }.limit || 60
|
@@name_max_length ||= self.columns.find { |c| c.name == 'name' }.limit || 60
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.responsible_name_max_length
|
||||||
|
@@responsible_name_max_length ||= self.columns.find { |c| c.name == 'responsible_name' }.limit || 60
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def validate_name_length
|
def validate_name_length
|
||||||
@@ -46,4 +52,11 @@ class Organization < ActiveRecord::Base
|
|||||||
validator.validate(self)
|
validator.validate(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_responsible_name_length
|
||||||
|
validator = ActiveModel::Validations::LengthValidator.new(
|
||||||
|
attributes: :responsible_name,
|
||||||
|
maximum: Organization.responsible_name_max_length)
|
||||||
|
validator.validate(self)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
validates_associated :organization, message: false
|
validates_associated :organization, message: false
|
||||||
|
|
||||||
accepts_nested_attributes_for :organization
|
accepts_nested_attributes_for :organization, update_only: true
|
||||||
|
|
||||||
scope :administrators, -> { joins(:administrators) }
|
scope :administrators, -> { joins(:administrators) }
|
||||||
scope :moderators, -> { joins(:moderator) }
|
scope :moderators, -> { joins(:moderator) }
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
<div class="row account">
|
<div class="row account">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: "button radius small secondary right" %>
|
<%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: "button radius small secondary right" %>
|
||||||
|
<% unless @account.organization? %>
|
||||||
<div>
|
<div>
|
||||||
<span class="right verify-account">
|
<span class="right verify-account">
|
||||||
<% if current_user.level_three_verified? %>
|
<% if current_user.level_three_verified? %>
|
||||||
<p class="verified">
|
<p class="verified">
|
||||||
<i class="icon-check"></i>
|
<i class="icon-check"></i>
|
||||||
<%= t("account.show.verified_account") %>
|
<%= t("account.show.verified_account") %>
|
||||||
</p>
|
</p>
|
||||||
<% elsif current_user.level_two_verified? %>
|
<% elsif current_user.level_two_verified? %>
|
||||||
<%= link_to t("account.show.finish_verification"), verification_path, class: "button radius small success right" %>
|
<%= link_to t("account.show.finish_verification"), verification_path, class: "button radius small success right" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t("account.show.verify_my_account"), verification_path, class: "button radius small success right" %>
|
<%= link_to t("account.show.verify_my_account"), verification_path, class: "button radius small success right" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
<h1 class="inline-block"><%= t("account.show.title") %></h1>
|
<h1 class="inline-block"><%= t("account.show.title") %></h1>
|
||||||
|
|
||||||
<%= form_for @account, as: :account, url: account_path do |f| %>
|
<%= form_for @account, as: :account, url: account_path do |f| %>
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
<% if @account.organization? %>
|
<% if @account.organization? %>
|
||||||
<%= f.fields_for :organization do |fo| %>
|
<%= f.fields_for :organization do |fo| %>
|
||||||
<%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("account.show.organization_name_label") %>
|
<%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("account.show.organization_name_label") %>
|
||||||
|
<%= fo.text_field :responsible_name, autofocus: true, maxlength: Organization.responsible_name_max_length, placeholder: t("account.show.organization_responsible_name_placeholder") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>
|
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
<td><%= organization.name %></td>
|
<td><%= organization.name %></td>
|
||||||
<td><%= organization.email %></td>
|
<td><%= organization.email %></td>
|
||||||
<td><%= organization.phone_number %></td>
|
<td><%= organization.phone_number %></td>
|
||||||
|
<td><%= organization.responsible_name %></td>
|
||||||
<% if organization.verified? %>
|
<% if organization.verified? %>
|
||||||
<td class="verified">
|
<td class="verified">
|
||||||
<i class="icon-check"></i>
|
<i class="icon-check"></i>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
<td><%= organization.name %></td>
|
<td><%= organization.name %></td>
|
||||||
<td><%= organization.email %></td>
|
<td><%= organization.email %></td>
|
||||||
<td><%= organization.phone_number %></td>
|
<td><%= organization.phone_number %></td>
|
||||||
|
<td><%= organization.responsible_name %></td>
|
||||||
<% if organization.verified? %>
|
<% if organization.verified? %>
|
||||||
<td class="verified">
|
<td class="verified">
|
||||||
<i class="icon-check"></i>
|
<i class="icon-check"></i>
|
||||||
|
|||||||
@@ -7,9 +7,12 @@
|
|||||||
|
|
||||||
<%= f.fields_for :organization do |fo| %>
|
<%= f.fields_for :organization do |fo| %>
|
||||||
<%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("devise_views.organizations.registrations.new.organization_name_label") %>
|
<%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("devise_views.organizations.registrations.new.organization_name_label") %>
|
||||||
|
<%= fo.label t("devise_views.organizations.registrations.new.responsible_name_label") %>
|
||||||
|
<span class="note"><%= t("devise_views.organizations.registrations.new.responsible_name_note") %></span>
|
||||||
|
<%= fo.text_field :responsible_name, maxlength: Organization.responsible_name_max_length, label: false %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %>
|
<%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %>
|
||||||
|
|
||||||
<%= f.text_field :phone_number, placeholder: t("devise_views.organizations.registrations.new.phone_number_label") %>
|
<%= f.text_field :phone_number, placeholder: t("devise_views.organizations.registrations.new.phone_number_label") %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
<div class="auth row">
|
<h2><%= t("devise_views.organizations.registrations.success.title") %></h2>
|
||||||
<div class="small-12 medium-8 column small-centered">
|
<p><%= t("devise_views.organizations.registrations.success.thank_you_html") %></p>
|
||||||
<div class="panel">
|
<p><%= t("devise_views.organizations.registrations.success.instructions_1_html") %></p>
|
||||||
<h2><%= t("devise_views.organizations.registrations.success.title") %></h2>
|
<p><%= t("devise_views.organizations.registrations.success.instructions_2_html") %></p>
|
||||||
<p><%= t("devise_views.organizations.registrations.success.thank_you_html") %></p>
|
<p><%= t("devise_views.organizations.registrations.success.instructions_3_html") %></p>
|
||||||
<p><%= t("devise_views.organizations.registrations.success.instructions_1_html") %></p>
|
<p>
|
||||||
<p><%= t("devise_views.organizations.registrations.success.instructions_2_html") %></p>
|
<%= link_to t("devise_views.organizations.registrations.success.back_to_index"),
|
||||||
<p><%= t("devise_views.organizations.registrations.success.instructions_3_html") %></p>
|
root_path, class: "button radius small margin-top expand" %>
|
||||||
<p>
|
</p>
|
||||||
<%= link_to t("devise_views.organizations.registrations.success.back_to_index"),
|
|
||||||
root_path, class: "button radius small margin-top" %>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -25,3 +25,4 @@ en:
|
|||||||
official_level: Official level
|
official_level: Official level
|
||||||
organization:
|
organization:
|
||||||
name: Organization name
|
name: Organization name
|
||||||
|
responsible_name: Person in charge
|
||||||
|
|||||||
@@ -25,3 +25,4 @@ es:
|
|||||||
official_level: Nivel del cargo
|
official_level: Nivel del cargo
|
||||||
organization:
|
organization:
|
||||||
name: Nombre de organización
|
name: Nombre de organización
|
||||||
|
responsible_name: Persona responsable del colectivo
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ en:
|
|||||||
new:
|
new:
|
||||||
title: "Sign up as organization / collective"
|
title: "Sign up as organization / collective"
|
||||||
organization_name_label: "Organization name"
|
organization_name_label: "Organization name"
|
||||||
|
responsible_name_label: "Name and surname of the person in charge"
|
||||||
|
responsible_name_note: "The responsible representative of the organization"
|
||||||
email_label: "Email"
|
email_label: "Email"
|
||||||
password_label: "Password"
|
password_label: "Password"
|
||||||
phone_number_label: "Phone number"
|
phone_number_label: "Phone number"
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ es:
|
|||||||
new:
|
new:
|
||||||
title: "Registrarse como organización / colectivo"
|
title: "Registrarse como organización / colectivo"
|
||||||
organization_name_label: "Nombre de la organización"
|
organization_name_label: "Nombre de la organización"
|
||||||
|
responsible_name_label: "Nombre y apellidos de la persona responsable del colectivo"
|
||||||
|
responsible_name_note: "Será la persona representante de la asociación/colectivo en cuyo nombre se presenten las propuestas"
|
||||||
email_label: "Email"
|
email_label: "Email"
|
||||||
password_label: "Contraseña"
|
password_label: "Contraseña"
|
||||||
phone_number_label: "Teléfono"
|
phone_number_label: "Teléfono"
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ en:
|
|||||||
username_label: "Username"
|
username_label: "Username"
|
||||||
phone_number_label: "Phone number"
|
phone_number_label: "Phone number"
|
||||||
organization_name_label: "Organization name"
|
organization_name_label: "Organization name"
|
||||||
|
organization_responsible_name_placeholder: "The responsible representative of the organization"
|
||||||
notifications: Notifications
|
notifications: Notifications
|
||||||
finish_verification: "Finish verification"
|
finish_verification: "Finish verification"
|
||||||
verified_account: Verified account
|
verified_account: Verified account
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ es:
|
|||||||
username_label: "Nombre de usuario"
|
username_label: "Nombre de usuario"
|
||||||
phone_number_label: "Teléfono"
|
phone_number_label: "Teléfono"
|
||||||
organization_name_label: "Nombre de la organización"
|
organization_name_label: "Nombre de la organización"
|
||||||
|
organization_responsible_name_placeholder: "Representante de la asociación/colectivo"
|
||||||
notifications: Notificaciones
|
notifications: Notificaciones
|
||||||
finish_verification: "Finalizar verificación"
|
finish_verification: "Finalizar verificación"
|
||||||
verified_account: Cuenta verificada
|
verified_account: Cuenta verificada
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ moderator.create_moderator
|
|||||||
(1..10).each do |i|
|
(1..10).each do |i|
|
||||||
org_name = Faker::Company.name
|
org_name = Faker::Company.name
|
||||||
org_user = create_user("org#{i}@madrid.es", org_name)
|
org_user = create_user("org#{i}@madrid.es", org_name)
|
||||||
org = org_user.create_organization(name: org_name)
|
org_responsible_name = Faker::Name.name
|
||||||
|
org = org_user.create_organization(name: org_name, responsible_name: org_responsible_name)
|
||||||
|
|
||||||
verified = [true, false].sample
|
verified = [true, false].sample
|
||||||
if verified then
|
if verified then
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class AddResponsibleNameToOrganizations < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :organizations, :responsible_name, :string, limit: 60
|
||||||
|
|
||||||
|
Organization.find_each do |org|
|
||||||
|
org.update(responsible_name: org.name) if org.responsible_name.blank?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_column :organizations, :responsible_name
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150910152734) do
|
ActiveRecord::Schema.define(version: 20150912145218) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -165,7 +165,7 @@ ActiveRecord::Schema.define(version: 20150910152734) do
|
|||||||
create_table "locks", force: :cascade do |t|
|
create_table "locks", force: :cascade do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.integer "tries", default: 0
|
t.integer "tries", default: 0
|
||||||
t.datetime "locked_until", default: '2015-09-10 13:46:11', null: false
|
t.datetime "locked_until", default: '2015-09-11 17:24:30', null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
@@ -180,9 +180,10 @@ ActiveRecord::Schema.define(version: 20150910152734) do
|
|||||||
|
|
||||||
create_table "organizations", force: :cascade do |t|
|
create_table "organizations", force: :cascade do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.string "name", limit: 60
|
t.string "name", limit: 60
|
||||||
t.datetime "verified_at"
|
t.datetime "verified_at"
|
||||||
t.datetime "rejected_at"
|
t.datetime "rejected_at"
|
||||||
|
t.string "responsible_name", limit: 60
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree
|
add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree
|
||||||
@@ -246,7 +247,7 @@ ActiveRecord::Schema.define(version: 20150910152734) do
|
|||||||
t.integer "official_level", default: 0
|
t.integer "official_level", default: 0
|
||||||
t.datetime "hidden_at"
|
t.datetime "hidden_at"
|
||||||
t.string "sms_confirmation_code"
|
t.string "sms_confirmation_code"
|
||||||
t.string "username", limit: 60
|
t.string "username", limit: 60
|
||||||
t.string "document_number"
|
t.string "document_number"
|
||||||
t.string "document_type"
|
t.string "document_type"
|
||||||
t.datetime "residence_verified_at"
|
t.datetime "residence_verified_at"
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ FactoryGirl.define do
|
|||||||
|
|
||||||
factory :organization do
|
factory :organization do
|
||||||
user
|
user
|
||||||
|
responsible_name "Johnny Utah"
|
||||||
sequence(:name) { |n| "org#{n}" }
|
sequence(:name) { |n| "org#{n}" }
|
||||||
|
|
||||||
trait :verified do
|
trait :verified do
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ feature 'Organizations' do
|
|||||||
visit new_organization_registration_path
|
visit new_organization_registration_path
|
||||||
|
|
||||||
fill_in 'user_organization_attributes_name', with: 'Greenpeace'
|
fill_in 'user_organization_attributes_name', with: 'Greenpeace'
|
||||||
|
fill_in 'user_organization_attributes_responsible_name', with: 'Dorothy Stowe'
|
||||||
fill_in 'user_email', with: 'green@peace.com'
|
fill_in 'user_email', with: 'green@peace.com'
|
||||||
fill_in 'user_password', with: 'greenpeace'
|
fill_in 'user_password', with: 'greenpeace'
|
||||||
fill_in 'user_password_confirmation', with: 'greenpeace'
|
fill_in 'user_password_confirmation', with: 'greenpeace'
|
||||||
|
|||||||
@@ -2,6 +2,16 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Verification path' do
|
feature 'Verification path' do
|
||||||
|
|
||||||
|
scenario "User is an organization" do
|
||||||
|
user = create(:user, verified_at: Time.now)
|
||||||
|
create(:organization, user: user)
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit verification_path
|
||||||
|
|
||||||
|
expect(current_path).to eq account_path
|
||||||
|
end
|
||||||
|
|
||||||
scenario "User is verified" do
|
scenario "User is verified" do
|
||||||
user = create(:user, verified_at: Time.now)
|
user = create(:user, verified_at: Time.now)
|
||||||
|
|
||||||
|
|||||||
@@ -161,11 +161,12 @@ describe User do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "organization_attributes" do
|
describe "organization_attributes" do
|
||||||
before(:each) { subject.organization_attributes = {name: 'org'} }
|
before(:each) { subject.organization_attributes = {name: 'org', responsible_name: 'julia'} }
|
||||||
|
|
||||||
it "triggers the creation of an associated organization" do
|
it "triggers the creation of an associated organization" do
|
||||||
expect(subject.organization).to be
|
expect(subject.organization).to be
|
||||||
expect(subject.organization.name).to eq('org')
|
expect(subject.organization.name).to eq('org')
|
||||||
|
expect(subject.organization.responsible_name).to eq('julia')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "deactivates the validation of username, and activates the validation of organization" do
|
it "deactivates the validation of username, and activates the validation of organization" do
|
||||||
|
|||||||
Reference in New Issue
Block a user