abhishek-ram / django-pyas2

AS2 file transfer Server built on Python and Django.
https://django-pyas2.readthedocs.io
GNU General Public License v3.0
78 stars 31 forks source link

Use variables in Command on Message Receipt #81

Open timfanda35 opened 1 year ago

timfanda35 commented 1 year ago

I'm confused about the variables $sender and $receiver in Command on Message Receipt .

Would the $sender be Partner AS2 Identifier, and the $receiver be Organization AS2 Identifier?

My test

Advanced Settings - Command on Message Receipt

echo "$receiver got a message from $sender"

When I send the message from tradingpartner to supplier, I expect the log would be

supplier got a message from tradingpartner

but I got:

tradingpartner got a message from supplier

Code Trace

The variables are defined at /pyas2/utils.py:

def run_post_receive(message, full_filename):
    """Execute command after successful receive, can be used to call the
    edi program for further processing"""

    command = message.partner.cmd_receive
    if command:
        logger.debug(f"Execute post successful receive command {command}")

        # Create command template and replace variables in the command
        command = Template(command)
        variables = {
            "filename": os.path.basename(full_filename),
            "fullfilename": full_filename,
            "sender": message.organization.as2_name,
            "receiver": message.partner.as2_name,
            "messageid": message.message_id,
        }
        variables.update(message.as2message.headers)

        # Execute the command
        os.system(command.safe_substitute(variables))

To swap sender and receiver values would more fit the meaning.

        command = Template(command)
        variables = {
            "filename": os.path.basename(full_filename),
            "fullfilename": full_filename,
            "sender": message.partner.as2_name,
            "receiver": message.organization.as2_name,
            "messageid": message.message_id,
        }
abhishek-ram commented 1 year ago

Makes sense, can you open a PR with this change?

timfanda35 commented 1 year ago

Sure.