-
Notifications
You must be signed in to change notification settings - Fork 111
feat(smtp): move smtp credentials to database #8454
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
Open
jniles
wants to merge
9
commits into
third-culture-software:master
Choose a base branch
from
jniles:8201-add-smtp-to-database
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e5ed69e
feat(smtp): move smtp credentials to database
jniles 00417eb
chore: follow smtp verification standard
jniles 631ba10
test(smtp): ensure ample timeout for smtp test
jniles c678668
chore(ci): bump nodejs version to latest LTS
jniles c2de42e
chore(ci): bump nodejs version to latest LTS
jniles e75ad62
chore: change smtp
jniles a09b8a8
Apply suggestions from code review
jniles bfde038
feat: add SMTP configuration modal
jniles cbda3e6
chore(i18n): sync french SMTP translations
jniles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "SMTP" : { | ||
| "FROM_ADDRESS" : "Sender (from) Address", | ||
| "FROM_NAME" : "Sender (from) Name", | ||
| "HOST" : "SMTP Host", | ||
| "PASSWORD" : "Password", | ||
| "PORT" : "SMTP Port", | ||
| "SECURE_DESCRIPTION" : "Use TLS in the connection (recommended for port 465)", | ||
| "SECURE" : "Secure", | ||
| "TEST_CONNECTION" : "Test Connection", | ||
| "USERNAME" : "Username" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "SMTP" : { | ||
| "FROM_ADDRESS" : "Adresse de l'expéditeur", | ||
| "FROM_NAME" : "Nom de l'expéditeur", | ||
| "HOST" : "Hôte SMTP", | ||
| "PASSWORD" : "Mot de passe", | ||
| "PORT" : "Port", | ||
| "SECURE_DESCRIPTION" : "Utiliser TLS dans la connexion (recommandé pour le port 465)", | ||
| "SECURE" : "Sécurisé", | ||
| "TEST_CONNECTION" : "Tester la connexion", | ||
| "USERNAME" : "Nom d'utilisateur" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
client/src/modules/enterprises/modals/bhSmtp-modal.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <form name="SMTPForm" bh-submit="ModalCtrl.submit(SMTPForm)" novalidate data-edit-password-modal> | ||
| <div class="modal-header"> | ||
| <ol class="headercrumb"> | ||
| <li class="static" translate>ENTERPRISE.TITLE</li> | ||
| <li class="title" translate>ENTERPRISE.SMTP_CONFIGURATION</li> | ||
| </ol> | ||
| </div> | ||
|
|
||
| <div class="modal-body"> | ||
|
|
||
| <div class="form-group has-feedback" ng-class="{ 'has-error' : SMTPForm.$submitted && SMTPForm.smtp_host.$error }"> | ||
| <label class="control-label" translate>SMTP.HOST</label> | ||
| <input | ||
| type="text" | ||
| name="smtp_host" | ||
| ng-model="ModalCtrl.smtp.smtp_host" | ||
| class="form-control" | ||
| required /> | ||
|
|
||
| <div class="help-block" ng-messages="SMTPForm.smtp_host.$error" ng-show="SMTPForm.$submitted && SMTPForm.smtp_host.$error"> | ||
| <div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="form-group has-feedback" ng-class="{ 'has-error' : SMTPForm.$submitted && SMTPForm.smtp_port.$error }"> | ||
| <label class="control-label" translate>SMTP.PORT</label> | ||
| <input | ||
| type="text" | ||
| name="smtp_port" | ||
| ng-model="ModalCtrl.smtp.smtp_port" | ||
| class="form-control" /> | ||
|
|
||
| <div class="help-block" ng-messages="SMTPForm.smtp_port.$error" ng-show="SMTPForm.$submitted && SMTPForm.smtp_port.$error"> | ||
| <div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="form-group" > | ||
| <div class="checkbox"> | ||
| <label> | ||
| <input type="checkbox" name="smtp_secure" ng-true-value="1" ng-false-value="0" | ||
| ng-model="ModalCtrl.user.smtp_secure"> | ||
| <span translate>SMTP.SECURE</span> | ||
| </label> | ||
| </div> | ||
| <div class="help-block"> | ||
| <p translate>SMTP.SECURE_DESCRIPTION</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="form-group has-feedback" ng-class="{ 'has-error' : SMTPForm.$submitted && SMTPForm.smtp_username.$error }"> | ||
| <label class="control-label" translate>SMTP.USERNAME</label> | ||
| <input | ||
| type="text" | ||
| name="smtp_username" | ||
| ng-model="ModalCtrl.smtp.smtp_username" | ||
| class="form-control" | ||
| required /> | ||
|
|
||
| <div class="help-block" ng-messages="SMTPForm.smtp_username.$error" ng-show="SMTPForm.$submitted && SMTPForm.smtp_username.$error"> | ||
| <div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="form-group has-feedback" ng-class="{ 'has-error' : SMTPForm.$submitted && SMTPForm.smtp_port.$error }"> | ||
| <label class="control-label" translate>SMTP.PASSWORD</label> | ||
| <input | ||
| type="password" | ||
| name="smtp_password" | ||
| ng-model="ModalCtrl.smtp.smtp_password" | ||
| class="form-control" | ||
| required /> | ||
|
|
||
| <div class="help-block" ng-messages="SMTPForm.smtp_port.$error" ng-show="SMTPForm.$submitted && SMTPForm.smtp_port.$error"> | ||
| <div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="form-group has-feedback" ng-class="{ 'has-error' : SMTPForm.$submitted && SMTPForm.from_address.$error }"> | ||
| <label class="control-label" translate>SMTP.FROM_ADDRESS</label> | ||
| <input | ||
| type="text" | ||
| name="from_address" | ||
| ng-model="ModalCtrl.smtp.from_address" | ||
| class="form-control" /> | ||
|
|
||
| <div class="help-block" ng-messages="SMTPForm.from_address.$error" ng-show="SMTPForm.$submitted && SMTPForm.from_address.$error"> | ||
| <div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="form-group has-feedback" ng-class="{ 'has-error' : SMTPForm.$submitted && SMTPForm.from_name.$error }"> | ||
| <label class="control-label" translate>SMTP.FROM_NAME</label> | ||
| <input | ||
| type="text" | ||
| name="from_name" | ||
| ng-model="ModalCtrl.smtp.from_name" | ||
| class="form-control" | ||
| required /> | ||
|
|
||
| <div class="help-block" ng-messages="SMTPForm.from_name.$error" ng-show="SMTPForm.$submitted && SMTPForm.from_name.$error"> | ||
| <div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="modal-footer"> | ||
| <button | ||
| type="button" | ||
| class="btn btn-default" | ||
| ng-click="ModalCtrl.cancel()" | ||
| data-method="cancel" | ||
| translate> | ||
| FORM.BUTTONS.CANCEL | ||
| </button> | ||
|
|
||
| <button | ||
| type="button" | ||
| class="btn btn-default" | ||
| ng-click="ModalCtrl.testConnection()" | ||
| data-method="test-connection" | ||
| translate> | ||
| SMTP.TEST_CONNECTION | ||
| </button> | ||
|
|
||
| <bh-loading-button loading-state="SMTPForm.$loading"> | ||
| <span translate>FORM.BUTTONS.SUBMIT</span> | ||
| </bh-loading-button> | ||
| </div> | ||
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| angular.module('bhima.controllers') | ||
| .controller('SMTPModalController', SMTPModalController); | ||
|
|
||
| SMTPModalController.$inject = [ | ||
| 'SessionService', '$uibModalInstance', '$stateParams', 'NotifyService', 'SMTPService', | ||
| ]; | ||
|
|
||
| /** | ||
| * @controller SMTPModalController | ||
| * @description Controller for the SMTP configuration modal. | ||
| */ | ||
| function SMTPModalController(Session, Instance, $stateParams, Notify, SMTP) { | ||
| const vm = this; | ||
|
|
||
| vm.smtp = {}; | ||
|
|
||
| /* ------------------------------------------------------------------------ */ | ||
| vm.cancel = () => Instance.close(false); | ||
| vm.submit = submit; | ||
| vm.testConnection = testConnection; | ||
|
|
||
| // loads a new set of cashboxes from the server that the user has management right. | ||
| function startup() { | ||
| toggleLoadingIndicator(); | ||
| SMTP.read() | ||
| .then(rows => { | ||
|
|
||
| if (rows.length > 0) { | ||
| [vm.smtp] = rows; | ||
| } | ||
|
|
||
| vm.isCreateState = (rows.length === 0); | ||
| }) | ||
| .catch(Notify.handleError) | ||
| .finally(toggleLoadingIndicator); | ||
| } | ||
|
|
||
| function toggleLoadingIndicator() { | ||
| vm.loading = !vm.loading; | ||
| } | ||
|
|
||
| function testConnection() { | ||
| toggleLoadingIndicator(); | ||
|
|
||
| SMTP.testConnection(vm.smtp) | ||
| .then(() => { | ||
| Notify.success('SMTP.CONNECTION.SUCCESS'); | ||
| }) | ||
| .catch(Notify.handleError) | ||
| .finally(toggleLoadingIndicator); | ||
| } | ||
|
|
||
| function submit(form) { | ||
| if (form.$invalid) { return 0; } | ||
|
|
||
| const promise = (vm.isCreateState) | ||
| ? SMTP.create(vm.smtp) | ||
| : SMTP.update(vm.smtp.id, vm.smtp); | ||
|
|
||
| return promise.then(() => { | ||
| const translateKey = (vm.isCreateState) ? 'FORM.INFO.CREATE_SUCCESS' : 'FORM.INFO.UPDATE_SUCCESS'; | ||
| Notify.success(translateKey); | ||
| return Instance.close(true); | ||
| }) | ||
| .catch(Notify.handleError); | ||
| } | ||
|
|
||
| // start up the module | ||
| startup(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| angular.module('bhima.services') | ||
| .service('SMTPService', SMTPService); | ||
|
|
||
| SMTPService.$inject = ['PrototypeApiService', '$uibModal']; | ||
|
|
||
| function SMTPService(Api, Modal) { | ||
| const baseUrl = '/smtp/'; | ||
| const service = new Api(baseUrl); | ||
|
|
||
| // allows the user to test the SMTP connection before | ||
| // saving to the database. | ||
| service.testConnection = (body) => { | ||
| return service.$http.post(`${baseUrl}test-connection`, body) | ||
| .then(service.util.unwrapHttpResponse); | ||
| }; | ||
|
|
||
| // opens the SMTP modal to configure the SMTP settings. | ||
| service.openSMTPModal = () => { | ||
| return Modal.open({ | ||
| templateUrl : 'modules/enterprises/modals/bhSmtp-modal.html', | ||
| controller : 'SMTPModalController as ModalCtrl', | ||
| }).result; | ||
| }; | ||
|
|
||
| return service; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SMTP configuration endpoints are protected by general authentication (requiring a logged-in user) but lack specific admin-level authorization. SMTP configuration is a sensitive system-level setting that should only be accessible to administrators, not all authenticated users. Consider adding role-based access control to restrict these endpoints to admin users only, similar to how other admin operations are protected in the codebase.