Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inline notifications for one-time installation and mail server configuration status #18

Merged
merged 19 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1a7b43b
Remove unused Python script for validating BCC server
stephdl May 14, 2024
f0350a9
Refactor relay rule configuration, we cannot use another server
stephdl May 14, 2024
4e0d84f
Refactor get-configuration to include always_bcc information
stephdl May 14, 2024
7680816
Refactor language.json to include additional tooltips and warnings
stephdl May 14, 2024
b08413a
Add inline notifications for one-time installation and mail server co…
stephdl May 14, 2024
1fc8577
Refactor get-configuration to include always_bcc information
stephdl May 14, 2024
d153e52
Refactor language.json to include additional tooltips and warnings
stephdl May 14, 2024
45104f4
Set PROVIDER_IP and MAIL_SERVER to empty string to avoid to bind agai…
stephdl May 15, 2024
2a83cac
Refactor language.json to improve tooltips and warnings
stephdl May 15, 2024
95eaca5
Add conditional rendering for inline notification in Settings.vue
stephdl May 15, 2024
96ef05c
Refactor get-configuration to include bcc_set with the module_id of t…
stephdl May 15, 2024
16ada9d
disable save button to avoid configuration in case of lost ownership
stephdl May 15, 2024
1de7b38
Refactor language.json to remove unused translations and improve tool…
stephdl May 16, 2024
9bd1670
code review of Davide Principi
stephdl May 16, 2024
49386ce
translation review of Davide Principi
stephdl May 16, 2024
5e3e20d
Refactor language.json to improve tooltips and warnings
stephdl May 17, 2024
1c09ffa
Merge branch 'sdl-6895-one-server-is-enough' of github.com:NethServer…
stephdl May 17, 2024
49433b9
Refactor language.json to update retention duration label
stephdl May 17, 2024
ef6186c
Fixup language.json
DavidePrincipi May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions imageroot/actions/configure-module/02_validate_bcc_server

This file was deleted.

68 changes: 10 additions & 58 deletions imageroot/actions/configure-module/90add-relay-rule
Original file line number Diff line number Diff line change
Expand Up @@ -44,69 +44,21 @@ if providers:
"bcc": "archive@"+os.environ['MODULE_ID']
})
agent.assert_exp(response['exit_code'] == 0)
elif os.environ.get("MAIL_SERVER") and data["mail_server"] != os.environ.get("MAIL_SERVER"):
# not the same mail server, we remove the old relay rule and add the new one
providers_old = agent.list_service_providers(rdb, 'imap', 'tcp', {
'module_uuid': os.environ.get("MAIL_SERVER")
})
if providers_old:
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']})
agent.assert_exp(response['exit_code'] == 0)
# we need to remove bcc address for the mail server
response = agent.tasks.run(f"module/{mail_id_old}", action='set-always-bcc', data={
"bcc": ""
})
agent.assert_exp(response['exit_code'] == 0)
# add the new relay rule
response = agent.tasks.run(f"module/{mail_id}", action='add-relay-rule', data={
"rule_type": "always-bcc",
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"host": ip_address,
"port": int(os.environ['TCP_PORT_ARCHIVE']),
"mandatory_tls": False,
"username": "",
"password": "",
"enabled": True})
else:
response = agent.tasks.run(f"module/{mail_id}", action='alter-relay-rule', data={
"rule_type": "always-bcc",
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"host": ip_address,
"port": int(os.environ['TCP_PORT_ARCHIVE']),
"mandatory_tls": False,
"username": "",
"password": "",
"enabled": True})
agent.assert_exp(response['exit_code'] == 0)
# we need to set bcc address for the mail server
response = agent.tasks.run(f"module/{mail_id}", action='set-always-bcc', data={
"bcc": "archive@"+os.environ['MODULE_ID']
})
agent.assert_exp(response['exit_code'] == 0)
else:
try:
response = agent.tasks.run(f"module/{mail_id}", action='alter-relay-rule', data={
"rule_type": "always-bcc",
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"host": ip_address,
"port": int(os.environ['TCP_PORT_ARCHIVE']),
"mandatory_tls": False,
"username": "",
"password": "",
"enabled": True})
agent.assert_exp(response['exit_code'] == 0)
# we need to set bcc address for the mail server
response = agent.tasks.run(f"module/{mail_id}", action='set-always-bcc', data={
"bcc": "archive@"+os.environ['MODULE_ID']
})
agent.assert_exp(response['exit_code'] == 0)
except:
response = agent.tasks.run(f"module/{mail_id}", action='add-relay-rule', data={
"rule_type": "always-bcc",
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"host": ip_address,
"port": int(os.environ['TCP_PORT_ARCHIVE']),
"mandatory_tls": False,
"username": "",
"password": "",
"enabled": True})
agent.assert_exp(response['exit_code'] == 0)
# we need to set bcc address for the mail server
response = agent.tasks.run(f"module/{mail_id}", action='set-always-bcc', data={
"bcc": "archive@"+os.environ['MODULE_ID']
})
agent.assert_exp(response['exit_code'] == 0)

