2015-11-21 09:27:06 +08:00
|
|
|
import ApiKey from 'admin/models/api-key';
|
|
|
|
|
2013-10-23 03:53:08 +08:00
|
|
|
/**
|
|
|
|
This controller supports the interface for dealing with API keys
|
|
|
|
|
|
|
|
@class AdminApiController
|
|
|
|
@extends Ember.ArrayController
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
|
|
|
**/
|
2014-07-23 11:20:45 +08:00
|
|
|
export default Ember.ArrayController.extend({
|
2013-10-23 03:53:08 +08:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
/**
|
|
|
|
Generates a master api key
|
|
|
|
|
|
|
|
@method generateMasterKey
|
|
|
|
**/
|
2013-12-31 02:29:52 +08:00
|
|
|
generateMasterKey: function() {
|
2013-10-23 03:53:08 +08:00
|
|
|
var self = this;
|
2015-11-21 09:27:06 +08:00
|
|
|
ApiKey.generateMasterKey().then(function (key) {
|
2013-10-23 03:53:08 +08:00
|
|
|
self.get('model').pushObject(key);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates an API key instance with internal user object
|
|
|
|
|
|
|
|
@method regenerateKey
|
2015-11-21 09:27:06 +08:00
|
|
|
@param {ApiKey} key the key to regenerate
|
2013-10-23 03:53:08 +08:00
|
|
|
**/
|
|
|
|
regenerateKey: function(key) {
|
|
|
|
bootbox.confirm(I18n.t("admin.api.confirm_regen"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
|
|
|
|
if (result) {
|
|
|
|
key.regenerate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Revokes an API key
|
|
|
|
|
|
|
|
@method revokeKey
|
2015-11-21 09:27:06 +08:00
|
|
|
@param {ApiKey} key the key to revoke
|
2013-10-23 03:53:08 +08:00
|
|
|
**/
|
|
|
|
revokeKey: function(key) {
|
|
|
|
var self = this;
|
|
|
|
bootbox.confirm(I18n.t("admin.api.confirm_revoke"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
|
|
|
|
if (result) {
|
|
|
|
key.revoke().then(function() {
|
|
|
|
self.get('model').removeObject(key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Has a master key already been generated?
|
|
|
|
|
|
|
|
@property hasMasterKey
|
|
|
|
@type {Boolean}
|
|
|
|
**/
|
|
|
|
hasMasterKey: function() {
|
|
|
|
return !!this.get('model').findBy('user', null);
|
2016-04-29 04:49:24 +08:00
|
|
|
}.property('model.[]')
|
2013-10-23 03:53:08 +08:00
|
|
|
|
|
|
|
});
|