Then implement it according to your business logic:
const { PermissionMiddlewareCreator } =require('forest-express-sequelize');constpermissionMiddlewareCreator=newPermissionMiddlewareCreator('orders');...router.post('/actions/refund-order',permissionMiddlewareCreator.smartAction(), (req, res) => {// Add your own logic, like calling a Stripe API for instanceres.send({ success:'Order refunded!' });});...module.exports= router;
You must make sure that all your Smart Actions routes are configured with the Smart Action middleware: permissionMiddlewareCreator.smartAction(). This is mandatory to ensure that all features built on top of Smart Actions work as expected (permissions, approval workflows,...).
Then implement it according to your business logic:
const { PermissionMiddlewareCreator } =require('forest-express-mongoose');constpermissionMiddlewareCreator=newPermissionMiddlewareCreator('orders');...router.post('/actions/refund-order',permissionMiddlewareCreator.smartAction(), (req, res) => {// Add your own logic, like calling a Stripe API for instanceres.send({ success:'Order refunded!' });});...module.exports= router;
You must make sure that all your Smart Actions routes are configured with the Smart Action middleware: permissionMiddlewareCreator.smartAction(). This is mandatory to ensure that all features built on top of Smart Actions work as expected (permissions, approval workflows,...).
Declare it in your /lib/forest_liana/collections/order.rb file:
Rails.application.routes.draw do# MUST be declared before the mount ForestLiana::Engine. namespace :forest do post '/actions/refund-order'=>'orders#refund_order'end mount ForestLiana::Engine=>'/forest'end
Lastly, implement the action according to your business logic:
classForest::OrdersController<ForestLiana::SmartActionsControllerdefrefund_order# Add your own logic, like calling a Stripe API for instance render json: { success: 'Order refunded!' }endend
You must make sure that all your Smart Actions controllers extend from the ForestLiana::SmartActionsController. This is mandatory to ensure that all features built on top of Smart Actions work as expected (authentication, permissions, approval workflows,...)
You may have to add CORS headers to enable the domain app.forestadmin.com to trigger API call on your Application URL, which is on a different domain name (e.g. localhost:8000).
Lastly, implement the action according to your business logic:
app/views.py
from django.http import JsonResponsefrom django_forest.utils.views.action import ActionViewclassRefundOrderView(ActionView):defpost(self,request,*args,**kwargs):# Add your own logic, like calling a Stripe API for instancereturnJsonResponse({'success': 'Order refunded!'})
Note that Forest Admin takes care of the authentication thanks to the ActionView parent class view.
You may have to add CORS headers to enable the domain app.forestadmin.com to trigger API call on your Application URL, which is on a different domain name (e.g. localhost:8000).
Now that you have a fully functional admin panel, the next logical step is to make it live, with your live (production) data. Click on Deploy to Production and follow the flow.
That's it! You are now fully operational on Forest Admin.