Merge pull request #479 from AyuntamientoMadrid/orgs-responsible

Orgs responsible
This commit is contained in:
Enrique García
2015-09-12 19:36:11 +02:00
23 changed files with 94 additions and 43 deletions

View File

@@ -23,7 +23,7 @@ class AccountController < ApplicationController
def account_params
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
params.require(:account).permit(:username, :email_on_debate_comment, :email_on_comment_reply)
end

View File

@@ -29,7 +29,7 @@ class Organizations::RegistrationsController < Devise::RegistrationsController
private
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

View File

@@ -11,7 +11,9 @@ class VerificationController < ApplicationController
private
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') }
elsif user.verification_letter_sent?
{ path: edit_letter_path }

View File

@@ -3,7 +3,9 @@ class Organization < ActiveRecord::Base
validates :name, presence: 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
@@ -37,6 +39,10 @@ class Organization < ActiveRecord::Base
@@name_max_length ||= self.columns.find { |c| c.name == 'name' }.limit || 60
end
def self.responsible_name_max_length
@@responsible_name_max_length ||= self.columns.find { |c| c.name == 'responsible_name' }.limit || 60
end
private
def validate_name_length
@@ -46,4 +52,11 @@ class Organization < ActiveRecord::Base
validator.validate(self)
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

View File

@@ -32,7 +32,7 @@ class User < ActiveRecord::Base
validates_associated :organization, message: false
accepts_nested_attributes_for :organization
accepts_nested_attributes_for :organization, update_only: true
scope :administrators, -> { joins(:administrators) }
scope :moderators, -> { joins(:moderator) }

View File

@@ -1,22 +1,22 @@
<div class="row account">
<div class="small-12 column">
<%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: "button radius small secondary right" %>
<div>
<span class="right verify-account">
<% if current_user.level_three_verified? %>
<p class="verified">
<i class="icon-check"></i>
<%= t("account.show.verified_account") %>
</p>
<% elsif current_user.level_two_verified? %>
<%= link_to t("account.show.finish_verification"), verification_path, class: "button radius small success right" %>
<% else %>
<%= link_to t("account.show.verify_my_account"), verification_path, class: "button radius small success right" %>
<% end %>
</span>
</div>
<% unless @account.organization? %>
<div>
<span class="right verify-account">
<% if current_user.level_three_verified? %>
<p class="verified">
<i class="icon-check"></i>
<%= t("account.show.verified_account") %>
</p>
<% elsif current_user.level_two_verified? %>
<%= link_to t("account.show.finish_verification"), verification_path, class: "button radius small success right" %>
<% else %>
<%= link_to t("account.show.verify_my_account"), verification_path, class: "button radius small success right" %>
<% end %>
</span>
</div>
<% end %>
<h1 class="inline-block"><%= t("account.show.title") %></h1>
<%= form_for @account, as: :account, url: account_path do |f| %>
@@ -33,6 +33,7 @@
<% if @account.organization? %>
<%= 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 :responsible_name, autofocus: true, maxlength: Organization.responsible_name_max_length, placeholder: t("account.show.organization_responsible_name_placeholder") %>
<% end %>
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>

View File

@@ -25,6 +25,7 @@
<td><%= organization.name %></td>
<td><%= organization.email %></td>
<td><%= organization.phone_number %></td>
<td><%= organization.responsible_name %></td>
<% if organization.verified? %>
<td class="verified">
<i class="icon-check"></i>

View File

@@ -21,6 +21,7 @@
<td><%= organization.name %></td>
<td><%= organization.email %></td>
<td><%= organization.phone_number %></td>
<td><%= organization.responsible_name %></td>
<% if organization.verified? %>
<td class="verified">
<i class="icon-check"></i>

View File

@@ -7,9 +7,12 @@
<%= 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.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 %>
<%= 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") %>

View File

@@ -1,15 +1,9 @@
<div class="auth row">
<div class="small-12 medium-8 column small-centered">
<div class="panel">
<h2><%= t("devise_views.organizations.registrations.success.title") %></h2>
<p><%= t("devise_views.organizations.registrations.success.thank_you_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_1_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_2_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_3_html") %></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>
<h2><%= t("devise_views.organizations.registrations.success.title") %></h2>
<p><%= t("devise_views.organizations.registrations.success.thank_you_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_1_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_2_html") %></p>
<p><%= t("devise_views.organizations.registrations.success.instructions_3_html") %></p>
<p>
<%= link_to t("devise_views.organizations.registrations.success.back_to_index"),
root_path, class: "button radius small margin-top expand" %>
</p>