FEATURE: allow themes to live in private git repos

This feature allows themes sourced from git to live on private
servers, it automatically generates key pairs.
This commit is contained in:
Sam
2018-03-09 16:14:21 +11:00
parent 200c6673f1
commit 39e679d3cb
13 changed files with 145 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import { ajax } from 'discourse/lib/ajax';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { observes } from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend(ModalFunctionality, {
local: Ember.computed.equal('selection', 'local'),
@@ -9,6 +10,25 @@ export default Ember.Controller.extend(ModalFunctionality, {
adminCustomizeThemes: Ember.inject.controller(),
loading: false,
checkPrivate: Ember.computed.match('uploadUrl', /^git/),
@observes('privateChecked')
privateWasChecked() {
const checked = this.get('privateChecked');
if (checked && !this._keyLoading) {
this._keyLoading = true;
ajax('/admin/themes/generate_key_pair', {method: 'POST'})
.then(pair => {
this.set('privateKey', pair.private_key);
this.set('publicKey', pair.public_key);
})
.catch(popupAjaxError)
.finally(()=>{
this._keyLoading = false;
});
}
},
actions: {
importTheme() {
@@ -22,7 +42,13 @@ export default Ember.Controller.extend(ModalFunctionality, {
options.data = new FormData();
options.data.append('theme', $('#file-input')[0].files[0]);
} else {
options.data = {remote: this.get('uploadUrl')};
options.data = {
remote: this.get('uploadUrl')
};
if (this.get('privateChecked')){
options.data.private_key = this.get('privateKey');
}
}
this.set('loading', true);
@@ -30,7 +56,13 @@ export default Ember.Controller.extend(ModalFunctionality, {
const theme = this.store.createRecord('theme',result.theme);
this.get('adminCustomizeThemes').send('addTheme', theme);
this.send('closeModal');
}).catch(popupAjaxError).finally(() => this.set('loading', false));
})
.then(()=>{
this.set('privateKey', null);
this.set('publicKey', null);
})
.catch(popupAjaxError)
.finally(() => this.set('loading', false));
}
}

View File

@@ -16,7 +16,24 @@
<div class="inputs">
{{input value=uploadUrl placeholder="https://github.com/discourse/discourse/sample_theme"}}
<span class="description">{{i18n 'admin.customize.theme.import_web_tip'}}</span>
{{#if checkPrivate}}
<div class='check-private'>
<label>
{{input type="checkbox" checked=privateChecked}}
{{i18n 'admin.customize.theme.is_private'}}
</label>
{{#if privateChecked}}
{{#if publicKey}}
<div class='public-key'>
{{i18n 'admin.customize.theme.public_key'}}
{{textarea disabled=true value=publicKey}}
</div>
{{/if}}
{{/if}}
</div>
{{/if}}
</div>
{{/if}}
</div>
{{/d-modal-body}}

View File

@@ -239,3 +239,23 @@
#custom_emoji {
width: 27%;
}
.modal-body .inputs .check-private {
margin-top: 10px;
label {
padding-left: 0;
}
label input {
width: auto;
margin: 3px 0;
}
.public-key {
margin-top: 10px;
textarea {
cursor: auto;
height: 150px;
}
}
}