Add validation when a organization user is created

pull/16341/head
cgonzalez 3 years ago
parent 9038098ef0
commit d1f6b149bd

@ -82,6 +82,13 @@ class Admin::OrganizationUsersController < Admin::AdminController
end
raise Carto::UnprocesableEntityError.new("Soft limits validation error") if validation_failure
if Cartodb::Central.api_sync_enabled?
response = central_new_organization_user_validation(@user)
unless response['valid']
raise Sequel::ValidationFailed.new("Validation failed: #{response['error']}")
end
end
@user.save(raise_on_failure: true)
@user.create_in_central
common_data_url = CartoDB::Visualization::CommonDataService.build_url(self)

@ -50,6 +50,10 @@ module OrganizationUsersHelper
hardened_params.symbolize_keys
end
def central_new_organization_user_validation(user)
Cartodb::Central.new.validate_new_organization_user(username: user.username, email: user.email)
end
# This is not run at model validation flow because we might want to override this rules.
# owner parameter allows validation before actual value setting
def soft_limits_validation(user, params_to_update, owner = user.organization.owner)

@ -24,10 +24,8 @@ module Cartodb
!api_sync_enabled?
end
class <<self
class << self
alias login_redirection_enabled? api_sync_enabled?
end
def initialize
@ -93,6 +91,15 @@ module Cartodb
send_request("api/organizations/#{ organization_name }/users/#{ username }", nil, :get, [200])
end
def validate_new_organization_user(username:, email:)
send_request(
'api/organizations/users/validate_new',
{ user: { username: username, email: email } },
:post,
[200, 400]
)
end
def create_organization_user(organization_name, user_attributes)
payload = {
organization_name: organization_name

Loading…
Cancel
Save