Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: include IP info in refreshed reviewable insight tab (#36273)

Kris75628079c118
diff --git a/app/assets/stylesheets/admin/admin_base.scss b/app/assets/stylesheets/admin/admin_base.scss
index 8bdc1b66928..449302b7c18 100644
--- a/app/assets/stylesheets/admin/admin_base.scss
+++ b/app/assets/stylesheets/admin/admin_base.scss
@@ -552,10 +552,6 @@ $mobile-breakpoint: 700px;
list-style: none;
}
- td {
- padding: 0.25em 0.25em 0.25em 0;
- }
-
td.user {
white-space: nowrap;
@@ -569,6 +565,31 @@ $mobile-breakpoint: 700px;
}
}
+.ip-lookup-table {
+ td {
+ padding: var(--space-1);
+ }
+
+ td,
+ th {
+ &:not(:first-child) {
+ text-align: center;
+ }
+ }
+
+ .user a {
+ display: flex;
+ align-items: center;
+ gap: var(--space-1);
+
+ span {
+ max-width: min(10em, 20vw);
+
+ @include ellipsis;
+ }
+ }
+}
+
.admin-container {
margin-top: var(--space-4);
margin-bottom: var(--space-4);
diff --git a/app/assets/stylesheets/common/base/review.scss b/app/assets/stylesheets/common/base/review.scss
index 8af2f02476e..f94f28c8852 100644
--- a/app/assets/stylesheets/common/base/review.scss
+++ b/app/assets/stylesheets/common/base/review.scss
@@ -400,13 +400,17 @@
gap: var(--space-3);
margin-top: var(--space-2);
+ &__item,
+ .loading-container {
+ padding-inline: var(--space-4);
+ padding-bottom: var(--space-3);
+ }
+
&__item {
display: grid;
grid-template-columns: auto 1fr;
column-gap: var(--space-2);
align-items: start;
- padding-bottom: var(--space-3);
- padding-inline: var(--space-4);
&:not(:last-child) {
border-bottom: 1px solid var(--content-border-color);
@@ -637,3 +641,15 @@
}
}
}
+
+.ip-lookup-other-accounts-modal {
+ .loading-container,
+ .ip-lookup-table {
+ width: 100%;
+ }
+}
+
+.ip-lookup-powered-by {
+ font-size: var(--font-down-2);
+ font-weight: normal;
+}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 1694848bcf7..fabec146835 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -971,7 +971,6 @@ en:
flagged_by_users:
one: "Flagged by %{count} unique user"
other: "Flagged by %{count} unique users"
- similar_posts: "Past violations"
flagged_in_timeframe:
one: "%{count} confirmed flag"
other: "%{count} confirmed flags"
@@ -985,7 +984,7 @@ en:
solution_marked: "Solution marked"
topic_has_solution: "This topic has a solution"
visibility: "Visibility"
- topic_unlisted: "This topic is unlisted. Only accessible via direct link — not public."
+ topic_unlisted: "This topic is unlisted and only accessible via direct link."
help:
moderation_guide: "Discourse moderation guide"
flag_priorities: "Managing user reputation and flag priorities"
@@ -1419,13 +1418,16 @@ en:
other: "Categories (%{count} more)…"
ip_lookup:
- title: IP Address Lookup
+ title: IP Address
hostname: Hostname
location: Location
location_not_found: (unknown)
organisation: Organization
phone: Phone
other_accounts: "Other accounts with this IP address:"
+ other_accounts_with_ip:
+ one: "%{count} other account with this IP address"
+ other: "%{count} other accounts with this IP address"
delete_other_accounts:
one: "Delete %{count}"
other: "Delete %{count}"
diff --git a/frontend/discourse/admin/components/ip-lookup-accounts-table.gjs b/frontend/discourse/admin/components/ip-lookup-accounts-table.gjs
new file mode 100644
index 00000000000..2e9e2fb5186
--- /dev/null
+++ b/frontend/discourse/admin/components/ip-lookup-accounts-table.gjs
@@ -0,0 +1,35 @@
+import { LinkTo } from "@ember/routing";
+import avatar from "discourse/helpers/avatar";
+import { i18n } from "discourse-i18n";
+
+const IpLookupAccountsTable = <template>
+ <table class="ip-lookup-table">
+ <thead>
+ <tr>
+ <th>{{i18n "ip_lookup.username"}}</th>
+ <th>{{i18n "ip_lookup.trust_level"}}</th>
+ <th>{{i18n "ip_lookup.read_time"}}</th>
+ <th>{{i18n "ip_lookup.topics_entered"}}</th>
+ <th>{{i18n "ip_lookup.post_count"}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#each @accounts as |account|}}
+ <tr>
+ <td class="user">
+ <LinkTo @route="adminUser" @model={{account}}>
+ {{avatar account imageSize="tiny"}}
+ <span>{{account.username}}</span>
+ </LinkTo>
+ </td>
+ <td>{{account.trustLevel.id}}</td>
+ <td>{{account.time_read}}</td>
+ <td>{{account.topics_entered}}</td>
+ <td>{{account.post_count}}</td>
+ </tr>
+ {{/each}}
+ </tbody>
+ </table>
+</template>;
+
+export default IpLookupAccountsTable;
diff --git a/frontend/discourse/admin/components/ip-lookup.gjs b/frontend/discourse/admin/components/ip-lookup.gjs
index 387147c1958..4ec3a0c9693 100644
--- a/frontend/discourse/admin/components/ip-lookup.gjs
+++ b/frontend/discourse/admin/components/ip-lookup.gjs
@@ -1,14 +1,13 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
-import { LinkTo } from "@ember/routing";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
+import IpLookupAccountsTable from "discourse/admin/components/ip-lookup-accounts-table";
import AdminUser from "discourse/admin/models/admin-user";
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
import DButton from "discourse/components/d-button";
import DMenu from "discourse/float-kit/components/d-menu";
-import avatar from "discourse/helpers/avatar";
import loadingSpinner from "discourse/helpers/loading-spinner";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
@@ -240,33 +239,7 @@ export default class IpLookup extends Component {
>
{{#if this.otherAccounts}}
<dd class="other-accounts">
- <table class="table table-condensed table-hover">
- <thead>
- <tr>
- <th>{{i18n "ip_lookup.username"}}</th>
- <th>{{i18n "ip_lookup.trust_level"}}</th>
- <th>{{i18n "ip_lookup.read_time"}}</th>
- <th>{{i18n "ip_lookup.topics_entered"}}</th>
- <th>{{i18n "ip_lookup.post_count"}}</th>
- </tr>
- </thead>
- <tbody>
- {{#each this.otherAccounts as |account|}}
- <tr>
- <td class="user">
- <LinkTo @route="adminUser" @model={{account}}>
- {{avatar account imageSize="tiny"}}
- <span>{{account.username}}</span>
- </LinkTo>
- </td>
- <td>{{account.trustLevel.id}}</td>
- <td>{{account.time_read}}</td>
- <td>{{account.topics_entered}}</td>
- <td>{{account.post_count}}</td>
- </tr>
- {{/each}}
- </tbody>
- </table>
+ <IpLookupAccountsTable @accounts={{this.otherAccounts}} />
</dd>
{{/if}}
</ConditionalLoadingSpinner>
diff --git a/frontend/discourse/app/components/reviewable-refresh/insights.gjs b/frontend/discourse/app/components/reviewable-refresh/insights.gjs
index 07e08f0697f..3db1d8b93ac 100644
--- a/frontend/discourse/app/components/reviewable-refresh/insights.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/insights.gjs
@@ -1,5 +1,6 @@
import Component from "@glimmer/component";
import { htmlSafe } from "@ember/template";
+import IpLookup from "discourse/components/reviewable-refresh/ip-lookup";
import { shortDate } from "discourse/lib/formatter";
import { i18n } from "discourse-i18n";
@@ -23,13 +24,16 @@ export default class ReviewableInsights extends Component {
const user = this.args.reviewable.target_created_by;
// Flag volume insight
- insights.push({
- icon: "triangle-exclamation",
- label: i18n("review.insights.flag_volume"),
- description: i18n("review.insights.flagged_by_users", {
- count: reviewable?.reviewable_scores?.length || 0,
- }),
- });
+ const flagCount = reviewable?.reviewable_scores?.length || 0;
+ if (flagCount > 1) {
+ insights.push({
+ icon: "triangle-exclamation",
+ label: i18n("review.insights.flag_volume"),
+ description: i18n("review.insights.flagged_by_users", {
+ count: flagCount,
+ }),
+ });
+ }
// Similar posts insight
if (user?.flags_agreed) {
@@ -103,6 +107,7 @@ export default class ReviewableInsights extends Component {
</div>
</div>
{{/each}}
+ <IpLookup @reviewable={{@reviewable}} />
</div>
</template>
}
diff --git a/frontend/discourse/app/components/reviewable-refresh/ip-lookup.gjs b/frontend/discourse/app/components/reviewable-refresh/ip-lookup.gjs
index 326307b5a9c..ce2217f2ddf 100644
--- a/frontend/discourse/app/components/reviewable-refresh/ip-lookup.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/ip-lookup.gjs
@@ -1,16 +1,39 @@
import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { on } from "@ember/modifier";
+import { action } from "@ember/object";
import { service } from "@ember/service";
-import { optionalRequire } from "discourse/lib/utilities";
+import { htmlSafe } from "@ember/template";
+import IpLookupAccountsTable from "discourse/admin/components/ip-lookup-accounts-table";
+import AdminUser from "discourse/admin/models/admin-user";
+import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
+import DButton from "discourse/components/d-button";
+import DModal from "discourse/components/d-modal";
+import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { i18n } from "discourse-i18n";
+
+const MAX_ACCOUNTS_TO_DELETE = 50;
export default class ReviewableIpLookup extends Component {
@service currentUser;
+ @service modal;
+ @service dialog;
- get showIpLookup() {
- return this.currentUser.staff && this.target;
+ @tracked location;
+ @tracked otherAccounts;
+ @tracked loading = true;
+ @tracked otherAccountsLoading = false;
+ @tracked totalOthersWithSameIP;
+ @tracked ipAddress;
+
+ constructor() {
+ super(...arguments);
+ this.loadIpData();
}
- get IpLookupComponent() {
- return optionalRequire("discourse/admin/components/ip-lookup");
+ get showIpLookup() {
+ return this.currentUser.staff && this.target;
}
get target() {
@@ -19,11 +42,192 @@ export default class ReviewableIpLookup extends Component {
: this.args.reviewable.target_created_by?.id;
}
+ get otherAccountsToDelete() {
+ return Math.min(MAX_ACCOUNTS_TO_DELETE, this.totalOthersWithSameIP || 0);
+ }
+
+ get canDeleteOtherAccounts() {
+ return this.totalOthersWithSameIP && !this.otherAccountsLoading;
+ }
+
+ get queryData() {
+ return {
+ ip: this.ipAddress,
+ exclude: this.target,
+ order: "trust_level DESC",
+ };
+ }
+
+ @action
+ async loadIpData() {
+ try {
+ const userInfo = await AdminUser.find(this.target);
+ this.ipAddress = userInfo.ip_address;
+
+ if (this.ipAddress) {
+ this.location = await ajax("/admin/users/ip-info", {
+ data: { ip: this.ipAddress },
+ });
+
+ const result = await ajax("/admin/users/total-others-with-same-ip", {
+ data: this.queryData,
+ });
+ this.totalOthersWithSameIP = result.total;
+ }
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.loading = false;
+ }
+ }
+
+ @action
+ async loadOtherAccounts() {
+ if (this.otherAccounts || this.otherAccountsLoading) {
+ return;
+ }
+
+ this.otherAccountsLoading = true;
+
+ try {
+ this.otherAccounts = await AdminUser.findAll("active", this.queryData);
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.otherAccountsLoading = false;
+ }
+ }
+
+ @action
+ async deleteOtherAccounts() {
+ this.dialog.yesNoConfirm({
+ message: i18n("ip_lookup.confirm_delete_other_accounts"),
+ didConfirm: async () => {
+ this.otherAccounts = null;
+ this.otherAccountsLoading = true;
+ this.totalOthersWithSameIP = null;
+
+ try {
+ await ajax("/admin/users/delete-others-with-same-ip.json", {
+ type: "DELETE",
+ data: this.queryData,
+ });
+ this.modal.close();
+ } catch (err) {
+ popupAjaxError(err);
+ } finally {
+ this.otherAccountsLoading = false;
+ }
+ },
+ });
+ }
+
+ @action
+ async showOtherAccountsModal() {
+ await this.loadOtherAccounts();
+
+ this.modal.show(OtherAccountsModal, {
+ model: {
+ otherAccounts: this.otherAccounts,
+ totalOthersWithSameIP: this.totalOthersWithSameIP,
+ otherAccountsLoading: this.otherAccountsLoading,
+ otherAccountsToDelete: this.otherAccountsToDelete,
+ canDeleteOtherAccounts: this.canDeleteOtherAccounts,
+ deleteOtherAccounts: this.deleteOtherAccounts,
+ },
+ });
+ }
+
<template>
{{#if this.showIpLookup}}
- <div class="reviewable-ip-lookup">
- <this.IpLookupComponent @ip="adminLookup" @userId={{this.target}} />
- </div>
+ {{#if this.loading}}
+ <ConditionalLoadingSpinner @size="small" @condition={{this.loading}} />
+ {{else if this.location}}
+ <div class="reviewable-ip-lookup">
+ <div class="review-insight__item">
+ <div class="review-insight__content">
+ <div class="review-insight__label">
+ {{i18n "ip_lookup.title"}}
+ <span class="ip-lookup-powered-by">
+ ({{htmlSafe (i18n "ip_lookup.powered_by")}})
+ </span>
+ </div>
+ <div class="review-insight__description">
+ {{#if this.location.hostname}}
+ {{i18n "ip_lookup.hostname"}}:
+ {{this.location.hostname}},
+ {{/if}}
+ {{i18n "ip_lookup.location"}}:
+ {{#if this.location.location}}
+ <a
+ href="https://maps.google.com/maps?q={{this.location.latitude}},{{this.location.longitude}}"
+ rel="noopener noreferrer"
+ target="_blank"
+ >
+ {{this.location.location}}
+ </a>
+ {{else}}
+ {{i18n "ip_lookup.location_not_found"}}
+ {{/if}}
+ {{#if this.location.organization}}
+ ,
+ {{i18n "ip_lookup.organisation"}}:
+ {{this.location.organization}}
+ {{/if}}
+ </div>
+ {{#if this.totalOthersWithSameIP}}
+ <div class="review-insight__description">
+ <button
+ type="button"
+ {{on "click" this.showOtherAccountsModal}}
+ class="btn-link ip-lookup-other-accounts-link"
+ >
+ {{i18n
+ "ip_lookup.other_accounts_with_ip"
+ count=this.totalOthersWithSameIP
+ }}
+ </button>
+ </div>
+ {{/if}}
+ </div>
+ </div>
+ </div>
+ {{/if}}
{{/if}}
</template>
}
+
+const OtherAccountsModal = <template>
+ <DModal
+ @title={{i18n
+ "ip_lookup.other_accounts_with_ip"
+ }}
+ @closeModal={{@closeModal}}
+ class="ip-lookup-other-accounts-modal"
+ >
+ <:body>
+ {{#if @model.otherAccountsLoading}}
+ <ConditionalLoadingSpinner
+ @size="small"
+ @condition={{@model.otherAccountsLoading}}
+ />
+ {{else if @model.otherAccounts}}
+ <IpLookupAccountsTable @accounts={{@model.otherAccounts}} />
+ {{/if}}
+ </:body>
+ <:footer>
+ {{#if @model.canDeleteOtherAccounts}}
+ <DButton
+ @action={{@model.deleteOtherAccounts}}
+ @icon="triangle-exclamation"
+ @translatedLabel={{i18n
+ "ip_lookup.delete_other_accounts"
+ }}
+ class="btn-danger"
+ />
+ {{/if}}
+ </:footer>
+ </DModal>
+</template>;
diff --git a/frontend/discourse/app/components/reviewable-refresh/item.gjs b/frontend/discourse/app/components/reviewable-refresh/item.gjs
index 7e283597c2f..855080db534 100644
--- a/frontend/discourse/app/components/reviewable-refresh/item.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/item.gjs
@@ -21,7 +21,6 @@ import ReviewableCreatedBy from "discourse/components/reviewable-created-by";
import ReviewableFlagReason from "discourse/components/reviewable-refresh/flag-reason";
import ReviewableHelpResources from "discourse/components/reviewable-refresh/help-resources";
import ReviewableInsights from "discourse/components/reviewable-refresh/insights";
-import IpLookup from "discourse/components/reviewable-refresh/ip-lookup";
import ReviewableTimeline from "discourse/components/reviewable-refresh/timeline";
import concatClass from "discourse/helpers/concat-class";
import icon from "discourse/helpers/d-icon";
@@ -285,15 +284,6 @@ export default class ReviewableItem extends Component {
return updatedCategoryId || categoryId;
}
- @discourseComputed("reviewable.type", "reviewable.target_created_by")
- showIpLookup(reviewableType) {
- return (
- reviewableType !== "ReviewableUser" &&
- this.currentUser.staff &&
- this.reviewable.target_created_by
- );
- }
-
@discourseComputed("reviewable.reviewable_scores")
scoreSummary(scores) {
const scoreData = scores.reduce((acc, score) => {
@@ -882,7 +872,6 @@ export default class ReviewableItem extends Component {
/>
</div>
{{/if}}
- <IpLookup @reviewable={{this.reviewable}} />
{{#if @showHelp}}
<ReviewableHelpResources />
diff --git a/spec/system/page_objects/pages/refreshed_review.rb b/spec/system/page_objects/pages/refreshed_review.rb
index 1318a5c01e1..36d4dbd4bb5 100644
--- a/spec/system/page_objects/pages/refreshed_review.rb
+++ b/spec/system/page_objects/pages/refreshed_review.rb
@@ -72,8 +72,36 @@ module PageObjects
find(".reviewable-action.save-edit").click
end
- def click_ip_lookup_button
- find(".reviewable-ip-lookup button").click
+ def has_ip_lookup_info?
+ page.has_css?(".reviewable-ip-lookup")
+ end
+
+ def has_ip_location?(location)
+ page.has_text?(location)
+ end
+
+ def has_ip_hostname?(hostname)
+ page.has_text?(hostname)
+ end
+
+ def has_ip_organization?(organization)
+ page.has_text?(organization)
+ end
+
+ def has_other_accounts_link?(count:)
+ page.has_button?(I18n.t("js.ip_lookup.other_accounts_with_ip", count: count))
+ end
+
+ def click_other_accounts_link
+ find(".ip-lookup-other-accounts-link").click
+ end
+
+ def has_ip_lookup_modal?
+ page.has_css?(".ip-lookup-other-accounts-modal")
+ end
+
+ def has_account_in_modal?(username)
+ within(".ip-lookup-other-accounts-modal") { page.has_text?(username) }
end
private
diff --git a/spec/system/viewing_reviewable_spec.rb b/spec/system/viewing_reviewable_spec.rb
index c6b8c49813d..d17b9e42418 100644
--- a/spec/system/viewing_reviewable_spec.rb
+++ b/spec/system/viewing_reviewable_spec.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require "discourse_ip_info"
+
describe "Viewing reviewable item", type: :system do
fab!(:admin)
fab!(:group)
@@ -143,11 +145,55 @@ describe "Viewing reviewable item", type: :system do
expect(page).to have_current_path("/")
end
- it "allows to lookup IP" do
- SiteSetting.reviewable_old_moderator_actions = true
- refreshed_review_page.visit_reviewable(reviewable_flagged_post)
- refreshed_review_page.click_ip_lookup_button
- expect(page).to have_content(I18n.t("js.ip_lookup.hostname"))
+ describe "IP lookup" do
+ fab!(:reviewable_flagged_post)
+
+ before do
+ reviewable_flagged_post.target_created_by.update!(ip_address: "81.2.69.142")
+
+ DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb"))
+ Resolv::DNS
+ .any_instance
+ .stubs(:getname)
+ .with("81.2.69.142")
+ .returns("ip-81-2-69-142.example.com")
+ end
+
+ it "shows IP lookup information when insights tab is viewed" do
+ refreshed_review_page.visit_reviewable(reviewable_flagged_post)
+ refreshed_review_page.click_insights_tab
+
+ expect(refreshed_review_page).to have_ip_lookup_info
+ end
+
+ it "displays IP location, hostname, and organization when available" do
+ refreshed_review_page.visit_reviewable(reviewable_flagged_post)
+ refreshed_review_page.click_insights_tab
+
+ expect(refreshed_review_page).to have_ip_location("London, England, United Kingdom")
+ expect(refreshed_review_page).to have_ip_hostname("ip-81-2-69-142.example.com")
+ end
+
+ it "shows other accounts link when there are multiple accounts with same IP" do
+ other_user_1 = Fabricate(:user, ip_address: "81.2.69.142")
+ other_user_2 = Fabricate(:user, ip_address: "81.2.69.142")
+
+ refreshed_review_page.visit_reviewable(reviewable_flagged_post)
+ refreshed_review_page.click_insights_tab
+
+ expect(refreshed_review_page).to have_other_accounts_link(count: 2)
+ end
+
+ it "opens modal with account list when clicking other accounts link" do
+ other_user = Fabricate(:user, username: "suspicious_user", ip_address: "81.2.69.142")
+
+ refreshed_review_page.visit_reviewable(reviewable_flagged_post)
+ refreshed_review_page.click_insights_tab
+ refreshed_review_page.click_other_accounts_link
+
+ expect(refreshed_review_page).to have_ip_lookup_modal
+ expect(refreshed_review_page).to have_account_in_modal(other_user.username)
+ end
end
end