Commit 4a72860850b9c38dfd68be8fd3b6521814e51293
1 parent
2340a574
Exists in
master
and in
29 other branches
[stoa] Confirmation through cpf and birth_date
(ActionItem2293)
Showing
3 changed files
with
17 additions
and
6 deletions
Show diff stats
plugins/stoa/lib/stoa_plugin.rb
@@ -21,7 +21,7 @@ class StoaPlugin < Noosfero::Plugin | @@ -21,7 +21,7 @@ class StoaPlugin < Noosfero::Plugin | ||
21 | lambda { | 21 | lambda { |
22 | required(labelled_form_field(_('USP number'), text_field_tag('profile_data[usp_id]', '', :id => 'usp_id_field'))) + | 22 | required(labelled_form_field(_('USP number'), text_field_tag('profile_data[usp_id]', '', :id => 'usp_id_field'))) + |
23 | labelled_form_field(_('Select a confirmation data'), select_tag('confirmation_field', | 23 | labelled_form_field(_('Select a confirmation data'), select_tag('confirmation_field', |
24 | - options_for_select([['CPF','cpf'], [_('Mother\'s name'), 'mother'], [_('Birth date (yyyy-mm-dd)'), 'birth']]) | 24 | + options_for_select([['CPF','cpf'], [_('Birth date (yyyy-mm-dd)'), 'birth_date']]) |
25 | )) + | 25 | )) + |
26 | required(labelled_form_field(_('Confirmation value'), text_field_tag('confirmation_value', '', :placeholder=>_('Confirmation value')))) + | 26 | required(labelled_form_field(_('Confirmation value'), text_field_tag('confirmation_value', '', :placeholder=>_('Confirmation value')))) + |
27 | javascript_tag(<<-EOF | 27 | javascript_tag(<<-EOF |
plugins/stoa/lib/stoa_plugin/usp_user.rb
@@ -6,7 +6,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base | @@ -6,7 +6,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base | ||
6 | SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | 6 | SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] |
7 | 7 | ||
8 | alias_attribute :cpf, :numcpf | 8 | alias_attribute :cpf, :numcpf |
9 | - alias_attribute :rg, :numdocidf | 9 | + alias_attribute :birth_date, :dtanas |
10 | 10 | ||
11 | def self.exists?(usp_id) | 11 | def self.exists?(usp_id) |
12 | !StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id}).nil? | 12 | !StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id}).nil? |
@@ -15,7 +15,12 @@ class StoaPlugin::UspUser < ActiveRecord::Base | @@ -15,7 +15,12 @@ class StoaPlugin::UspUser < ActiveRecord::Base | ||
15 | def self.matches?(usp_id, field, value) | 15 | def self.matches?(usp_id, field, value) |
16 | user = StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id}) | 16 | user = StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id}) |
17 | return false if user.nil? || !user.respond_to?(field) || value.blank? | 17 | return false if user.nil? || !user.respond_to?(field) || value.blank? |
18 | - user.send(field) == Digest::MD5.hexdigest(SALT+value.to_s) | 18 | + case field.to_sym |
19 | + when :cpf | ||
20 | + user.cpf == Digest::MD5.hexdigest(SALT+value.to_s) | ||
21 | + when :birth_date | ||
22 | + user.birth_date.to_s == value | ||
23 | + end | ||
19 | end | 24 | end |
20 | 25 | ||
21 | end | 26 | end |
plugins/stoa/test/unit/usp_user.rb
@@ -11,10 +11,10 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | @@ -11,10 +11,10 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | ||
11 | ActiveRecord::Schema.create_table "pessoa" do |t| | 11 | ActiveRecord::Schema.create_table "pessoa" do |t| |
12 | t.integer "codpes" | 12 | t.integer "codpes" |
13 | t.text "numcpf" | 13 | t.text "numcpf" |
14 | - t.text "numdocidf" | 14 | + t.date "dtanas" |
15 | end | 15 | end |
16 | ActiveRecord::Base.establish_connection(:test) | 16 | ActiveRecord::Base.establish_connection(:test) |
17 | - StoaPlugin::UspUser.create!(:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :rg => Digest::MD5.hexdigest(SALT+'87654321')) | 17 | + StoaPlugin::UspUser.create!(:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30') |
18 | end | 18 | end |
19 | 19 | ||
20 | def teardown | 20 | def teardown |
@@ -26,10 +26,16 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | @@ -26,10 +26,16 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | ||
26 | assert !StoaPlugin::UspUser.exists?(654321) | 26 | assert !StoaPlugin::UspUser.exists?(654321) |
27 | end | 27 | end |
28 | 28 | ||
29 | - should 'check if usp_id matches with a field' do | 29 | + should 'check if usp_id matches with a cpf' do |
30 | assert StoaPlugin::UspUser.matches?(123456, :cpf, 12345678) | 30 | assert StoaPlugin::UspUser.matches?(123456, :cpf, 12345678) |
31 | assert !StoaPlugin::UspUser.matches?(123456, :cpf, 87654321) | 31 | assert !StoaPlugin::UspUser.matches?(123456, :cpf, 87654321) |
32 | assert !StoaPlugin::UspUser.matches?(654321, :cpf, 12345678) | 32 | assert !StoaPlugin::UspUser.matches?(654321, :cpf, 12345678) |
33 | end | 33 | end |
34 | + | ||
35 | + should 'check if usp_id matches with a birth_date' do | ||
36 | + assert StoaPlugin::UspUser.matches?(123456, :birth_date, '1970-01-30') | ||
37 | + assert !StoaPlugin::UspUser.matches?(123456, :birth_date, '1999-01-30') | ||
38 | + assert !StoaPlugin::UspUser.matches?(654321, :birth_date, '1970-01-30') | ||
39 | + end | ||
34 | end | 40 | end |
35 | 41 |