agent.set_env("MAIL_SERVER", data["mail_server"])
34 changes: 20 additions & 14 deletions imageroot/actions/get-configuration/20read
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,30 @@ config["http2https"] = os.environ.get("TRAEFIK_HTTP2HTTPS","False") == "True"
config["lets_encrypt"] = os.environ.get("TRAEFIK_LETS_ENCRYPT","False") == "True"
config["mail_server"] = os.getenv("MAIL_SERVER", "")
config['retention_days'] = int(os.getenv("RETENTION_DAYS", 2557))

# function to test get-alaways-bcc
def get_always_bcc(mail_id):
response = agent.tasks.run(f"module/{mail_id}", action='get-always-bcc')
agent.assert_exp(response['exit_code'] == 0)
# check if the always_bcc is not set
if response['output']['bcc'] == '':
return 'not_set'
else:
return response['output']['bcc'].removeprefix('archive@')

rdb = agent.redis_connect() # full read-only access on every key
modules=[]
# we query about all mail server to use it inside the user interface
for key in agent.list_service_providers(rdb,'imap','tcp'):
node_name = rdb.get('node/'+ key['node'] + '/ui_name') or ""
obj = {
"name": key['module_id'],
"label": key['module_id'] + ' ('+key['mail_hostname']+')',
"value": key['module_uuid'],
"module_id": key['module_id'],
"module_uuid": key['module_uuid'],
"mail_hostname": key['mail_hostname'],
"ui_name" : "" if key['ui_name'] == None else key['ui_name'],
"node": key['node'],
"node_name": node_name,
"bcc_set": get_always_bcc(key['module_id'])
}
modules.append(obj)

