Skip to content

Commit

Permalink
feat(moderation): hide domaines by default
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Oct 2, 2024
1 parent 6bbd058 commit ebc1e23
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 26 deletions.
6 changes: 4 additions & 2 deletions e2e/features/moderations/jean_bon_join_abracadabra.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Fonctionnalité: Moderation blockante à accepter
Quand sur la même ligne je clique sur "➡️"
Alors je vois "Jean Bon veut rejoindre l'organisation « Abracadabra » avec l’adresse [email protected]"

Quand je clique sur "🌐 1 domaine connu dans l'organisation"

Scénario: Domaine interne
Soit le tableau sous le title "Domaines de l'organisation"
Soit le tableau sous le title "🌐 1 domaine connu dans l'organisation"
* je vois la ligne "yopmail.com" dans le tableau
* sur la même ligne je vois "❓"
* sur la même ligne je vois "Menu"
Expand All @@ -40,7 +42,7 @@ Fonctionnalité: Moderation blockante à accepter
Alors sur la même ligne je vois "✅"

Scénario: Domaine externe
Soit le tableau sous le title "Domaines de l'organisation"
Soit le tableau sous le title "🌐 1 domaine connu dans l'organisation"
* je vois la ligne "yopmail.com" dans le tableau
Quand j'ouvre le menu déroulant sur la même ligne
* je clique sur le bouton "❎ Domaine externe"
Expand Down
4 changes: 2 additions & 2 deletions e2e/features/moderations/marie_bon_join_bosch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Fonctionnalité: Moderation non blockante
Alors je vois "Marie Bon a rejoint une organisation avec un domain non vérifié « Robert bosch france » avec l’adresse [email protected]"

Scénario: Le nom de domaine est vérifié
Soit le tableau sous le title "Domaines de l'organisation"
Soit le tableau sous le title "domaine connu dans l'organisation"
* le tableau est vide
Quand je clique sur "Je valide ce membre ✅"
Quand je clique sur "J’autorise le domaine fr.bosch.com pour toute l’organisation"
Expand All @@ -30,7 +30,7 @@ Fonctionnalité: Moderation non blockante
* je vois la ligne de table "57206768400017"
Quand sur la même ligne je clique sur "✅"

Soit le tableau sous le title "Domaines de l'organisation"
Soit le tableau sous le title "domaine connu dans l'organisation"
* je vois la ligne "fr.bosch.com" dans le tableau
* sur la même ligne je vois "✅"

Expand Down
4 changes: 2 additions & 2 deletions e2e/features/organizations/dinum.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Fonctionnalité: Page organisation
* je vois "État administratif : A (liste état administratif INSEE)"
* je vois "Siret : 13002526500013 (Voir la fiche annuaire entreprise de cette organisation)"

# Scénario: Domaines de l'organisation DINUM
Soit le tableau sous le title "Domaines de l'organisation"
# Scénario: domaine connu dans l'organisation DINUM
Soit le tableau sous le title "domaine connu dans l'organisation"
* je vois la ligne "beta.gouv.fr" dans le tableau
* sur la même ligne je vois "✅"
* sur la même ligne je vois "verified"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Fonctionnalité: Page organisation - domaine à vérifier
Alors je vois "A propos de « Yes we hack »"
* je vois "Dénomination : Yes we hack"

Soit le tableau sous le title "Domaines de l'organisation"
Soit le tableau sous le title "domaine connu dans l'organisation"
* je vois la ligne "yeswehack.com" dans le tableau
* sur la même ligne je vois "❓"

