2017-07-26 16:33:17 -04:00
|
|
|
import { iconHTML } from 'discourse-common/lib/icon-library';
|
2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2016-05-06 13:34:33 -04:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
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-11-20 20:27:06 -05:00
|
|
|
import ApiKey from 'admin/models/api-key';
|
|
|
|
import Group from 'discourse/models/group';
|
|
|
|
import TL3Requirements from 'admin/models/tl3-requirements';
|
2017-03-28 14:27:54 -04:00
|
|
|
import { userPath } from 'discourse/lib/url';
|
2015-05-19 10:56:32 -04:00
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
const wrapAdmin = user => user ? AdminUser.create(user) : null;
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
const AdminUser = Discourse.User.extend({
|
2017-09-14 14:10:39 -04:00
|
|
|
adminUserView: true,
|
2016-05-06 13:34:33 -04: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-17 17:59:05 -04:00
|
|
|
|
2016-01-19 10:41:07 -05:00
|
|
|
canViewProfile: Ember.computed.or("active", "staged"),
|
|
|
|
|
2016-05-06 13:34:33 -04: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-18 16:38:35 -04:00
|
|
|
@computed
|
|
|
|
bounceLink() {
|
|
|
|
return Discourse.getURL("/admin/email/bounced");
|
|
|
|
},
|
|
|
|
|
2016-05-06 13:34:33 -04:00
|
|
|
canResetBounceScore: Ember.computed.gt("bounce_score", 0),
|
|
|
|
|
|
|
|
resetBounceScore() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax(`/admin/users/${this.get("id")}/reset_bounce_score`, {
|
2016-05-06 13:34:33 -04:00
|
|
|
type: 'POST'
|
|
|
|
}).then(() => this.setProperties({
|
|
|
|
"bounce_score": 0,
|
|
|
|
"reset_bounce_score_after": null
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
generateApiKey() {
|
|
|
|
const self = this;
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/generate_api_key", {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: 'POST'
|
|
|
|
}).then(function (result) {
|
2015-11-20 20:27:06 -05:00
|
|
|
const apiKey = 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) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/groups", {
|
2014-07-15 10:11:39 -04:00
|
|
|
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) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/groups/" + groupId, {
|
2014-07-15 10:11:39 -04:00
|
|
|
type: 'DELETE'
|
2017-05-17 12:42:04 -04: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 10:11:39 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
revokeApiKey() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/revoke_api_key", {
|
2015-03-17 17:59:05 -04:00
|
|
|
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,
|
2016-08-10 13:24:28 -04:00
|
|
|
message = I18n.messageFormat('admin.user.delete_all_posts_confirm_MF', { "POSTS": user.get('post_count'), "TOPICS": user.get('topic_count') }),
|
2015-03-17 17:59:05 -04:00
|
|
|
buttons = [{
|
|
|
|
"label": I18n.t("composer.cancel"),
|
2017-09-13 13:23:19 -04:00
|
|
|
"class": "d-modal-cancel",
|
2015-03-17 17:59:05 -04:00
|
|
|
"link": true
|
|
|
|
}, {
|
2017-07-26 16:33:17 -04:00
|
|
|
"label": `${iconHTML('exclamation-triangle')} ` + I18n.t("admin.user.delete_all_posts"),
|
2015-03-17 17:59:05 -04:00
|
|
|
"class": "btn btn-danger",
|
|
|
|
"callback": function() {
|
2016-06-30 13:55:44 -04:00
|
|
|
ajax("/admin/users/" + user.get('id') + "/delete_all_posts", {
|
2015-03-17 17:59:05 -04:00
|
|
|
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() {
|
2017-04-04 13:59:22 -04:00
|
|
|
return ajax(`/admin/users/${this.get('id')}/revoke_admin`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: 'PUT'
|
2017-04-04 13:59:22 -04:00
|
|
|
}).then(() => {
|
|
|
|
this.setProperties({
|
2015-03-17 17:59:05 -04:00
|
|
|
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() {
|
2017-04-04 13:59:22 -04:00
|
|
|
return ajax(`/admin/users/${this.get('id')}/grant_admin`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: 'PUT'
|
2017-04-04 13:59:22 -04:00
|
|
|
}).then(() => {
|
|
|
|
bootbox.alert(I18n.t("admin.user.grant_admin_confirm"));
|
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;
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/revoke_moderation", {
|
2015-03-17 17:59:05 -04:00
|
|
|
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;
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/grant_moderation", {
|
2015-03-17 17:59:05 -04:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2017-12-21 20:18:12 -05:00
|
|
|
disableSecondFactor() {
|
2018-02-20 01:44:51 -05:00
|
|
|
return ajax(`/admin/users/${this.get('id')}/disable_second_factor`, {
|
2017-12-21 20:18:12 -05:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(() => {
|
|
|
|
this.set('second_factor_enabled', false);
|
|
|
|
}).catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
refreshBrowsers() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/refresh_browsers", {
|
2015-03-17 17:59:05 -04:00
|
|
|
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;
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + this.get('id') + "/approve", {
|
2015-03-17 17:59:05 -04:00
|
|
|
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() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return 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) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return 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),
|
2017-11-13 13:41:36 -05:00
|
|
|
isSilenced: Ember.computed.equal('silenced', true),
|
2013-11-07 13:53:32 -05:00
|
|
|
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
|
|
|
|
2017-09-13 14:11:33 -04:00
|
|
|
suspend(data) {
|
|
|
|
return ajax(`/admin/users/${this.id}/suspend`, {
|
2013-11-01 10:47:03 -04:00
|
|
|
type: 'PUT',
|
2017-09-13 14:11:33 -04:00
|
|
|
data
|
2017-09-13 14:43:36 -04:00
|
|
|
}).then(result => this.setProperties(result.suspension));
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
unsuspend() {
|
2017-09-13 14:11:33 -04:00
|
|
|
return ajax(`/admin/users/${this.id}/unsuspend`, {
|
2013-04-03 16:06:55 -04:00
|
|
|
type: 'PUT'
|
2017-09-13 14:43:36 -04:00
|
|
|
}).then(result => this.setProperties(result.suspension));
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2016-12-20 06:26:53 -05:00
|
|
|
logOut() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return 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() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return 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-11-23 09:44:44 -05:00
|
|
|
document.location = Discourse.getURL("/");
|
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() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax('/admin/users/' + this.id + '/activate', {
|
2015-03-17 17:59:05 -04:00
|
|
|
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() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax('/admin/users/' + this.id + '/deactivate', {
|
2015-03-17 17:59:05 -04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-11-10 12:18:08 -05:00
|
|
|
unsilence() {
|
|
|
|
this.set('silencingUser', true);
|
2017-11-13 13:41:36 -05:00
|
|
|
|
|
|
|
return ajax(`/admin/users/${this.id}/unsilence`, {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: 'PUT'
|
2017-11-13 13:41:36 -05:00
|
|
|
}).then(result => {
|
|
|
|
this.setProperties(result.unsilence);
|
|
|
|
}).catch(e => {
|
|
|
|
let error = I18n.t('admin.user.unsilence_failed', {
|
|
|
|
error: `http: ${e.status} - ${e.body}`
|
|
|
|
});
|
2013-05-31 11:41:40 -04:00
|
|
|
bootbox.alert(error);
|
2017-11-13 13:41:36 -05:00
|
|
|
}).finally(() => {
|
|
|
|
this.set('silencingUser', false);
|
2013-05-31 11:41:40 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
silence(data) {
|
|
|
|
this.set('silencingUser', true);
|
|
|
|
return ajax(`/admin/users/${this.id}/silence`, {
|
|
|
|
type: 'PUT',
|
|
|
|
data
|
|
|
|
}).then(result => {
|
|
|
|
this.setProperties(result.silence);
|
|
|
|
}).catch(e => {
|
|
|
|
let error = I18n.t('admin.user.silence_failed', {
|
|
|
|
error: `http: ${e.status} - ${e.body}`
|
2016-01-14 14:42:06 -05:00
|
|
|
});
|
2017-11-13 13:41:36 -05:00
|
|
|
bootbox.alert(error);
|
|
|
|
}).finally(() => {
|
|
|
|
this.set('silencingUser', false);
|
|
|
|
});
|
2013-05-31 11:41:40 -04:00
|
|
|
},
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
sendActivationEmail() {
|
2017-03-28 14:27:54 -04:00
|
|
|
return ajax(userPath('action/send_activation_email'), {
|
2015-03-17 17:59:05 -04:00
|
|
|
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-10-27 16:25:30 -04:00
|
|
|
}).catch(popupAjaxError);
|
2013-05-07 21:58:34 -04:00
|
|
|
},
|
|
|
|
|
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() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + user.get('id') + '/anonymize.json', {
|
2015-03-17 17:59:05 -04:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function(data) {
|
2015-03-06 16:44:54 -05:00
|
|
|
if (data.success) {
|
|
|
|
if (data.username) {
|
2016-03-03 11:58:58 -05:00
|
|
|
document.location = Discourse.getURL("/admin/users/" + user.get('id') + "/" + 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
|
|
|
|
}, {
|
2017-07-26 16:33:17 -04:00
|
|
|
"label": `${iconHTML('exclamation-triangle')} ` + I18n.t('admin.user.anonymize_yes'),
|
2015-03-06 16:44:54 -05:00
|
|
|
"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;
|
|
|
|
}
|
2016-06-30 13:55:44 -04:00
|
|
|
return 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() {
|
2015-09-26 09:56:36 -04:00
|
|
|
AdminUser.find(user.get('id')).then(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
|
|
|
}, {
|
2017-07-26 16:33:17 -04:00
|
|
|
"label": `${iconHTML('exclamation-triangle')} ` + 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
|
|
|
loadDetails() {
|
|
|
|
const user = this;
|
|
|
|
|
|
|
|
if (user.get('loadedDetails')) { return Ember.RSVP.resolve(user); }
|
2013-06-13 13:46:50 -04:00
|
|
|
|
2015-09-26 09:56:36 -04:00
|
|
|
return AdminUser.find(user.get('id')).then(result => {
|
2015-03-17 17:59:05 -04:00
|
|
|
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')) {
|
2015-11-20 20:27:06 -05:00
|
|
|
return 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
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
@computed('suspended_by')
|
|
|
|
suspendedBy: wrapAdmin,
|
2014-03-24 11:43:06 -04:00
|
|
|
|
2017-11-13 13:41:36 -05:00
|
|
|
@computed('silenced_by')
|
|
|
|
silencedBy: wrapAdmin,
|
|
|
|
|
|
|
|
@computed('approved_by')
|
|
|
|
approvedBy: wrapAdmin,
|
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
|
|
|
|
2016-06-30 13:55:44 -04:00
|
|
|
return 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);
|
|
|
|
});
|
|
|
|
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/reject-bulk", {
|
2013-08-16 11:42:24 -04:00
|
|
|
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-09-26 09:56:36 -04:00
|
|
|
find(user_id) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/users/" + user_id + ".json").then(result => {
|
2013-06-13 13:46:50 -04:00
|
|
|
result.loadedDetails = true;
|
2015-11-20 20:27:06 -05:00
|
|
|
return 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) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return 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-11-20 20:27:06 -05:00
|
|
|
return users.map((u) => AdminUser.create(u));
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-03-17 17:59:05 -04:00
|
|
|
|
|
|
|
export default AdminUser;
|