mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user