2021-01-14 15:05:22 +00:00
|
|
|
class Platform::Api::V1::AccountsController < PlatformController
|
|
|
|
def create
|
|
|
|
@resource = Account.new(account_params)
|
2022-11-08 01:49:45 +00:00
|
|
|
update_resource_features
|
2021-01-14 15:05:22 +00:00
|
|
|
@resource.save!
|
|
|
|
@platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource)
|
|
|
|
end
|
|
|
|
|
2022-10-20 04:16:36 +00:00
|
|
|
def show; end
|
2021-01-14 15:05:22 +00:00
|
|
|
|
|
|
|
def update
|
2022-11-08 01:49:45 +00:00
|
|
|
@resource.assign_attributes(account_params)
|
|
|
|
update_resource_features
|
|
|
|
@resource.save!
|
2021-01-14 15:05:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2021-09-02 12:59:45 +00:00
|
|
|
DeleteObjectJob.perform_later(@resource)
|
2021-01-14 15:05:22 +00:00
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_resource
|
|
|
|
@resource = Account.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_params
|
2022-11-08 01:49:45 +00:00
|
|
|
permitted_params.except(:features)
|
|
|
|
end
|
2022-10-20 04:16:36 +00:00
|
|
|
|
2022-11-08 01:49:45 +00:00
|
|
|
def update_resource_features
|
|
|
|
return if permitted_params[:features].blank?
|
|
|
|
|
|
|
|
permitted_params[:features].each do |key, value|
|
|
|
|
value.present? ? @resource.enable_features(key) : @resource.disable_features(key)
|
|
|
|
end
|
2022-10-20 04:16:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_params
|
2022-11-08 01:49:45 +00:00
|
|
|
params.permit(:name, :locale, :domain, :support_email, :status, features: {}, limits: {}, custom_attributes: {})
|
2021-01-14 15:05:22 +00:00
|
|
|
end
|
|
|
|
end
|