Expand Down
49 changes: 31 additions & 18 deletions packages/~/moderations/api/src/:id/Domain_Organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { hyper_ref } from "@~/app.core/html";
import { hx_trigger_from_body } from "@~/app.core/htmx";
import { Loader } from "@~/app.ui/loader/Loader";
import { formattedPlural } from "@~/app.ui/plurial";
import { hx_urls } from "@~/app.urls";
import { ORGANISATION_EVENTS } from "@~/organizations.lib/event";
import { usePageRequestContext } from "./context";
Expand All @@ -14,28 +15,40 @@ export async function Domain_Organization() {
const {
var: {
moderation: { organization },
query_domain_count,
},
} = usePageRequestContext();
const count = await query_domain_count;
return (
<section>
<h3 id={$describedby}>🌐 Domaines de l'organisation</h3>

<div
{...await hx_urls.organizations[":id"].domains.$get({
param: {
id: organization.id.toString(),
},
query: { describedby: $describedby },
})}
hx-trigger={[
"load",
...hx_trigger_from_body([ORGANISATION_EVENTS.Enum.DOMAIN_UPDATED]),
].join(", ")}
>
<center>
<Loader />
</center>
</div>
<details>
<summary>
<h3 class="inline-block" id={$describedby}>
🌐 {count}{" "}
{formattedPlural(count, {
one: "domaine connu",
other: "domaine connus",
})}{" "}
dans l'organisation
</h3>
</summary>
<div
{...await hx_urls.organizations[":id"].domains.$get({
param: {
id: organization.id.toString(),
},
query: { describedby: $describedby },
})}
hx-trigger={[
"load",
...hx_trigger_from_body([ORGANISATION_EVENTS.Enum.DOMAIN_UPDATED]),
].join(", ")}
>
<center>
<Loader />
</center>
</div>
</details>
</section>
);
}
2 changes: 2 additions & 0 deletions packages/~/moderations/api/src/:id/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NotFoundError } from "@~/app.core/error";
import type { App_Context } from "@~/app.middleware/context";
import { urls } from "@~/app.urls";
import { schema, type MonComptePro_PgDatabase } from "@~/moncomptepro.database";
import { type get_domain_count_dto } from "@~/organizations.repository/get_domain_count";
import { type get_organization_members_count_dto } from "@~/organizations.repository/get_organization_members_count";
import { and, eq } from "drizzle-orm";
import type { Env, InferRequestType } from "hono";
Expand All @@ -24,6 +25,7 @@ export interface ContextVariablesType extends Env {
moderation: get_moderation_dto;
organization_member: get_organization_member_dto;
query_organization_members_count: Promise<get_organization_members_count_dto>;
query_domain_count: Promise<get_domain_count_dto>;
};
}
export type ContextType = App_Context & ContextVariablesType;
Expand Down
13 changes: 13 additions & 0 deletions packages/~/moderations/api/src/:id/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NotFoundError } from "@~/app.core/error";
import { Entity_Schema } from "@~/app.core/schema";
import { z_email_domain } from "@~/app.core/schema/z_email_domain";
import { Main_Layout } from "@~/app.layout/index";
import { get_domain_count } from "@~/organizations.repository/get_domain_count";
import { get_organization_members_count } from "@~/organizations.repository/get_organization_members_count";
import { to } from "await-to-js";
import { Hono } from "hono";
Expand Down Expand Up @@ -68,6 +69,18 @@ export default new Hono<ContextType>()
set("organization_member", organization_member);
return next();
},
async function set_query_domain_count(
{ set, var: { moderation, moncomptepro_pg } },
next,
) {
set(
"query_domain_count",
get_domain_count(moncomptepro_pg, {
organization_id: moderation.organization_id,
}),
);
return next();
},
async function set_query_organization_members_count(
{ set, var: { moderation, moncomptepro_pg } },
next,
Expand Down
2 changes: 1 addition & 1 deletion packages/~/organizations/api/src/:id/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function Page() {

<Fiche />

<h3 id={$domains_describedby}>🌐 Domaines de l'organisation</h3>
<h3 id={$domains_describedby}>🌐 domaine connu dans l'organisation</h3>
<div
{...hx_get_domains_query_props}
hx-trigger={[
Expand Down
52 changes: 52 additions & 0 deletions packages/~/organizations/repository/src/get_domain_count.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//

import { schema } from "@~/moncomptepro.database";
import { create_unicorn_organization } from "@~/moncomptepro.database/seed/unicorn";
import { empty_database, migrate, pg } from "@~/moncomptepro.database/testing";
import { beforeAll, beforeEach, expect, test } from "bun:test";
import { get_domain_count } from "./get_domain_count";

//

beforeAll(migrate);
beforeEach(empty_database);

//

test("returns no member", async () => {
const unicorn_organization_id = await create_unicorn_organization(pg);

const domain_unicorn = await get_domain_count(pg, {
organization_id: unicorn_organization_id,
});

expect(domain_unicorn).toEqual(0);
});

test("returns 1 member", async () => {
const unicorn_organization_id = await create_unicorn_organization(pg);

const domain_unicorn = await get_domain_count(pg, {
organization_id: unicorn_organization_id,
});

expect(domain_unicorn).toBe(1);
});

test.only("returns 3 domains", async () => {
const unicorn_organization_id = await create_unicorn_organization(pg);
await pg.insert(schema.email_domains).values({
domain: "bi.corn",
organization_id: unicorn_organization_id,
});
await pg.insert(schema.email_domains).values({
domain: "xorn.corn",
organization_id: unicorn_organization_id,
});

const domain_unicorn = await get_domain_count(pg, {
organization_id: unicorn_organization_id,
});

expect(domain_unicorn).toBe(3);
});
24 changes: 24 additions & 0 deletions packages/~/organizations/repository/src/get_domain_count.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//

import { schema, type MonComptePro_PgDatabase } from "@~/moncomptepro.database";
import { count as drizzle_count, eq } from "drizzle-orm";

//

export async function get_domain_count(
pg: MonComptePro_PgDatabase,
{ organization_id }: { organization_id: number },
) {
const [{ value: count }] = await pg
.select({ value: drizzle_count() })
.from(schema.email_domains)
.innerJoin(
schema.organizations,
eq(schema.email_domains.organization_id, schema.organizations.id),
)
.where(eq(schema.organizations.id, organization_id));

return count;
}

export type get_domain_count_dto = Awaited<ReturnType<typeof get_domain_count>>;

0 comments on commit ebc1e23

Please sign in to comment.