feat: Platform API improvements (#2900)

- Platform APIs to add and update custom attributes to users
- Platform APIs to delete accounts
- Platform APIs to delete users
This commit is contained in:
Sojan Jose 2021-09-02 18:29:45 +05:30 committed by GitHub
parent a60a33679f
commit ad83d1bb71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 160 additions and 12 deletions

View file

@ -19,21 +19,33 @@ class Platform::Api::V1::UsersController < PlatformController
def show; end
def update
@resource.update!(user_params)
@resource.assign_attributes(user_update_params)
@resource.save!
end
def destroy
# TODO: obfusicate user
DeleteObjectJob.perform_later(@resource)
head :ok
end
private
def user_custom_attributes
return @resource.custom_attributes.merge(user_params[:custom_attributes]) if user_params[:custom_attributes]
@resource.custom_attributes
end
def user_update_params
# we want the merged custom attributes not the original one
user_params.except(:custom_attributes).merge({ custom_attributes: user_custom_attributes })
end
def set_resource
@resource = User.find(params[:id])
end
def user_params
params.permit(:name, :email, :password)
params.permit(:name, :email, :password, custom_attributes: {})
end
end