Add `reason` param to `POST /api/v1/accounts` REST API (#12064)

For approval-required registrations mode
master
Eugen Rochko 5 years ago committed by GitHub
parent 9a1be333b8
commit eb83d6256e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/api/v1/accounts_controller.rb
  2. 3
      app/services/app_sign_up_service.rb
  3. 9
      spec/services/app_sign_up_service_spec.rb

@ -78,7 +78,7 @@ class Api::V1::AccountsController < Api::BaseController
end end
def account_params def account_params
params.permit(:username, :email, :password, :agreement, :locale) params.permit(:username, :email, :password, :agreement, :locale, :reason)
end end
def check_enabled_registrations def check_enabled_registrations

@ -6,7 +6,8 @@ class AppSignUpService < BaseService
user_params = params.slice(:email, :password, :agreement, :locale) user_params = params.slice(:email, :password, :agreement, :locale)
account_params = params.slice(:username) account_params = params.slice(:username)
user = User.create!(user_params.merge(created_by_application: app, password_confirmation: user_params[:password], account_attributes: account_params)) invite_request_params = { text: params[:reason] }
user = User.create!(user_params.merge(created_by_application: app, password_confirmation: user_params[:password], account_attributes: account_params, invite_request_attributes: invite_request_params))
Doorkeeper::AccessToken.create!(application: app, Doorkeeper::AccessToken.create!(application: app,
resource_owner_id: user.id, resource_owner_id: user.id,

@ -38,6 +38,15 @@ RSpec.describe AppSignUpService, type: :service do
user = User.find_by(id: access_token.resource_owner_id) user = User.find_by(id: access_token.resource_owner_id)
expect(user).to_not be_nil expect(user).to_not be_nil
expect(user.account).to_not be_nil expect(user.account).to_not be_nil
expect(user.invite_request).to be_nil
end
it 'creates an account with invite request text' do
access_token = subject.call(app, good_params.merge(reason: 'Foo bar'))
expect(access_token).to_not be_nil
user = User.find_by(id: access_token.resource_owner_id)
expect(user).to_not be_nil
expect(user.invite_request&.text).to eq 'Foo bar'
end end
end end
end end

Loading…
Cancel
Save