2021-02-24 08:43:35 +01:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
2020-03-21 18:30:11 +01:00
|
|
|
import EmberObject from "@ember/object";
|
2020-04-05 03:37:09 +02:00
|
|
|
import { A } from "@ember/array";
|
2019-05-30 07:04:34 +02:00
|
|
|
|
2020-03-21 18:30:11 +01:00
|
|
|
const CustomWizardApi = EmberObject.extend({
|
2021-02-24 08:43:35 +01:00
|
|
|
@discourseComputed("name")
|
2019-06-02 12:54:31 +02:00
|
|
|
redirectUri(name) {
|
|
|
|
let nameParam = name.toString().dasherize();
|
2021-02-24 08:43:35 +01: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`;
|
2021-02-24 08:43:35 +01:00
|
|
|
},
|
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,
|
2020-04-05 03:37:09 +02:00
|
|
|
authParams: A(authorization.auth_params),
|
2019-05-31 09:54:11 +02:00
|
|
|
authorized: authorization.authorized,
|
|
|
|
accessToken: authorization.access_token,
|
|
|
|
refreshToken: authorization.refresh_token,
|
|
|
|
code: authorization.code,
|
|
|
|
tokenExpiresAt: authorization.token_expires_at,
|
|
|
|
tokenRefreshAt: authorization.token_refresh_at,
|
2020-04-05 03:37:09 +02:00
|
|
|
endpoints: A(endpoints),
|
2019-06-06 18:10:13 +02:00
|
|
|
isNew: params.isNew,
|
2021-02-24 08:43:35 +01:00
|
|
|
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) {
|
2020-04-22 15:03:18 +02:00
|
|
|
return ajax(`/admin/wizards/api/${name}`, {
|
2021-02-24 08:43:35 +01: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() {
|
2020-04-22 15:03:18 +02:00
|
|
|
return ajax("/admin/wizards/api", {
|
2021-02-24 08:43:35 +01:00
|
|
|
type: "GET",
|
|
|
|
}).then((result) => {
|
2019-05-30 07:04:34 +02:00
|
|
|
return result;
|
|
|
|
});
|
2021-02-24 08:43:35 +01:00
|
|
|
},
|
2019-05-30 07:04:34 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
export default CustomWizardApi;
|