Expand All @@ -48,19 +64,9 @@ config['is_default_password_auditor'] = True if is_found_auditor else False
providers = agent.list_service_providers(rdb, 'imap', 'tcp', {
'module_uuid': os.getenv("MAIL_SERVER", ""),
})
# function to test get-always-bcc
def get_always_bcc(email):
mail_id = providers[0]["module_id"]
response = agent.tasks.run(f"module/{mail_id}", 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
if providers:
# we need to get bcc address for the mail server to display a warning in the UI if it is not set correctly
config['always_bcc_correctly_set'] = get_always_bcc('archive@'+os.environ['MODULE_ID'])
config['always_bcc_correctly_set'] = True if os.environ['MODULE_ID'] in get_always_bcc(providers[0]["module_id"]) else False
else:
config['always_bcc_correctly_set'] = False
# check if the piler service is running
Expand Down
13 changes: 11 additions & 2 deletions ui/public/i18n/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@
"import_old_emails_to_piler_description": "Import old emails to Piler, this process may take a long time",
"always_bcc_is_already_set": "Always BCC is already set in the server, you need to manually remove it (POSTFIX_ALWAYS_BCC)",
"always_bcc_not_set_warning": "Always BCC is not set",
"always_bcc_not_set_description": "Always BCC is not set in the mail server, you could try to configure again piler",
"always_bcc_not_set_description": "Always BCC is not set in the mail server, probably configured by another archive, the emails will not be archived",
"retention_days": "Retention days",
"retention_days_error": "Enter a number greater than 0",
"placeholder_retention_days": "Type the number of days",
"retention_days_tooltip": "The number of days to keep the emails in the archive"
"retention_days_tooltip": "The number of days to keep the emails in the archive",
"node": "Node {nodeId}",
"warnings_one_time_installation_description": "You won't be able to change it after the first configuration",
"warnings_one_time_installation": "Choose mail server carefully",
"configured_to_archive": "Configured to archive : {archive}",
"not_configured_to_archive": "Not used by an archive",
"the_mail_server_is_already_configured_description": "You can overwrite the mail server configuration but you will not be able to choose another mail server after that",
"the_mail_server_is_already_configured": "This mail server is already configured",
"bound_to_this_archive": "Bound to this archive",
"not_bound_to_a_mail_server": "Not bound to a mail server"
},
"about": {
"title": "About"
Expand Down
55 changes: 48 additions & 7 deletions ui/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@
$t("settings.enabled")
}}</template>
</cv-toggle>
<cv-row v-if="!mail_already_configured && ! piler_is_running">
<cv-column>
<NsInlineNotification
kind="info"
:title="$t('settings.warnings_one_time_installation')"
:description="$t('settings.warnings_one_time_installation_description')"
:showCloseButton="false"
/>
</cv-column>
</cv-row>
<cv-row v-if="mail_already_configured && ! piler_is_running">
<cv-column>
<NsInlineNotification
kind="warning"
:title="$t('settings.the_mail_server_is_already_configured')"
:description="$t('settings.the_mail_server_is_already_configured_description')"
:showCloseButton="false"
/>
</cv-column>
</cv-row>
<NsComboBox
v-model.trim="mail_server"
:autoFilter="true"
Expand All @@ -115,7 +135,7 @@
:acceptUserInput="false"
:showItemType="true"
:invalid-message="$t(error.mail_server)"
:disabled="loading.getConfiguration || loading.configureModule"
:disabled="loading.getConfiguration || loading.configureModule || mail_server !== '' && piler_is_running"
tooltipAlignment="start"
tooltipDirection="top"
ref="mail_server"
Expand Down Expand Up @@ -153,7 +173,7 @@
kind="primary"
:icon="Save20"
:loading="loading.configureModule"
:disabled="loading.getConfiguration || loading.configureModule"
:disabled="loading.getConfiguration || loading.configureModule || piler_is_running && !always_bcc_correctly_set"
>
{{ $t("settings.save") }}
</NsButton>
Expand Down Expand Up @@ -203,6 +223,7 @@ export default {
isLetsEncryptEnabled: false,
isHttpToHttpsEnabled: false,
retention_days: "2557",
mail_already_configured: false,
loading: {
getConfiguration: false,
configureModule: false,
Expand Down Expand Up @@ -234,6 +255,17 @@ export default {
clearInterval(this.urlCheckInterval);
next();
},
watch: {
mail_server: function() {
//function to display the warning message if the mail server is already configured
let server = this.mail_server_URL.find(server => server.value === this.mail_server);
if (server && server.bcc_set === 'not_set') {
this.mail_already_configured = false;
} else if (server && server.bcc_set !== 'not_set') {
this.mail_already_configured = true;
}
}
},
methods: {
goToPilerWebapp() {
window.open(`https://${this.host}`, "_blank");
Expand Down Expand Up @@ -280,21 +312,32 @@ export default {
this.error.getConfiguration = this.$t("error.generic_error");
this.loading.getConfiguration = false;
},
convertToComboboxObject(server) {
const label = `${server.ui_name ? server.ui_name : server.module_id} (${server.node_name ? server.node_name : this.$t("settings.node", { nodeId: server.node })}): ${server.bcc_set === 'not_set' ? this.$t("settings.not_configured_to_archive") : this.$t("settings.configured_to_archive", {archive: server.bcc_set})}`;
return {
name: label,
label: label,
value: server.module_uuid,
bcc_set: server.bcc_set
};
},
getConfigurationCompleted(taskContext, taskResult) {
const config = taskResult.output;
this.host = config.host;
this.always_bcc_correctly_set = config.always_bcc_correctly_set;
this.isLetsEncryptEnabled = config.lets_encrypt;
this.isHttpToHttpsEnabled = config.http2https;
// force to reload mail_server value after dom update
this.$nextTick(() => {
this.mail_server = config.mail_server;
});
this.mail_server_URL = config.mail_server_URL;
this.is_default_password_admin = config.is_default_password_admin;
this.is_default_password_auditor = config.is_default_password_auditor;
this.piler_is_running = config.piler_is_running;
this.always_bcc_correctly_set = config.always_bcc_correctly_set;
this.retention_days = config.retention_days.toString();
this.mail_server_URL = config.mail_server_URL.map(
this.convertToComboboxObject
);;
this.loading.getConfiguration = false;
this.focusElement("host");
},
Expand Down Expand Up @@ -406,9 +449,7 @@ export default {
this.loading.configureModule = false;
},
configureModuleCompleted() {
// reload configuration
this.getConfiguration();
this.loading.configureModule = false;
window.location.reload();
},
},
};
Expand Down
Loading