2015-08-07 15:08:27 -04:00
|
|
|
import { propertyNotEqual } from 'discourse/lib/computed';
|
2015-05-19 10:56:32 -04:00
|
|
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const AdminUser = Discourse.User.extend({
|
|
|
|
|
2015-04-15 20:44:55 -04:00
|
|
|
customGroups: Em.computed.filter("groups", (g) => !g.automatic && Discourse.Group.create(g)),
|
2015-03-17 17:59:05 -04:00
|
|
|
automaticGroups: Em.computed.filter("groups", (g) => g.automatic && Discourse.Group.create(g)),
|
|
|
|
|
|
|
|
generateApiKey() {
|
|
|
|
const self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/generate_api_key", {
|
|
|
|
type: 'POST'
|
|
|
|
}).then(function (result) {
|
|
|
|
const apiKey = Discourse.ApiKey.create(result.api_key);
|
2013-10-22 15:53:08 -04:00
|
|
|
self.set('api_key', apiKey);
|
|
|
|
return apiKey;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
groupAdded(added) {
|
2014-07-15 10:11:39 -04:00
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups", {
|
|
|
|
type: 'POST',
|
2015-03-17 17:59:05 -04:00
|
|
|
data: { group_id: added.id }
|
|
|
|
}).then(() => this.get('groups').pushObject(added));
|
2014-07-15 10:11:39 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
groupRemoved(groupId) {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + groupId, {
|
2014-07-15 10:11:39 -04:00
|
|
|
type: 'DELETE'
|
2015-03-17 17:59:05 -04:00
|
|
|
}).then(() => this.set('groups.[]', this.get('groups').rejectBy("id", groupId)));
|
2014-07-15 10:11:39 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
revokeApiKey() {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/revoke_api_key", {
|
|
|
|
type: 'DELETE'
|
|
|
|
}).then(() => this.set('api_key', null));
|
2013-10-22 15:53:08 -04:00
|
|
|
},
|
|
|
|
|
2014-02-20 12:29:40 -05:00
|
|
|
deleteAllPostsExplanation: function() {
|
|
|
|
if (!this.get('can_delete_all_posts')) {
|
2015-03-06 14:11:48 -05:00
|
|
|
if (this.get('deleteForbidden') && this.get('staff')) {
|
|
|
|
return I18n.t('admin.user.delete_posts_forbidden_because_staff');
|
|
|
|
}
|
2014-04-14 15:10:32 -04: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-20 12:29:40 -05:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2015-03-06 14:11:48 -05:00
|
|
|
}.property('can_delete_all_posts', 'deleteForbidden'),
|
2014-02-20 12:29:40 -05:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
deleteAllPosts() {
|
|
|
|
const user = this,
|
|
|
|
message = I18n.t('admin.user.delete_all_posts_confirm', { posts: user.get('post_count'), topics: user.get('topic_count') }),
|
|
|
|
buttons = [{
|
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "cancel-inline",
|
|
|
|
"link": true
|
|
|
|
}, {
|
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t("admin.user.delete_all_posts"),
|
|
|
|
"class": "btn btn-danger",
|
|
|
|
"callback": function() {
|
|
|
|
Discourse.ajax("/admin/users/" + user.get('id') + "/delete_all_posts", {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(() => user.set('post_count', 0));
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
bootbox.dialog(message, buttons, { "classes": "delete-all-posts" });
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
revokeAdmin() {
|
|
|
|
const self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/revoke_admin", {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
admin: false,
|
|
|
|
can_grant_admin: true,
|
|
|
|
can_revoke_admin: false
|
|
|
|
});
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
grantAdmin() {
|
|
|
|
const self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/grant_admin", {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
admin: true,
|
|
|
|
can_grant_admin: false,
|
|
|
|
can_revoke_admin: true
|
2015-02-03 17:41:54 -05:00
|
|
|
});
|
2015-05-19 10:56:32 -04:00
|
|
|
}).catch(popupAjaxError);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
revokeModeration() {
|
|
|
|
const self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/revoke_moderation", {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
moderator: false,
|
|
|
|
can_grant_moderation: true,
|
|
|
|
can_revoke_moderation: false
|
|
|
|
});
|
2015-05-19 10:56:32 -04:00
|
|
|
}).catch(popupAjaxError);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
grantModeration() {
|
|
|
|
const self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/grant_moderation", {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
moderator: true,
|
|
|
|
can_grant_moderation: false,
|
|
|
|
can_revoke_moderation: true
|
|
|
|
});
|
2015-05-19 10:56:32 -04:00
|
|
|
}).catch(popupAjaxError);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
refreshBrowsers() {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/refresh_browsers", {
|
|
|
|
type: 'POST'
|
|
|
|
}).finally(() => bootbox.alert(I18n.t("admin.user.refresh_browsers_message")));
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
approve() {
|
|
|
|
const self = this;
|
|
|
|
return Discourse.ajax("/admin/users/" + this.get('id') + "/approve", {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
can_approve: false,
|
|
|
|
approved: true,
|
|
|
|
approved_by: Discourse.User.current()
|
|
|
|
});
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
setOriginalTrustLevel() {
|
2013-07-04 07:01:01 -04:00
|
|
|
this.set('originalTrustLevel', this.get('trust_level'));
|
|
|
|
},
|
|
|
|
|
2015-08-07 15:08:27 -04:00
|
|
|
dirty: propertyNotEqual('originalTrustLevel', 'trustLevel.id'),
|
2013-07-01 10:22:21 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
saveTrustLevel() {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
|
2013-07-01 10:22:21 -04:00
|
|
|
type: 'PUT',
|
2015-03-17 17:59:05 -04:00
|
|
|
data: { level: this.get('trustLevel.id') }
|
|
|
|
}).then(function() {
|
2013-07-01 10:22:21 -04:00
|
|
|
window.location.reload();
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
|
|
|
let error;
|
2014-07-29 15:54:20 -04:00
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
error = e.responseJSON.errors[0];
|
|
|
|
}
|
|
|
|
error = error || I18n.t('admin.user.trust_level_change_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-07-01 10:22:21 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
restoreTrustLevel() {
|
2013-07-04 03:32:12 -04:00
|
|
|
this.set('trustLevel.id', this.get('originalTrustLevel'));
|
2013-07-01 10:22:21 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
lockTrustLevel(locked) {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.id + "/trust_level_lock", {
|
2014-09-13 16:55:26 -04:00
|
|
|
type: 'PUT',
|
|
|
|
data: { locked: !!locked }
|
|
|
|
}).then(function() {
|
|
|
|
window.location.reload();
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
|
|
|
let error;
|
2014-09-13 16:55:26 -04:00
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
error = e.responseJSON.errors[0];
|
|
|
|
}
|
|
|
|
error = error || I18n.t('admin.user.trust_level_change_failed', { error: "http: " + e.status + " - " + e.body });
|
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
canLockTrustLevel: function() {
|
2014-09-29 23:12:33 -04:00
|
|
|
return this.get('trust_level') < 4;
|
|
|
|
}.property('trust_level'),
|
|
|
|
|
2013-11-07 13:53:32 -05:00
|
|
|
isSuspended: Em.computed.equal('suspended', true),
|
|
|
|
canSuspend: Em.computed.not('staff'),
|
2013-03-20 20:25:41 -04:00
|
|
|
|
2013-11-07 13:53:32 -05:00
|
|
|
suspendDuration: function() {
|
2015-03-17 17:59:05 -04:00
|
|
|
const suspended_at = moment(this.suspended_at),
|
|
|
|
suspended_till = moment(this.suspended_till);
|
2013-11-07 13:53:32 -05:00
|
|
|
return suspended_at.format('L') + " - " + suspended_till.format('L');
|
|
|
|
}.property('suspended_till', 'suspended_at'),
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
suspend(duration, reason) {
|
2013-11-07 13:53:32 -05:00
|
|
|
return Discourse.ajax("/admin/users/" + this.id + "/suspend", {
|
2013-11-01 10:47:03 -04:00
|
|
|
type: 'PUT',
|
2015-03-17 17:59:05 -04:00
|
|
|
data: { duration: duration, reason: reason }
|
2013-11-01 10:47:03 -04:00
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
unsuspend() {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.id + "/unsuspend", {
|
2013-04-03 16:06:55 -04:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
window.location.reload();
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
2013-11-07 13:53:32 -05:00
|
|
|
var error = I18n.t('admin.user.unsuspend_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-04-03 16:06:55 -04:00
|
|
|
bootbox.alert(error);
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
log_out() {
|
|
|
|
return Discourse.ajax("/admin/users/" + this.id + "/log_out", {
|
2014-06-05 23:02:52 -04:00
|
|
|
type: 'POST',
|
|
|
|
data: { username_or_email: this.get('username') }
|
2015-03-17 17:59:05 -04:00
|
|
|
}).then(function() {
|
|
|
|
bootbox.alert(I18n.t("admin.user.logged_out"));
|
|
|
|
});
|
2014-06-05 23:02:52 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
impersonate() {
|
|
|
|
return Discourse.ajax("/admin/impersonate", {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'POST',
|
2013-04-03 16:06:55 -04:00
|
|
|
data: { username_or_email: this.get('username') }
|
|
|
|
}).then(function() {
|
2015-10-12 15:14:39 -04:00
|
|
|
document.location = Discourse.getURL(Discourse.BaseUri);
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
2013-04-03 16:06:55 -04:00
|
|
|
if (e.status === 404) {
|
2013-07-08 19:32:16 -04:00
|
|
|
bootbox.alert(I18n.t('admin.impersonate.not_found'));
|
2013-04-03 16:06:55 -04:00
|
|
|
} else {
|
2013-07-08 19:32:16 -04:00
|
|
|
bootbox.alert(I18n.t('admin.impersonate.invalid'));
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
});
|
2013-04-11 16:04:20 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
activate() {
|
|
|
|
return Discourse.ajax('/admin/users/' + this.id + '/activate', {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
2013-05-07 21:58:34 -04:00
|
|
|
window.location.reload();
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
2013-07-08 19:32:16 -04:00
|
|
|
var error = I18n.t('admin.user.activate_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-07 21:58:34 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
deactivate() {
|
|
|
|
return Discourse.ajax('/admin/users/' + this.id + '/deactivate', {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
2013-05-07 21:58:34 -04:00
|
|
|
window.location.reload();
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
2013-07-08 19:32:16 -04:00
|
|
|
var error = I18n.t('admin.user.deactivate_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-07 21:58:34 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
unblock() {
|
|
|
|
return Discourse.ajax('/admin/users/' + this.id + '/unblock', {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
2013-05-31 11:41:40 -04:00
|
|
|
window.location.reload();
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
2013-07-08 19:32:16 -04:00
|
|
|
var error = I18n.t('admin.user.unblock_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-31 11:41:40 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
block() {
|
|
|
|
return Discourse.ajax('/admin/users/' + this.id + '/block', {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
2013-05-31 11:41:40 -04:00
|
|
|
window.location.reload();
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
2013-07-08 19:32:16 -04:00
|
|
|
var error = I18n.t('admin.user.block_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-31 11:41:40 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
sendActivationEmail() {
|
|
|
|
return Discourse.ajax('/users/action/send_activation_email', {
|
|
|
|
type: 'POST',
|
|
|
|
data: { username: this.get('username') }
|
|
|
|
}).then(function() {
|
2013-07-08 19:32:16 -04:00
|
|
|
bootbox.alert( I18n.t('admin.user.activation_email_sent') );
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function(e) {
|
2013-07-08 19:32:16 -04:00
|
|
|
var error = I18n.t('admin.user.send_activation_email_failed', { error: "http: " + e.status + " - " + e.body });
|
2013-05-07 21:58:34 -04:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-06 16:44:54 -05:00
|
|
|
anonymizeForbidden: Em.computed.not("can_be_anonymized"),
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
anonymize() {
|
|
|
|
const user = this,
|
|
|
|
message = I18n.t("admin.user.anonymize_confirm");
|
2015-03-06 16:44:54 -05:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const performAnonymize = function() {
|
|
|
|
return Discourse.ajax("/admin/users/" + user.get('id') + '/anonymize.json', {
|
|
|
|
type: 'PUT'
|
|
|
|
}).then(function(data) {
|
2015-03-06 16:44:54 -05:00
|
|
|
if (data.success) {
|
|
|
|
if (data.username) {
|
2015-05-21 15:02:52 -04:00
|
|
|
document.location = Discourse.getURL("/admin/users/" + data.username);
|
2015-03-06 16:44:54 -05:00
|
|
|
} else {
|
2015-05-21 15:02:52 -04:00
|
|
|
document.location = Discourse.getURL("/admin/users/list/active");
|
2015-03-06 16:44:54 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("admin.user.anonymize_failed"));
|
|
|
|
if (data.user) {
|
|
|
|
user.setProperties(data.user);
|
|
|
|
}
|
|
|
|
}
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function() {
|
2015-03-06 16:44:54 -05:00
|
|
|
bootbox.alert(I18n.t("admin.user.anonymize_failed"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const buttons = [{
|
2015-03-06 16:44:54 -05:00
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "cancel",
|
|
|
|
"link": true
|
|
|
|
}, {
|
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i>' + I18n.t('admin.user.anonymize_yes'),
|
|
|
|
"class": "btn btn-danger",
|
2015-03-17 17:59:05 -04:00
|
|
|
"callback": function() { performAnonymize(); }
|
2015-03-06 16:44:54 -05:00
|
|
|
}];
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
bootbox.dialog(message, buttons, { "classes": "delete-user-modal" });
|
2015-03-06 16:44:54 -05:00
|
|
|
},
|
|
|
|
|
2014-12-03 07:00:02 -05:00
|
|
|
deleteForbidden: Em.computed.not("canBeDeleted"),
|
2013-04-11 16:04:20 -04:00
|
|
|
|
2013-12-20 11:36:43 -05:00
|
|
|
deleteExplanation: function() {
|
2013-04-11 16:04:20 -04:00
|
|
|
if (this.get('deleteForbidden')) {
|
2013-12-20 11:36:43 -05:00
|
|
|
if (this.get('staff')) {
|
|
|
|
return I18n.t('admin.user.delete_forbidden_because_staff');
|
|
|
|
} else {
|
2014-02-20 12:29:40 -05:00
|
|
|
return I18n.t('admin.user.delete_forbidden', {count: Discourse.SiteSettings.delete_user_max_post_age});
|
2013-12-20 11:36:43 -05:00
|
|
|
}
|
2013-04-11 16:04:20 -04:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.property('deleteForbidden'),
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
destroy(opts) {
|
|
|
|
const user = this,
|
|
|
|
message = I18n.t("admin.user.delete_confirm"),
|
|
|
|
location = document.location.pathname;
|
2013-07-25 16:51:24 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const performDestroy = function(block) {
|
|
|
|
let formData = { context: location };
|
2013-07-25 18:04:51 -04:00
|
|
|
if (block) {
|
|
|
|
formData["block_email"] = true;
|
2013-08-14 11:05:53 -04:00
|
|
|
formData["block_urls"] = true;
|
2013-10-21 14:49:51 -04:00
|
|
|
formData["block_ip"] = true;
|
2013-07-25 18:04:51 -04:00
|
|
|
}
|
2014-11-14 15:23:09 -05:00
|
|
|
if (opts && opts.deletePosts) {
|
|
|
|
formData["delete_posts"] = true;
|
|
|
|
}
|
2015-03-17 17:59:05 -04:00
|
|
|
return Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
2013-07-25 16:51:24 -04:00
|
|
|
type: 'DELETE',
|
2013-07-25 18:04:51 -04:00
|
|
|
data: formData
|
2013-07-25 16:51:24 -04:00
|
|
|
}).then(function(data) {
|
|
|
|
if (data.deleted) {
|
2014-12-25 12:25:07 -05:00
|
|
|
if (/^\/admin\/users\/list\//.test(location)) {
|
|
|
|
document.location = location;
|
|
|
|
} else {
|
2015-05-21 15:02:52 -04:00
|
|
|
document.location = Discourse.getURL("/admin/users/list/active");
|
2014-12-25 12:25:07 -05:00
|
|
|
}
|
2013-07-25 16:51:24 -04:00
|
|
|
} else {
|
2013-07-08 19:32:16 -04:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
2013-07-25 16:51:24 -04:00
|
|
|
if (data.user) {
|
2014-07-21 13:39:23 -04:00
|
|
|
user.setProperties(data.user);
|
2013-07-25 16:51:24 -04:00
|
|
|
}
|
|
|
|
}
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function() {
|
2014-07-21 13:39:23 -04:00
|
|
|
Discourse.AdminUser.find( user.get('username') ).then(function(u){ user.setProperties(u); });
|
2013-07-25 16:51:24 -04:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const buttons = [{
|
2013-07-25 16:51:24 -04:00
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "btn",
|
2015-09-30 19:06:55 -04:00
|
|
|
"link": true
|
2013-07-25 16:51:24 -04:00
|
|
|
}, {
|
2014-08-12 06:14:50 -04:00
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i>' + I18n.t('admin.user.delete_and_block'),
|
2014-05-04 03:38:29 -04:00
|
|
|
"class": "btn btn-danger",
|
2015-03-17 17:59:05 -04:00
|
|
|
"callback": function(){ performDestroy(true); }
|
2015-09-30 19:06:55 -04:00
|
|
|
}, {
|
|
|
|
"label": I18n.t('admin.user.delete_dont_block'),
|
|
|
|
"class": "btn btn-primary",
|
|
|
|
"callback": function(){ performDestroy(false); }
|
2013-07-25 16:51:24 -04:00
|
|
|
}];
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
bootbox.dialog(message, buttons, { "classes": "delete-user-modal" });
|
2013-06-13 13:46:50 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
deleteAsSpammer(successCallback) {
|
|
|
|
const user = this;
|
2014-10-06 15:55:52 -04:00
|
|
|
|
|
|
|
user.checkEmail().then(function() {
|
2015-03-17 17:59:05 -04:00
|
|
|
const data = {
|
2014-10-06 15:55:52 -04:00
|
|
|
posts: user.get('post_count'),
|
|
|
|
topics: user.get('topic_count'),
|
|
|
|
email: user.get('email') || I18n.t("flagging.hidden_email_address"),
|
|
|
|
ip_address: user.get('ip_address') || I18n.t("flagging.ip_address_missing")
|
2015-03-17 17:59:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const message = I18n.t('flagging.delete_confirm', data),
|
|
|
|
buttons = [{
|
2014-10-06 15:55:52 -04:00
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "cancel-inline",
|
|
|
|
"link": true
|
|
|
|
}, {
|
|
|
|
"label": '<i class="fa fa-exclamation-triangle"></i> ' + I18n.t("flagging.yes_delete_spammer"),
|
|
|
|
"class": "btn btn-danger",
|
|
|
|
"callback": function() {
|
2015-03-17 17:59:05 -04:00
|
|
|
return Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
2014-10-06 15:55:52 -04:00
|
|
|
type: 'DELETE',
|
|
|
|
data: {
|
|
|
|
delete_posts: true,
|
|
|
|
block_email: true,
|
|
|
|
block_urls: true,
|
|
|
|
block_ip: true,
|
2014-10-20 10:59:06 -04:00
|
|
|
delete_as_spammer: true,
|
2014-10-06 15:55:52 -04:00
|
|
|
context: window.location.pathname
|
|
|
|
}
|
|
|
|
}).then(function(result) {
|
|
|
|
if (result.deleted) {
|
|
|
|
if (successCallback) successCallback();
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
|
|
}
|
2015-03-17 17:59:05 -04:00
|
|
|
}).catch(function() {
|
2013-07-26 15:40:08 -04:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
2014-10-06 15:55:52 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}];
|
2015-03-17 17:59:05 -04:00
|
|
|
|
2014-10-06 15:55:52 -04:00
|
|
|
bootbox.dialog(message, buttons, {"classes": "flagging-delete-spammer"});
|
|
|
|
});
|
2013-07-26 15:40:08 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
loadDetails() {
|
|
|
|
const user = this;
|
|
|
|
|
|
|
|
if (user.get('loadedDetails')) { return Ember.RSVP.resolve(user); }
|
2013-06-13 13:46:50 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
return Discourse.AdminUser.find(user.get('username_lower')).then(function (result) {
|
|
|
|
user.setProperties(result);
|
|
|
|
user.set('loadedDetails', true);
|
2013-06-13 13:46:50 -04:00
|
|
|
});
|
2014-01-23 16:40:10 -05:00
|
|
|
},
|
|
|
|
|
2014-09-24 20:19:26 -04:00
|
|
|
tl3Requirements: function() {
|
|
|
|
if (this.get('tl3_requirements')) {
|
|
|
|
return Discourse.TL3Requirements.create(this.get('tl3_requirements'));
|
2014-01-23 16:40:10 -05:00
|
|
|
}
|
2014-09-24 20:19:26 -04:00
|
|
|
}.property('tl3_requirements'),
|
2014-03-24 10:19:15 -04:00
|
|
|
|
|
|
|
suspendedBy: function() {
|
|
|
|
if (this.get('suspended_by')) {
|
2014-03-24 11:43:06 -04:00
|
|
|
return Discourse.AdminUser.create(this.get('suspended_by'));
|
2014-03-24 10:19:15 -04:00
|
|
|
}
|
2014-03-24 11:43:06 -04:00
|
|
|
}.property('suspended_by'),
|
|
|
|
|
|
|
|
approvedBy: function() {
|
|
|
|
if (this.get('approved_by')) {
|
|
|
|
return Discourse.AdminUser.create(this.get('approved_by'));
|
|
|
|
}
|
|
|
|
}.property('approved_by')
|
2013-02-22 15:41:12 -05:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
AdminUser.reopenClass({
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
bulkApprove(users) {
|
2013-06-26 13:24:30 -04:00
|
|
|
_.each(users, function(user) {
|
2015-03-17 17:59:05 -04:00
|
|
|
user.setProperties({
|
|
|
|
approved: true,
|
|
|
|
can_approve: false,
|
|
|
|
selected: false
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
2013-06-06 00:18:22 -04:00
|
|
|
|
2013-05-07 13:30:12 -04:00
|
|
|
return Discourse.ajax("/admin/users/approve-bulk", {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'PUT',
|
2015-03-17 17:59:05 -04:00
|
|
|
data: { users: users.map((u) => u.id) }
|
|
|
|
}).finally(() => bootbox.alert(I18n.t("admin.user.approve_bulk_success")));
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
bulkReject(users) {
|
|
|
|
_.each(users, function(user) {
|
2013-08-16 11:42:24 -04:00
|
|
|
user.set('can_approve', false);
|
|
|
|
user.set('selected', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
return Discourse.ajax("/admin/users/reject-bulk", {
|
|
|
|
type: 'DELETE',
|
|
|
|
data: {
|
2015-03-17 17:59:05 -04:00
|
|
|
users: users.map((u) => u.id),
|
2013-08-16 11:42:24 -04:00
|
|
|
context: window.location.pathname
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
find(username) {
|
2014-02-10 12:43:17 -05:00
|
|
|
return Discourse.ajax("/admin/users/" + username + ".json").then(function (result) {
|
2013-06-13 13:46:50 -04:00
|
|
|
result.loadedDetails = true;
|
2013-03-14 14:45:29 -04:00
|
|
|
return Discourse.AdminUser.create(result);
|
2013-04-11 16:04:20 -04:00
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
findAll(query, filter) {
|
2013-05-07 13:30:12 -04:00
|
|
|
return Discourse.ajax("/admin/users/list/" + query + ".json", {
|
2014-07-07 16:18:18 -04:00
|
|
|
data: filter
|
2013-04-03 16:06:55 -04:00
|
|
|
}).then(function(users) {
|
2015-03-17 17:59:05 -04:00
|
|
|
return users.map((u) => Discourse.AdminUser.create(u));
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-03-17 17:59:05 -04:00
|
|
|
|
|
|
|
export default AdminUser;
|