Allow to filter reports by domain
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
26b1ea401a
commit
193fcde123
|
@ -2,8 +2,13 @@ import gql from "graphql-tag";
|
||||||
import { ACTOR_FRAGMENT } from "./actor";
|
import { ACTOR_FRAGMENT } from "./actor";
|
||||||
|
|
||||||
export const REPORTS = gql`
|
export const REPORTS = gql`
|
||||||
query Reports($status: ReportStatus, $page: Int, $limit: Int) {
|
query Reports(
|
||||||
reports(status: $status, page: $page, limit: $limit) {
|
$status: ReportStatus
|
||||||
|
$domain: String
|
||||||
|
$page: Int
|
||||||
|
$limit: Int
|
||||||
|
) {
|
||||||
|
reports(status: $status, domain: $domain, page: $page, limit: $limit) {
|
||||||
total
|
total
|
||||||
elements {
|
elements {
|
||||||
id
|
id
|
||||||
|
|
|
@ -20,7 +20,7 @@ export enum SettingsRouteName {
|
||||||
ADMIN_GROUPS = "ADMIN_GROUPS",
|
ADMIN_GROUPS = "ADMIN_GROUPS",
|
||||||
ADMIN_GROUP_PROFILE = "ADMIN_GROUP_PROFILE",
|
ADMIN_GROUP_PROFILE = "ADMIN_GROUP_PROFILE",
|
||||||
MODERATION = "MODERATION",
|
MODERATION = "MODERATION",
|
||||||
REPORTS = "Reports",
|
REPORTS = "REPORTS",
|
||||||
REPORT = "Report",
|
REPORT = "Report",
|
||||||
REPORT_LOGS = "Logs",
|
REPORT_LOGS = "Logs",
|
||||||
CREATE_IDENTITY = "CreateIdentity",
|
CREATE_IDENTITY = "CreateIdentity",
|
||||||
|
@ -234,7 +234,7 @@ export const settingsRoutes: RouteConfig[] = [
|
||||||
meta: { requiredAuth: true, announcer: { skip: true } },
|
meta: { requiredAuth: true, announcer: { skip: true } },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/moderation/reports/:filter?",
|
path: "/moderation/reports",
|
||||||
name: SettingsRouteName.REPORTS,
|
name: SettingsRouteName.REPORTS,
|
||||||
component: (): Promise<ImportedComponent> =>
|
component: (): Promise<ImportedComponent> =>
|
||||||
import(
|
import(
|
||||||
|
|
|
@ -70,7 +70,10 @@
|
||||||
<span class="text-sm block">{{ $t("Followers") }}</span>
|
<span class="text-sm block">{{ $t("Followers") }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-gray-50 rounded-xl p-8 dark:bg-gray-800">
|
<div class="bg-gray-50 rounded-xl p-8 dark:bg-gray-800">
|
||||||
<router-link to="/" class="dark:text-white hover:dark:text-slate-300">
|
<router-link
|
||||||
|
:to="{ name: RouteName.REPORTS, query: { domain: instance.domain } }"
|
||||||
|
class="dark:text-white hover:dark:text-slate-300"
|
||||||
|
>
|
||||||
<span class="mb-4 text-xl font-semibold block">{{
|
<span class="mb-4 text-xl font-semibold block">{{
|
||||||
instance.reportsCount
|
instance.reportsCount
|
||||||
}}</span>
|
}}</span>
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<section>
|
<section>
|
||||||
<b-field>
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<b-field :label="$t('Report status')">
|
||||||
<b-radio-button
|
<b-radio-button
|
||||||
v-model="status"
|
v-model="status"
|
||||||
:native-value="ReportStatusEnum.OPEN"
|
:native-value="ReportStatusEnum.OPEN"
|
||||||
|
@ -32,6 +33,19 @@
|
||||||
>{{ $t("Closed") }}</b-radio-button
|
>{{ $t("Closed") }}</b-radio-button
|
||||||
>
|
>
|
||||||
</b-field>
|
</b-field>
|
||||||
|
<b-field
|
||||||
|
:label="$t('Domain')"
|
||||||
|
label-for="domain-filter"
|
||||||
|
class="flex-auto"
|
||||||
|
>
|
||||||
|
<b-input
|
||||||
|
id="domain-filter"
|
||||||
|
:placeholder="$t('mobilizon-instance.tld')"
|
||||||
|
:value="filterDomain"
|
||||||
|
@input="debouncedUpdateDomainFilter"
|
||||||
|
/>
|
||||||
|
</b-field>
|
||||||
|
</div>
|
||||||
<ul v-if="reports.elements.length > 0">
|
<ul v-if="reports.elements.length > 0">
|
||||||
<li v-for="report in reports.elements" :key="report.id">
|
<li v-for="report in reports.elements" :key="report.id">
|
||||||
<router-link
|
<router-link
|
||||||
|
@ -79,7 +93,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue } from "vue-property-decorator";
|
import { Component, Ref, Vue } from "vue-property-decorator";
|
||||||
import { IReport } from "@/types/report.model";
|
import { IReport } from "@/types/report.model";
|
||||||
import { REPORTS } from "@/graphql/report";
|
import { REPORTS } from "@/graphql/report";
|
||||||
import ReportCard from "@/components/Report/ReportCard.vue";
|
import ReportCard from "@/components/Report/ReportCard.vue";
|
||||||
|
@ -88,6 +102,7 @@ import { ReportStatusEnum } from "@/types/enums";
|
||||||
import RouteName from "../../router/name";
|
import RouteName from "../../router/name";
|
||||||
import VueRouter from "vue-router";
|
import VueRouter from "vue-router";
|
||||||
import { Paginate } from "@/types/paginate";
|
import { Paginate } from "@/types/paginate";
|
||||||
|
import debounce from "lodash/debounce";
|
||||||
const { isNavigationFailure, NavigationFailureType } = VueRouter;
|
const { isNavigationFailure, NavigationFailureType } = VueRouter;
|
||||||
|
|
||||||
const REPORT_PAGE_LIMIT = 10;
|
const REPORT_PAGE_LIMIT = 10;
|
||||||
|
@ -106,6 +121,7 @@ const REPORT_PAGE_LIMIT = 10;
|
||||||
page: this.page,
|
page: this.page,
|
||||||
status: this.status,
|
status: this.status,
|
||||||
limit: REPORT_PAGE_LIMIT,
|
limit: REPORT_PAGE_LIMIT,
|
||||||
|
domain: this.filterDomain,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
pollInterval: 120000, // 2 minutes
|
pollInterval: 120000, // 2 minutes
|
||||||
|
@ -128,18 +144,28 @@ export default class ReportList extends Vue {
|
||||||
|
|
||||||
REPORT_PAGE_LIMIT = REPORT_PAGE_LIMIT;
|
REPORT_PAGE_LIMIT = REPORT_PAGE_LIMIT;
|
||||||
|
|
||||||
|
data(): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
debouncedUpdateDomainFilter: debounce(this.updateDomainFilter, 500),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateDomainFilter(domain: string) {
|
||||||
|
this.filterDomain = domain;
|
||||||
|
}
|
||||||
|
|
||||||
get page(): number {
|
get page(): number {
|
||||||
return parseInt((this.$route.query.page as string) || "1", 10);
|
return parseInt((this.$route.query.page as string) || "1", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
set page(page: number) {
|
set page(page: number) {
|
||||||
this.pushRouter(RouteName.REPORTS, {
|
this.pushRouter({
|
||||||
page: page.toString(),
|
page: page.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get status(): ReportStatusEnum {
|
get status(): ReportStatusEnum {
|
||||||
const filter = this.$route.params.filter?.toUpperCase();
|
const filter = (this.$route.query.status || "") as string;
|
||||||
if (filter in ReportStatusEnum) {
|
if (filter in ReportStatusEnum) {
|
||||||
return filter as ReportStatusEnum;
|
return filter as ReportStatusEnum;
|
||||||
}
|
}
|
||||||
|
@ -147,19 +173,21 @@ export default class ReportList extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
set status(status: ReportStatusEnum) {
|
set status(status: ReportStatusEnum) {
|
||||||
this.$router.push({
|
this.pushRouter({ status });
|
||||||
name: RouteName.REPORTS,
|
|
||||||
params: { filter: status.toLowerCase() },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async pushRouter(
|
get filterDomain(): string {
|
||||||
routeName: string,
|
return (this.$route.query.domain as string) || "";
|
||||||
args: Record<string, string>
|
}
|
||||||
): Promise<void> {
|
|
||||||
|
set filterDomain(domain: string) {
|
||||||
|
this.pushRouter({ domain });
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async pushRouter(args: Record<string, string>): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await this.$router.push({
|
await this.$router.push({
|
||||||
name: routeName,
|
name: RouteName.REPORTS,
|
||||||
params: this.$route.params,
|
params: this.$route.params,
|
||||||
query: { ...this.$route.query, ...args },
|
query: { ...this.$route.query, ...args },
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,11 +17,19 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
||||||
{:ok, Page.t(Report.t())} | {:error, String.t()}
|
{:ok, Page.t(Report.t())} | {:error, String.t()}
|
||||||
def list_reports(
|
def list_reports(
|
||||||
_parent,
|
_parent,
|
||||||
%{page: page, limit: limit, status: status},
|
%{page: page, limit: limit} = args,
|
||||||
%{context: %{current_user: %User{role: role}}}
|
%{context: %{current_user: %User{role: role}}}
|
||||||
)
|
)
|
||||||
when is_moderator(role) do
|
when is_moderator(role) do
|
||||||
{:ok, Mobilizon.Reports.list_reports(page, limit, :updated_at, :desc, status)}
|
{:ok,
|
||||||
|
Mobilizon.Reports.list_reports(
|
||||||
|
page: page,
|
||||||
|
limit: limit,
|
||||||
|
sort: :updated_at,
|
||||||
|
direction: :desc,
|
||||||
|
status: Map.get(args, :status),
|
||||||
|
domain: Map.get(args, :domain)
|
||||||
|
)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_reports(_parent, _args, _resolution) do
|
def list_reports(_parent, _args, _resolution) do
|
||||||
|
|
|
@ -67,6 +67,7 @@ defmodule Mobilizon.GraphQL.Schema.ReportType do
|
||||||
|
|
||||||
arg(:limit, :integer, default_value: 10, description: "The limit of reports per page")
|
arg(:limit, :integer, default_value: 10, description: "The limit of reports per page")
|
||||||
arg(:status, :report_status, default_value: :open, description: "Filter reports by status")
|
arg(:status, :report_status, default_value: :open, description: "Filter reports by status")
|
||||||
|
arg(:domain, :string, default_value: nil, description: "Filter reports by domain name")
|
||||||
resolve(&Report.list_reports/3)
|
resolve(&Report.list_reports/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule Mobilizon.Reports do
|
||||||
|
|
||||||
import Mobilizon.Storage.Ecto
|
import Mobilizon.Storage.Ecto
|
||||||
|
|
||||||
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Reports.{Note, Report}
|
alias Mobilizon.Reports.{Note, Report}
|
||||||
alias Mobilizon.Storage.{Page, Repo}
|
alias Mobilizon.Storage.{Page, Repo}
|
||||||
|
|
||||||
|
@ -49,17 +50,18 @@ defmodule Mobilizon.Reports do
|
||||||
@doc """
|
@doc """
|
||||||
Returns the list of reports.
|
Returns the list of reports.
|
||||||
"""
|
"""
|
||||||
@spec list_reports(integer | nil, integer | nil, atom, atom, ReportStatus.t()) ::
|
@spec list_reports(Keyword.t()) :: Page.t(Report.t())
|
||||||
Page.t(Report.t())
|
def list_reports(options) do
|
||||||
def list_reports(
|
page = Keyword.get(options, :page)
|
||||||
page \\ nil,
|
limit = Keyword.get(options, :limit)
|
||||||
limit \\ nil,
|
sort = Keyword.get(options, :sort, :updated_at)
|
||||||
sort \\ :updated_at,
|
direction = Keyword.get(options, :direction, :asc)
|
||||||
direction \\ :asc,
|
status = Keyword.get(options, :status, :open)
|
||||||
status \\ :open
|
domain = Keyword.get(options, :domain)
|
||||||
) do
|
|
||||||
status
|
status
|
||||||
|> list_reports_query()
|
|> list_reports_query()
|
||||||
|
|> filter_domain_name(domain)
|
||||||
|> sort(sort, direction)
|
|> sort(sort, direction)
|
||||||
|> Page.build_page(page, limit)
|
|> Page.build_page(page, limit)
|
||||||
end
|
end
|
||||||
|
@ -99,11 +101,19 @@ defmodule Mobilizon.Reports do
|
||||||
|
|
||||||
@spec list_reports_query(ReportStatus.t()) :: Ecto.Query.t()
|
@spec list_reports_query(ReportStatus.t()) :: Ecto.Query.t()
|
||||||
defp list_reports_query(status) do
|
defp list_reports_query(status) do
|
||||||
from(
|
Report
|
||||||
r in Report,
|
|> preload([:reported, :reporter, :manager, :event, :comments, :notes])
|
||||||
preload: [:reported, :reporter, :manager, :event, :comments, :notes],
|
|> where([r], r.status == ^status)
|
||||||
where: r.status == ^status
|
end
|
||||||
)
|
|
||||||
|
@spec filter_domain_name(Ecto.Queryable.t(), String.t() | nil) :: Ecto.Queryable.t()
|
||||||
|
defp filter_domain_name(query, nil), do: query
|
||||||
|
defp filter_domain_name(query, ""), do: query
|
||||||
|
|
||||||
|
defp filter_domain_name(query, domain) do
|
||||||
|
query
|
||||||
|
|> join(:inner, [r], a in Actor, on: a.id == r.reported_id)
|
||||||
|
|> where([_r, a], like(a.domain, ^"%#{domain}%"))
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec count_reports_query :: Ecto.Query.t()
|
@spec count_reports_query :: Ecto.Query.t()
|
||||||
|
|
Loading…
Reference in a new issue