2020-02-05 11:14:42 -05:00
|
|
|
import Controller from "@ember/controller";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2020-03-06 17:49:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
import { isBlank } from "@ember/utils";
|
2019-11-05 09:10:23 -05:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2021-02-01 05:07:11 -05:00
|
|
|
import { get } from "@ember/object";
|
2020-08-18 14:12:04 -04:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2020-02-05 11:14:42 -05:00
|
|
|
export default Controller.extend({
|
2019-11-05 09:10:23 -05:00
|
|
|
userModes: [
|
|
|
|
{ id: "all", name: I18n.t("admin.api.all_users") },
|
|
|
|
{ id: "single", name: I18n.t("admin.api.single_user") },
|
|
|
|
],
|
2020-07-16 14:51:24 -04:00
|
|
|
useGlobalKey: false,
|
|
|
|
scopes: null,
|
2019-11-05 09:10:23 -05:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("userMode")
|
2019-11-05 09:10:23 -05:00
|
|
|
showUserSelector(mode) {
|
|
|
|
return mode === "single";
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("model.description", "model.username", "userMode")
|
2019-11-05 09:10:23 -05:00
|
|
|
saveDisabled(description, username, userMode) {
|
2020-09-22 10:28:28 -04:00
|
|
|
if (isBlank(description)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (userMode === "single" && isBlank(username)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-05 09:10:23 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2021-02-01 05:07:11 -05:00
|
|
|
updateUsername(selected) {
|
|
|
|
this.set("model.username", get(selected, "firstObject"));
|
|
|
|
},
|
|
|
|
|
2019-11-05 09:10:23 -05:00
|
|
|
changeUserMode(value) {
|
|
|
|
if (value === "all") {
|
|
|
|
this.model.set("username", null);
|
|
|
|
}
|
|
|
|
this.set("userMode", value);
|
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
2020-07-16 14:51:24 -04:00
|
|
|
if (!this.useGlobalKey) {
|
|
|
|
const selectedScopes = Object.values(this.scopes)
|
|
|
|
.flat()
|
|
|
|
.filter((action) => {
|
|
|
|
return action.selected;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.model.set("scopes", selectedScopes);
|
|
|
|
}
|
|
|
|
|
2019-12-12 06:45:00 -05:00
|
|
|
this.model.save().catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
|
|
|
continue() {
|
|
|
|
this.transitionToRoute("adminApiKeys.show", this.model.id);
|
2020-08-18 14:12:04 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
showURLs(urls) {
|
|
|
|
return showModal("admin-api-key-urls", {
|
|
|
|
admin: true,
|
|
|
|
model: {
|
|
|
|
urls,
|
|
|
|
},
|
|
|
|
});
|
2019-11-05 09:10:23 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|