2017-07-27 04:33:17 +08:00
|
|
|
import { iconHTML } from 'discourse-common/lib/icon-library';
|
2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2016-05-07 01:34:33 +08:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
2015-08-08 03:08:27 +08:00
|
|
|
import { propertyNotEqual } from 'discourse/lib/computed';
|
2015-05-19 22:56:32 +08:00
|
|
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
2015-11-21 09:27:06 +08:00
|
|
|
import ApiKey from 'admin/models/api-key';
|
|
|
|
import Group from 'discourse/models/group';
|
|
|
|
import TL3Requirements from 'admin/models/tl3-requirements';
|
2017-03-29 02:27:54 +08:00
|
|
|
import { userPath } from 'discourse/lib/url';
|
2015-05-19 22:56:32 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
const AdminUser = Discourse.User.extend({
|
2017-09-15 02:10:39 +08:00
|
|
|
adminUserView: true,
|
2016-05-07 01:34:33 +08:00
|
|
|
customGroups: Ember.computed.filter("groups", g => !g.automatic && Group.create(g)),
|
|
|
|
automaticGroups: Ember.computed.filter("groups", g => g.automatic && Group.create(g)),
|
2015-03-18 05:59:05 +08:00
|
|
|
|
2016-01-19 23:41:07 +08:00
|
|
|
canViewProfile: Ember.computed.or("active", "staged"),
|
|
|
|
|
2016-05-07 01:34:33 +08:00
|
|
|
@computed("bounce_score", "reset_bounce_score_after")
|
|
|
|
bounceScore(bounce_score, reset_bounce_score_after) {
|
|
|
|
if (bounce_score > 0) {
|
|
|
|
return `${bounce_score} - ${moment(reset_bounce_score_after).format('LL')}`;
|
|
|
|
} else {
|
|
|
|
return bounce_score;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("bounce_score")
|
|
|
|
bounceScoreExplanation(bounce_score) {
|
|
|
|
if (bounce_score === 0) {
|
|
|
|
return I18n.t("admin.user.bounce_score_explanation.none");
|
|
|
|
} else if (bounce_score < Discourse.SiteSettings.bounce_score_threshold) {
|
|
|
|
return I18n.t("admin.user.bounce_score_explanation.some");
|
|
|
|
} else {
|
|
|
|
return I18n.t("admin.user.bounce_score_explanation.threshold_reached");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-19 04:38:35 +08:00
|
|
|
@computed
|
|
|
|
bounceLink() {
|
|
|
|
return Discourse.getURL("/admin/email/bounced");
|
|
|
|
},
|
|
|
|
|
2016-05-07 01:34:33 +08:00
|
|
|
canResetBounceScore: Ember.computed.gt("bounce_score", 0),
|
|
|
|
|
|
|
|
resetBounceScore() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax(`/admin/users/${this.get("id")}/reset_bounce_score`, {
|
2016-05-07 01:34:33 +08:00
|
|
|
type: 'POST'
|
|
|
|
}).then(() => this.setProperties({
|
|
|
|
"bounce_score": 0,
|
|
|
|
"reset_bounce_score_after": null
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
generateApiKey() {
|
|
|
|
const self = this;
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/generate_api_key", {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'POST'
|
|
|
|
}).then(function (result) {
|
2015-11-21 09:27:06 +08:00
|
|
|
const apiKey = ApiKey.create(result.api_key);
|
2013-10-23 03:53:08 +08:00
|
|
|
self.set('api_key', apiKey);
|
|
|
|
return apiKey;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
groupAdded(added) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/groups", {
|
2014-07-15 22:11:39 +08:00
|
|
|
type: 'POST',
|
2015-03-18 05:59:05 +08:00
|
|
|
data: { group_id: added.id }
|
|
|
|
}).then(() => this.get('groups').pushObject(added));
|
2014-07-15 22:11:39 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
groupRemoved(groupId) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/groups/" + groupId, {
|
2014-07-15 22:11:39 +08:00
|
|
|
type: 'DELETE'
|
2017-05-18 00:42:04 +08:00
|
|
|
}).then(() => {
|
|
|
|
this.set('groups.[]', this.get('groups').rejectBy("id", groupId));
|
|
|
|
if (this.get('primary_group_id') === groupId) {
|
|
|
|
this.set('primary_group_id', null);
|
|
|
|
}
|
|
|
|
});
|
2014-07-15 22:11:39 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
revokeApiKey() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/revoke_api_key", {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'DELETE'
|
|
|
|
}).then(() => this.set('api_key', null));
|
2013-10-23 03:53:08 +08:00
|
|
|
},
|
|
|
|
|
2014-02-21 01:29:40 +08:00
|
|
|
deleteAllPostsExplanation: function() {
|
|
|
|
if (!this.get('can_delete_all_posts')) {
|
2015-03-07 03:11:48 +08:00
|
|
|
if (this.get('deleteForbidden') && this.get('staff')) {
|
|
|
|
return I18n.t('admin.user.delete_posts_forbidden_because_staff');
|
|
|
|
}
|
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;
|
|
|
|
}
|
2015-03-07 03:11:48 +08:00
|
|
|
}.property('can_delete_all_posts', 'deleteForbidden'),
|
2014-02-21 01:29:40 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
deleteAllPosts() {
|
|
|
|
const user = this,
|
2016-08-11 01:24:28 +08:00
|
|
|
message = I18n.messageFormat('admin.user.delete_all_posts_confirm_MF', { "POSTS": user.get('post_count'), "TOPICS": user.get('topic_count') }),
|
2015-03-18 05:59:05 +08:00
|
|
|
buttons = [{
|
|
|
|
"label": I18n.t("composer.cancel"),
|
2017-09-14 01:23:19 +08:00
|
|
|
"class": "d-modal-cancel",
|
2015-03-18 05:59:05 +08:00
|
|
|
"link": true
|
|
|
|
}, {
|
2017-07-27 04:33:17 +08:00
|
|
|
"label": `${iconHTML('exclamation-triangle')} ` + I18n.t("admin.user.delete_all_posts"),
|
2015-03-18 05:59:05 +08:00
|
|
|
"class": "btn btn-danger",
|
|
|
|
"callback": function() {
|
2016-07-01 01:55:44 +08:00
|
|
|
ajax("/admin/users/" + user.get('id') + "/delete_all_posts", {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(() => user.set('post_count', 0));
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
bootbox.dialog(message, buttons, { "classes": "delete-all-posts" });
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
revokeAdmin() {
|
2017-04-05 01:59:22 +08:00
|
|
|
return ajax(`/admin/users/${this.get('id')}/revoke_admin`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
2017-04-05 01:59:22 +08:00
|
|
|
}).then(() => {
|
|
|
|
this.setProperties({
|
2015-03-18 05:59:05 +08:00
|
|
|
admin: false,
|
|
|
|
can_grant_admin: true,
|
|
|
|
can_revoke_admin: false
|
|
|
|
});
|
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
grantAdmin() {
|
2017-04-05 01:59:22 +08:00
|
|
|
return ajax(`/admin/users/${this.get('id')}/grant_admin`, {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
2017-04-05 01:59:22 +08:00
|
|
|
}).then(() => {
|
|
|
|
bootbox.alert(I18n.t("admin.user.grant_admin_confirm"));
|
2015-05-19 22:56:32 +08:00
|
|
|
}).catch(popupAjaxError);
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
revokeModeration() {
|
|
|
|
const self = this;
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/revoke_moderation", {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
moderator: false,
|
|
|
|
can_grant_moderation: true,
|
|
|
|
can_revoke_moderation: false
|
|
|
|
});
|
2015-05-19 22:56:32 +08:00
|
|
|
}).catch(popupAjaxError);
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
grantModeration() {
|
|
|
|
const self = this;
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/grant_moderation", {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
moderator: true,
|
|
|
|
can_grant_moderation: false,
|
|
|
|
can_revoke_moderation: true
|
|
|
|
});
|
2015-05-19 22:56:32 +08:00
|
|
|
}).catch(popupAjaxError);
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
refreshBrowsers() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/refresh_browsers", {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'POST'
|
|
|
|
}).finally(() => bootbox.alert(I18n.t("admin.user.refresh_browsers_message")));
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
approve() {
|
|
|
|
const self = this;
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/approve", {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
self.setProperties({
|
|
|
|
can_approve: false,
|
|
|
|
approved: true,
|
|
|
|
approved_by: Discourse.User.current()
|
|
|
|
});
|
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
setOriginalTrustLevel() {
|
2013-07-04 19:01:01 +08:00
|
|
|
this.set('originalTrustLevel', this.get('trust_level'));
|
|
|
|
},
|
|
|
|
|
2015-08-08 03:08:27 +08:00
|
|
|
dirty: propertyNotEqual('originalTrustLevel', 'trustLevel.id'),
|
2013-07-01 22:22:21 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
saveTrustLevel() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.id + "/trust_level", {
|
2013-07-01 22:22:21 +08:00
|
|
|
type: 'PUT',
|
2015-03-18 05:59:05 +08:00
|
|
|
data: { level: this.get('trustLevel.id') }
|
|
|
|
}).then(function() {
|
2013-07-01 22:22:21 +08:00
|
|
|
window.location.reload();
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function(e) {
|
|
|
|
let error;
|
2014-07-30 03:54:20 +08: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 22:22:21 +08:00
|
|
|
bootbox.alert(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
restoreTrustLevel() {
|
2013-07-04 15:32:12 +08:00
|
|
|
this.set('trustLevel.id', this.get('originalTrustLevel'));
|
2013-07-01 22:22:21 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
lockTrustLevel(locked) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.id + "/trust_level_lock", {
|
2014-09-14 04:55:26 +08:00
|
|
|
type: 'PUT',
|
|
|
|
data: { locked: !!locked }
|
|
|
|
}).then(function() {
|
|
|
|
window.location.reload();
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function(e) {
|
|
|
|
let error;
|
2014-09-14 04:55:26 +08: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-18 05:59:05 +08:00
|
|
|
canLockTrustLevel: function() {
|
2014-09-30 11:12:33 +08:00
|
|
|
return this.get('trust_level') < 4;
|
|
|
|
}.property('trust_level'),
|
|
|
|
|
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() {
|
2015-03-18 05:59:05 +08:00
|
|
|
const suspended_at = moment(this.suspended_at),
|
|
|
|
suspended_till = moment(this.suspended_till);
|
2013-11-08 02:53:32 +08:00
|
|
|
return suspended_at.format('L') + " - " + suspended_till.format('L');
|
|
|
|
}.property('suspended_till', 'suspended_at'),
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2017-09-14 02:11:33 +08:00
|
|
|
suspend(data) {
|
|
|
|
return ajax(`/admin/users/${this.id}/suspend`, {
|
2013-11-01 22:47:03 +08:00
|
|
|
type: 'PUT',
|
2017-09-14 02:11:33 +08:00
|
|
|
data
|
2017-09-14 02:43:36 +08:00
|
|
|
}).then(result => this.setProperties(result.suspension));
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
unsuspend() {
|
2017-09-14 02:11:33 +08:00
|
|
|
return ajax(`/admin/users/${this.id}/unsuspend`, {
|
2013-04-04 04:06:55 +08:00
|
|
|
type: 'PUT'
|
2017-09-14 02:43:36 +08:00
|
|
|
}).then(result => this.setProperties(result.suspension));
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2016-12-20 19:26:53 +08:00
|
|
|
logOut() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + this.id + "/log_out", {
|
2014-06-06 11:02:52 +08:00
|
|
|
type: 'POST',
|
|
|
|
data: { username_or_email: this.get('username') }
|
2015-03-18 05:59:05 +08:00
|
|
|
}).then(function() {
|
|
|
|
bootbox.alert(I18n.t("admin.user.logged_out"));
|
|
|
|
});
|
2014-06-06 11:02:52 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
impersonate() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return 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() {
|
2015-11-23 22:44:44 +08:00
|
|
|
document.location = Discourse.getURL("/");
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function(e) {
|
2013-04-04 04:06:55 +08:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
activate() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/admin/users/' + this.id + '/activate', {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
2013-05-08 09:58:34 +08:00
|
|
|
window.location.reload();
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function(e) {
|
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);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
deactivate() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/admin/users/' + this.id + '/deactivate', {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
2013-05-08 09:58:34 +08:00
|
|
|
window.location.reload();
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function(e) {
|
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);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
unblock() {
|
2016-01-15 03:42:06 +08:00
|
|
|
this.set('blockingUser', true);
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/admin/users/' + this.id + '/unblock', {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
2013-05-31 23:41:40 +08:00
|
|
|
window.location.reload();
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function(e) {
|
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);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
block() {
|
2016-01-15 03:42:06 +08:00
|
|
|
const user = this,
|
|
|
|
message = I18n.t("admin.user.block_confirm");
|
|
|
|
|
|
|
|
const performBlock = function() {
|
|
|
|
user.set('blockingUser', true);
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/admin/users/' + user.id + '/block', {
|
2016-01-15 03:42:06 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
window.location.reload();
|
|
|
|
}).catch(function(e) {
|
|
|
|
var error = I18n.t('admin.user.block_failed', { error: "http: " + e.status + " - " + e.body });
|
|
|
|
bootbox.alert(error);
|
|
|
|
user.set('blockingUser', false);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const buttons = [{
|
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "cancel",
|
|
|
|
"link": true
|
|
|
|
}, {
|
2017-07-27 04:33:17 +08:00
|
|
|
"label": `${iconHTML('exclamation-triangle')} ` + I18n.t('admin.user.block_accept'),
|
2016-01-15 03:42:06 +08:00
|
|
|
"class": "btn btn-danger",
|
|
|
|
"callback": function() { performBlock(); }
|
|
|
|
}];
|
|
|
|
|
|
|
|
bootbox.dialog(message, buttons, { "classes": "delete-user-modal" });
|
2013-05-31 23:41:40 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
sendActivationEmail() {
|
2017-03-29 02:27:54 +08:00
|
|
|
return ajax(userPath('action/send_activation_email'), {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'POST',
|
|
|
|
data: { username: this.get('username') }
|
|
|
|
}).then(function() {
|
2013-07-09 07:32:16 +08:00
|
|
|
bootbox.alert( I18n.t('admin.user.activation_email_sent') );
|
2015-10-28 04:25:30 +08:00
|
|
|
}).catch(popupAjaxError);
|
2013-05-08 09:58:34 +08:00
|
|
|
},
|
|
|
|
|
2015-03-07 05:44:54 +08:00
|
|
|
anonymizeForbidden: Em.computed.not("can_be_anonymized"),
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
anonymize() {
|
|
|
|
const user = this,
|
|
|
|
message = I18n.t("admin.user.anonymize_confirm");
|
2015-03-07 05:44:54 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
const performAnonymize = function() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + user.get('id') + '/anonymize.json', {
|
2015-03-18 05:59:05 +08:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function(data) {
|
2015-03-07 05:44:54 +08:00
|
|
|
if (data.success) {
|
|
|
|
if (data.username) {
|
2016-03-04 00:58:58 +08:00
|
|
|
document.location = Discourse.getURL("/admin/users/" + user.get('id') + "/" + data.username);
|
2015-03-07 05:44:54 +08:00
|
|
|
} else {
|
2015-05-22 03:02:52 +08:00
|
|
|
document.location = Discourse.getURL("/admin/users/list/active");
|
2015-03-07 05:44:54 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("admin.user.anonymize_failed"));
|
|
|
|
if (data.user) {
|
|
|
|
user.setProperties(data.user);
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function() {
|
2015-03-07 05:44:54 +08:00
|
|
|
bootbox.alert(I18n.t("admin.user.anonymize_failed"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
const buttons = [{
|
2015-03-07 05:44:54 +08:00
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "cancel",
|
|
|
|
"link": true
|
|
|
|
}, {
|
2017-07-27 04:33:17 +08:00
|
|
|
"label": `${iconHTML('exclamation-triangle')} ` + I18n.t('admin.user.anonymize_yes'),
|
2015-03-07 05:44:54 +08:00
|
|
|
"class": "btn btn-danger",
|
2015-03-18 05:59:05 +08:00
|
|
|
"callback": function() { performAnonymize(); }
|
2015-03-07 05:44:54 +08:00
|
|
|
}];
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
bootbox.dialog(message, buttons, { "classes": "delete-user-modal" });
|
2015-03-07 05:44:54 +08:00
|
|
|
},
|
|
|
|
|
2014-12-03 20:00:02 +08:00
|
|
|
deleteForbidden: Em.computed.not("canBeDeleted"),
|
2013-04-12 04:04:20 +08:00
|
|
|
|
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'),
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
destroy(opts) {
|
|
|
|
const user = this,
|
|
|
|
message = I18n.t("admin.user.delete_confirm"),
|
|
|
|
location = document.location.pathname;
|
2013-07-26 04:51:24 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
const performDestroy = function(block) {
|
|
|
|
let formData = { context: location };
|
2013-07-26 06:04:51 +08:00
|
|
|
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
|
|
|
}
|
2014-11-15 04:23:09 +08:00
|
|
|
if (opts && opts.deletePosts) {
|
|
|
|
formData["delete_posts"] = true;
|
|
|
|
}
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + user.get('id') + '.json', {
|
2013-07-26 04:51:24 +08:00
|
|
|
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) {
|
2014-12-26 01:25:07 +08:00
|
|
|
if (/^\/admin\/users\/list\//.test(location)) {
|
|
|
|
document.location = location;
|
|
|
|
} else {
|
2015-05-22 03:02:52 +08:00
|
|
|
document.location = Discourse.getURL("/admin/users/list/active");
|
2014-12-26 01:25:07 +08:00
|
|
|
}
|
2013-07-26 04:51:24 +08:00
|
|
|
} 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) {
|
2014-07-22 01:39:23 +08:00
|
|
|
user.setProperties(data.user);
|
2013-07-26 04:51:24 +08:00
|
|
|
}
|
|
|
|
}
|
2015-03-18 05:59:05 +08:00
|
|
|
}).catch(function() {
|
2015-09-26 21:56:36 +08:00
|
|
|
AdminUser.find(user.get('id')).then(u => user.setProperties(u));
|
2013-07-26 04:51:24 +08:00
|
|
|
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
const buttons = [{
|
2013-07-26 04:51:24 +08:00
|
|
|
"label": I18n.t("composer.cancel"),
|
|
|
|
"class": "btn",
|
2015-10-01 07:06:55 +08:00
|
|
|
"link": true
|
2013-07-26 04:51:24 +08:00
|
|
|
}, {
|
2017-07-27 04:33:17 +08:00
|
|
|
"label": `${iconHTML('exclamation-triangle')} ` + I18n.t('admin.user.delete_and_block'),
|
2014-05-04 15:38:29 +08:00
|
|
|
"class": "btn btn-danger",
|
2015-03-18 05:59:05 +08:00
|
|
|
"callback": function(){ performDestroy(true); }
|
2015-10-01 07:06:55 +08:00
|
|
|
}, {
|
|
|
|
"label": I18n.t('admin.user.delete_dont_block'),
|
|
|
|
"class": "btn btn-primary",
|
|
|
|
"callback": function(){ performDestroy(false); }
|
2013-07-26 04:51:24 +08:00
|
|
|
}];
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
bootbox.dialog(message, buttons, { "classes": "delete-user-modal" });
|
2013-06-14 01:46:50 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
loadDetails() {
|
|
|
|
const user = this;
|
|
|
|
|
|
|
|
if (user.get('loadedDetails')) { return Ember.RSVP.resolve(user); }
|
2013-06-14 01:46:50 +08:00
|
|
|
|
2015-09-26 21:56:36 +08:00
|
|
|
return AdminUser.find(user.get('id')).then(result => {
|
2015-03-18 05:59:05 +08:00
|
|
|
user.setProperties(result);
|
|
|
|
user.set('loadedDetails', true);
|
2013-06-14 01:46:50 +08:00
|
|
|
});
|
2014-01-24 05:40:10 +08:00
|
|
|
},
|
|
|
|
|
2014-09-25 08:19:26 +08:00
|
|
|
tl3Requirements: function() {
|
|
|
|
if (this.get('tl3_requirements')) {
|
2015-11-21 09:27:06 +08:00
|
|
|
return TL3Requirements.create(this.get('tl3_requirements'));
|
2014-01-24 05:40:10 +08:00
|
|
|
}
|
2014-09-25 08:19:26 +08:00
|
|
|
}.property('tl3_requirements'),
|
2014-03-24 22:19:15 +08:00
|
|
|
|
|
|
|
suspendedBy: function() {
|
|
|
|
if (this.get('suspended_by')) {
|
2015-11-21 09:27:06 +08:00
|
|
|
return 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')) {
|
2015-11-21 09:27:06 +08:00
|
|
|
return AdminUser.create(this.get('approved_by'));
|
2014-03-24 23:43:06 +08:00
|
|
|
}
|
|
|
|
}.property('approved_by')
|
2013-02-23 04:41:12 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
AdminUser.reopenClass({
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
bulkApprove(users) {
|
2013-06-27 01:24:30 +08:00
|
|
|
_.each(users, function(user) {
|
2015-03-18 05:59:05 +08:00
|
|
|
user.setProperties({
|
|
|
|
approved: true,
|
|
|
|
can_approve: false,
|
|
|
|
selected: false
|
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
2013-06-06 12:18:22 +08:00
|
|
|
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/approve-bulk", {
|
2013-02-23 04:41:12 +08:00
|
|
|
type: 'PUT',
|
2015-03-18 05:59:05 +08:00
|
|
|
data: { users: users.map((u) => u.id) }
|
|
|
|
}).finally(() => bootbox.alert(I18n.t("admin.user.approve_bulk_success")));
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
bulkReject(users) {
|
|
|
|
_.each(users, function(user) {
|
2013-08-16 23:42:24 +08:00
|
|
|
user.set('can_approve', false);
|
|
|
|
user.set('selected', false);
|
|
|
|
});
|
|
|
|
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/reject-bulk", {
|
2013-08-16 23:42:24 +08:00
|
|
|
type: 'DELETE',
|
|
|
|
data: {
|
2015-03-18 05:59:05 +08:00
|
|
|
users: users.map((u) => u.id),
|
2013-08-16 23:42:24 +08:00
|
|
|
context: window.location.pathname
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-09-26 21:56:36 +08:00
|
|
|
find(user_id) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/users/" + user_id + ".json").then(result => {
|
2013-06-14 01:46:50 +08:00
|
|
|
result.loadedDetails = true;
|
2015-11-21 09:27:06 +08:00
|
|
|
return AdminUser.create(result);
|
2013-04-12 04:04:20 +08:00
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2015-03-18 05:59:05 +08:00
|
|
|
findAll(query, filter) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return 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) {
|
2015-11-21 09:27:06 +08:00
|
|
|
return users.map((u) => AdminUser.create(u));
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-03-18 05:59:05 +08:00
|
|
|
|
|
|
|
export default AdminUser;
|