2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
Our data model for dealing with users from the admin section.
|
|
|
|
|
2013-03-06 03:52:35 +08:00
|
|
|
@class AdminUser
|
2013-02-23 04:41:12 +08:00
|
|
|
@extends Discourse.Model
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-06 03:52:35 +08:00
|
|
|
**/
|
2013-05-08 01:30:12 +08:00
|
|
|
Discourse.AdminUser = Discourse.User.extend({
|
2013-03-06 03:52:35 +08:00
|
|
|
|
2013-10-23 03:53:08 +08:00
|
|
|
/**
|
|
|
|
Generates an API key for the user. Will regenerate if they already have one.
|
|
|
|
|
|
|
|
@method generateApiKey
|
|
|
|
@returns {Promise} a promise that resolves to the newly generated API key
|
|
|
|
**/
|
|
|
|
generateApiKey: function() {
|
|
|
|
var self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/generate_api_key", {type: 'POST'}).then(function (result) {
|
|
|
|
var apiKey = Discourse.ApiKey.create(result.api_key);
|
|
|
|
self.set('api_key', apiKey);
|
|
|
|
return apiKey;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-15 22:11:39 +08:00
|
|
|
groupAdded: function(added){
|
|
|
|
var self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups", {
|
|
|
|
type: 'POST',
|
|
|
|
data: {group_id: added.id}
|
|
|
|
}).then(function () {
|
|
|
|
self.get('groups').pushObject(added);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
groupRemoved: function(removed){
|
|
|
|
var self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + removed.id, {
|
|
|
|
type: 'DELETE'
|
|
|
|
}).then(function () {
|
|
|
|
self.set('groups.[]', self.get('groups').rejectBy("id", removed.id));
|
2014-07-15 23:12:03 +08:00
|
|
|
});
|
2014-07-15 22:11:39 +08:00
|
|
|
},
|
|
|
|
|
2013-10-23 03:53:08 +08:00
|
|
|
/**
|
|
|
|
Revokes a user's current API key
|
|
|
|
|
|
|
|
@method revokeApiKey
|
|
|
|
@returns {Promise} a promise that resolves when the API key has been deleted
|
|
|
|
**/
|
|
|
|
revokeApiKey: function() {
|
|
|
|
var self = this;
|
2013-12-31 02:29:52 +08:00
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/revoke_api_key", {type: 'DELETE'}).then(function () {
|
2013-10-23 03:53:08 +08:00
|
|
|
self.set('api_key', null);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-02-21 01:29:40 +08:00
|
|
|
deleteAllPostsExplanation: function() {
|
|
|
|
if (!this.get('can_delete_all_posts')) {
|
2014-04-15 03:10:32 +08:00
|
|
|
if (this.get('post_count') > Discourse.SiteSettings.delete_all_posts_max) {
|
|
|
|
return I18n.t('admin.user.cant_delete_all_too_many_posts', {count: Discourse.SiteSettings.delete_all_posts_max});
|
|
|
|
} else {
|
|
|
|
return I18n.t('admin.user.cant_delete_all_posts', {count: Discourse.SiteSettings.delete_user_max_post_age});
|
|
|
|
}
|
2014-02-21 01:29:40 +08:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.property('can_delete_all_posts'),
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
deleteAllPosts: function() {
|
|
|
|
this.set('can_delete_all_posts', false);
|
2013-08-14 23:48:18 +08:00
|
|
|
var user = this;
|
|
|
|
var message = I18n.t('admin.user.delete_all_posts_confirm', {posts: user.get('post_count'), topics: user.get('topic_count')});
|
|
|
|
var buttons = [{
|
|
|
|
"label": I18n.t("composer.cancel"),
|
2014-02-14 00:42:35 +08:00
|
|
|
"class": "cancel-inline",
|
2013-08-14 23:48:18 +08:00
|
|
|
"link": true,
|
|
|
|
"callback": function() {
|
|
|
|
user.set('can_delete_all_posts', true);
|
|
|
|
}
|
|
|
|
}, {
|
2013-12-10 05:27:49 +08:00
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t("admin.user.delete_all_posts"),
|
2013-08-14 23:48:18 +08:00
|
|
|
"class": "btn btn-danger",
|
|
|
|
"callback": function() {
|
2013-12-31 02:29:52 +08:00
|
|
|
Discourse.ajax("/admin/users/" + (user.get('id')) + "/delete_all_posts", {type: 'PUT'}).then(function(){
|
2013-08-14 23:48:18 +08:00
|
|
|
user.set('post_count', 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
bootbox.dialog(message, buttons, {"classes": "delete-all-posts"});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// Revoke the user's admin access
|
|
|
|
revokeAdmin: function() {
|
|
|
|
this.set('admin', false);
|
|
|
|
this.set('can_grant_admin', true);
|
|
|
|
this.set('can_revoke_admin', false);
|
2013-05-08 01:30:12 +08:00
|
|
|
return Discourse.ajax("/admin/users/" + (this.get('id')) + "/revoke_admin", {type: 'PUT'});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
grantAdmin: function() {
|
|
|
|
this.set('admin', true);
|
|
|
|
this.set('can_grant_admin', false);
|
|
|
|
this.set('can_revoke_admin', true);
|
2013-05-08 01:30:12 +08:00
|
|
|
Discourse.ajax("/admin/users/" + (this.get('id')) + "/grant_admin", {type: 'PUT'});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// Revoke the user's moderation access
|
|
|
|
revokeModeration: function() {
|
|
|
|
this.set('moderator', false);
|
|
|
|
this.set('can_grant_moderation', true);
|
|
|
|
this.set('can_revoke_moderation', false);
|
2013-05-08 01:30:12 +08:00
|
|
|
return Discourse.ajax("/admin/users/" + (this.get('id')) + "/revoke_moderation", {type: 'PUT'});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
grantModeration: function() {
|
|
|
|
this.set('moderator', true);
|
|
|
|
this.set('can_grant_moderation', false);
|
|
|
|
this.set('can_revoke_moderation', true);
|
2013-05-08 01:30:12 +08:00
|
|
|
Discourse.ajax("/admin/users/" + (this.get('id')) + "/grant_moderation", {type: 'PUT'});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
refreshBrowsers: function() {
|
2013-05-08 01:30:12 +08:00
|
|
|
Discourse.ajax("/admin/users/" + (this.get('id')) + "/refresh_browsers", {type: 'POST'});
|
2013-02-23 04:41:12 +08:00
|
|
|
bootbox.alert("Message sent to all clients!");
|
|
|
|
},
|
|
|
|
|
|
|
|
approve: function() {
|
|
|
|
this.set('can_approve', false);
|
|
|
|
this.set('approved', true);
|
2013-05-28 23:08:32 +08:00
|
|
|
this.set('approved_by', Discourse.User.current());
|
2013-05-08 01:30:12 +08:00
|
|
|
Discourse.ajax("/admin/users/" + (this.get('id')) + "/approve", {type: 'PUT'});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
username_lower: (function() {
|
|
|
|
return this.get('username').toLowerCase();
|
|
|
|
}).property('username'),
|
|
|
|
|
2013-07-04 19:01:01 +08:00
|
|
|
setOriginalTrustLevel: function() {
|
|
|
|
this.set('originalTrustLevel', this.get('trust_level'));
|
|
|
|
},
|
|
|
|
|
2013-07-01 22:22:21 +08:00
|
|
|
trustLevels: function() {
|
2013-08-09 00:49:58 +08:00
|
|
|
return Discourse.Site.currentProp('trustLevels');
|
2013-07-13 04:24:15 +08:00
|
|
|
}.property(),
|
2013-07-01 22:22:21 +08:00
|
|
|
|
2013-07-13 04:18:32 +08:00
|
|
|
dirty: Discourse.computed.propertyNotEqual('originalTrustLevel', 'trustLevel.id'),
|
2013-07-01 22:22:21 +08:00
|
|
|
|
|
|
|
saveTrustLevel: function() {
|
|
|
|
Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
|
|
|
|
type: 'PUT',
|
|
|
|
data: {level: this.get('trustLevel.id')}
|
|
|
|
}).then(function () {
|
|
|
|
// succeeded
|
|
|
|
window.location.reload();
|
|
|
|
}, function(e) {
|
|
|
|
// failure
|
2013-07-09 07:32:16 +08:00
|
|
|
var error = I18n.t('admin.user.trust_level_change_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-07-01 22:22:21 +08:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreTrustLevel: function() {
|
2013-07-04 15:32:12 +08:00
|
|
|
this.set('trustLevel.id', this.get('originalTrustLevel'));
|
2013-07-01 22:22:21 +08:00
|
|
|
},
|
|
|
|
|
2013-11-08 02:53:32 +08:00
|
|
|
isSuspended: Em.computed.equal('suspended', true),
|
|
|
|
canSuspend: Em.computed.not('staff'),
|
2013-03-21 08:25:41 +08:00
|
|
|
|
2013-11-08 02:53:32 +08:00
|
|
|
suspendDuration: function() {
|
|
|
|
var suspended_at = moment(this.suspended_at);
|
|
|
|
var suspended_till = moment(this.suspended_till);
|
|
|
|
return suspended_at.format('L') + " - " + suspended_till.format('L');
|
|
|
|
}.property('suspended_till', 'suspended_at'),
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2013-11-08 02:53:32 +08:00
|
|
|
suspend: function(duration, reason) {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.id + "/suspend", {
|
2013-11-01 22:47:03 +08:00
|
|
|
type: 'PUT',
|
|
|
|
data: {duration: duration, reason: reason}
|
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2013-11-08 02:53:32 +08:00
|
|
|
unsuspend: function() {
|
|
|
|
Discourse.ajax("/admin/users/" + this.id + "/unsuspend", {
|
2013-04-04 04:06:55 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
// succeeded
|
|
|
|
window.location.reload();
|
|
|
|
}, function(e) {
|
|
|
|
// failed
|
2013-11-08 02:53:32 +08:00
|
|
|
var error = I18n.t('admin.user.unsuspend_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-04-04 04:06:55 +08:00
|
|
|
bootbox.alert(error);
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-06-06 11:02:52 +08:00
|
|
|
log_out: function(){
|
|
|
|
Discourse.ajax("/admin/users/" + this.id + "/log_out", {
|
|
|
|
type: 'POST',
|
|
|
|
data: { username_or_email: this.get('username') }
|
|
|
|
}).then(
|
|
|
|
function(){
|
|
|
|
bootbox.alert(I18n.t("admin.user.logged_out"));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
impersonate: function() {
|
2013-05-08 01:30:12 +08:00
|
|
|
Discourse.ajax("/admin/impersonate", {
|
2013-02-23 04:41:12 +08:00
|
|
|
type: 'POST',
|
2013-04-04 04:06:55 +08:00
|
|
|
data: { username_or_email: this.get('username') }
|
|
|
|
}).then(function() {
|
|
|
|
// succeeded
|
|
|
|
document.location = "/";
|
|
|
|
}, function(e) {
|
|
|
|
// failed
|
|
|
|
if (e.status === 404) {
|
2013-07-09 07:32:16 +08:00
|
|
|
bootbox.alert(I18n.t('admin.impersonate.not_found'));
|
2013-04-04 04:06:55 +08:00
|
|
|
} else {
|
2013-07-09 07:32:16 +08:00
|
|
|
bootbox.alert(I18n.t('admin.impersonate.invalid'));
|
2013-02-23 04:41:12 +08:00
|
|
|
}
|
|
|
|
});
|
2013-04-12 04:04:20 +08:00
|
|
|
},
|
|
|
|
|
2013-05-08 09:58:34 +08:00
|
|
|
activate: function() {
|
|
|
|
Discourse.ajax('/admin/users/' + this.id + '/activate', {type: 'PUT'}).then(function() {
|
|
|
|
// succeeded
|
|
|
|
window.location.reload();
|
|
|
|
}, function(e) {
|
|
|
|
// failed
|
2013-07-09 07:32:16 +08:00
|
|
|
var error = I18n.t('admin.user.activate_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-08 09:58:34 +08:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate: function() {
|
|
|
|
Discourse.ajax('/admin/users/' + this.id + '/deactivate', {type: 'PUT'}).then(function() {
|
|
|
|
// succeeded
|
|
|
|
window.location.reload();
|
|
|
|
}, function(e) {
|
|
|
|
// failed
|
2013-07-09 07:32:16 +08:00
|
|
|
var error = I18n.t('admin.user.deactivate_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-08 09:58:34 +08:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-05-31 23:41:40 +08:00
|
|
|
unblock: function() {
|
|
|
|
Discourse.ajax('/admin/users/' + this.id + '/unblock', {type: 'PUT'}).then(function() {
|
|
|
|
// succeeded
|
|
|
|
window.location.reload();
|
|
|
|
}, function(e) {
|
|
|
|
// failed
|
2013-07-09 07:32:16 +08:00
|
|
|
var error = I18n.t('admin.user.unblock_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-31 23:41:40 +08:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
block: function() {
|
|
|
|
Discourse.ajax('/admin/users/' + this.id + '/block', {type: 'PUT'}).then(function() {
|
|
|
|
// succeeded
|
|
|
|
window.location.reload();
|
|
|
|
}, function(e) {
|
|
|
|
// failed
|
2013-07-09 07:32:16 +08:00
|
|
|
var error = I18n.t('admin.user.block_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-31 23:41:40 +08:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-05-08 09:58:34 +08:00
|
|
|
sendActivationEmail: function() {
|
2013-07-06 00:26:46 +08:00
|
|
|
Discourse.ajax('/users/' + this.get('username') + '/send_activation_email', {type: 'POST'}).then(function() {
|
2013-05-08 09:58:34 +08:00
|
|
|
// succeeded
|
2013-07-09 07:32:16 +08:00
|
|
|
bootbox.alert( I18n.t('admin.user.activation_email_sent') );
|
2013-05-08 09:58:34 +08:00
|
|
|
}, function(e) {
|
|
|
|
// failed
|
2013-07-09 07:32:16 +08:00
|
|
|
var error = I18n.t('admin.user.send_activation_email_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-08 09:58:34 +08:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-04-12 04:04:20 +08:00
|
|
|
deleteForbidden: function() {
|
2013-08-09 00:34:42 +08:00
|
|
|
return (!this.get('can_be_deleted') || this.get('post_count') > 0);
|
2013-04-12 04:04:20 +08:00
|
|
|
}.property('post_count'),
|
|
|
|
|
2013-12-21 00:36:43 +08:00
|
|
|
deleteExplanation: function() {
|
2013-04-12 04:04:20 +08:00
|
|
|
if (this.get('deleteForbidden')) {
|
2013-12-21 00:36:43 +08:00
|
|
|
if (this.get('staff')) {
|
|
|
|
return I18n.t('admin.user.delete_forbidden_because_staff');
|
|
|
|
} else {
|
2014-02-21 01:29:40 +08:00
|
|
|
return I18n.t('admin.user.delete_forbidden', {count: Discourse.SiteSettings.delete_user_max_post_age});
|
2013-12-21 00:36:43 +08:00
|
|
|
}
|
2013-04-12 04:04:20 +08:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.property('deleteForbidden'),
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
var user = this;
|
2013-07-26 04:51:24 +08:00
|
|
|
|
|
|
|
var performDestroy = function(block) {
|
2013-07-26 06:04:51 +08:00
|
|
|
var formData = { context: window.location.pathname };
|
|
|
|
if (block) {
|
|
|
|
formData["block_email"] = true;
|
2013-08-14 23:05:53 +08:00
|
|
|
formData["block_urls"] = true;
|
2013-10-22 02:49:51 +08:00
|
|
|
formData["block_ip"] = true;
|
2013-07-26 06:04:51 +08:00
|
|
|
}
|
2013-07-26 04:51:24 +08:00
|
|
|
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
|
|
|
type: 'DELETE',
|
2013-07-26 06:04:51 +08:00
|
|
|
data: formData
|
2013-07-26 04:51:24 +08:00
|
|
|
}).then(function(data) {
|
|
|
|
if (data.deleted) {
|
|
|
|
bootbox.alert(I18n.t("admin.user.deleted"), function() {
|
|
|
|
document.location = "/admin/users/list/active";
|
|
|
|
});
|
|
|
|
} else {
|
2013-07-09 07:32:16 +08:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
2013-07-26 04:51:24 +08:00
|
|
|
if (data.user) {
|
|
|
|
user.mergeAttributes(data.user);
|
|
|
|
}
|
|
|
|
}
|
2013-12-31 02:29:52 +08:00
|
|
|
}, function() {
|
2013-07-26 04:51:24 +08:00
|
|
|
Discourse.AdminUser.find( user.get('username') ).then(function(u){ user.mergeAttributes(u); });
|
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var message = I18n.t("admin.user.delete_confirm");
|
|
|
|
|
|
|
|
var buttons = [{
|
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "cancel",
|
|
|
|
"link": true
|
|
|
|
}, {
|
2013-12-10 05:27:49 +08:00
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t('admin.user.delete_dont_block'),
|
2013-07-26 04:51:24 +08:00
|
|
|
"class": "btn",
|
|
|
|
"callback": function(){
|
|
|
|
performDestroy(false);
|
2013-04-12 04:04:20 +08:00
|
|
|
}
|
2013-07-26 04:51:24 +08:00
|
|
|
}, {
|
2013-12-10 05:27:49 +08:00
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t('admin.user.delete_and_block'),
|
2014-05-04 15:38:29 +08:00
|
|
|
"class": "btn btn-danger",
|
2013-07-26 04:51:24 +08:00
|
|
|
"callback": function(){
|
|
|
|
performDestroy(true);
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
bootbox.dialog(message, buttons, {"classes": "delete-user-modal"});
|
2013-06-14 01:46:50 +08:00
|
|
|
},
|
|
|
|
|
2013-07-27 03:40:08 +08:00
|
|
|
deleteAsSpammer: function(successCallback) {
|
|
|
|
var user = this;
|
2013-10-22 02:49:51 +08:00
|
|
|
var message = I18n.t('flagging.delete_confirm', {posts: user.get('post_count'), topics: user.get('topic_count'), email: user.get('email'), ip_address: user.get('ip_address')});
|
2013-07-27 03:40:08 +08:00
|
|
|
var buttons = [{
|
|
|
|
"label": I18n.t("composer.cancel"),
|
2014-02-14 00:42:35 +08:00
|
|
|
"class": "cancel-inline",
|
2013-07-27 03:40:08 +08:00
|
|
|
"link": true
|
|
|
|
}, {
|
2013-12-10 05:27:49 +08:00
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t("flagging.yes_delete_spammer"),
|
2013-07-27 03:40:08 +08:00
|
|
|
"class": "btn btn-danger",
|
|
|
|
"callback": function() {
|
|
|
|
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
|
|
|
type: 'DELETE',
|
2013-10-22 02:49:51 +08:00
|
|
|
data: {delete_posts: true, block_email: true, block_urls: true, block_ip: true, context: window.location.pathname}
|
2013-07-27 03:40:08 +08:00
|
|
|
}).then(function(data) {
|
|
|
|
if (data.deleted) {
|
|
|
|
bootbox.alert(I18n.t("admin.user.deleted"), function() {
|
|
|
|
if (successCallback) successCallback();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
|
|
}
|
2013-12-31 02:29:52 +08:00
|
|
|
}, function() {
|
2013-07-27 03:40:08 +08:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
bootbox.dialog(message, buttons, {"classes": "flagging-delete-spammer"});
|
|
|
|
},
|
|
|
|
|
2013-06-14 01:46:50 +08:00
|
|
|
loadDetails: function() {
|
|
|
|
var model = this;
|
2013-07-17 01:24:59 +08:00
|
|
|
if (model.get('loadedDetails')) { return Ember.RSVP.resolve(model); }
|
2013-06-14 01:46:50 +08:00
|
|
|
|
2013-07-17 01:24:59 +08:00
|
|
|
return Discourse.AdminUser.find(model.get('username_lower')).then(function (result) {
|
2013-06-14 01:46:50 +08:00
|
|
|
model.setProperties(result);
|
|
|
|
model.set('loadedDetails', true);
|
|
|
|
});
|
2014-01-24 05:40:10 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
leaderRequirements: function() {
|
|
|
|
if (this.get('leader_requirements')) {
|
|
|
|
return Discourse.LeaderRequirements.create(this.get('leader_requirements'));
|
|
|
|
}
|
2014-03-24 22:19:15 +08:00
|
|
|
}.property('leader_requirements'),
|
|
|
|
|
|
|
|
suspendedBy: function() {
|
|
|
|
if (this.get('suspended_by')) {
|
2014-03-24 23:43:06 +08:00
|
|
|
return Discourse.AdminUser.create(this.get('suspended_by'));
|
2014-03-24 22:19:15 +08:00
|
|
|
}
|
2014-03-24 23:43:06 +08:00
|
|
|
}.property('suspended_by'),
|
|
|
|
|
|
|
|
approvedBy: function() {
|
|
|
|
if (this.get('approved_by')) {
|
|
|
|
return Discourse.AdminUser.create(this.get('approved_by'));
|
|
|
|
}
|
|
|
|
}.property('approved_by')
|
2013-02-23 04:41:12 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-03-06 03:52:35 +08:00
|
|
|
Discourse.AdminUser.reopenClass({
|
2013-02-23 04:41:12 +08:00
|
|
|
|
|
|
|
bulkApprove: function(users) {
|
2013-06-27 01:24:30 +08:00
|
|
|
_.each(users, function(user) {
|
2013-02-23 04:41:12 +08:00
|
|
|
user.set('approved', true);
|
|
|
|
user.set('can_approve', false);
|
|
|
|
return user.set('selected', false);
|
|
|
|
});
|
2013-06-06 12:18:22 +08:00
|
|
|
|
2013-07-09 07:32:16 +08:00
|
|
|
bootbox.alert(I18n.t("admin.user.approve_bulk_success"));
|
2013-06-06 12:18:22 +08:00
|
|
|
|
2013-05-08 01:30:12 +08:00
|
|
|
return Discourse.ajax("/admin/users/approve-bulk", {
|
2013-02-23 04:41:12 +08:00
|
|
|
type: 'PUT',
|
|
|
|
data: {
|
|
|
|
users: users.map(function(u) {
|
|
|
|
return u.id;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-08-16 23:42:24 +08:00
|
|
|
bulkReject: function(users) {
|
|
|
|
_.each(users, function(user){
|
|
|
|
user.set('can_approve', false);
|
|
|
|
user.set('selected', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
return Discourse.ajax("/admin/users/reject-bulk", {
|
|
|
|
type: 'DELETE',
|
|
|
|
data: {
|
|
|
|
users: users.map(function(u) { return u.id; }),
|
|
|
|
context: window.location.pathname
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
find: function(username) {
|
2014-02-11 01:43:17 +08:00
|
|
|
return Discourse.ajax("/admin/users/" + username + ".json").then(function (result) {
|
2013-06-14 01:46:50 +08:00
|
|
|
result.loadedDetails = true;
|
2013-03-15 02:45:29 +08:00
|
|
|
return Discourse.AdminUser.create(result);
|
2013-04-12 04:04:20 +08:00
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2013-05-07 23:15:28 +08:00
|
|
|
findAll: function(query, filter) {
|
2013-05-08 01:30:12 +08:00
|
|
|
return Discourse.ajax("/admin/users/list/" + query + ".json", {
|
2014-07-08 04:18:18 +08:00
|
|
|
data: filter
|
2013-04-04 04:06:55 +08:00
|
|
|
}).then(function(users) {
|
2013-05-07 23:15:28 +08:00
|
|
|
return users.map(function(u) {
|
|
|
|
return Discourse.AdminUser.create(u);
|
2013-04-04 04:06:55 +08:00
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|