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

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

56 lines
1.4 KiB
JavaScript
Raw Normal View History

import { computed } from "@ember/object";
2017-07-06 04:47:01 +08:00
import AdminUser from "admin/models/admin-user";
import RestModel from "discourse/models/rest";
2016-07-01 01:55:44 +08:00
import { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse-common/utils/decorators";
import { fmt } from "discourse/lib/computed";
2017-07-06 04:47:01 +08:00
export default class ApiKey extends RestModel {
@fmt("truncated_key", "%@...") truncatedKey;
@computed("_user")
get user() {
return this._user;
}
set user(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)}...`;
}
2019-01-24 00:40:05 +08:00
revoke() {
return ajax(`${this.basePath}/revoke`, {
type: "POST",
}).then((result) => this.setProperties(result.api_key));
}
2013-10-23 03:53:08 +08:00
undoRevoke() {
return ajax(`${this.basePath}/undo-revoke`, {
type: "POST",
}).then((result) => this.setProperties(result.api_key));
}
2013-10-23 03:53:08 +08:00
createProperties() {
return this.getProperties("description", "username", "scopes");
}
2013-10-23 03:53:08 +08:00
@discourseComputed()
basePath() {
return this.store
.adapterFor("api-key")
.pathFor(this.store, "api-key", this.id);
}
}