Adds a user controller for management

This commit is contained in:
kikito
2015-10-07 20:18:17 +02:00
parent 6cfb23bc40
commit b6aaad87af
8 changed files with 98 additions and 2 deletions

View File

@@ -35,6 +35,8 @@ class User < ActiveRecord::Base
accepts_nested_attributes_for :organization, update_only: true
attr_accessor :skip_password_validation
scope :administrators, -> { joins(:administrators) }
scope :moderators, -> { joins(:moderator) }
scope :organizations, -> { joins(:organization) }
@@ -162,6 +164,11 @@ class User < ActiveRecord::Base
sign_in_count == 1 && unverified? && !organization && !administrator?
end
def password_required?
return false if skip_password_validation
super
end
private
def validate_username_length

View File

@@ -1,4 +1,4 @@
<h2><%= t("management.users.title") %></h2>
<h2><%= t("management.document_verifications.title") %></h2>
<div class="row">
<div class="small-12 medium-8 column">

View File

@@ -25,7 +25,7 @@
<strong><%= t("management.email_verifications.if_no_existing_account") %></strong>
<p class="margin-top">
<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>
<%= link_to t('management.users.create_user'), new_management_user_path(user: params[:email_verification]), class: "button warning radius" %>
</p>
</li>
</ul>

View File

@@ -0,0 +1,25 @@
<%= render 'management/account_info.html', account: @user %>
<p><%= t("management.users.create_user_info") %></p>
<%= render 'management/user_permissions',
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %>
<div class="row">
<div class="small-12 medium-9 column">
<%= form_for @user, url: management_users_path do |f| %>
<%= f.hidden_field :document_type %>
<%= f.hidden_field :document_number %>
<%= f.text_field :username,
label: t('management.username_label'),
placeholder: t('management.username_label') %>
<%= f.text_field :email,
label: t('management.email_label'),
placeholder: t('management.email_label') %>
<%= f.submit t("management.users.create_user_submit"), class: "button success radius" %>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,9 @@
<%= render 'management/account_info.html', account: @user %>
<p><%= t("management.users.create_user_success_html",
link: link_to("http://decide.madrid.es", "http://decide.madrid.es", target: "_blank")) %>
</p>
<%= render 'management/user_permissions',
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %>

View File

@@ -36,3 +36,11 @@ en:
if_no_existing_account: "If this person has not created an account yet"
document_mismatch: "This email belongs to a user which already has an associated id: %{document_number}(%{document_type})"
already_verified: "This user account is already verified."
users:
create_user: "Create a new account"
create_user_info: "We will create an account with the following data:"
create_user_submit: "Create user"
create_user_success_html:
"We have sent an email to the email address used to create the account in order to verify that it belongs to him.
We recommend changing the password on the first login. In order to do that go to %{link} with your user and password,
and enter the <b>'My account / Change access data'</b> section"

View File

@@ -173,6 +173,8 @@ Rails.application.routes.draw do
end
resources :email_verifications, only: [:new, :create]
resources :users, only: [:new, :create]
end
# Example of regular route:

View File

@@ -0,0 +1,45 @@
require 'rails_helper'
feature 'users' do
scenario 'Creating a level 3 user from scratch' do
visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '1234'
click_button 'Check'
expect(page).to have_content "Please introduce the email used on the account"
click_link 'Create a new account'
fill_in 'user_username', with: 'pepe'
fill_in 'user_email', with: 'pepe@gmail.com'
click_button 'Create user'
expect(page).to have_content "We have sent an email"
user = User.find_by_email('pepe@gmail.com')
expect(user).to be_level_three_verified
expect(user).to be_residence_verified
expect(user).to_not be_confirmed
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 "Confirming the account with email"
fill_in 'user_password', with: '12345678'
fill_in 'user_password_confirmation', with: '12345678'
click_button 'Confirm'
expect(user.reload).to be_confirmed
expect(page).to have_content "Your email address has been successfully confirmed."
end
end