Skip to content

Commit

Permalink
Merge pull request #8 from NethServer/sdl-6895-restore
Browse files Browse the repository at this point in the history
Refactor destroy-module action in imageroot to remove relay from mail server and set always_bcc if necessary NethServer/dev#6895
  • Loading branch information
stephdl authored May 3, 2024
2 parents e129403 + a880199 commit 31fd3b1
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions imageroot/actions/destroy-module/20destroy
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,31 @@ response = agent.tasks.run(
'instance': os.environ['MODULE_ID']
},
)

# we want to remove the relay from the mail server
# retrieve the mail server module from the redis db
rdb = agent.redis_connect()
providers_old = agent.list_service_providers(rdb, 'imap', 'tcp', {
'module_uuid': os.environ.get("MAIL_SERVER")
})

if providers_old:
# we want to remove the relay from the mail server
mail_id_old = providers_old[0]["module_id"]
response = agent.tasks.run(f"module/{mail_id_old}", action='remove-relay-rule', data={
"rule_subject": "archive@"+os.environ['MODULE_ID']})
# we need to set bcc address for the mail server
response = agent.tasks.run(f"module/{mail_id_old}", action='set-always-bcc', data={
"bcc": ""
})

# function to test get-always-bcc
def get_always_bcc(email):
response = agent.tasks.run(f"module/{mail_id_old}", action='get-always-bcc')
agent.assert_exp(response['exit_code'] == 0)
# check if the always_bcc is set to the email
if response['output']['bcc'] == email:
return True
else:
return False
# we need to verify if the always_bcc is set to this module, if true we need to remove it
# in case of restoration of the module we want to prevent to remove the always_bcc set
# to the restored new module
if get_always_bcc('archive@'+os.environ['MODULE_ID']):
response = agent.tasks.run(f"module/{mail_id_old}", action='set-always-bcc', data={
"bcc": ""
})

0 comments on commit 31fd3b1

Please sign in to comment.