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

Enhance email settings functionality by adding sender address support #668

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
14 changes: 9 additions & 5 deletions api/app/Http/Requests/Workspace/EmailSettingsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,33 @@ public function __construct(Request $request, Workspace $workspace)
*/
public function rules()
{
$allFieldsPresent = $this->filled(['host', 'port', 'username', 'password']);
$allFieldsPresent = $this->filled(['host', 'port', 'username', 'password', 'sender_address']);

return [
'host' => [
$allFieldsPresent ? 'required' : 'nullable',
'required_with:port,username,password',
'required_with:port,username,password,sender_address',
'string',
],
'port' => [
$allFieldsPresent ? 'required' : 'nullable',
'required_with:host,username,password',
'required_with:host,username,password,sender_address',
'integer',
],
'username' => [
$allFieldsPresent ? 'required' : 'nullable',
'required_with:host,port,password',
'required_with:host,port,password,sender_address',
'string',
],
'password' => [
$allFieldsPresent ? 'required' : 'nullable',
'required_with:host,port,username',
'required_with:host,port,username,sender_address',
'string',
],
'sender_address' => [
'nullable',
'email',
],
Comment on lines +48 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add custom error message for sender_address validation.

The sender_address field is missing a custom error message in the messages() method.

     public function messages()
     {
         return [
             'host.required_with' => 'The host field is required.',
             'port.required_with' => 'The port field is required.',
             'username.required_with' => 'The username field is required.',
             'password.required_with' => 'The password field is required.',
+            'sender_address.email' => 'The sender address must be a valid email address.',
         ];
     }

Committable suggestion skipped: line range outside the PR's diff.

];
}

Expand Down
11 changes: 11 additions & 0 deletions api/app/Notifications/Forms/FormEmailNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ private function formatSubmissionData($createLinks = true): array

private function getFromEmail(): string
{
$workspace = $this->event->form->workspace;
$emailSettings = $workspace->settings['email_settings'] ?? [];

if (
$workspace->is_pro
&& $emailSettings
&& !empty($emailSettings['sender_address'])
) {
return $emailSettings['sender_address'];
}

if (
config('app.self_hosted')
&& isset($this->integrationData->sender_email)
Expand Down
12 changes: 11 additions & 1 deletion client/components/pages/settings/WorkSpaceEmailSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
label="Password"
placeholder="Password"
/>
<TextInput
:form="emailSettingsForm"
name="sender_address"
:disabled="!workspace.is_pro"
label="Sender address"
placeholder="sender@example.com"
/>

<div class="flex justify-between gap-2">
<UButton
Expand Down Expand Up @@ -115,7 +122,8 @@ const emailSettingsForm = useForm({
host: '',
port: '',
username: '',
password: ''
password: '',
sender_address: ''
})
const emailSettingsLoading = ref(false)
const showEmailSettingsModal = ref(false)
Expand Down Expand Up @@ -148,6 +156,7 @@ const saveChanges = () => {
port: emailSettingsForm?.port,
username: emailSettingsForm?.username,
password: emailSettingsForm?.password,
sender_address: emailSettingsForm?.sender_address,
},
})
.then((data) => {
Expand All @@ -171,5 +180,6 @@ const initEmailSettings = () => {
emailSettingsForm.port = emailSettings?.port
emailSettingsForm.username = emailSettings?.username
emailSettingsForm.password = emailSettings?.password
emailSettingsForm.sender_address = emailSettings?.sender_address
}
</script>
Loading