Commit 41139fee0b81f6ef6d79501b01096ade5a05f17e
Exists in
staging
and in
4 other branches
Merge branch 'staging' of gitlab.com:participa/noosfero into staging
Showing
4 changed files
with
10 additions
and
15 deletions
Show diff stats
app/models/user.rb
@@ -102,12 +102,6 @@ class User < ActiveRecord::Base | @@ -102,12 +102,6 @@ class User < ActiveRecord::Base | ||
102 | end | 102 | end |
103 | end | 103 | end |
104 | 104 | ||
105 | - def signup | ||
106 | - User.transaction do | ||
107 | - self.person.save if self.save | ||
108 | - end | ||
109 | - end | ||
110 | - | ||
111 | has_one :person, :dependent => :destroy | 105 | has_one :person, :dependent => :destroy |
112 | belongs_to :environment | 106 | belongs_to :environment |
113 | 107 |
lib/noosfero/api/session.rb
@@ -45,16 +45,16 @@ module Noosfero | @@ -45,16 +45,16 @@ module Noosfero | ||
45 | # test_captcha will render_api_error! and exit in case of any problem | 45 | # test_captcha will render_api_error! and exit in case of any problem |
46 | # this return is just to improve the clarity of the execution path | 46 | # this return is just to improve the clarity of the execution path |
47 | return unless test_captcha(remote_ip, params, environment) | 47 | return unless test_captcha(remote_ip, params, environment) |
48 | - user = User.new(attrs) | ||
49 | - params[:name].present? ? name = params[:name] : name = attrs[:email] | ||
50 | - person = Person.new(name: name, identifier: user.login) | ||
51 | - user.person = person | ||
52 | - if user.signup | 48 | + |
49 | + name = params[:name].present? ? params[:name] : attrs[:email] | ||
50 | + user = User.new(attrs.merge(:name => name)) | ||
51 | + | ||
52 | + begin | ||
53 | + user.signup! | ||
53 | user.generate_private_token! if user.activated? | 54 | user.generate_private_token! if user.activated? |
54 | present user, :with => Entities::UserLogin | 55 | present user, :with => Entities::UserLogin |
55 | - else | ||
56 | - user.destroy | ||
57 | - message = user.errors.as_json.merge(person.errors.as_json).to_json | 56 | + rescue ActiveRecord::RecordInvalid |
57 | + message = user.errors.as_json.merge((user.person.present? ? user.person.errors : {}).as_json).to_json | ||
58 | render_api_error!(message, 400) | 58 | render_api_error!(message, 400) |
59 | end | 59 | end |
60 | end | 60 | end |
plugins/dialoga
test/unit/api/session_test.rb
@@ -26,6 +26,7 @@ class SessionTest < ActiveSupport::TestCase | @@ -26,6 +26,7 @@ class SessionTest < ActiveSupport::TestCase | ||
26 | post "/api/v1/register?#{params.to_query}" | 26 | post "/api/v1/register?#{params.to_query}" |
27 | assert_equal 201, last_response.status | 27 | assert_equal 201, last_response.status |
28 | json = JSON.parse(last_response.body) | 28 | json = JSON.parse(last_response.body) |
29 | + assert User['newuserapi'].activated? | ||
29 | assert json['activated'] | 30 | assert json['activated'] |
30 | assert json['private_token'].present? | 31 | assert json['private_token'].present? |
31 | end | 32 | end |