0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-16 06:40:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/models/custom-wizard-api.js.es6

69 Zeilen
1,9 KiB
Text

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";
2020-03-21 18:30:11 +01:00
const CustomWizardApi = EmberObject.extend({
@discourseComputed("name")
redirectUri(name) {
let nameParam = name.toString().dasherize();
const baseUrl =
location.protocol +
"//" +
location.hostname +
(location.port ? ":" + location.port : "");
return baseUrl + `/admin/wizards/apis/${nameParam}/redirect`;
},
});
CustomWizardApi.reopenClass({
create(params = {}) {
const api = this._super.apply(this);
const authorization = params.authorization || {};
2019-05-31 09:54:11 +02:00
const endpoints = params.endpoints;
api.setProperties({
name: params.name,
title: params.title,
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,
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,
log: params.log,
});
2019-05-31 09:54:11 +02:00
return api;
},
find(name) {
2020-04-22 15:03:18 +02:00
return ajax(`/admin/wizards/api/${name}`, {
type: "GET",
}).then((result) => {
2019-05-31 09:54:11 +02:00
return CustomWizardApi.create(result);
});
},
list() {
2020-04-22 15:03:18 +02:00
return ajax("/admin/wizards/api", {
type: "GET",
}).then((result) => {
return result;
});
},
});
export default CustomWizardApi;