2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
Our data model for dealing with users from the admin section.
|
|
|
|
|
2013-03-05 14:52:35 -05:00
|
|
|
@class AdminUser
|
2013-02-22 15:41:12 -05:00
|
|
|
@extends Discourse.Model
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-05 14:52:35 -05:00
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
Discourse.AdminUser = Discourse.Model.extend({
|
2013-03-05 14:52:35 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
deleteAllPosts: function() {
|
|
|
|
this.set('can_delete_all_posts', false);
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'});
|
2013-02-22 15:41:12 -05: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-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/admin/users/" + (this.get('id')) + "/revoke_admin", {type: 'PUT'});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
grantAdmin: function() {
|
|
|
|
this.set('admin', true);
|
|
|
|
this.set('can_grant_admin', false);
|
|
|
|
this.set('can_revoke_admin', true);
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax("/admin/users/" + (this.get('id')) + "/grant_admin", {type: 'PUT'});
|
2013-02-22 15:41:12 -05: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-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/admin/users/" + (this.get('id')) + "/revoke_moderation", {type: 'PUT'});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
grantModeration: function() {
|
|
|
|
this.set('moderator', true);
|
|
|
|
this.set('can_grant_moderation', false);
|
|
|
|
this.set('can_revoke_moderation', true);
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax("/admin/users/" + (this.get('id')) + "/grant_moderation", {type: 'PUT'});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
refreshBrowsers: function() {
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax("/admin/users/" + (this.get('id')) + "/refresh_browsers", {type: 'POST'});
|
2013-02-22 15:41:12 -05:00
|
|
|
bootbox.alert("Message sent to all clients!");
|
|
|
|
},
|
|
|
|
|
|
|
|
approve: function() {
|
|
|
|
this.set('can_approve', false);
|
|
|
|
this.set('approved', true);
|
|
|
|
this.set('approved_by', Discourse.get('currentUser'));
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax("/admin/users/" + (this.get('id')) + "/approve", {type: 'PUT'});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
username_lower: (function() {
|
|
|
|
return this.get('username').toLowerCase();
|
|
|
|
}).property('username'),
|
|
|
|
|
|
|
|
trustLevel: (function() {
|
|
|
|
return Discourse.get('site.trust_levels').findProperty('id', this.get('trust_level'));
|
|
|
|
}).property('trust_level'),
|
|
|
|
|
|
|
|
canBan: (function() {
|
|
|
|
return !this.admin && !this.moderator;
|
|
|
|
}).property('admin', 'moderator'),
|
|
|
|
|
|
|
|
banDuration: (function() {
|
|
|
|
var banned_at, banned_till;
|
|
|
|
banned_at = Date.create(this.banned_at);
|
|
|
|
banned_till = Date.create(this.banned_till);
|
|
|
|
return "" + (banned_at.short()) + " - " + (banned_till.short());
|
|
|
|
}).property('banned_till', 'banned_at'),
|
|
|
|
|
|
|
|
ban: function() {
|
|
|
|
var duration,
|
|
|
|
_this = this;
|
|
|
|
if (duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10)) {
|
|
|
|
if (duration > 0) {
|
2013-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/admin/users/" + this.id + "/ban", {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'PUT',
|
|
|
|
data: {duration: duration},
|
|
|
|
success: function() {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
var error;
|
|
|
|
error = Em.String.i18n('admin.user.ban_failed', {
|
|
|
|
error: "http: " + e.status + " - " + e.body
|
|
|
|
});
|
|
|
|
bootbox.alert(error);
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
}
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
unban: function() {
|
|
|
|
var _this = this;
|
2013-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/admin/users/" + this.id + "/unban", {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'PUT',
|
|
|
|
success: function() {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
var error;
|
|
|
|
error = Em.String.i18n('admin.user.unban_failed', {
|
|
|
|
error: "http: " + e.status + " - " + e.body
|
|
|
|
});
|
|
|
|
bootbox.alert(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
impersonate: function() {
|
|
|
|
var _this = this;
|
2013-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/admin/impersonate", {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
username_or_email: this.get('username')
|
|
|
|
},
|
|
|
|
success: function() {
|
|
|
|
document.location = "/";
|
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
_this.set('loading', false);
|
|
|
|
if (e.status === 404) {
|
|
|
|
return bootbox.alert(Em.String.i18n('admin.impersonate.not_found'));
|
|
|
|
} else {
|
|
|
|
return bootbox.alert(Em.String.i18n('admin.impersonate.invalid'));
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-03-05 14:52:35 -05:00
|
|
|
Discourse.AdminUser.reopenClass({
|
2013-02-22 15:41:12 -05:00
|
|
|
|
|
|
|
bulkApprove: function(users) {
|
|
|
|
users.each(function(user) {
|
|
|
|
user.set('approved', true);
|
|
|
|
user.set('can_approve', false);
|
|
|
|
return user.set('selected', false);
|
|
|
|
});
|
2013-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/admin/users/approve-bulk", {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'PUT',
|
|
|
|
data: {
|
|
|
|
users: users.map(function(u) {
|
|
|
|
return u.id;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
find: function(username) {
|
2013-03-14 14:45:29 -04:00
|
|
|
return $.ajax({url: "/admin/users/" + username}).then(function (result) {
|
|
|
|
return Discourse.AdminUser.create(result);
|
|
|
|
})
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
findAll: function(query, filter) {
|
|
|
|
var result;
|
|
|
|
result = Em.A();
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax({
|
2013-02-22 15:41:12 -05:00
|
|
|
url: "/admin/users/list/" + query + ".json",
|
|
|
|
data: {
|
|
|
|
filter: filter
|
|
|
|
},
|
|
|
|
success: function(users) {
|
|
|
|
return users.each(function(u) {
|
|
|
|
return result.pushObject(Discourse.AdminUser.create(u));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
});
|