View | Details | Raw Unified | Return to bug 27424
Collapse All | Expand All

(-)a/Koha/SMTP/Servers.pm (-1 / +5 lines)
Lines 44-52 sub get_default { Link Here
44
    my ($self) = @_;
44
    my ($self) = @_;
45
45
46
    my $default;
46
    my $default;
47
47
    my $smtp_config = C4::Context->config('smtp_server');
48
    my $smtp_config = C4::Context->config('smtp_server');
48
49
49
    if ( $smtp_config ) {
50
    if ( $default = $self->search({ is_default => 1 }, { rows => 1 })->single ) {
51
52
    }
53
    elsif ( $smtp_config ) {
50
        $default = Koha::SMTP::Server->new( $smtp_config );
54
        $default = Koha::SMTP::Server->new( $smtp_config );
51
    }
55
    }
52
    else {
56
    else {
(-)a/admin/smtp_servers.pl (-7 / +26 lines)
Lines 52-59 if ( $op eq 'add' ) { Link Here
52
    my $user_name  = $input->param('smtp_user_name') || undef;
52
    my $user_name  = $input->param('smtp_user_name') || undef;
53
    my $password   = $input->param('smtp_password') || undef;
53
    my $password   = $input->param('smtp_password') || undef;
54
    my $debug      = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0;
54
    my $debug      = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0;
55
    my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0;
55
56
57
    my $schema = Koha::Database->new->schema;
56
    try {
58
    try {
59
        $schema->storage->txn_begin;
60
61
        Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default;
62
57
        Koha::SMTP::Server->new(
63
        Koha::SMTP::Server->new(
58
            {
64
            {
59
                name       => $name,
65
                name       => $name,
Lines 64-75 if ( $op eq 'add' ) { Link Here
64
                user_name  => $user_name,
70
                user_name  => $user_name,
65
                password   => $password,
71
                password   => $password,
66
                debug      => $debug,
72
                debug      => $debug,
73
                is_default => $is_default,
67
            }
74
            }
68
        )->store;
75
        )->store;
69
76
70
        push @messages, { type => 'message', code => 'success_on_insert' };
77
        push @messages, { type => 'message', code => 'success_on_insert' };
78
        $schema->storage->txn_commit;
71
    }
79
    }
72
    catch {
80
    catch {
81
        $schema->storage->txn_rollback;
73
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
82
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
74
            push @messages,
83
            push @messages,
75
              {
84
              {
Lines 122-142 elsif ( $op eq 'edit_save' ) { Link Here
122
        my $user_name  = $input->param('smtp_user_name') || undef;
131
        my $user_name  = $input->param('smtp_user_name') || undef;
123
        my $password   = $input->param('smtp_password') || undef;
132
        my $password   = $input->param('smtp_password') || undef;
124
        my $debug      = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0;
133
        my $debug      = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0;
134
        my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0;
135
136
        my $schema = Koha::Database->new->schema;
125
137
126
        try {
138
        try {
139
            $schema->storage->txn_begin;
140
141
            Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default;
142
127
            $smtp_server->password( $password )
143
            $smtp_server->password( $password )
128
                if defined $password and $password ne '****'
144
                if defined $password and $password ne '****'
129
                    or not defined $password;
145
                    or not defined $password;
130
146
131
            $smtp_server->set(
147
            $smtp_server->set(
132
                {
148
                {
133
                    name      => $name,
149
                    name       => $name,
134
                    host      => $host,
150
                    host       => $host,
135
                    port      => $port,
151
                    port       => $port,
136
                    timeout   => $timeout,
152
                    timeout    => $timeout,
137
                    ssl_mode  => $ssl_mode,
153
                    ssl_mode   => $ssl_mode,
138
                    user_name => $user_name,
154
                    user_name  => $user_name,
139
                    debug     => $debug
155
                    debug      => $debug,
156
                    is_default => $is_default,
140
                }
157
                }
141
            )->store;
158
            )->store;
142
159
Lines 145-152 elsif ( $op eq 'edit_save' ) { Link Here
145
                type => 'message',
162
                type => 'message',
146
                code => 'success_on_update'
163
                code => 'success_on_update'
147
            };
164
            };
165
            $schema->storage->txn_commit;
148
        }
166
        }
149
        catch {
167
        catch {
168
            $schema->storage->txn_rollback;
150
            push @messages,
169
            push @messages,
151
            {
170
            {
152
                type   => 'alert',
171
                type   => 'alert',
(-)a/api/v1/swagger/definitions/smtp_server.yaml (+3 lines)
Lines 37-42 properties: Link Here
37
  debug:
37
  debug:
38
    type: boolean
38
    type: boolean
39
    description: If the SMTP connection is set to debug mode
39
    description: If the SMTP connection is set to debug mode
40
  is_default:
41
    type: boolean
42
    description: Is this the default SMTP server
40
additionalProperties: false
43
additionalProperties: false
41
required:
44
required:
42
  - name
45
  - name
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 4647-4652 CREATE TABLE `smtp_servers` ( Link Here
4647
  `user_name` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4647
  `user_name` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4648
  `password` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4648
  `password` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4649
  `debug` tinyint(1) NOT NULL DEFAULT 0,
4649
  `debug` tinyint(1) NOT NULL DEFAULT 0,
4650
  `is_default` tinyint(1) NOT NULL DEFAULT 0,
4650
  PRIMARY KEY (`id`),
4651
  PRIMARY KEY (`id`),
4651
  KEY `host_idx` (`host`)
4652
  KEY `host_idx` (`host`)
4652
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4653
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt (+27 lines)
Lines 134-139 Link Here
134
                    </select>
134
                    </select>
135
                    <span>Enables additional debug output in the logs</span>
135
                    <span>Enables additional debug output in the logs</span>
136
                </li>
136
                </li>
137
                <li>
138
                    <label for="smtp_default">Default server: </label>
139
                    <input type="checkbox" name="smtp_default" id="smtp_default" />
140
                    <span>Sets this SMTP server as the default SMTP server.</span>
141
                </li>
137
            </ol>
142
            </ol>
138
        </fieldset>
143
        </fieldset>
139
        <fieldset class="action">
144
        <fieldset class="action">
Lines 216-221 Link Here
216
                    [%- END -%]
221
                    [%- END -%]
217
                    </select>
222
                    </select>
218
                </li>
223
                </li>
224
                <li>
225
                    <label for="smtp_default">Default server: </label>
226
                    [% IF smtp_server.is_default %]
227
                        <input type="checkbox" name="smtp_default" id="smtp_default" checked="checked"/>
228
                    [% ELSE %]
229
                        <input type="checkbox" name="smtp_default" id="smtp_default" />
230
                    [% END %]
231
                    <span>Sets this SMTP server as the default SMTP server.</span>
232
                </li>
219
            </ol>
233
            </ol>
220
        </fieldset>
234
        </fieldset>
221
        <fieldset class="action">
235
        <fieldset class="action">
Lines 255-260 Link Here
255
                    <th>Timeout (secs)</th>
269
                    <th>Timeout (secs)</th>
256
                    <th>SSL</th>
270
                    <th>SSL</th>
257
                    <th>Authenticated</th>
271
                    <th>Authenticated</th>
272
                    <th>Is default</th>
258
                    <th data-class-name="actions noExport">Actions</th>
273
                    <th data-class-name="actions noExport">Actions</th>
259
                </tr>
274
                </tr>
260
            </thead>
275
            </thead>
Lines 368-373 Link Here
368
                        "searchable": false,
383
                        "searchable": false,
369
                        "orderable": false
384
                        "orderable": false
370
                    },
385
                    },
386
                    {
387
                        "data": function( row, type, val, meta ) {
388
                            if ( row.is_default ) {
389
                                return _("Yes");
390
                            }
391
                            else {
392
                                return _("No");
393
                            }
394
                        },
395
                        "searchable": false,
396
                        "orderable": false
397
                    },
371
                    {
398
                    {
372
                        "data": function( row, type, val, meta ) {
399
                        "data": function( row, type, val, meta ) {
373
                            var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&amp;smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
400
                            var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&amp;smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
(-)a/t/db_dependent/Koha/SMTP/Server.t (-3 / +18 lines)
Lines 64-79 subtest 'transport() tests' => sub { Link Here
64
64
65
subtest 'is_system_default() tests' => sub {
65
subtest 'is_system_default() tests' => sub {
66
66
67
    plan tests => 2;
67
    plan tests => 3;
68
68
69
    $schema->storage->txn_begin;
69
    $schema->storage->txn_begin;
70
70
71
    my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' });
71
    Koha::SMTP::Servers->search()->delete();
72
73
    my $smtp_server = $builder->build_object(
74
        {
75
            class => 'Koha::SMTP::Servers',
76
            value => { is_default => 0 }
77
        }
78
    );
79
72
    ok( !$smtp_server->is_system_default, 'A generated server is not the system default' );
80
    ok( !$smtp_server->is_system_default, 'A generated server is not the system default' );
73
81
74
    my $system_default_server = Koha::SMTP::Servers->get_default;
82
    my $system_default_server = Koha::SMTP::Servers->get_default;
75
    ok( $system_default_server->is_system_default, 'The server returned by get_default is the system default' );
83
    ok( $system_default_server->is_system_default, 'The server returned by get_default is the system default' );
76
84
85
    $smtp_server = $builder->build_object(
86
        {
87
            class => 'Koha::SMTP::Servers',
88
            value => { ssl_mode => 'disabled', debug => 0, is_default => 1 }
89
        }
90
    );
91
    is( Koha::SMTP::Servers->get_default->id, $smtp_server->id, "Default server correctly retrieved from database" );
92
77
    $schema->storage->txn_rollback;
93
    $schema->storage->txn_rollback;
78
};
94
};
79
95
80
- 

Return to bug 27424