...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#
# This controller handles notification of people leaving a group (remove_user action) or companies
# cancelling their subscription to your service (destroy_group)
class WebhookAccountController
# The 'destroy_group' controller action responds the following route
# DESTROY /mno-enterprise/:tenant_key/account/group/:id
function destroy_group
# Authenticate request as usual
unless Maestrano.with(tenant_key).authenticate(http_basic['login'],http_basic['password'])
render json: "Unauthorized, code: '401'
end
# Retrieve the request parameters
tenant_key = params[:tenant_key]
group_uid = params[:id]
# Retrieve the group/company
organization = Organization.find_by_tenant_and_uid(tenant_key,group_uid)
# Destroy it
organization.destroy
end
# The 'destroy_group' controller action responds the following route
# DESTROY /mno-enterprise/:tenant_key/account/group/:group_id/user/:id
function remove_user
# Authenticate request as usual
unless Maestrano.with(tenant_key).authenticate(http_basic['login'],http_basic['password'])
render json: "Unauthorized, code: '401'
end
# Retrieve the request parameters
tenant_key = params[:tenant_key]
group_uid = params[:group_id]
user_uid = params[:id]
# Retrieve the group/company as well as the user
organization = Organization.find_by_tenant_and_uid(tenant_key,group_uid)
user = User.find_by_tenant_and_uid(tenant_key,user_uid)
# Remove the user
organization.remove_user(user)
end
end |
...