discourse/app/assets/javascripts/admin/models/api-key.js.es6

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.4 KiB
Plaintext
Raw Normal View History

import discourseComputed from "discourse-common/utils/decorators";
2017-07-05 16:47:01 -04:00
import AdminUser from "admin/models/admin-user";
import RestModel from "discourse/models/rest";
2016-06-30 13:55:44 -04:00
import { ajax } from "discourse/lib/ajax";
import { computed } from "@ember/object";
import { fmt } from "discourse/lib/computed";
2017-07-05 16:47:01 -04:00
const ApiKey = RestModel.extend({
user: computed("_user", {
get() {
return this._user;
},
set(key, value) {
if (value && !(value instanceof AdminUser)) {
this.set("_user", AdminUser.create(value));
} else {
this.set("_user", value);
}
return this._user;
}
}),
@discourseComputed("description")
shortDescription(description) {
if (!description || description.length < 40) return description;
return `${description.substring(0, 40)}...`;
2013-10-22 15:53:08 -04:00
},
truncatedKey: fmt("truncated_key", "%@..."),
2019-01-23 11:40:05 -05:00
revoke() {
return ajax(`${this.basePath}/revoke`, {
type: "POST"
}).then(result => this.setProperties(result.api_key));
},
2013-10-22 15:53:08 -04:00
undoRevoke() {
return ajax(`${this.basePath}/undo-revoke`, {
type: "POST"
}).then(result => this.setProperties(result.api_key));
2013-10-22 15:53:08 -04:00
},
createProperties() {
return this.getProperties("description", "username");
2013-10-22 15:53:08 -04:00
},
@discourseComputed()
basePath() {
return this.store
.adapterFor("api-key")
.pathFor(this.store, "api-key", this.id);
2013-10-22 15:53:08 -04:00
}
});
export default ApiKey;