@@ -90,6 +90,7 @@ module.exports = Mn.View.extend({
90
90
}
91
91
92
92
let data = this . ui . form . serializeJSON ( ) ;
93
+ data . id = this . model . get ( 'id' ) ;
93
94
data . provider = this . model . get ( 'provider' ) ;
94
95
let ssl_files = [ ] ;
95
96
@@ -125,30 +126,38 @@ module.exports = Mn.View.extend({
125
126
if ( typeof data . domain_names === 'string' && data . domain_names ) {
126
127
data . domain_names = data . domain_names . split ( ',' ) ;
127
128
}
128
- } else if ( data . provider === 'other' && ! this . model . hasSslFiles ( ) ) {
129
+ } else if ( data . provider === 'other' ) {
130
+ const isNew = data . id == null ;
129
131
// check files are attached
130
- if ( ! this . ui . other_certificate [ 0 ] . files . length || ! this . ui . other_certificate [ 0 ] . files [ 0 ] . size ) {
132
+ // Check Certificate
133
+ const hasCertificateFile = this . ui . other_certificate [ 0 ] . files . length && this . ui . other_certificate [ 0 ] . files [ 0 ] . size
134
+ if ( isNew && ! hasCertificateFile ) {
131
135
alert ( 'Certificate file is not attached' ) ;
132
136
return ;
133
- } else {
137
+ }
138
+ if ( hasCertificateFile ) {
134
139
if ( this . ui . other_certificate [ 0 ] . files [ 0 ] . size > this . max_file_size ) {
135
140
alert ( 'Certificate file is too large (> 100kb)' ) ;
136
141
return ;
137
142
}
138
- ssl_files . push ( { name : 'certificate' , file : this . ui . other_certificate [ 0 ] . files [ 0 ] } ) ;
143
+ ssl_files . push ( { name : 'certificate' , file : this . ui . other_certificate [ 0 ] . files [ 0 ] } ) ;
139
144
}
140
145
141
- if ( ! this . ui . other_certificate_key [ 0 ] . files . length || ! this . ui . other_certificate_key [ 0 ] . files [ 0 ] . size ) {
146
+ // Check Certificate Key
147
+ const hasCertificateKeyFile = this . ui . other_certificate_key [ 0 ] . files . length && this . ui . other_certificate_key [ 0 ] . files [ 0 ] . size
148
+ if ( isNew && ! hasCertificateKeyFile ) {
142
149
alert ( 'Certificate key file is not attached' ) ;
143
150
return ;
144
- } else {
151
+ }
152
+ if ( hasCertificateKeyFile ) {
145
153
if ( this . ui . other_certificate_key [ 0 ] . files [ 0 ] . size > this . max_file_size ) {
146
154
alert ( 'Certificate key file is too large (> 100kb)' ) ;
147
155
return ;
148
156
}
149
- ssl_files . push ( { name : 'certificate_key' , file : this . ui . other_certificate_key [ 0 ] . files [ 0 ] } ) ;
157
+ ssl_files . push ( { name : 'certificate_key' , file : this . ui . other_certificate_key [ 0 ] . files [ 0 ] } ) ;
150
158
}
151
159
160
+ // Check Intermediate Certificate
152
161
if ( this . ui . other_intermediate_certificate [ 0 ] . files . length && this . ui . other_intermediate_certificate [ 0 ] . files [ 0 ] . size ) {
153
162
if ( this . ui . other_intermediate_certificate [ 0 ] . files [ 0 ] . size > this . max_file_size ) {
154
163
alert ( 'Intermediate Certificate file is too large (> 100kb)' ) ;
@@ -170,20 +179,23 @@ module.exports = Mn.View.extend({
170
179
}
171
180
172
181
new Promise ( resolve => {
173
- if ( data . provider === 'other' ) {
182
+ if ( data . provider === 'other' && ssl_files . length ) {
174
183
resolve ( App . Api . Nginx . Certificates . validate ( form_data ) ) ;
175
184
} else {
176
185
resolve ( ) ;
177
186
}
178
187
} )
179
188
. then ( ( ) => {
180
- return App . Api . Nginx . Certificates . create ( data ) ;
189
+ return data . id == null
190
+ ? App . Api . Nginx . Certificates . create ( data )
191
+ : App . Api . Nginx . Certificates . update ( data ) ;
181
192
} )
182
193
. then ( result => {
183
194
this . model . set ( result ) ;
184
195
185
196
// Now upload the certs if we need to
186
- if ( data . provider === 'other' ) {
197
+ const hasCertificateFiles = form_data . has ( 'certificate' ) || form_data . has ( 'certificate_key' ) || form_data . has ( 'intermediate_certificate' ) ;
198
+ if ( data . provider === 'other' && hasCertificateFiles ) {
187
199
return App . Api . Nginx . Certificates . upload ( this . model . get ( 'id' ) , form_data )
188
200
. then ( result => {
189
201
this . model . set ( 'meta' , _ . assign ( { } , this . model . get ( 'meta' ) , result ) ) ;
@@ -240,6 +252,9 @@ module.exports = Mn.View.extend({
240
252
this . getUI ( ui ) . text ( e . target . files [ 0 ] . name )
241
253
} ,
242
254
templateContext : {
255
+ isNew : function ( ) {
256
+ return this . isNew ( ) ;
257
+ } ,
243
258
getLetsencryptEmail : function ( ) {
244
259
return typeof this . meta . letsencrypt_email !== 'undefined' ? this . meta . letsencrypt_email : App . Cache . User . get ( 'email' ) ;
245
260
} ,
0 commit comments