Skip to content

Commit

Permalink
Merge pull request cypht-org#1074 from josaphatim/edit-server
Browse files Browse the repository at this point in the history
Added possibility to edit server data
  • Loading branch information
kroky authored Jun 13, 2024
2 parents cdeee04 + 71b1266 commit 680400e
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 86 deletions.
2 changes: 1 addition & 1 deletion lib/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function add($entity, $save = true) {

public static function edit($id, $entity) {
if (array_key_exists($id, self::$entities)) {
self::$entities[$id] = $entity;
self::$entities[$id] = array_merge(self::$entities[$id], $entity);
self::save();
return true;
}
Expand Down
36 changes: 25 additions & 11 deletions modules/core/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,10 @@ public function process() {
'srv_setup_stepper_profile_reply_to',
'srv_setup_stepper_imap_sieve_host',
'srv_setup_stepper_only_jmap',
'srv_setup_stepper_jmap_hide_from_c_page',
'srv_setup_stepper_imap_hide_from_c_page',
'srv_setup_stepper_jmap_address',
'srv_setup_stepper_imap_server_id',
'srv_setup_stepper_smtp_server_id',
));

if ($success) {
Expand All @@ -1017,8 +1019,10 @@ public function process() {
'srv_setup_stepper_profile_reply_to' => $profileReplyTo,
'srv_setup_stepper_imap_sieve_host' => $imapSieveHost,
'srv_setup_stepper_only_jmap' => $onlyJmap,
'srv_setup_stepper_jmap_hide_from_c_page' => $jmapHideFromCPage,
'srv_setup_stepper_imap_hide_from_c_page' => $hideFromCombinedView,
'srv_setup_stepper_jmap_address' => $jmapAddress,
'srv_setup_stepper_imap_server_id' => $imapServerId,
'srv_setup_stepper_smtp_server_id' => $smtpServerId
] = $form;

/*
Expand All @@ -1041,30 +1045,37 @@ public function process() {
false,
'jmap',
$this,
$jmapHideFromCPage
$hideFromCombinedView,
$imapServerId
);

if(!isset($this->jmap_server_id)) {
Hm_Msgs::add("ERRCould not save JMAP server");
return;
};

Hm_Msgs::add("JMAP Server saved");
$this->out('just_saved_credentials', true);
return;
} else {
/*
* Connect to SMTP server if user wants to send emails
*/
* Connect to SMTP server if user wants to send emails
*/
if($isSender){
if (!$this->module_is_supported('smtp')) {
Hm_Msgs::add("ERRSMTP module is not enabled");
return;
}

$this->smtp_server_id = connect_to_smtp_server($smtpAddress, $profileName, $smtpPort, $email, $password, $smtpTls, $this);
$this->smtp_server_id = connect_to_smtp_server($smtpAddress, $profileName, $smtpPort, $email, $password, $smtpTls, $smtpServerId);
if(!isset($this->smtp_server_id)){
Hm_Msgs::add("ERRCould not save server");
return;
}
}

/*
* Connect to IMAP server if user wants to receive emails
*/
* Connect to IMAP server if user wants to receive emails
*/
if($isReceiver){
if (!$this->module_is_supported('imap')) {
Hm_Msgs::add("ERRIMAP module is not enabled");
Expand All @@ -1081,18 +1092,21 @@ public function process() {
$imapSieveHost,
$enableSieve,
'imap',
$this
$this,
$hideFromCombinedView,
$imapServerId,
);

if(!isset($this->imap_server_id)) {
if($isSender && isset($this->smtp_server_id)){
delete_smtp_server($this->smtp_server_id, $this);
}
Hm_Msgs::add("ERRCould not save server");
return;
};
}

if($isSender && $isReceiver && $createProfile && isset($this->imap_server_id) && isset($this->smtp_server_id)) {
if($isSender && $isReceiver && $createProfile && isset($this->imap_server_id) && isset($this->smtp_server_id) && ! ($smtpServerId || $imapServerId)) {
if (!$this->module_is_supported('profiles')) {
Hm_Msgs::add("ERRProfiles module is not enabled");
return;
Expand Down
15 changes: 6 additions & 9 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,8 @@ protected function output() {
<div>
<form class=" me-0" method="POST">
<input type="hidden" name="hm_page_key" value="'.$this->html_safe(Hm_Request_Key::generate()).'" />
<input type="hidden" name="srv_setup_stepper_imap_server_id" id="srv_setup_stepper_imap_server_id" />
<input type="hidden" name="srv_setup_stepper_smtp_server_id" id="srv_setup_stepper_smtp_server_id" />
<div class="form-floating mb-3">
<input required type="text" id="srv_setup_stepper_profile_name" name="srv_setup_stepper_profile_name" class="txt_fld form-control" value="" placeholder="'.$this->trans('Name').'">
<label class="" for="srv_setup_stepper_profile_name">'.$this->trans('Name').'</label>
Expand All @@ -2169,7 +2171,7 @@ protected function output() {
</form>
</div>
<div class="step_config-actions mt-4 d-flex justify-content-between">
<button class="btn btn-primary px-5" onclick="display_config_step(0)">'.$this->trans('Cancel').'</button>
<button class="btn btn-primary px-5" onclick="display_config_step(0);resetQuickSetupForm();">'.$this->trans('Cancel').'</button>
<button class="btn btn-primary px-5" onclick="display_config_step(2)">'.$this->trans('Next').'</button>
</div>
</div>
Expand Down Expand Up @@ -2236,19 +2238,14 @@ protected function output() {

$res .= '</form>
</div>
<div class="srv_setup_stepper_form_loader hide" id="srv_setup_stepper_form_loader">
<div class="spinner-border text-dark" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div class="step_config-actions mt-4 d-flex justify-content-between">
<button class="btn btn-danger px-3" onclick="display_config_step(0)">'.$this->trans('Cancel').'</button>
<button class="btn btn-danger px-3" onclick="display_config_step(0);resetQuickSetupForm();">'.$this->trans('Cancel').'</button>
<button class="btn btn-primary px-4" onclick="display_config_step(1)">'.$this->trans('Previous').'</button>
<button class="btn btn-primary px-3" onclick="display_config_step(3)">'.$this->trans('Finish').'</button>
<button class="btn btn-primary px-3" onclick="display_config_step(3)" id="stepper-action-finish">'.$this->trans('Finish').'</button>
</div>
</div>
<div id="step_config_0" class="step_config current_config_step">
<button class="btn btn-primary px-4" onclick="display_config_step(1)"><i class="bi bi-plus-square-fill me-2"></i> '.$this->trans('Add a new server').'</button>
<button class="imap-jmap-smtp-btn btn btn-primary px-4" onclick="display_config_step(1)"><i class="bi bi-plus-square-fill me-2"></i> '.$this->trans('Add a new server').'</button>
</div>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion modules/core/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@
'drafts_per_source' => FILTER_DEFAULT,
'drafts_since' => FILTER_DEFAULT,
'warn_for_unsaved_changes' => FILTER_VALIDATE_BOOLEAN,
'srv_setup_stepper_imap_server_id' => FILTER_DEFAULT,
'srv_setup_stepper_smtp_server_id' => FILTER_DEFAULT,
'srv_setup_stepper_profile_name' => FILTER_DEFAULT,
'srv_setup_stepper_email' => FILTER_DEFAULT,
'srv_setup_stepper_password' => FILTER_UNSAFE_RAW,
Expand All @@ -330,6 +332,7 @@
'srv_setup_stepper_imap_sieve_host' => FILTER_DEFAULT,
'srv_setup_stepper_only_jmap' => FILTER_VALIDATE_BOOLEAN,
'srv_setup_stepper_jmap_hide_from_c_page' => FILTER_VALIDATE_BOOLEAN,
'srv_setup_stepper_jmap_address' => FILTER_DEFAULT
'srv_setup_stepper_jmap_address' => FILTER_DEFAULT,
'srv_setup_stepper_imap_hide_from_c_page' => FILTER_VALIDATE_BOOLEAN
)
);
Loading

0 comments on commit 680400e

Please sign in to comment.