Generating links for email task

Hi guys,
Is it somehow possible to implement this scenario:
When bpm user task is created send email with data of entity being approved with 2 buttons with outcomes eg. Approve, Reject.
Handling create task event, sending email (created using report) is no problem tho.
But is it somehow possible to create safe generated links (not something like ip/app?finishTask=12442&outcome=approve&userId=123412-123123-123123-231231), but something like recovery password links eg. ip/app?qweqw-ver3qwe3eqwe-fasdqwd3#1dwad_331 … which are used for one time only and do not require user session.
Is it of course possible to do this using standard url building in which I would build url for entity with some parameter to open view in cuba web, but this would require user session = user would have to login.

Thank you for any help, advise.

Michal

1 Like

Hi,
If you don’t want the user to login, then you’ll have to write a custom controller that will handle request.
Take a look at this example: https://github.com/gorbunkov/sample-rest-controllers
In the MyOauth2UnprotectedController class there is a method loginAndGetUsersCount. This method does the trusted login, after that you can perform any operation with the database.
In this example the custom controller is located in the portal module. If you want it to be in the web module, there won’t be much difference.
You’ll have to:

  1. Create a file rest-dispatcher-spring.xml in the web module
  2. Register it in web-app.properties file:
cuba.restSpringContextConfig = +com/company/demo/rest-dispatcher-spring.xml
  1. In this file define component-scan for the packages with your controller
  2. In the controller method analyze request parameters, ensure the user can login, do trustedLogin on behalf of some user and complete the BPM task using the bpm API.

Thank you for your reply, I will take a look.