2019-05-30 07:04:34 +02:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
|
|
|
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
|
|
|
|
|
|
|
const CustomWizardApi = Discourse.Model.extend({
|
2019-06-02 12:54:31 +02:00
|
|
|
@computed('name')
|
|
|
|
redirectUri(name) {
|
|
|
|
let nameParam = name.toString().dasherize();
|
2019-05-30 07:04:34 +02:00
|
|
|
const baseUrl = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
|
2019-06-02 12:54:31 +02:00
|
|
|
return baseUrl + `/admin/wizards/apis/${nameParam}/redirect`;
|
2019-05-30 07:04:34 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
CustomWizardApi.reopenClass({
|
2019-06-01 04:25:09 +02:00
|
|
|
create(params = {}) {
|
2019-05-30 07:04:34 +02:00
|
|
|
const api = this._super.apply(this);
|
2019-06-01 04:25:09 +02:00
|
|
|
const authorization = params.authorization || {};
|
2019-05-31 09:54:11 +02:00
|
|
|
const endpoints = params.endpoints;
|
|
|
|
|
2019-05-30 07:04:34 +02:00
|
|
|
api.setProperties({
|
2019-06-02 12:54:31 +02:00
|
|
|
name: params.name,
|
|
|
|
title: params.title,
|
2019-06-03 04:49:54 +02:00
|
|
|
originalTitle: params.title,
|
2019-05-31 09:54:11 +02:00
|
|
|
authType: authorization.auth_type,
|
|
|
|
authUrl: authorization.auth_url,
|
|
|
|
tokenUrl: authorization.token_url,
|
|
|
|
clientId: authorization.client_id,
|
|
|
|
clientSecret: authorization.client_secret,
|
2019-06-03 00:59:35 +02:00
|
|
|
username: authorization.username,
|
|
|
|
password: authorization.password,
|
2019-05-31 09:54:11 +02:00
|
|
|
authParams: Ember.A(authorization.auth_params),
|
|
|
|
authorized: authorization.authorized,
|
|
|
|
accessToken: authorization.access_token,
|
|
|
|
refreshToken: authorization.refresh_token,
|
|
|
|
code: authorization.code,
|
|
|
|
tokenExpiresAt: authorization.token_expires_at,
|
|
|
|
tokenRefreshAt: authorization.token_refresh_at,
|
2019-06-02 12:54:31 +02:00
|
|
|
endpoints: Ember.A(endpoints),
|
2019-06-06 18:10:13 +02:00
|
|
|
isNew: params.isNew,
|
|
|
|
log: params.log
|
2019-05-30 07:04:34 +02:00
|
|
|
});
|
2019-05-31 09:54:11 +02:00
|
|
|
|
2019-05-30 07:04:34 +02:00
|
|
|
return api;
|
|
|
|
},
|
|
|
|
|
2019-06-02 12:54:31 +02:00
|
|
|
find(name) {
|
|
|
|
return ajax(`/admin/wizards/apis/${name}`, {
|
2019-05-30 07:04:34 +02:00
|
|
|
type: 'GET'
|
|
|
|
}).then(result => {
|
2019-05-31 09:54:11 +02:00
|
|
|
return CustomWizardApi.create(result);
|
2019-05-30 07:04:34 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
list() {
|
|
|
|
return ajax("/admin/wizards/apis", {
|
|
|
|
type: 'GET'
|
|
|
|
}).then(result => {
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default CustomWizardApi;
|