Commit 41139fee0b81f6ef6d79501b01096ade5a05f17e
Exists in
theme-brasil-digital-from-staging
and in
9 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
lib/noosfero/api/session.rb
| ... | ... | @@ -45,16 +45,16 @@ module Noosfero |
| 45 | 45 | # test_captcha will render_api_error! and exit in case of any problem |
| 46 | 46 | # this return is just to improve the clarity of the execution path |
| 47 | 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 | 54 | user.generate_private_token! if user.activated? |
| 54 | 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 | 58 | render_api_error!(message, 400) |
| 59 | 59 | end |
| 60 | 60 | end | ... | ... |
plugins/dialoga
test/unit/api/session_test.rb
| ... | ... | @@ -26,6 +26,7 @@ class SessionTest < ActiveSupport::TestCase |
| 26 | 26 | post "/api/v1/register?#{params.to_query}" |
| 27 | 27 | assert_equal 201, last_response.status |
| 28 | 28 | json = JSON.parse(last_response.body) |
| 29 | + assert User['newuserapi'].activated? | |
| 29 | 30 | assert json['activated'] |
| 30 | 31 | assert json['private_token'].present? |
| 31 | 32 | end | ... | ... |