mirror of
https://github.com/discourse/discourse.git
synced 2025-02-19 01:46:01 +00:00
This splits off the logic between SSO keys used incoming vs outgoing, it allows to far better restrict who is allowed to log in using a site. This allows for better auditing of the SSO provider feature
88 lines
2.0 KiB
JavaScript
88 lines
2.0 KiB
JavaScript
import { on } from "ember-addons/ember-computed-decorators";
|
|
|
|
export default Ember.Component.extend({
|
|
classNameBindings: [":value-list", ":secret-value-list"],
|
|
inputInvalidKey: Ember.computed.empty("newKey"),
|
|
inputInvalidSecret: Ember.computed.empty("newSecret"),
|
|
inputDelimiter: null,
|
|
collection: null,
|
|
values: null,
|
|
|
|
@on("didReceiveAttrs")
|
|
_setupCollection() {
|
|
const values = this.get("values");
|
|
|
|
this.set(
|
|
"collection",
|
|
this._splitValues(values, this.get("inputDelimiter") || "\n")
|
|
);
|
|
},
|
|
|
|
actions: {
|
|
changeKey(index, newValue) {
|
|
this._replaceValue(index, newValue, "key");
|
|
},
|
|
|
|
changeSecret(index, newValue) {
|
|
this._replaceValue(index, newValue, "secret");
|
|
},
|
|
|
|
addValue() {
|
|
if (this.get("inputInvalidKey") || this.get("inputInvalidSecret")) return;
|
|
this._addValue(this.get("newKey"), this.get("newSecret"));
|
|
this.setProperties({ newKey: "", newSecret: "" });
|
|
},
|
|
|
|
removeValue(value) {
|
|
this._removeValue(value);
|
|
}
|
|
},
|
|
|
|
_addValue(value, secret) {
|
|
this.get("collection").addObject({ key: value, secret: secret });
|
|
this._saveValues();
|
|
},
|
|
|
|
_removeValue(value) {
|
|
const collection = this.get("collection");
|
|
collection.removeObject(value);
|
|
this._saveValues();
|
|
},
|
|
|
|
_replaceValue(index, newValue, keyName) {
|
|
let item = this.get("collection")[index];
|
|
Ember.set(item, keyName, newValue);
|
|
|
|
this._saveValues();
|
|
},
|
|
|
|
_saveValues() {
|
|
this.set(
|
|
"values",
|
|
this.get("collection")
|
|
.map(function(elem) {
|
|
return `${elem.key}|${elem.secret}`;
|
|
})
|
|
.join("\n")
|
|
);
|
|
},
|
|
|
|
_splitValues(values, delimiter) {
|
|
if (values && values.length) {
|
|
const keys = ["key", "secret"];
|
|
var res = [];
|
|
values.split(delimiter).forEach(function(str) {
|
|
var object = {};
|
|
str.split("|").forEach(function(a, i) {
|
|
object[keys[i]] = a;
|
|
});
|
|
res.push(object);
|
|
});
|
|
|
|
return res;
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
});
|