mirror of
https://github.com/discourse/discourse.git
synced 2025-01-16 04:52:43 +08:00
FEATURE: Add IP Lookup to review queue (#30688)
Moves the theme component https://github.com/discourse/discourse-review-ip-lookup into core, this allows looking up a user's IP directly from the review queue and seeing if there are other users with the same IP on the forum
This commit is contained in:
parent
3e00e994a6
commit
0caeadd9b1
|
@ -16,6 +16,8 @@ import { i18n } from "discourse-i18n";
|
||||||
import AdminUser from "admin/models/admin-user";
|
import AdminUser from "admin/models/admin-user";
|
||||||
import DMenu from "float-kit/components/d-menu";
|
import DMenu from "float-kit/components/d-menu";
|
||||||
|
|
||||||
|
const MAX_ACCOUNTS_TO_DELETE = 50;
|
||||||
|
|
||||||
export default class IpLookup extends Component {
|
export default class IpLookup extends Component {
|
||||||
@service dialog;
|
@service dialog;
|
||||||
@service site;
|
@service site;
|
||||||
|
@ -26,13 +28,13 @@ export default class IpLookup extends Component {
|
||||||
@tracked loading = false;
|
@tracked loading = false;
|
||||||
@tracked otherAccountsLoading = false;
|
@tracked otherAccountsLoading = false;
|
||||||
@tracked totalOthersWithSameIP;
|
@tracked totalOthersWithSameIP;
|
||||||
|
@tracked ipToLookup = this.args.ip;
|
||||||
|
|
||||||
get otherAccountsToDelete() {
|
get otherAccountsToDelete() {
|
||||||
const otherAccountsLength = this.otherAccounts?.length || 0;
|
const otherAccountsLength = this.otherAccounts?.length || 0;
|
||||||
const totalOthers = this.totalOthersWithSameIP || 0;
|
const totalOthers = this.totalOthersWithSameIP || 0;
|
||||||
// can only delete up to 50 accounts at a time
|
const total = Math.min(MAX_ACCOUNTS_TO_DELETE, totalOthers);
|
||||||
const total = Math.min(50, totalOthers);
|
const visible = Math.min(MAX_ACCOUNTS_TO_DELETE, otherAccountsLength);
|
||||||
const visible = Math.min(50, otherAccountsLength);
|
|
||||||
return Math.max(visible, total);
|
return Math.max(visible, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,18 +42,27 @@ export default class IpLookup extends Component {
|
||||||
async lookup() {
|
async lookup() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
if (!this.location && this.args.ip) {
|
if (this.args.ip === "adminLookup") {
|
||||||
const loc = await ajax("/admin/users/ip-info", {
|
try {
|
||||||
data: { ip: this.args.ip },
|
const userInfo = await AdminUser.find(this.args.userId);
|
||||||
});
|
this.ipToLookup = userInfo.ip_address;
|
||||||
this.location = loc;
|
} catch (err) {
|
||||||
|
popupAjaxError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.otherAccounts && this.args.ip) {
|
if (!this.location && this.ipToLookup) {
|
||||||
|
this.location = await ajax("/admin/users/ip-info", {
|
||||||
|
data: { ip: this.ipToLookup },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.otherAccounts && this.ipToLookup) {
|
||||||
this.otherAccountsLoading = true;
|
this.otherAccountsLoading = true;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
ip: this.args.ip,
|
ip: this.ipToLookup,
|
||||||
exclude: this.args.userId,
|
exclude: this.args.userId,
|
||||||
order: "trust_level DESC",
|
order: "trust_level DESC",
|
||||||
};
|
};
|
||||||
|
@ -75,7 +86,7 @@ export default class IpLookup extends Component {
|
||||||
@action
|
@action
|
||||||
async copy() {
|
async copy() {
|
||||||
const { location } = this;
|
const { location } = this;
|
||||||
let text = `IP: ${this.args.ip}`;
|
let text = `IP: ${this.ipToLookup}`;
|
||||||
|
|
||||||
if (location) {
|
if (location) {
|
||||||
if (location.hostname) {
|
if (location.hostname) {
|
||||||
|
@ -111,7 +122,6 @@ export default class IpLookup extends Component {
|
||||||
this.dialog.yesNoConfirm({
|
this.dialog.yesNoConfirm({
|
||||||
message: i18n("ip_lookup.confirm_delete_other_accounts"),
|
message: i18n("ip_lookup.confirm_delete_other_accounts"),
|
||||||
didConfirm: async () => {
|
didConfirm: async () => {
|
||||||
// reset state
|
|
||||||
this.otherAccounts = null;
|
this.otherAccounts = null;
|
||||||
this.otherAccountsLoading = true;
|
this.otherAccountsLoading = true;
|
||||||
this.totalOthersWithSameIP = null;
|
this.totalOthersWithSameIP = null;
|
||||||
|
@ -120,7 +130,7 @@ export default class IpLookup extends Component {
|
||||||
await ajax("/admin/users/delete-others-with-same-ip.json", {
|
await ajax("/admin/users/delete-others-with-same-ip.json", {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
data: {
|
data: {
|
||||||
ip: this.args.ip,
|
ip: this.ipToLookup,
|
||||||
exclude: this.args.userId,
|
exclude: this.args.userId,
|
||||||
order: "trust_level DESC",
|
order: "trust_level DESC",
|
||||||
},
|
},
|
||||||
|
|
|
@ -135,6 +135,13 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if this.showIpLookup}}
|
||||||
|
<IpLookup
|
||||||
|
@ip="adminLookup"
|
||||||
|
@userId={{this.reviewable.target_created_by.id}}
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<PluginOutlet
|
<PluginOutlet
|
||||||
@name="reviewable-item-actions"
|
@name="reviewable-item-actions"
|
||||||
@connectorTagName="div"
|
@connectorTagName="div"
|
||||||
|
|
|
@ -188,6 +188,15 @@ export default class ReviewableItem extends Component {
|
||||||
return updatedCategoryId || categoryId;
|
return updatedCategoryId || categoryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discourseComputed("reviewable.type", "reviewable.target_created_by")
|
||||||
|
showIpLookup(reviewableType) {
|
||||||
|
return (
|
||||||
|
reviewableType !== "ReviewableUser" &&
|
||||||
|
this.currentUser.staff &&
|
||||||
|
this.reviewable.target_created_by
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
_performConfirmed(performableAction, additionalData = {}) {
|
_performConfirmed(performableAction, additionalData = {}) {
|
||||||
let reviewable = this.reviewable;
|
let reviewable = this.reviewable;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user