Compare commits
8 Commits
9b6322c546
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f56d84e76b | |||
| 3423ac2e7e | |||
| 2d2ac79cd5 | |||
| 21bca67e6a | |||
| 56d72eeec2 | |||
| 3b339b643c | |||
| 3ba9c43ce3 | |||
| 1f92f153c5 |
@@ -0,0 +1,301 @@
|
|||||||
|
"""initial schema
|
||||||
|
|
||||||
|
Revision ID: 0b9c1d2e3f4a
|
||||||
|
Revises:
|
||||||
|
Create Date: 2026-04-23 00:00:00.000000+00:00
|
||||||
|
|
||||||
|
Idempotent: uses CREATE TABLE IF NOT EXISTS so it is safe to run
|
||||||
|
against a DB that was already bootstrapped via SQLAlchemy create_all().
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision: str = '0b9c1d2e3f4a'
|
||||||
|
down_revision: Union[str, None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS duniter_identities (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
address VARCHAR(64) NOT NULL,
|
||||||
|
display_name VARCHAR(128),
|
||||||
|
wot_status VARCHAR(32) NOT NULL DEFAULT 'unknown',
|
||||||
|
is_smith BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
is_techcomm BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
op.execute("CREATE UNIQUE INDEX IF NOT EXISTS ix_duniter_identities_address ON duniter_identities (address)")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS sessions (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
token_hash VARCHAR(128) NOT NULL,
|
||||||
|
identity_id UUID NOT NULL REFERENCES duniter_identities(id),
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
expires_at TIMESTAMPTZ NOT NULL
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
op.execute("CREATE UNIQUE INDEX IF NOT EXISTS ix_sessions_token_hash ON sessions (token_hash)")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS organizations (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
name VARCHAR(128) NOT NULL,
|
||||||
|
slug VARCHAR(128) NOT NULL,
|
||||||
|
org_type VARCHAR(64) NOT NULL DEFAULT 'community',
|
||||||
|
is_transparent BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
color VARCHAR(32),
|
||||||
|
icon VARCHAR(64),
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
op.execute("CREATE UNIQUE INDEX IF NOT EXISTS ix_organizations_slug ON organizations (slug)")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS org_members (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
org_id UUID NOT NULL REFERENCES organizations(id),
|
||||||
|
identity_id UUID NOT NULL REFERENCES duniter_identities(id),
|
||||||
|
role VARCHAR(32) NOT NULL DEFAULT 'member',
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS formula_configs (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
name VARCHAR(128) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
duration_days INTEGER NOT NULL DEFAULT 30,
|
||||||
|
majority_pct INTEGER NOT NULL DEFAULT 50,
|
||||||
|
base_exponent FLOAT NOT NULL DEFAULT 0.1,
|
||||||
|
gradient_exponent FLOAT NOT NULL DEFAULT 0.2,
|
||||||
|
constant_base FLOAT NOT NULL DEFAULT 0.0,
|
||||||
|
smith_exponent FLOAT,
|
||||||
|
techcomm_exponent FLOAT,
|
||||||
|
nuanced_min_participants INTEGER,
|
||||||
|
nuanced_threshold_pct INTEGER,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS voting_protocols (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
name VARCHAR(128) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
vote_type VARCHAR(32) NOT NULL,
|
||||||
|
formula_config_id UUID NOT NULL REFERENCES formula_configs(id),
|
||||||
|
mode_params VARCHAR(64),
|
||||||
|
is_meta_governed BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS sanctuary_entries (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
entry_type VARCHAR(64) NOT NULL,
|
||||||
|
reference_id UUID NOT NULL,
|
||||||
|
title VARCHAR(256),
|
||||||
|
content_hash VARCHAR(128) NOT NULL,
|
||||||
|
ipfs_cid VARCHAR(128),
|
||||||
|
chain_tx_hash VARCHAR(128),
|
||||||
|
chain_block INTEGER,
|
||||||
|
metadata_json TEXT,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS blockchain_cache (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
cache_key VARCHAR(256) NOT NULL,
|
||||||
|
cache_value JSON NOT NULL,
|
||||||
|
fetched_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
expires_at TIMESTAMPTZ NOT NULL
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
op.execute("CREATE UNIQUE INDEX IF NOT EXISTS ix_blockchain_cache_cache_key ON blockchain_cache (cache_key)")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS documents (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
slug VARCHAR(128) NOT NULL,
|
||||||
|
title VARCHAR(256) NOT NULL,
|
||||||
|
doc_type VARCHAR(64) NOT NULL,
|
||||||
|
version VARCHAR(32) NOT NULL DEFAULT '0.1.0',
|
||||||
|
status VARCHAR(32) NOT NULL DEFAULT 'draft',
|
||||||
|
description TEXT,
|
||||||
|
ipfs_cid VARCHAR(128),
|
||||||
|
chain_anchor VARCHAR(128),
|
||||||
|
genesis_json TEXT,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
op.execute("CREATE UNIQUE INDEX IF NOT EXISTS ix_documents_slug ON documents (slug)")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS decisions (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
title VARCHAR(256) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
context TEXT,
|
||||||
|
decision_type VARCHAR(64) NOT NULL,
|
||||||
|
status VARCHAR(32) NOT NULL DEFAULT 'draft',
|
||||||
|
voting_protocol_id UUID REFERENCES voting_protocols(id),
|
||||||
|
created_by_id UUID REFERENCES duniter_identities(id),
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS item_versions (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
item_id UUID NOT NULL,
|
||||||
|
proposed_text TEXT NOT NULL,
|
||||||
|
diff_text TEXT,
|
||||||
|
rationale TEXT,
|
||||||
|
status VARCHAR(32) NOT NULL DEFAULT 'proposed',
|
||||||
|
decision_id UUID REFERENCES decisions(id),
|
||||||
|
proposed_by_id UUID REFERENCES duniter_identities(id),
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS vote_sessions (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
decision_id UUID REFERENCES decisions(id),
|
||||||
|
item_version_id UUID REFERENCES item_versions(id),
|
||||||
|
voting_protocol_id UUID NOT NULL REFERENCES voting_protocols(id),
|
||||||
|
wot_size INTEGER NOT NULL DEFAULT 0,
|
||||||
|
smith_size INTEGER NOT NULL DEFAULT 0,
|
||||||
|
techcomm_size INTEGER NOT NULL DEFAULT 0,
|
||||||
|
starts_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
ends_at TIMESTAMPTZ NOT NULL,
|
||||||
|
status VARCHAR(32) NOT NULL DEFAULT 'open',
|
||||||
|
votes_for INTEGER NOT NULL DEFAULT 0,
|
||||||
|
votes_against INTEGER NOT NULL DEFAULT 0,
|
||||||
|
votes_total INTEGER NOT NULL DEFAULT 0,
|
||||||
|
smith_votes_for INTEGER NOT NULL DEFAULT 0,
|
||||||
|
techcomm_votes_for INTEGER NOT NULL DEFAULT 0,
|
||||||
|
threshold_required FLOAT NOT NULL DEFAULT 0.0,
|
||||||
|
result VARCHAR(32),
|
||||||
|
chain_recorded BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
chain_tx_hash VARCHAR(128),
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS decision_steps (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
decision_id UUID NOT NULL REFERENCES decisions(id),
|
||||||
|
step_order INTEGER NOT NULL,
|
||||||
|
step_type VARCHAR(32) NOT NULL,
|
||||||
|
title VARCHAR(256),
|
||||||
|
description TEXT,
|
||||||
|
status VARCHAR(32) NOT NULL DEFAULT 'pending',
|
||||||
|
vote_session_id UUID REFERENCES vote_sessions(id),
|
||||||
|
outcome TEXT,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS document_items (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
document_id UUID NOT NULL REFERENCES documents(id),
|
||||||
|
position VARCHAR(16) NOT NULL,
|
||||||
|
item_type VARCHAR(32) NOT NULL DEFAULT 'clause',
|
||||||
|
title VARCHAR(256),
|
||||||
|
current_text TEXT NOT NULL,
|
||||||
|
voting_protocol_id UUID REFERENCES voting_protocols(id),
|
||||||
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||||
|
section_tag VARCHAR(64),
|
||||||
|
inertia_preset VARCHAR(16) NOT NULL DEFAULT 'standard',
|
||||||
|
is_permanent_vote BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM information_schema.table_constraints
|
||||||
|
WHERE constraint_name = 'item_versions_item_id_fkey'
|
||||||
|
AND table_name = 'item_versions'
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE item_versions
|
||||||
|
ADD CONSTRAINT item_versions_item_id_fkey
|
||||||
|
FOREIGN KEY (item_id) REFERENCES document_items(id);
|
||||||
|
END IF;
|
||||||
|
END $$
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS votes (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
session_id UUID NOT NULL REFERENCES vote_sessions(id),
|
||||||
|
voter_id UUID NOT NULL REFERENCES duniter_identities(id),
|
||||||
|
vote_value VARCHAR(32) NOT NULL,
|
||||||
|
nuanced_level INTEGER,
|
||||||
|
comment TEXT,
|
||||||
|
signature TEXT NOT NULL,
|
||||||
|
signed_payload TEXT NOT NULL,
|
||||||
|
voter_wot_status VARCHAR(32) NOT NULL DEFAULT 'member',
|
||||||
|
voter_is_smith BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
voter_is_techcomm BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS mandates (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
title VARCHAR(256) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
mandate_type VARCHAR(64) NOT NULL,
|
||||||
|
status VARCHAR(32) NOT NULL DEFAULT 'draft',
|
||||||
|
mandatee_id UUID REFERENCES duniter_identities(id),
|
||||||
|
decision_id UUID REFERENCES decisions(id),
|
||||||
|
starts_at TIMESTAMPTZ,
|
||||||
|
ends_at TIMESTAMPTZ,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
op.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS mandate_steps (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
mandate_id UUID NOT NULL REFERENCES mandates(id),
|
||||||
|
step_order INTEGER NOT NULL,
|
||||||
|
step_type VARCHAR(32) NOT NULL,
|
||||||
|
title VARCHAR(256),
|
||||||
|
description TEXT,
|
||||||
|
status VARCHAR(32) NOT NULL DEFAULT 'pending',
|
||||||
|
vote_session_id UUID REFERENCES vote_sessions(id),
|
||||||
|
outcome TEXT,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# Intentionally left empty — dropping the initial schema would destroy all data.
|
||||||
|
pass
|
||||||
@@ -12,22 +12,21 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
|
|
||||||
revision: str = '70914b334cfb'
|
revision: str = '70914b334cfb'
|
||||||
down_revision: Union[str, None] = None
|
down_revision: Union[str, None] = '0b9c1d2e3f4a'
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
# SQLite does not support ADD CONSTRAINT via ALTER TABLE — FK constraints
|
# ADD COLUMN IF NOT EXISTS — idempotent (safe on DBs bootstrapped via create_all)
|
||||||
# are declared in models only; integrity is enforced at app layer.
|
op.execute("ALTER TABLE decisions ADD COLUMN IF NOT EXISTS organization_id UUID REFERENCES organizations(id)")
|
||||||
op.add_column('decisions', sa.Column('organization_id', sa.Uuid(), nullable=True))
|
op.execute("CREATE INDEX IF NOT EXISTS ix_decisions_organization_id ON decisions (organization_id)")
|
||||||
op.create_index(op.f('ix_decisions_organization_id'), 'decisions', ['organization_id'], unique=False)
|
op.execute("ALTER TABLE documents ADD COLUMN IF NOT EXISTS organization_id UUID REFERENCES organizations(id)")
|
||||||
op.add_column('documents', sa.Column('organization_id', sa.Uuid(), nullable=True))
|
op.execute("CREATE INDEX IF NOT EXISTS ix_documents_organization_id ON documents (organization_id)")
|
||||||
op.create_index(op.f('ix_documents_organization_id'), 'documents', ['organization_id'], unique=False)
|
op.execute("ALTER TABLE mandates ADD COLUMN IF NOT EXISTS organization_id UUID REFERENCES organizations(id)")
|
||||||
op.add_column('mandates', sa.Column('organization_id', sa.Uuid(), nullable=True))
|
op.execute("CREATE INDEX IF NOT EXISTS ix_mandates_organization_id ON mandates (organization_id)")
|
||||||
op.create_index(op.f('ix_mandates_organization_id'), 'mandates', ['organization_id'], unique=False)
|
op.execute("ALTER TABLE voting_protocols ADD COLUMN IF NOT EXISTS organization_id UUID REFERENCES organizations(id)")
|
||||||
op.add_column('voting_protocols', sa.Column('organization_id', sa.Uuid(), nullable=True))
|
op.execute("CREATE INDEX IF NOT EXISTS ix_voting_protocols_organization_id ON voting_protocols (organization_id)")
|
||||||
op.create_index(op.f('ix_voting_protocols_organization_id'), 'voting_protocols', ['organization_id'], unique=False)
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
|||||||
+11
-16
@@ -16,23 +16,18 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
op.create_table(
|
op.execute("""
|
||||||
'qualification_protocols',
|
CREATE TABLE IF NOT EXISTS qualification_protocols (
|
||||||
sa.Column('id', sa.Uuid(), nullable=False),
|
id UUID PRIMARY KEY,
|
||||||
sa.Column('name', sa.String(128), nullable=False),
|
name VARCHAR(128) NOT NULL,
|
||||||
sa.Column('description', sa.Text(), nullable=True),
|
description TEXT,
|
||||||
sa.Column('small_group_max', sa.Integer(), nullable=False, server_default='5'),
|
small_group_max INTEGER NOT NULL DEFAULT 5,
|
||||||
sa.Column('collective_wot_min', sa.Integer(), nullable=False, server_default='50'),
|
collective_wot_min INTEGER NOT NULL DEFAULT 50,
|
||||||
sa.Column(
|
default_modalities_json TEXT NOT NULL DEFAULT '["vote_wot","vote_smith","consultation_avis","election"]',
|
||||||
'default_modalities_json',
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
sa.Text(),
|
created_at TIMESTAMPTZ DEFAULT now()
|
||||||
nullable=False,
|
|
||||||
server_default='["vote_wot","vote_smith","consultation_avis","election"]',
|
|
||||||
),
|
|
||||||
sa.Column('is_active', sa.Boolean(), nullable=False, server_default='1'),
|
|
||||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now()),
|
|
||||||
sa.PrimaryKeyConstraint('id'),
|
|
||||||
)
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
|||||||
@@ -17,31 +17,28 @@ depends_on = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
op.create_table(
|
op.execute("""
|
||||||
"groups",
|
CREATE TABLE IF NOT EXISTS groups (
|
||||||
sa.Column("id", sa.Uuid(), nullable=False),
|
id UUID PRIMARY KEY,
|
||||||
sa.Column("name", sa.String(128), nullable=False),
|
name VARCHAR(128) NOT NULL,
|
||||||
sa.Column("description", sa.Text(), nullable=True),
|
description TEXT,
|
||||||
sa.Column("organization_id", sa.Uuid(), nullable=True),
|
organization_id UUID REFERENCES organizations(id),
|
||||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
sa.ForeignKeyConstraint(["organization_id"], ["organizations.id"]),
|
|
||||||
sa.PrimaryKeyConstraint("id"),
|
|
||||||
)
|
)
|
||||||
op.create_index("ix_groups_organization_id", "groups", ["organization_id"])
|
""")
|
||||||
|
op.execute("CREATE INDEX IF NOT EXISTS ix_groups_organization_id ON groups (organization_id)")
|
||||||
|
|
||||||
op.create_table(
|
op.execute("""
|
||||||
"group_members",
|
CREATE TABLE IF NOT EXISTS group_members (
|
||||||
sa.Column("id", sa.Uuid(), nullable=False),
|
id UUID PRIMARY KEY,
|
||||||
sa.Column("group_id", sa.Uuid(), nullable=False),
|
group_id UUID NOT NULL REFERENCES groups(id),
|
||||||
sa.Column("identity_id", sa.Uuid(), nullable=True),
|
identity_id UUID REFERENCES duniter_identities(id),
|
||||||
sa.Column("display_name", sa.String(128), nullable=False),
|
display_name VARCHAR(128) NOT NULL,
|
||||||
sa.Column("added_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
added_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
sa.ForeignKeyConstraint(["group_id"], ["groups.id"]),
|
|
||||||
sa.ForeignKeyConstraint(["identity_id"], ["duniter_identities.id"]),
|
|
||||||
sa.PrimaryKeyConstraint("id"),
|
|
||||||
)
|
)
|
||||||
op.create_index("ix_group_members_group_id", "group_members", ["group_id"])
|
""")
|
||||||
|
op.execute("CREATE INDEX IF NOT EXISTS ix_group_members_group_id ON group_members (group_id)")
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"""Add origin column to mandates table.
|
||||||
|
|
||||||
|
Revision ID: d91a3c7f8b02
|
||||||
|
Revises: c4e812fb3a01
|
||||||
|
Create Date: 2026-04-24 10:00:00.000000
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision = "d91a3c7f8b02"
|
||||||
|
down_revision = "c4e812fb3a01"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.execute("ALTER TABLE mandates ADD COLUMN IF NOT EXISTS origin TEXT")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.drop_column("mandates", "origin")
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
"""Mandate origin: replace free-text with FK to duniter_identities.
|
||||||
|
|
||||||
|
Revision ID: e3f4a5b6c7d8
|
||||||
|
Revises: d91a3c7f8b02
|
||||||
|
Create Date: 2026-04-25 10:00:00.000000
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision = "e3f4a5b6c7d8"
|
||||||
|
down_revision = "d91a3c7f8b02"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.execute("ALTER TABLE mandates DROP COLUMN IF EXISTS origin")
|
||||||
|
op.execute("ALTER TABLE mandates ADD COLUMN IF NOT EXISTS origin_id UUID REFERENCES duniter_identities(id)")
|
||||||
|
op.execute("CREATE INDEX IF NOT EXISTS ix_mandates_origin_id ON mandates (origin_id)")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.execute("DROP INDEX IF EXISTS ix_mandates_origin_id")
|
||||||
|
op.execute("ALTER TABLE mandates DROP COLUMN IF EXISTS origin_id")
|
||||||
|
op.execute("ALTER TABLE mandates ADD COLUMN IF NOT EXISTS origin TEXT")
|
||||||
@@ -39,9 +39,8 @@ class Settings(BaseSettings):
|
|||||||
RATE_LIMIT_AUTH: int = 10
|
RATE_LIMIT_AUTH: int = 10
|
||||||
RATE_LIMIT_VOTE: int = 30
|
RATE_LIMIT_VOTE: int = 30
|
||||||
|
|
||||||
# AI (Claude — substitut Qwen en attendant le déploiement local)
|
# AI — Qwen3.6 (MacStudio) endpoint, branché plus tard
|
||||||
ANTHROPIC_API_KEY: str = ""
|
QWEN_API_URL: str = ""
|
||||||
ANTHROPIC_MODEL: str = "claude-haiku-4-5-20251001"
|
|
||||||
|
|
||||||
# Blockchain cache
|
# Blockchain cache
|
||||||
BLOCKCHAIN_CACHE_TTL_SECONDS: int = 3600
|
BLOCKCHAIN_CACHE_TTL_SECONDS: int = 3600
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ class Mandate(Base):
|
|||||||
|
|
||||||
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4)
|
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4)
|
||||||
title: Mapped[str] = mapped_column(String(256), nullable=False)
|
title: Mapped[str] = mapped_column(String(256), nullable=False)
|
||||||
|
origin_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("duniter_identities.id"), nullable=True, index=True)
|
||||||
description: Mapped[str | None] = mapped_column(Text)
|
description: Mapped[str | None] = mapped_column(Text)
|
||||||
mandate_type: Mapped[str] = mapped_column(String(64), nullable=False) # techcomm, smith, custom
|
mandate_type: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||||
status: Mapped[str] = mapped_column(String(32), default="draft") # draft, candidacy, voting, active, reporting, completed, revoked
|
status: Mapped[str] = mapped_column(String(32), default="draft")
|
||||||
organization_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("organizations.id"), nullable=True, index=True)
|
organization_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("organizations.id"), nullable=True, index=True)
|
||||||
mandatee_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("duniter_identities.id"))
|
mandatee_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("duniter_identities.id"))
|
||||||
decision_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("decisions.id"))
|
decision_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("decisions.id"))
|
||||||
@@ -23,7 +24,27 @@ class Mandate(Base):
|
|||||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||||
|
|
||||||
steps: Mapped[list["MandateStep"]] = relationship(back_populates="mandate", cascade="all, delete-orphan", order_by="MandateStep.step_order")
|
steps: Mapped[list["MandateStep"]] = relationship(
|
||||||
|
back_populates="mandate", cascade="all, delete-orphan", order_by="MandateStep.step_order"
|
||||||
|
)
|
||||||
|
origin_identity: Mapped["DuniterIdentity | None"] = relationship( # type: ignore[name-defined]
|
||||||
|
"DuniterIdentity", foreign_keys=[origin_id]
|
||||||
|
)
|
||||||
|
mandatee: Mapped["DuniterIdentity | None"] = relationship( # type: ignore[name-defined]
|
||||||
|
"DuniterIdentity", foreign_keys=[mandatee_id]
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def origin_display_name(self) -> str | None:
|
||||||
|
if self.origin_identity is not None:
|
||||||
|
return self.origin_identity.display_name or self.origin_identity.address
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mandatee_display_name(self) -> str | None:
|
||||||
|
if self.mandatee is not None:
|
||||||
|
return self.mandatee.display_name or self.mandatee.address
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class MandateStep(Base):
|
class MandateStep(Base):
|
||||||
@@ -32,12 +53,16 @@ class MandateStep(Base):
|
|||||||
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4)
|
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4)
|
||||||
mandate_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("mandates.id"), nullable=False)
|
mandate_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("mandates.id"), nullable=False)
|
||||||
step_order: Mapped[int] = mapped_column(Integer, nullable=False)
|
step_order: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||||
step_type: Mapped[str] = mapped_column(String(32), nullable=False) # formulation, candidacy, vote, assignment, reporting, completion, revocation
|
step_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||||
title: Mapped[str | None] = mapped_column(String(256))
|
title: Mapped[str | None] = mapped_column(String(256))
|
||||||
description: Mapped[str | None] = mapped_column(Text)
|
description: Mapped[str | None] = mapped_column(Text)
|
||||||
status: Mapped[str] = mapped_column(String(32), default="pending") # pending, active, completed, skipped
|
status: Mapped[str] = mapped_column(String(32), default="pending")
|
||||||
vote_session_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("vote_sessions.id"))
|
vote_session_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("vote_sessions.id"))
|
||||||
outcome: Mapped[str | None] = mapped_column(Text)
|
outcome: Mapped[str | None] = mapped_column(Text)
|
||||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
|
||||||
mandate: Mapped["Mandate"] = relationship(back_populates="steps")
|
mandate: Mapped["Mandate"] = relationship(back_populates="steps")
|
||||||
|
|
||||||
|
|
||||||
|
# Avoid circular import — DuniterIdentity imported at runtime by SQLAlchemy relationship resolution
|
||||||
|
from app.models.user import DuniterIdentity # noqa: E402, F401
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ from __future__ import annotations
|
|||||||
import secrets
|
import secrets
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Response, status
|
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
||||||
|
from sqlalchemy import or_, select
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
@@ -132,7 +133,11 @@ async def verify_challenge(
|
|||||||
detail="Challenge invalide",
|
detail="Challenge invalide",
|
||||||
)
|
)
|
||||||
|
|
||||||
# 4. Verify signature (bypass for demo profiles in dev/demo mode)
|
# 4. Verify signature
|
||||||
|
# TODO: trustWallet — déléguer la vérification au protocole trustWallet (librodrome)
|
||||||
|
# Quand trustWallet sera disponible : remplacer le bloc ci-dessous par une vérification
|
||||||
|
# du token signé fourni par trustWallet (JWT ou preuve Ed25519 via iframe postMessage).
|
||||||
|
# Le bypass DEMO_MODE sera alors supprimé.
|
||||||
_demo_addresses = {p["address"] for p in DEV_PROFILES}
|
_demo_addresses = {p["address"] for p in DEV_PROFILES}
|
||||||
is_demo_bypass = (settings.DEMO_MODE or settings.ENVIRONMENT == "development") and payload.address in _demo_addresses
|
is_demo_bypass = (settings.DEMO_MODE or settings.ENVIRONMENT == "development") and payload.address in _demo_addresses
|
||||||
|
|
||||||
@@ -228,3 +233,24 @@ async def logout(
|
|||||||
for session in sessions:
|
for session in sessions:
|
||||||
await db.delete(session)
|
await db.delete(session)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/identities", response_model=list[IdentityOut])
|
||||||
|
async def search_identities(
|
||||||
|
q: str = Query(..., min_length=1, description="Recherche par adresse ou nom"),
|
||||||
|
limit: int = Query(default=10, ge=1, le=50),
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
) -> list[IdentityOut]:
|
||||||
|
"""Search Duniter identities by address prefix or display_name."""
|
||||||
|
result = await db.execute(
|
||||||
|
select(DuniterIdentity)
|
||||||
|
.where(
|
||||||
|
or_(
|
||||||
|
DuniterIdentity.address.ilike(f"{q}%"),
|
||||||
|
DuniterIdentity.display_name.ilike(f"%{q}%"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.order_by(DuniterIdentity.display_name)
|
||||||
|
.limit(limit)
|
||||||
|
)
|
||||||
|
return [IdentityOut.model_validate(i) for i in result.scalars().all()]
|
||||||
|
|||||||
@@ -38,10 +38,13 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
async def _get_mandate(db: AsyncSession, mandate_id: uuid.UUID) -> Mandate:
|
async def _get_mandate(db: AsyncSession, mandate_id: uuid.UUID) -> Mandate:
|
||||||
"""Fetch a mandate by ID with its steps eagerly loaded, or raise 404."""
|
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
select(Mandate)
|
select(Mandate)
|
||||||
.options(selectinload(Mandate.steps))
|
.options(
|
||||||
|
selectinload(Mandate.steps),
|
||||||
|
selectinload(Mandate.origin_identity),
|
||||||
|
selectinload(Mandate.mandatee),
|
||||||
|
)
|
||||||
.where(Mandate.id == mandate_id)
|
.where(Mandate.id == mandate_id)
|
||||||
)
|
)
|
||||||
mandate = result.scalar_one_or_none()
|
mandate = result.scalar_one_or_none()
|
||||||
@@ -50,6 +53,13 @@ async def _get_mandate(db: AsyncSession, mandate_id: uuid.UUID) -> Mandate:
|
|||||||
return mandate
|
return mandate
|
||||||
|
|
||||||
|
|
||||||
|
def _mandate_out(mandate: Mandate) -> MandateOut:
|
||||||
|
out = MandateOut.model_validate(mandate)
|
||||||
|
out.origin_display_name = mandate.origin_display_name
|
||||||
|
out.mandatee_display_name = mandate.mandatee_display_name
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
# ── Mandate routes ──────────────────────────────────────────────────────────
|
# ── Mandate routes ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
@@ -57,13 +67,16 @@ async def _get_mandate(db: AsyncSession, mandate_id: uuid.UUID) -> Mandate:
|
|||||||
async def list_mandates(
|
async def list_mandates(
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
org_id: uuid.UUID | None = Depends(get_active_org_id),
|
org_id: uuid.UUID | None = Depends(get_active_org_id),
|
||||||
mandate_type: str | None = Query(default=None, description="Filtrer par type de mandat"),
|
mandate_type: str | None = Query(default=None),
|
||||||
status_filter: str | None = Query(default=None, alias="status", description="Filtrer par statut"),
|
status_filter: str | None = Query(default=None, alias="status"),
|
||||||
skip: int = Query(default=0, ge=0),
|
skip: int = Query(default=0, ge=0),
|
||||||
limit: int = Query(default=50, ge=1, le=200),
|
limit: int = Query(default=50, ge=1, le=200),
|
||||||
) -> list[MandateOut]:
|
) -> list[MandateOut]:
|
||||||
"""List all mandates with optional filters."""
|
stmt = select(Mandate).options(
|
||||||
stmt = select(Mandate).options(selectinload(Mandate.steps))
|
selectinload(Mandate.steps),
|
||||||
|
selectinload(Mandate.origin_identity),
|
||||||
|
selectinload(Mandate.mandatee),
|
||||||
|
)
|
||||||
|
|
||||||
if org_id is not None:
|
if org_id is not None:
|
||||||
stmt = stmt.where(Mandate.organization_id == org_id)
|
stmt = stmt.where(Mandate.organization_id == org_id)
|
||||||
@@ -76,7 +89,7 @@ async def list_mandates(
|
|||||||
result = await db.execute(stmt)
|
result = await db.execute(stmt)
|
||||||
mandates = result.scalars().unique().all()
|
mandates = result.scalars().unique().all()
|
||||||
|
|
||||||
return [MandateOut.model_validate(m) for m in mandates]
|
return [_mandate_out(m) for m in mandates]
|
||||||
|
|
||||||
|
|
||||||
@router.post("/", response_model=MandateOut, status_code=status.HTTP_201_CREATED)
|
@router.post("/", response_model=MandateOut, status_code=status.HTTP_201_CREATED)
|
||||||
@@ -86,15 +99,20 @@ async def create_mandate(
|
|||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
org_id: uuid.UUID | None = Depends(get_active_org_id),
|
org_id: uuid.UUID | None = Depends(get_active_org_id),
|
||||||
) -> MandateOut:
|
) -> MandateOut:
|
||||||
"""Create a new mandate."""
|
data = payload.model_dump()
|
||||||
mandate = Mandate(**payload.model_dump(), organization_id=org_id)
|
nomination_mode = data.pop("nomination_mode", "postpone")
|
||||||
|
|
||||||
|
mandate = Mandate(**data, organization_id=org_id)
|
||||||
|
|
||||||
|
if nomination_mode == "auto":
|
||||||
|
mandate.mandatee_id = identity.id
|
||||||
|
|
||||||
db.add(mandate)
|
db.add(mandate)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(mandate)
|
await db.refresh(mandate)
|
||||||
|
|
||||||
# Reload with steps (empty at creation)
|
|
||||||
mandate = await _get_mandate(db, mandate.id)
|
mandate = await _get_mandate(db, mandate.id)
|
||||||
return MandateOut.model_validate(mandate)
|
return _mandate_out(mandate)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{id}", response_model=MandateOut)
|
@router.get("/{id}", response_model=MandateOut)
|
||||||
@@ -102,9 +120,8 @@ async def get_mandate(
|
|||||||
id: uuid.UUID,
|
id: uuid.UUID,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
) -> MandateOut:
|
) -> MandateOut:
|
||||||
"""Get a single mandate with all its steps."""
|
|
||||||
mandate = await _get_mandate(db, id)
|
mandate = await _get_mandate(db, id)
|
||||||
return MandateOut.model_validate(mandate)
|
return _mandate_out(mandate)
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{id}", response_model=MandateOut)
|
@router.put("/{id}", response_model=MandateOut)
|
||||||
@@ -114,19 +131,14 @@ async def update_mandate(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
) -> MandateOut:
|
) -> MandateOut:
|
||||||
"""Update a mandate's metadata."""
|
|
||||||
mandate = await _get_mandate(db, id)
|
mandate = await _get_mandate(db, id)
|
||||||
|
|
||||||
update_data = payload.model_dump(exclude_unset=True)
|
for field, value in payload.model_dump(exclude_unset=True).items():
|
||||||
for field, value in update_data.items():
|
|
||||||
setattr(mandate, field, value)
|
setattr(mandate, field, value)
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(mandate)
|
|
||||||
|
|
||||||
# Reload with steps
|
|
||||||
mandate = await _get_mandate(db, mandate.id)
|
mandate = await _get_mandate(db, mandate.id)
|
||||||
return MandateOut.model_validate(mandate)
|
return _mandate_out(mandate)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT, response_class=Response, response_model=None)
|
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT, response_class=Response, response_model=None)
|
||||||
@@ -135,7 +147,6 @@ async def delete_mandate(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Delete a mandate (only if in draft status)."""
|
|
||||||
mandate = await _get_mandate(db, id)
|
mandate = await _get_mandate(db, id)
|
||||||
|
|
||||||
if mandate.status != "draft":
|
if mandate.status != "draft":
|
||||||
@@ -158,13 +169,9 @@ async def add_step(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
) -> MandateStepOut:
|
) -> MandateStepOut:
|
||||||
"""Add a step to a mandate process."""
|
|
||||||
mandate = await _get_mandate(db, id)
|
mandate = await _get_mandate(db, id)
|
||||||
|
|
||||||
step = MandateStep(
|
step = MandateStep(mandate_id=mandate.id, **payload.model_dump())
|
||||||
mandate_id=mandate.id,
|
|
||||||
**payload.model_dump(),
|
|
||||||
)
|
|
||||||
db.add(step)
|
db.add(step)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(step)
|
await db.refresh(step)
|
||||||
@@ -177,7 +184,6 @@ async def list_steps(
|
|||||||
id: uuid.UUID,
|
id: uuid.UUID,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
) -> list[MandateStepOut]:
|
) -> list[MandateStepOut]:
|
||||||
"""List all steps for a mandate, ordered by step_order."""
|
|
||||||
mandate = await _get_mandate(db, id)
|
mandate = await _get_mandate(db, id)
|
||||||
return [MandateStepOut.model_validate(s) for s in mandate.steps]
|
return [MandateStepOut.model_validate(s) for s in mandate.steps]
|
||||||
|
|
||||||
@@ -191,17 +197,17 @@ async def advance_mandate_endpoint(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
) -> MandateAdvanceOut:
|
) -> MandateAdvanceOut:
|
||||||
"""Advance a mandate to its next step or status."""
|
|
||||||
try:
|
try:
|
||||||
mandate = await advance_mandate(id, db)
|
mandate = await advance_mandate(id, db)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc))
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc))
|
||||||
|
|
||||||
# Reload with steps for complete output
|
|
||||||
mandate = await _get_mandate(db, mandate.id)
|
mandate = await _get_mandate(db, mandate.id)
|
||||||
data = MandateOut.model_validate(mandate).model_dump()
|
out = _mandate_out(mandate)
|
||||||
data["message"] = f"Mandat avance au statut : {mandate.status}"
|
return MandateAdvanceOut(
|
||||||
return MandateAdvanceOut(**data)
|
**out.model_dump(),
|
||||||
|
message=f"Mandat avance au statut : {mandate.status}",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{id}/assign", response_model=MandateOut)
|
@router.post("/{id}/assign", response_model=MandateOut)
|
||||||
@@ -211,15 +217,13 @@ async def assign_mandatee_endpoint(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
) -> MandateOut:
|
) -> MandateOut:
|
||||||
"""Assign a mandatee to a mandate."""
|
|
||||||
try:
|
try:
|
||||||
mandate = await assign_mandatee(id, payload.mandatee_id, db)
|
mandate = await assign_mandatee(id, payload.mandatee_id, db)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc))
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc))
|
||||||
|
|
||||||
# Reload with steps
|
|
||||||
mandate = await _get_mandate(db, mandate.id)
|
mandate = await _get_mandate(db, mandate.id)
|
||||||
return MandateOut.model_validate(mandate)
|
return _mandate_out(mandate)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{id}/revoke", response_model=MandateOut)
|
@router.post("/{id}/revoke", response_model=MandateOut)
|
||||||
@@ -228,15 +232,13 @@ async def revoke_mandate_endpoint(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
) -> MandateOut:
|
) -> MandateOut:
|
||||||
"""Revoke an active mandate."""
|
|
||||||
try:
|
try:
|
||||||
mandate = await revoke_mandate(id, db)
|
mandate = await revoke_mandate(id, db)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc))
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc))
|
||||||
|
|
||||||
# Reload with steps
|
|
||||||
mandate = await _get_mandate(db, mandate.id)
|
mandate = await _get_mandate(db, mandate.id)
|
||||||
return MandateOut.model_validate(mandate)
|
return _mandate_out(mandate)
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
@@ -250,7 +252,6 @@ async def create_vote_session_for_step_endpoint(
|
|||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
identity: DuniterIdentity = Depends(get_current_identity),
|
identity: DuniterIdentity = Depends(get_current_identity),
|
||||||
) -> VoteSessionOut:
|
) -> VoteSessionOut:
|
||||||
"""Create a vote session linked to a mandate step."""
|
|
||||||
try:
|
try:
|
||||||
session = await create_vote_session_for_step(id, step_id, db)
|
session = await create_vote_session_for_step(id, step_id, db)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from app.services.qualify_ai_service import (
|
|||||||
AIMessage,
|
AIMessage,
|
||||||
AIQuestion,
|
AIQuestion,
|
||||||
AIQualifyResult,
|
AIQualifyResult,
|
||||||
ai_frame_async,
|
ai_frame,
|
||||||
)
|
)
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -127,7 +127,7 @@ async def ai_chat(payload: AIChatRequest) -> AIChatResponse:
|
|||||||
context=payload.context,
|
context=payload.context,
|
||||||
messages=[AIMessage(role=m.role, content=m.content) for m in payload.messages],
|
messages=[AIMessage(role=m.role, content=m.content) for m in payload.messages],
|
||||||
)
|
)
|
||||||
resp = await ai_frame_async(req)
|
resp = ai_frame(req)
|
||||||
|
|
||||||
return AIChatResponse(
|
return AIChatResponse(
|
||||||
done=resp.done,
|
done=resp.done,
|
||||||
|
|||||||
@@ -10,21 +10,13 @@ from pydantic import BaseModel, ConfigDict, Field
|
|||||||
|
|
||||||
|
|
||||||
class MandateStepCreate(BaseModel):
|
class MandateStepCreate(BaseModel):
|
||||||
"""Payload for creating a step within a mandate process."""
|
|
||||||
|
|
||||||
step_order: int = Field(..., ge=0)
|
step_order: int = Field(..., ge=0)
|
||||||
step_type: str = Field(
|
step_type: str = Field(..., max_length=32)
|
||||||
...,
|
|
||||||
max_length=32,
|
|
||||||
description="formulation, candidacy, vote, assignment, reporting, completion, revocation",
|
|
||||||
)
|
|
||||||
title: str | None = Field(default=None, max_length=256)
|
title: str | None = Field(default=None, max_length=256)
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class MandateStepOut(BaseModel):
|
class MandateStepOut(BaseModel):
|
||||||
"""Full mandate step representation."""
|
|
||||||
|
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
id: UUID
|
id: UUID
|
||||||
@@ -43,40 +35,45 @@ class MandateStepOut(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class MandateCreate(BaseModel):
|
class MandateCreate(BaseModel):
|
||||||
"""Payload for creating a new mandate."""
|
|
||||||
|
|
||||||
title: str = Field(..., min_length=1, max_length=256)
|
title: str = Field(..., min_length=1, max_length=256)
|
||||||
|
origin_id: UUID | None = None
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
mandate_type: str = Field(..., max_length=64, description="techcomm, smith, custom")
|
mandate_type: str = Field(..., max_length=64)
|
||||||
|
nomination_mode: str = Field(
|
||||||
|
default="postpone",
|
||||||
|
description="auto (auto-assign author), collective, postpone",
|
||||||
|
)
|
||||||
decision_id: UUID | None = None
|
decision_id: UUID | None = None
|
||||||
|
starts_at: datetime | None = None
|
||||||
|
ends_at: datetime | None = None
|
||||||
|
|
||||||
|
|
||||||
class MandateUpdate(BaseModel):
|
class MandateUpdate(BaseModel):
|
||||||
"""Partial update for a mandate."""
|
|
||||||
|
|
||||||
title: str | None = Field(default=None, max_length=256)
|
title: str | None = Field(default=None, max_length=256)
|
||||||
|
origin_id: UUID | None = None
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
mandate_type: str | None = Field(default=None, max_length=64)
|
mandate_type: str | None = Field(default=None, max_length=64)
|
||||||
decision_id: UUID | None = None
|
decision_id: UUID | None = None
|
||||||
|
starts_at: datetime | None = None
|
||||||
|
ends_at: datetime | None = None
|
||||||
|
|
||||||
|
|
||||||
class MandateAssignRequest(BaseModel):
|
class MandateAssignRequest(BaseModel):
|
||||||
"""Request body for assigning a mandatee to a mandate."""
|
mandatee_id: UUID = Field(..., description="UUID de l'identite Duniter du mandataire")
|
||||||
|
|
||||||
mandatee_id: UUID = Field(..., description="ID de l'identite Duniter du mandataire")
|
|
||||||
|
|
||||||
|
|
||||||
class MandateOut(BaseModel):
|
class MandateOut(BaseModel):
|
||||||
"""Full mandate representation returned by the API."""
|
|
||||||
|
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
id: UUID
|
id: UUID
|
||||||
title: str
|
title: str
|
||||||
|
origin_id: UUID | None = None
|
||||||
|
origin_display_name: str | None = None
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
mandate_type: str
|
mandate_type: str
|
||||||
status: str
|
status: str
|
||||||
mandatee_id: UUID | None = None
|
mandatee_id: UUID | None = None
|
||||||
|
mandatee_display_name: str | None = None
|
||||||
decision_id: UUID | None = None
|
decision_id: UUID | None = None
|
||||||
starts_at: datetime | None = None
|
starts_at: datetime | None = None
|
||||||
ends_at: datetime | None = None
|
ends_at: datetime | None = None
|
||||||
@@ -85,21 +82,5 @@ class MandateOut(BaseModel):
|
|||||||
steps: list[MandateStepOut] = Field(default_factory=list)
|
steps: list[MandateStepOut] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
class MandateAdvanceOut(BaseModel):
|
class MandateAdvanceOut(MandateOut):
|
||||||
"""Output after advancing a mandate through its workflow."""
|
|
||||||
|
|
||||||
model_config = ConfigDict(from_attributes=True)
|
|
||||||
|
|
||||||
id: UUID
|
|
||||||
title: str
|
|
||||||
description: str | None = None
|
|
||||||
mandate_type: str
|
|
||||||
status: str
|
|
||||||
mandatee_id: UUID | None = None
|
|
||||||
decision_id: UUID | None = None
|
|
||||||
starts_at: datetime | None = None
|
|
||||||
ends_at: datetime | None = None
|
|
||||||
created_at: datetime
|
|
||||||
updated_at: datetime
|
|
||||||
steps: list[MandateStepOut] = Field(default_factory=list)
|
|
||||||
message: str = Field(..., description="Message decrivant l'avancement effectue")
|
message: str = Field(..., description="Message decrivant l'avancement effectue")
|
||||||
|
|||||||
@@ -3,23 +3,14 @@
|
|||||||
Orchestrates a 2-round conversation that clarifies reversibility and urgency
|
Orchestrates a 2-round conversation that clarifies reversibility and urgency
|
||||||
before producing a final QualificationResult.
|
before producing a final QualificationResult.
|
||||||
|
|
||||||
Two entry points:
|
Rule-based stub — Qwen3.6 (MacStudio) calls will replace ai_frame() internals
|
||||||
ai_frame() — synchronous, rule-based only. Used by tests.
|
once the local endpoint is available. The interface is stable.
|
||||||
ai_frame_async() — async, enriched by Claude API (or Qwen3.6 later).
|
|
||||||
Falls back to ai_frame() if ANTHROPIC_API_KEY is unset.
|
|
||||||
|
|
||||||
The interface (AIFrameRequest / AIFrameResponse) is stable; the underlying
|
|
||||||
engine is swappable (Qwen3.6 MacStudio planned to replace Claude calls).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Schemas (dataclasses — no Pydantic dependency in the engine layer)
|
# Schemas (dataclasses — no Pydantic dependency in the engine layer)
|
||||||
@@ -74,7 +65,7 @@ class AIFrameResponse:
|
|||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Standard clarifying questions (fallback when no context or API unavailable)
|
# Standard clarifying questions
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@@ -101,12 +92,12 @@ _CLARIFYING_QUESTIONS: list[AIQuestion] = [
|
|||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Synchronous rule-based engine (used directly by tests)
|
# Core function
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def ai_frame(request: AIFrameRequest) -> AIFrameResponse:
|
def ai_frame(request: AIFrameRequest) -> AIFrameResponse:
|
||||||
"""Run one round of rule-based AI framing.
|
"""Run one round of AI framing.
|
||||||
|
|
||||||
Round 1 (messages=[]) → return 2 clarifying questions, done=False
|
Round 1 (messages=[]) → return 2 clarifying questions, done=False
|
||||||
Round 2 (messages set) → parse answers, qualify, return result, done=True
|
Round 2 (messages set) → parse answers, qualify, return result, done=True
|
||||||
@@ -134,135 +125,7 @@ def ai_frame(request: AIFrameRequest) -> AIFrameResponse:
|
|||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Async Claude-enriched entry point (used by the router)
|
# Helpers
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
async def ai_frame_async(request: AIFrameRequest) -> AIFrameResponse:
|
|
||||||
"""Async entry point: rule engine + Claude enrichment.
|
|
||||||
|
|
||||||
Falls back to ai_frame() if ANTHROPIC_API_KEY is not configured.
|
|
||||||
Qwen3.6 (MacStudio) will replace Claude calls when available.
|
|
||||||
"""
|
|
||||||
base = ai_frame(request)
|
|
||||||
|
|
||||||
client = _get_claude_client()
|
|
||||||
if client is None:
|
|
||||||
return base
|
|
||||||
|
|
||||||
messages = request.messages or []
|
|
||||||
|
|
||||||
if not messages:
|
|
||||||
# Round 1: context-aware questions
|
|
||||||
enriched_questions = await _claude_questions(client, request.context, base.questions)
|
|
||||||
return AIFrameResponse(done=False, questions=enriched_questions, result=None, explanation=None)
|
|
||||||
else:
|
|
||||||
# Round 2: enriched explanation
|
|
||||||
enriched_explanation = await _claude_explanation(client, request, base)
|
|
||||||
return AIFrameResponse(
|
|
||||||
done=True,
|
|
||||||
questions=[],
|
|
||||||
result=base.result,
|
|
||||||
explanation=enriched_explanation or base.explanation,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Claude helpers
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
def _get_claude_client():
|
|
||||||
"""Return an AsyncAnthropic client if ANTHROPIC_API_KEY is set, else None."""
|
|
||||||
try:
|
|
||||||
from app.config import settings
|
|
||||||
if not settings.ANTHROPIC_API_KEY:
|
|
||||||
return None
|
|
||||||
import anthropic
|
|
||||||
return anthropic.AsyncAnthropic(api_key=settings.ANTHROPIC_API_KEY)
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
async def _claude_questions(client, context: str | None, fallback: list[AIQuestion]) -> list[AIQuestion]:
|
|
||||||
"""Generate context-aware clarifying questions. Falls back to standard questions on error."""
|
|
||||||
if not context:
|
|
||||||
return fallback
|
|
||||||
|
|
||||||
from app.config import settings
|
|
||||||
prompt = f"""Tu assistes à la qualification d'une décision collective dans la communauté Duniter/G1 (monnaie libre).
|
|
||||||
|
|
||||||
Contexte de la décision : {context}
|
|
||||||
|
|
||||||
Génère 2 questions de clarification courtes et précises pour mieux qualifier cette décision.
|
|
||||||
Chaque question doit avoir exactement 3 options de réponse.
|
|
||||||
Les questions doivent porter sur la réversibilité et l'urgence, adaptées au contexte.
|
|
||||||
|
|
||||||
Réponds UNIQUEMENT en JSON valide, sans texte avant ni après :
|
|
||||||
[
|
|
||||||
{{"id": "reversibility", "text": "...", "options": ["option1", "option2", "option3"]}},
|
|
||||||
{{"id": "urgency", "text": "...", "options": ["option1", "option2", "option3"]}}
|
|
||||||
]"""
|
|
||||||
|
|
||||||
try:
|
|
||||||
message = await client.messages.create(
|
|
||||||
model=settings.ANTHROPIC_MODEL,
|
|
||||||
max_tokens=512,
|
|
||||||
messages=[{"role": "user", "content": prompt}],
|
|
||||||
)
|
|
||||||
raw = message.content[0].text.strip()
|
|
||||||
start = raw.find("[")
|
|
||||||
end = raw.rfind("]") + 1
|
|
||||||
data = json.loads(raw[start:end])
|
|
||||||
return [AIQuestion(id=q["id"], text=q["text"], options=q["options"]) for q in data]
|
|
||||||
except Exception as exc:
|
|
||||||
logger.warning("Claude question generation failed: %s — using fallback", exc)
|
|
||||||
return fallback
|
|
||||||
|
|
||||||
|
|
||||||
async def _claude_explanation(client, request: AIFrameRequest, base: AIFrameResponse) -> str | None:
|
|
||||||
"""Generate a contextual explanation for the qualification result."""
|
|
||||||
if base.result is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
from app.config import settings
|
|
||||||
answers = _parse_answers(request.messages or [])
|
|
||||||
rev = answers.get("reversibility", "non précisé")
|
|
||||||
urg = answers.get("urgency", "non précisé")
|
|
||||||
context_line = f"\nContexte : {request.context}" if request.context else ""
|
|
||||||
|
|
||||||
prompt = f"""Tu qualifies une décision collective pour la communauté Duniter/G1 (monnaie libre).{context_line}
|
|
||||||
|
|
||||||
Paramètres :
|
|
||||||
- Personnes concernées : {request.affected_count or 'non précisé'}
|
|
||||||
- Dans le cadre d'un mandat : {'oui' if request.within_mandate else 'non'}
|
|
||||||
- Décision structurante (on-chain) : {'oui' if request.is_structural else 'non'}
|
|
||||||
- Réversibilité : {rev}
|
|
||||||
- Urgence : {urg}
|
|
||||||
|
|
||||||
Résultat du moteur de qualification :
|
|
||||||
- Type : {base.result.decision_type}
|
|
||||||
- Processus recommandé : {base.result.process}
|
|
||||||
- Modalités : {', '.join(base.result.recommended_modalities) or 'aucune'}
|
|
||||||
- Gravure on-chain : {'recommandée' if base.result.recommend_onchain else 'non nécessaire'}
|
|
||||||
|
|
||||||
Rédige une explication courte (2-3 phrases) qui explique pourquoi ce processus est recommandé \
|
|
||||||
pour cette décision spécifique. Sois direct et concis. Réponds en français."""
|
|
||||||
|
|
||||||
try:
|
|
||||||
message = await client.messages.create(
|
|
||||||
model=settings.ANTHROPIC_MODEL,
|
|
||||||
max_tokens=300,
|
|
||||||
messages=[{"role": "user", "content": prompt}],
|
|
||||||
)
|
|
||||||
return message.content[0].text.strip()
|
|
||||||
except Exception as exc:
|
|
||||||
logger.warning("Claude explanation generation failed: %s — using fallback", exc)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Rule-based helpers (shared by sync and async paths)
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,405 @@
|
|||||||
|
"""Integration tests for mandate flows: nomination, lifecycle, assignment, revocation.
|
||||||
|
|
||||||
|
Uses a real in-memory SQLite database — no mocks of the DB layer.
|
||||||
|
Tests the service functions directly to verify interconnected business logic.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||||
|
from sqlalchemy.orm import selectinload
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
|
import app.models # noqa: F401 — registers all models with Base.metadata
|
||||||
|
from app.database import Base
|
||||||
|
from app.models.mandate import Mandate, MandateStep
|
||||||
|
from app.models.user import DuniterIdentity
|
||||||
|
from app.services.mandate_service import (
|
||||||
|
advance_mandate,
|
||||||
|
assign_mandatee,
|
||||||
|
revoke_mandate,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Fixtures
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@pytest_asyncio.fixture
|
||||||
|
async def engine():
|
||||||
|
eng = create_async_engine("sqlite+aiosqlite:///:memory:", echo=False)
|
||||||
|
async with eng.begin() as conn:
|
||||||
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
|
yield eng
|
||||||
|
await eng.dispose()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest_asyncio.fixture
|
||||||
|
async def db(engine):
|
||||||
|
factory = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||||
|
async with factory() as session:
|
||||||
|
yield session
|
||||||
|
|
||||||
|
|
||||||
|
async def _mk_identity(db: AsyncSession, display_name: str = "Alice") -> DuniterIdentity:
|
||||||
|
ident = DuniterIdentity(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
address=f"5{uuid.uuid4().hex[:46]}",
|
||||||
|
display_name=display_name,
|
||||||
|
wot_status="member",
|
||||||
|
is_smith=False,
|
||||||
|
is_techcomm=False,
|
||||||
|
)
|
||||||
|
db.add(ident)
|
||||||
|
await db.commit()
|
||||||
|
await db.refresh(ident)
|
||||||
|
return ident
|
||||||
|
|
||||||
|
|
||||||
|
async def _mk_mandate(
|
||||||
|
db: AsyncSession,
|
||||||
|
*,
|
||||||
|
mandatee_id: uuid.UUID | None = None,
|
||||||
|
origin_id: uuid.UUID | None = None,
|
||||||
|
status: str = "draft",
|
||||||
|
steps: list[dict] | None = None,
|
||||||
|
) -> Mandate:
|
||||||
|
mandate = Mandate(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
title="Mandat test",
|
||||||
|
mandate_type="functional",
|
||||||
|
status=status,
|
||||||
|
mandatee_id=mandatee_id,
|
||||||
|
origin_id=origin_id,
|
||||||
|
)
|
||||||
|
db.add(mandate)
|
||||||
|
await db.flush()
|
||||||
|
|
||||||
|
for i, s in enumerate(steps or []):
|
||||||
|
step = MandateStep(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
mandate_id=mandate.id,
|
||||||
|
step_order=i,
|
||||||
|
step_type=s.get("step_type", "formulation"),
|
||||||
|
title=s.get("title"),
|
||||||
|
status=s.get("status", "pending"),
|
||||||
|
)
|
||||||
|
db.add(step)
|
||||||
|
|
||||||
|
await db.commit()
|
||||||
|
await db.refresh(mandate)
|
||||||
|
return mandate
|
||||||
|
|
||||||
|
|
||||||
|
async def _reload(db: AsyncSession, mandate_id: uuid.UUID) -> Mandate:
|
||||||
|
result = await db.execute(
|
||||||
|
select(Mandate)
|
||||||
|
.options(
|
||||||
|
selectinload(Mandate.steps),
|
||||||
|
selectinload(Mandate.origin_identity),
|
||||||
|
selectinload(Mandate.mandatee),
|
||||||
|
)
|
||||||
|
.where(Mandate.id == mandate_id)
|
||||||
|
)
|
||||||
|
return result.scalar_one()
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# TestMandateOrigin
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class TestMandateOrigin:
|
||||||
|
"""origin_id must link to a real DuniterIdentity and expose display_name."""
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_origin_id_linked(self, db: AsyncSession):
|
||||||
|
author = await _mk_identity(db, "Baptiste")
|
||||||
|
mandate = await _mk_mandate(db, origin_id=author.id)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
|
||||||
|
assert loaded.origin_id == author.id
|
||||||
|
assert loaded.origin_display_name == "Baptiste"
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_origin_id_optional(self, db: AsyncSession):
|
||||||
|
mandate = await _mk_mandate(db)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
|
||||||
|
assert loaded.origin_id is None
|
||||||
|
assert loaded.origin_display_name is None
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# TestAutoNomination
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class TestAutoNomination:
|
||||||
|
"""Auto-désignation: mandatee = author, no candidacy steps needed."""
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_auto_assign_author(self, db: AsyncSession):
|
||||||
|
author = await _mk_identity(db, "Constance")
|
||||||
|
mandate = await _mk_mandate(db, mandatee_id=author.id)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
|
||||||
|
assert loaded.mandatee_id == author.id
|
||||||
|
assert loaded.mandatee_display_name == "Constance"
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_auto_assign_then_advance_to_active(self, db: AsyncSession):
|
||||||
|
author = await _mk_identity(db, "David")
|
||||||
|
mandate = await _mk_mandate(
|
||||||
|
db,
|
||||||
|
mandatee_id=author.id,
|
||||||
|
steps=[
|
||||||
|
{"step_type": "formulation", "status": "pending"},
|
||||||
|
{"step_type": "assignment", "status": "pending"},
|
||||||
|
{"step_type": "reporting", "status": "pending"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# First advance: draft → candidacy, activates step 0
|
||||||
|
result = await advance_mandate(mandate.id, db)
|
||||||
|
assert result.status == "candidacy"
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.steps[0].status == "active"
|
||||||
|
assert loaded.steps[1].status == "pending"
|
||||||
|
|
||||||
|
# Second advance: step 0 → completed, step 1 → active
|
||||||
|
await advance_mandate(mandate.id, db)
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.steps[0].status == "completed"
|
||||||
|
assert loaded.steps[1].status == "active"
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# TestMandateAssign
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class TestMandateAssign:
|
||||||
|
"""assign_mandatee service: proper UUID lookup, display_name populated."""
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_assign_sets_mandatee_and_starts_at(self, db: AsyncSession):
|
||||||
|
identity = await _mk_identity(db, "Elodie")
|
||||||
|
mandate = await _mk_mandate(db, status="active")
|
||||||
|
|
||||||
|
await assign_mandatee(mandate.id, identity.id, db)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.mandatee_id == identity.id
|
||||||
|
assert loaded.starts_at is not None
|
||||||
|
assert loaded.mandatee_display_name == "Elodie"
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_assign_unknown_identity_raises(self, db: AsyncSession):
|
||||||
|
mandate = await _mk_mandate(db, status="active")
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="Identite Duniter introuvable"):
|
||||||
|
await assign_mandatee(mandate.id, uuid.uuid4(), db)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_assign_completed_mandate_raises(self, db: AsyncSession):
|
||||||
|
identity = await _mk_identity(db, "Fabien")
|
||||||
|
mandate = await _mk_mandate(db, status="completed")
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="statut terminal"):
|
||||||
|
await assign_mandatee(mandate.id, identity.id, db)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_reassign_replaces_mandatee(self, db: AsyncSession):
|
||||||
|
first = await _mk_identity(db, "Gilles")
|
||||||
|
second = await _mk_identity(db, "Hélène")
|
||||||
|
mandate = await _mk_mandate(db, mandatee_id=first.id, status="active")
|
||||||
|
|
||||||
|
await assign_mandatee(mandate.id, second.id, db)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.mandatee_id == second.id
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# TestMandateLifecycle
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class TestMandateLifecycle:
|
||||||
|
"""advance_mandate: full lifecycle with and without steps."""
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_full_lifecycle_no_steps(self, db: AsyncSession):
|
||||||
|
mandate = await _mk_mandate(db)
|
||||||
|
statuses = [mandate.status]
|
||||||
|
|
||||||
|
for _ in range(10):
|
||||||
|
m = await advance_mandate(mandate.id, db)
|
||||||
|
statuses.append(m.status)
|
||||||
|
if m.status == "completed":
|
||||||
|
break
|
||||||
|
|
||||||
|
assert statuses == ["draft", "candidacy", "voting", "active", "reporting", "completed"]
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_steps_activate_in_order(self, db: AsyncSession):
|
||||||
|
mandate = await _mk_mandate(
|
||||||
|
db,
|
||||||
|
steps=[
|
||||||
|
{"step_type": "formulation", "status": "pending"},
|
||||||
|
{"step_type": "candidacy", "status": "pending"},
|
||||||
|
{"step_type": "vote", "status": "pending"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Advance 1: activates step 0, moves to candidacy
|
||||||
|
await advance_mandate(mandate.id, db)
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.status == "candidacy"
|
||||||
|
assert loaded.steps[0].status == "active"
|
||||||
|
assert loaded.steps[1].status == "pending"
|
||||||
|
|
||||||
|
# Advance 2: step 0 → completed, step 1 → active
|
||||||
|
await advance_mandate(mandate.id, db)
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.steps[0].status == "completed"
|
||||||
|
assert loaded.steps[1].status == "active"
|
||||||
|
|
||||||
|
# Advance 3: step 1 → completed, step 2 → active
|
||||||
|
await advance_mandate(mandate.id, db)
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.steps[1].status == "completed"
|
||||||
|
assert loaded.steps[2].status == "active"
|
||||||
|
|
||||||
|
# Advance 4: step 2 → completed, no more pending → advance mandate status
|
||||||
|
await advance_mandate(mandate.id, db)
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.steps[2].status == "completed"
|
||||||
|
assert loaded.status == "voting"
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_advance_terminal_raises(self, db: AsyncSession):
|
||||||
|
for terminal in ("completed", "revoked"):
|
||||||
|
mandate = await _mk_mandate(db, status=terminal)
|
||||||
|
with pytest.raises(ValueError, match="statut terminal"):
|
||||||
|
await advance_mandate(mandate.id, db)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# TestMandateRevocation
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class TestMandateRevocation:
|
||||||
|
"""revoke_mandate: active/pending steps cancelled, completed steps preserved."""
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_revoke_cancels_active_and_pending(self, db: AsyncSession):
|
||||||
|
mandate = await _mk_mandate(
|
||||||
|
db,
|
||||||
|
status="active",
|
||||||
|
steps=[
|
||||||
|
{"step_type": "formulation", "status": "completed"},
|
||||||
|
{"step_type": "assignment", "status": "active"},
|
||||||
|
{"step_type": "reporting", "status": "pending"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
await revoke_mandate(mandate.id, db)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.status == "revoked"
|
||||||
|
assert loaded.ends_at is not None
|
||||||
|
assert loaded.steps[0].status == "completed"
|
||||||
|
assert loaded.steps[1].status == "cancelled"
|
||||||
|
assert loaded.steps[2].status == "cancelled"
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_revoke_sets_ends_at(self, db: AsyncSession):
|
||||||
|
mandate = await _mk_mandate(db, status="draft")
|
||||||
|
|
||||||
|
await revoke_mandate(mandate.id, db)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.ends_at is not None
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_revoke_already_revoked_raises(self, db: AsyncSession):
|
||||||
|
mandate = await _mk_mandate(db, status="revoked")
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="statut terminal"):
|
||||||
|
await revoke_mandate(mandate.id, db)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# TestNominationInteractions
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class TestNominationInteractions:
|
||||||
|
"""Cross-process: nomination + assignment + lifecycle are consistent."""
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_assign_then_advance_full_cycle(self, db: AsyncSession):
|
||||||
|
"""Assigning a mandatee then running the full lifecycle completes cleanly."""
|
||||||
|
mandatee = await _mk_identity(db, "Isabelle")
|
||||||
|
mandate = await _mk_mandate(
|
||||||
|
db,
|
||||||
|
steps=[
|
||||||
|
{"step_type": "formulation", "status": "pending"},
|
||||||
|
{"step_type": "assignment", "status": "pending"},
|
||||||
|
{"step_type": "completion", "status": "pending"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assign before starting
|
||||||
|
await assign_mandatee(mandate.id, mandatee.id, db)
|
||||||
|
|
||||||
|
# Run through all steps
|
||||||
|
for _ in range(5):
|
||||||
|
m = await advance_mandate(mandate.id, db)
|
||||||
|
if m.status in ("completed", "revoked"):
|
||||||
|
break
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
# All steps completed, mandate advanced beyond steps
|
||||||
|
assert all(s.status == "completed" for s in loaded.steps)
|
||||||
|
assert loaded.mandatee_id == mandatee.id
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_revoke_after_assign_preserves_mandatee_id(self, db: AsyncSession):
|
||||||
|
"""Revoking a mandate keeps mandatee_id (for audit trail)."""
|
||||||
|
mandatee = await _mk_identity(db, "Jacques")
|
||||||
|
mandate = await _mk_mandate(db, mandatee_id=mandatee.id, status="active")
|
||||||
|
|
||||||
|
await revoke_mandate(mandate.id, db)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.status == "revoked"
|
||||||
|
assert loaded.mandatee_id == mandatee.id
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_origin_and_mandatee_can_differ(self, db: AsyncSession):
|
||||||
|
"""The person who proposed the mandate (origin) is different from the mandatee."""
|
||||||
|
proposer = await _mk_identity(db, "Kim")
|
||||||
|
mandatee = await _mk_identity(db, "Laurent")
|
||||||
|
|
||||||
|
mandate = await _mk_mandate(db, origin_id=proposer.id)
|
||||||
|
await assign_mandatee(mandate.id, mandatee.id, db)
|
||||||
|
|
||||||
|
loaded = await _reload(db, mandate.id)
|
||||||
|
assert loaded.origin_id == proposer.id
|
||||||
|
assert loaded.mandatee_id == mandatee.id
|
||||||
|
assert loaded.origin_display_name == "Kim"
|
||||||
|
assert loaded.mandatee_display_name == "Laurent"
|
||||||
@@ -14,8 +14,21 @@ from __future__ import annotations
|
|||||||
import pytest
|
import pytest
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
|
import app.models # noqa: F401 — registers all models with Base.metadata before create_all
|
||||||
|
from app.database import init_db
|
||||||
from app.main import app
|
from app.main import app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module", autouse=True)
|
||||||
|
async def _create_tables():
|
||||||
|
"""Create DB tables once for this module.
|
||||||
|
|
||||||
|
ASGITransport does not trigger the FastAPI lifespan, so init_db() would
|
||||||
|
never run. Tests that hit endpoints backed by the DB need the tables to
|
||||||
|
exist beforehand.
|
||||||
|
"""
|
||||||
|
await init_db()
|
||||||
|
|
||||||
ORIGIN = "http://localhost:3002"
|
ORIGIN = "http://localhost:3002"
|
||||||
CHALLENGE_URL = "/api/v1/auth/challenge"
|
CHALLENGE_URL = "/api/v1/auth/challenge"
|
||||||
VERIFY_URL = "/api/v1/auth/verify"
|
VERIFY_URL = "/api/v1/auth/verify"
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ substrate-interface==1.7.10
|
|||||||
py-sr25519-bindings==0.2.1
|
py-sr25519-bindings==0.2.1
|
||||||
base58==2.1.1
|
base58==2.1.1
|
||||||
httpx==0.28.1
|
httpx==0.28.1
|
||||||
anthropic>=0.97.0
|
|
||||||
aioipfs==0.7.1
|
aioipfs==0.7.1
|
||||||
pytest==8.3.4
|
pytest==8.3.4
|
||||||
pytest-asyncio==0.24.0
|
pytest-asyncio==0.24.0
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ COPY backend/requirements.txt .
|
|||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8002 --reload"]
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8002", "--reload"]
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ const confidenceLabel: Record<string, string> = {
|
|||||||
Aucun mandat actif pour l'espace de travail sélectionné.
|
Aucun mandat actif pour l'espace de travail sélectionné.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<NuxtLink to="/mandates" class="mandate-request-btn">
|
<NuxtLink to="/mandates/new" class="mandate-request-btn">
|
||||||
<UIcon name="i-lucide-plus" />
|
<UIcon name="i-lucide-plus" />
|
||||||
Demander un mandat
|
Demander un mandat
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ const activeStepIndex = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isProtoMode = computed(() => devProfiles.value.length > 0)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (auth.isAuthenticated) {
|
if (auth.isAuthenticated) {
|
||||||
router.push('/')
|
router.push('/')
|
||||||
@@ -166,45 +168,50 @@ onMounted(() => {
|
|||||||
<span>Connecte. Redirection...</span>
|
<span>Connecte. Redirection...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Button -->
|
<!-- Mode prototype : profils démo -->
|
||||||
<button
|
<template v-if="isProtoMode">
|
||||||
class="login-card__btn"
|
<div class="proto-panel">
|
||||||
:disabled="!address.trim() || step === 'success' || auth.loading"
|
<div class="proto-panel__header">
|
||||||
@click="handleLogin"
|
<UIcon name="i-lucide-flask-conical" />
|
||||||
>
|
<span>Mode prototype — sélectionnez un profil</span>
|
||||||
<UIcon v-if="auth.loading" name="i-lucide-loader-2" class="animate-spin" />
|
</div>
|
||||||
<UIcon v-else name="i-lucide-log-in" />
|
<div class="proto-panel__profiles">
|
||||||
<span>{{ auth.loading ? 'Verification...' : 'Se connecter' }}</span>
|
<button
|
||||||
</button>
|
v-for="p in devProfiles"
|
||||||
|
:key="p.address"
|
||||||
<!-- Dev Mode Panel -->
|
class="dev-profile"
|
||||||
<div v-if="devProfiles.length" class="dev-panel">
|
:disabled="devLoading || step === 'success'"
|
||||||
<div class="dev-panel__header">
|
@click="loginAsProfile(p)"
|
||||||
<UIcon name="i-lucide-bug" />
|
>
|
||||||
<span>Mode Dev — Connexion rapide</span>
|
<div class="dev-profile__dot" :style="{ background: statusColor(p) }" />
|
||||||
|
<div class="dev-profile__info">
|
||||||
|
<span class="dev-profile__name">{{ p.display_name }}</span>
|
||||||
|
<span class="dev-profile__status">{{ statusLabel(p) }}</span>
|
||||||
|
</div>
|
||||||
|
<span class="dev-profile__addr">{{ p.address.slice(0, 8) }}...</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="proto-panel__note">
|
||||||
|
Authentification trustWallet à venir — intégration librodrome
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="dev-panel__profiles">
|
</template>
|
||||||
<button
|
|
||||||
v-for="p in devProfiles"
|
|
||||||
:key="p.address"
|
|
||||||
class="dev-profile"
|
|
||||||
:disabled="devLoading || step === 'success'"
|
|
||||||
@click="loginAsProfile(p)"
|
|
||||||
>
|
|
||||||
<div class="dev-profile__dot" :style="{ background: statusColor(p) }" />
|
|
||||||
<div class="dev-profile__info">
|
|
||||||
<span class="dev-profile__name">{{ p.display_name }}</span>
|
|
||||||
<span class="dev-profile__status">{{ statusLabel(p) }}</span>
|
|
||||||
</div>
|
|
||||||
<span class="dev-profile__addr">{{ p.address.slice(0, 8) }}...</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Note -->
|
<!-- Mode production : formulaire + extension -->
|
||||||
<p class="login-card__note">
|
<template v-else>
|
||||||
Aucun mot de passe. Authentification par signature cryptographique.
|
<button
|
||||||
</p>
|
class="login-card__btn"
|
||||||
|
:disabled="!address.trim() || step === 'success' || auth.loading"
|
||||||
|
@click="handleLogin"
|
||||||
|
>
|
||||||
|
<UIcon v-if="auth.loading" name="i-lucide-loader-2" class="animate-spin" />
|
||||||
|
<UIcon v-else name="i-lucide-log-in" />
|
||||||
|
<span>{{ auth.loading ? 'Verification...' : 'Se connecter' }}</span>
|
||||||
|
</button>
|
||||||
|
<p class="login-card__note">
|
||||||
|
Aucun mot de passe. Authentification par signature cryptographique.
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -453,32 +460,40 @@ onMounted(() => {
|
|||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dev panel */
|
/* Proto panel */
|
||||||
.dev-panel {
|
.proto-panel {
|
||||||
border: 2px dashed var(--mood-warning, #f59e0b);
|
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
background: rgba(245, 158, 11, 0.04);
|
background: var(--mood-accent-soft);
|
||||||
|
box-shadow: 0 2px 12px var(--mood-shadow, rgba(0,0,0,0.06));
|
||||||
}
|
}
|
||||||
|
|
||||||
.dev-panel__header {
|
.proto-panel__header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
font-size: 0.8125rem;
|
font-size: 0.8125rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: var(--mood-warning, #f59e0b);
|
color: var(--mood-accent);
|
||||||
margin-bottom: 0.75rem;
|
margin-bottom: 0.75rem;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 0.04em;
|
letter-spacing: 0.04em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dev-panel__profiles {
|
.proto-panel__profiles {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.proto-panel__note {
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: var(--mood-text-muted);
|
||||||
|
opacity: 0.7;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.dev-profile {
|
.dev-profile {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const mandates = useMandatesStore()
|
const mandates = useMandatesStore()
|
||||||
|
const { $api } = useApi()
|
||||||
|
|
||||||
const mandateId = computed(() => route.params.id as string)
|
const mandateId = computed(() => route.params.id as string)
|
||||||
|
|
||||||
@@ -13,77 +14,95 @@ onUnmounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
watch(mandateId, async (newId) => {
|
watch(mandateId, async (newId) => {
|
||||||
if (newId) {
|
if (newId) await mandates.fetchById(newId)
|
||||||
await mandates.fetchById(newId)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// --- Status helpers ---
|
// --- Helpers ---
|
||||||
|
|
||||||
const typeLabel = (mandateType: string) => {
|
const typeLabel = (t: string) => ({ statutory: 'Statutaire', functional: 'Fonctionnel' }[t] ?? t)
|
||||||
switch (mandateType) {
|
|
||||||
case 'techcomm': return 'Comite technique'
|
function formatDate(d: string | null): string {
|
||||||
case 'smith': return 'Forgeron'
|
if (!d) return '-'
|
||||||
case 'custom': return 'Personnalise'
|
return new Date(d).toLocaleDateString('fr-FR', { day: 'numeric', month: 'long', year: 'numeric' })
|
||||||
default: return mandateType
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDate(dateStr: string | null): string {
|
|
||||||
if (!dateStr) return '-'
|
|
||||||
return new Date(dateStr).toLocaleDateString('fr-FR', {
|
|
||||||
day: 'numeric',
|
|
||||||
month: 'long',
|
|
||||||
year: 'numeric',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Terminal state check ---
|
|
||||||
|
|
||||||
const terminalStatuses = ['completed', 'revoked']
|
const terminalStatuses = ['completed', 'revoked']
|
||||||
const isTerminal = computed(() => {
|
const isTerminal = computed(() => !mandates.current || terminalStatuses.includes(mandates.current.status))
|
||||||
if (!mandates.current) return true
|
const canRevoke = computed(() => mandates.current?.status === 'active')
|
||||||
return terminalStatuses.includes(mandates.current.status)
|
const isDraft = computed(() => mandates.current?.status === 'draft')
|
||||||
})
|
|
||||||
|
|
||||||
const canRevoke = computed(() => {
|
// --- Advance ---
|
||||||
if (!mandates.current) return false
|
|
||||||
return mandates.current.status === 'active'
|
|
||||||
})
|
|
||||||
|
|
||||||
// --- Advance action ---
|
|
||||||
|
|
||||||
const advancing = ref(false)
|
const advancing = ref(false)
|
||||||
|
|
||||||
async function handleAdvance() {
|
async function handleAdvance() {
|
||||||
advancing.value = true
|
advancing.value = true
|
||||||
try {
|
try { await mandates.advance(mandateId.value) } catch { /* store holds error */ } finally { advancing.value = false }
|
||||||
await mandates.advance(mandateId.value)
|
}
|
||||||
} catch {
|
|
||||||
// Error handled by store
|
// --- Identity search (shared for assign + edit) ---
|
||||||
} finally {
|
|
||||||
advancing.value = false
|
interface IdentityResult { id: string; address: string; display_name: string | null }
|
||||||
|
|
||||||
|
function useIdentitySearch() {
|
||||||
|
const query = ref('')
|
||||||
|
const results = ref<IdentityResult[]>([])
|
||||||
|
const searching = ref(false)
|
||||||
|
const selectedId = ref<string | null>(null)
|
||||||
|
const selectedLabel = ref('')
|
||||||
|
let timer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
|
async function search(q: string) {
|
||||||
|
if (q.length < 2) { results.value = []; return }
|
||||||
|
searching.value = true
|
||||||
|
try {
|
||||||
|
results.value = await $api<IdentityResult[]>('/auth/identities', { query: { q } })
|
||||||
|
} catch { results.value = [] } finally { searching.value = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onInput(q: string) {
|
||||||
|
query.value = q
|
||||||
|
selectedId.value = null
|
||||||
|
if (timer) clearTimeout(timer)
|
||||||
|
timer = setTimeout(() => search(q), 300)
|
||||||
|
}
|
||||||
|
|
||||||
|
function select(i: IdentityResult) {
|
||||||
|
selectedId.value = i.id
|
||||||
|
selectedLabel.value = i.display_name || i.address
|
||||||
|
query.value = i.display_name || i.address
|
||||||
|
results.value = []
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
query.value = ''
|
||||||
|
results.value = []
|
||||||
|
selectedId.value = null
|
||||||
|
selectedLabel.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return { query, results, searching, selectedId, selectedLabel, onInput, select, reset }
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Assign mandatee ---
|
// --- Assign mandatee ---
|
||||||
|
|
||||||
const showAssignModal = ref(false)
|
const showAssignModal = ref(false)
|
||||||
const mandateeAddress = ref('')
|
|
||||||
const assigning = ref(false)
|
const assigning = ref(false)
|
||||||
|
const assignSearch = useIdentitySearch()
|
||||||
|
|
||||||
async function handleAssign() {
|
async function handleAssign() {
|
||||||
if (!mandateeAddress.value.trim()) return
|
if (!assignSearch.selectedId.value) return
|
||||||
assigning.value = true
|
assigning.value = true
|
||||||
try {
|
try {
|
||||||
await mandates.assignMandatee(mandateId.value, mandateeAddress.value.trim())
|
await mandates.assignMandatee(mandateId.value, assignSearch.selectedId.value)
|
||||||
showAssignModal.value = false
|
showAssignModal.value = false
|
||||||
mandateeAddress.value = ''
|
assignSearch.reset()
|
||||||
} catch {
|
} catch { /* store holds error */ } finally { assigning.value = false }
|
||||||
// Error handled by store
|
}
|
||||||
} finally {
|
|
||||||
assigning.value = false
|
function openAssign() {
|
||||||
}
|
assignSearch.reset()
|
||||||
|
showAssignModal.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Revoke ---
|
// --- Revoke ---
|
||||||
@@ -96,27 +115,28 @@ async function handleRevoke() {
|
|||||||
try {
|
try {
|
||||||
await mandates.revoke(mandateId.value)
|
await mandates.revoke(mandateId.value)
|
||||||
showRevokeConfirm.value = false
|
showRevokeConfirm.value = false
|
||||||
} catch {
|
} catch { /* store holds error */ } finally { revoking.value = false }
|
||||||
// Error handled by store
|
|
||||||
} finally {
|
|
||||||
revoking.value = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Edit modal ---
|
// --- Edit ---
|
||||||
|
|
||||||
const showEditModal = ref(false)
|
const showEditModal = ref(false)
|
||||||
const editData = ref({
|
const editData = ref({ title: '', origin_id: null as string | null, description: '' })
|
||||||
title: '',
|
const editOriginSearch = useIdentitySearch()
|
||||||
description: '' as string | null,
|
|
||||||
})
|
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
|
|
||||||
function openEdit() {
|
function openEdit() {
|
||||||
if (!mandates.current) return
|
if (!mandates.current) return
|
||||||
editData.value = {
|
editData.value = {
|
||||||
title: mandates.current.title,
|
title: mandates.current.title,
|
||||||
description: mandates.current.description,
|
origin_id: mandates.current.origin_id,
|
||||||
|
description: mandates.current.description ?? '',
|
||||||
|
}
|
||||||
|
if (mandates.current.origin_display_name) {
|
||||||
|
editOriginSearch.query.value = mandates.current.origin_display_name
|
||||||
|
editOriginSearch.selectedId.value = mandates.current.origin_id
|
||||||
|
} else {
|
||||||
|
editOriginSearch.reset()
|
||||||
}
|
}
|
||||||
showEditModal.value = true
|
showEditModal.value = true
|
||||||
}
|
}
|
||||||
@@ -124,50 +144,35 @@ function openEdit() {
|
|||||||
async function saveEdit() {
|
async function saveEdit() {
|
||||||
saving.value = true
|
saving.value = true
|
||||||
try {
|
try {
|
||||||
await mandates.update(mandateId.value, editData.value)
|
await mandates.update(mandateId.value, {
|
||||||
|
title: editData.value.title,
|
||||||
|
origin_id: editOriginSearch.selectedId.value ?? editData.value.origin_id,
|
||||||
|
description: editData.value.description || null,
|
||||||
|
})
|
||||||
showEditModal.value = false
|
showEditModal.value = false
|
||||||
} catch {
|
} catch { /* store holds error */ } finally { saving.value = false }
|
||||||
// Error handled by store
|
|
||||||
} finally {
|
|
||||||
saving.value = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Delete ---
|
// --- Delete ---
|
||||||
|
|
||||||
const showDeleteConfirm = ref(false)
|
const showDeleteConfirm = ref(false)
|
||||||
const deleting = ref(false)
|
const deleting = ref(false)
|
||||||
const isDraft = computed(() => mandates.current?.status === 'draft')
|
|
||||||
|
|
||||||
async function handleDelete() {
|
async function handleDelete() {
|
||||||
deleting.value = true
|
deleting.value = true
|
||||||
try {
|
try {
|
||||||
await mandates.delete(mandateId.value)
|
await mandates.delete(mandateId.value)
|
||||||
navigateTo('/mandates')
|
navigateTo('/mandates')
|
||||||
} catch {
|
} catch { /* store holds error */ } finally { deleting.value = false; showDeleteConfirm.value = false }
|
||||||
// Error handled by store
|
|
||||||
} finally {
|
|
||||||
deleting.value = false
|
|
||||||
showDeleteConfirm.value = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
<!-- Back link -->
|
|
||||||
<div>
|
<div>
|
||||||
<UButton
|
<UButton to="/mandates" variant="ghost" color="neutral" icon="i-lucide-arrow-left" label="Retour aux mandats" size="sm" />
|
||||||
to="/mandates"
|
|
||||||
variant="ghost"
|
|
||||||
color="neutral"
|
|
||||||
icon="i-lucide-arrow-left"
|
|
||||||
label="Retour aux mandats"
|
|
||||||
size="sm"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Loading state -->
|
|
||||||
<template v-if="mandates.loading">
|
<template v-if="mandates.loading">
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<USkeleton class="h-8 w-96" />
|
<USkeleton class="h-8 w-96" />
|
||||||
@@ -178,7 +183,6 @@ async function handleDelete() {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Error state -->
|
|
||||||
<template v-else-if="mandates.error">
|
<template v-else-if="mandates.error">
|
||||||
<UCard>
|
<UCard>
|
||||||
<div class="flex items-center gap-3 text-red-500">
|
<div class="flex items-center gap-3 text-red-500">
|
||||||
@@ -188,79 +192,35 @@ async function handleDelete() {
|
|||||||
</UCard>
|
</UCard>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Mandate detail -->
|
|
||||||
<template v-else-if="mandates.current">
|
<template v-else-if="mandates.current">
|
||||||
<!-- Header with actions -->
|
<!-- Header -->
|
||||||
<div class="flex items-start justify-between">
|
<div class="flex items-start justify-between">
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-2xl font-bold text-gray-900 dark:text-white">
|
<h1 class="text-2xl font-bold text-gray-900 dark:text-white">{{ mandates.current.title }}</h1>
|
||||||
{{ mandates.current.title }}
|
|
||||||
</h1>
|
|
||||||
<div class="flex items-center gap-3 mt-2">
|
<div class="flex items-center gap-3 mt-2">
|
||||||
<UBadge variant="subtle" color="primary">
|
<UBadge variant="subtle" color="primary">{{ typeLabel(mandates.current.mandate_type) }}</UBadge>
|
||||||
{{ typeLabel(mandates.current.mandate_type) }}
|
|
||||||
</UBadge>
|
|
||||||
<StatusBadge :status="mandates.current.status" type="mandate" />
|
<StatusBadge :status="mandates.current.status" type="mandate" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Action buttons -->
|
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<UButton
|
<UButton v-if="!isTerminal" icon="i-lucide-fast-forward" label="Avancer" color="primary" variant="soft" size="sm" :loading="advancing" @click="handleAdvance" />
|
||||||
v-if="!isTerminal"
|
<UButton v-if="!isTerminal && !mandates.current.mandatee_id" icon="i-lucide-user-plus" label="Assigner un mandataire" variant="soft" color="primary" size="sm" @click="openAssign" />
|
||||||
icon="i-lucide-fast-forward"
|
<UButton icon="i-lucide-pen-line" label="Modifier" variant="soft" color="neutral" size="sm" @click="openEdit" />
|
||||||
label="Avancer"
|
<UButton v-if="canRevoke" icon="i-lucide-shield-off" label="Revoquer" variant="soft" color="error" size="sm" @click="showRevokeConfirm = true" />
|
||||||
color="primary"
|
<UButton v-if="isDraft" icon="i-lucide-trash-2" label="Supprimer" variant="soft" color="error" size="sm" @click="showDeleteConfirm = true" />
|
||||||
variant="soft"
|
|
||||||
size="sm"
|
|
||||||
:loading="advancing"
|
|
||||||
@click="handleAdvance"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
v-if="!isTerminal && !mandates.current.mandatee_id"
|
|
||||||
icon="i-lucide-user-plus"
|
|
||||||
label="Assigner un mandataire"
|
|
||||||
variant="soft"
|
|
||||||
color="primary"
|
|
||||||
size="sm"
|
|
||||||
@click="showAssignModal = true"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
icon="i-lucide-pen-line"
|
|
||||||
label="Modifier"
|
|
||||||
variant="soft"
|
|
||||||
color="neutral"
|
|
||||||
size="sm"
|
|
||||||
@click="openEdit"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
v-if="canRevoke"
|
|
||||||
icon="i-lucide-shield-off"
|
|
||||||
label="Revoquer"
|
|
||||||
variant="soft"
|
|
||||||
color="error"
|
|
||||||
size="sm"
|
|
||||||
@click="showRevokeConfirm = true"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
v-if="isDraft"
|
|
||||||
icon="i-lucide-trash-2"
|
|
||||||
label="Supprimer"
|
|
||||||
variant="soft"
|
|
||||||
color="error"
|
|
||||||
size="sm"
|
|
||||||
@click="showDeleteConfirm = true"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Description -->
|
<!-- Error feedback -->
|
||||||
|
<div v-if="mandates.error" class="text-sm text-red-500 bg-red-50 dark:bg-red-950 px-4 py-2 rounded-lg">
|
||||||
|
{{ mandates.error }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<UCard v-if="mandates.current.description">
|
<UCard v-if="mandates.current.description">
|
||||||
<div>
|
<div>
|
||||||
<h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wide mb-1">Description</h3>
|
<h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wide mb-1">Description</h3>
|
||||||
<p class="text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap">
|
<p class="text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap">{{ mandates.current.description }}</p>
|
||||||
{{ mandates.current.description }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</UCard>
|
</UCard>
|
||||||
|
|
||||||
@@ -270,199 +230,204 @@ async function handleDelete() {
|
|||||||
<div>
|
<div>
|
||||||
<p class="text-gray-500">Mandataire</p>
|
<p class="text-gray-500">Mandataire</p>
|
||||||
<p class="font-medium text-gray-900 dark:text-white">
|
<p class="font-medium text-gray-900 dark:text-white">
|
||||||
<template v-if="mandates.current.mandatee_id">
|
<template v-if="mandates.current.mandatee_display_name">{{ mandates.current.mandatee_display_name }}</template>
|
||||||
<span class="font-mono text-xs">{{ mandates.current.mandatee_id.slice(0, 12) }}...</span>
|
<template v-else-if="mandates.current.mandatee_id"><span class="font-mono text-xs">{{ mandates.current.mandatee_id.slice(0, 12) }}…</span></template>
|
||||||
</template>
|
<template v-else><span class="text-gray-400 italic">Non assigne</span></template>
|
||||||
<template v-else>
|
</p>
|
||||||
<span class="text-gray-400 italic">Non assigne</span>
|
</div>
|
||||||
</template>
|
<div>
|
||||||
|
<p class="text-gray-500">Origine</p>
|
||||||
|
<p class="font-medium text-gray-900 dark:text-white">
|
||||||
|
<template v-if="mandates.current.origin_display_name">{{ mandates.current.origin_display_name }}</template>
|
||||||
|
<template v-else><span class="text-gray-400 italic">Non renseigné</span></template>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class="text-gray-500">Debut</p>
|
<p class="text-gray-500">Debut</p>
|
||||||
<p class="font-medium text-gray-900 dark:text-white">
|
<p class="font-medium text-gray-900 dark:text-white">{{ formatDate(mandates.current.starts_at) }}</p>
|
||||||
{{ formatDate(mandates.current.starts_at) }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class="text-gray-500">Fin</p>
|
<p class="text-gray-500">Fin</p>
|
||||||
<p class="font-medium text-gray-900 dark:text-white">
|
<p class="font-medium text-gray-900 dark:text-white">{{ formatDate(mandates.current.ends_at) }}</p>
|
||||||
{{ formatDate(mandates.current.ends_at) }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p class="text-gray-500">Nombre d'etapes</p>
|
|
||||||
<p class="font-medium text-gray-900 dark:text-white">
|
|
||||||
{{ mandates.current.steps.length }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</UCard>
|
</UCard>
|
||||||
|
|
||||||
<!-- Dates metadata -->
|
|
||||||
<UCard>
|
<UCard>
|
||||||
<div class="grid grid-cols-2 gap-4 text-sm">
|
<div class="grid grid-cols-2 gap-4 text-sm">
|
||||||
<div>
|
<div>
|
||||||
<p class="text-gray-500">Cree le</p>
|
<p class="text-gray-500">Cree le</p>
|
||||||
<p class="font-medium text-gray-900 dark:text-white">
|
<p class="font-medium text-gray-900 dark:text-white">{{ formatDate(mandates.current.created_at) }}</p>
|
||||||
{{ formatDate(mandates.current.created_at) }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class="text-gray-500">Mis a jour le</p>
|
<p class="text-gray-500">Mis a jour le</p>
|
||||||
<p class="font-medium text-gray-900 dark:text-white">
|
<p class="font-medium text-gray-900 dark:text-white">{{ formatDate(mandates.current.updated_at) }}</p>
|
||||||
{{ formatDate(mandates.current.updated_at) }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</UCard>
|
</UCard>
|
||||||
|
|
||||||
<!-- Steps timeline -->
|
<!-- Steps -->
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">
|
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Etapes du mandat</h2>
|
||||||
Etapes du mandat
|
<MandateTimeline :steps="mandates.current.steps" :current-status="mandates.current.status" />
|
||||||
</h2>
|
|
||||||
|
|
||||||
<MandateTimeline
|
|
||||||
:steps="mandates.current.steps"
|
|
||||||
:current-status="mandates.current.status"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Assign mandatee modal -->
|
<!-- Modal : Assigner un mandataire -->
|
||||||
<UModal v-model:open="showAssignModal">
|
<UModal v-model:open="showAssignModal">
|
||||||
<template #content>
|
<template #content>
|
||||||
<div class="p-6 space-y-4">
|
<div class="p-6 space-y-4">
|
||||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">
|
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Assigner un mandataire</h3>
|
||||||
Assigner un mandataire
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||||
Adresse du mandataire <span class="text-red-500">*</span>
|
Rechercher un membre <span class="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
<UInput
|
<div class="relative">
|
||||||
v-model="mandateeAddress"
|
<input
|
||||||
placeholder="Adresse Duniter (ex: 5Grw...)
|
:value="assignSearch.query.value"
|
||||||
"
|
type="text"
|
||||||
/>
|
class="w-full rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500"
|
||||||
<p class="text-xs text-gray-500">
|
placeholder="Nom ou adresse Duniter…"
|
||||||
Adresse SS58 du membre de la toile de confiance
|
@input="assignSearch.onInput(($event.target as HTMLInputElement).value)"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="assignSearch.results.value.length"
|
||||||
|
class="absolute z-10 mt-1 w-full bg-white dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-700 shadow-lg overflow-hidden"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-for="r in assignSearch.results.value"
|
||||||
|
:key="r.id"
|
||||||
|
class="w-full flex items-center gap-3 px-4 py-2 text-left text-sm hover:bg-gray-50 dark:hover:bg-gray-800"
|
||||||
|
@click="assignSearch.select(r)"
|
||||||
|
>
|
||||||
|
<UIcon name="i-lucide-user" class="text-gray-400 shrink-0" />
|
||||||
|
<div>
|
||||||
|
<p class="font-medium text-gray-900 dark:text-white">{{ r.display_name || r.address }}</p>
|
||||||
|
<p class="text-xs text-gray-500 font-mono">{{ r.address.slice(0, 20) }}…</p>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p v-if="assignSearch.selectedId.value" class="text-xs text-green-600 flex items-center gap-1">
|
||||||
|
<UIcon name="i-lucide-check-circle" /> {{ assignSearch.selectedLabel.value }} sélectionné
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||||
<UButton
|
<button class="px-4 py-2 text-sm text-gray-600 hover:text-gray-900" @click="showAssignModal = false">Annuler</button>
|
||||||
label="Annuler"
|
<button
|
||||||
variant="ghost"
|
class="px-4 py-2 text-sm font-medium bg-primary-600 text-white rounded-xl hover:bg-primary-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||||
color="neutral"
|
:disabled="!assignSearch.selectedId.value || assigning"
|
||||||
@click="showAssignModal = false"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
label="Assigner"
|
|
||||||
icon="i-lucide-user-plus"
|
|
||||||
color="primary"
|
|
||||||
:loading="assigning"
|
|
||||||
:disabled="!mandateeAddress.trim()"
|
|
||||||
@click="handleAssign"
|
@click="handleAssign"
|
||||||
/>
|
>
|
||||||
|
<UIcon v-if="assigning" name="i-lucide-loader-2" class="animate-spin text-sm" />
|
||||||
|
Assigner
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
|
|
||||||
<!-- Revoke confirmation modal -->
|
<!-- Modal : Révoquer -->
|
||||||
<UModal v-model:open="showRevokeConfirm">
|
<UModal v-model:open="showRevokeConfirm">
|
||||||
<template #content>
|
<template #content>
|
||||||
<div class="p-6 space-y-4">
|
<div class="p-6 space-y-4">
|
||||||
<h3 class="text-lg font-semibold text-red-600">
|
<h3 class="text-lg font-semibold text-red-600">Confirmer la revocation</h3>
|
||||||
Confirmer la revocation
|
|
||||||
</h3>
|
|
||||||
<p class="text-sm text-gray-600 dark:text-gray-400">
|
<p class="text-sm text-gray-600 dark:text-gray-400">
|
||||||
Etes-vous sur de vouloir revoquer ce mandat ? Le mandataire perdra ses droits et responsabilites.
|
Etes-vous sur de vouloir revoquer ce mandat ? Le mandataire perdra ses droits et responsabilites.
|
||||||
</p>
|
</p>
|
||||||
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||||
<UButton
|
<button class="px-4 py-2 text-sm text-gray-600 hover:text-gray-900" @click="showRevokeConfirm = false">Annuler</button>
|
||||||
label="Annuler"
|
<button
|
||||||
variant="ghost"
|
class="px-4 py-2 text-sm font-medium bg-red-600 text-white rounded-xl hover:bg-red-700 flex items-center gap-2"
|
||||||
color="neutral"
|
:disabled="revoking"
|
||||||
@click="showRevokeConfirm = false"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
label="Revoquer"
|
|
||||||
icon="i-lucide-shield-off"
|
|
||||||
color="error"
|
|
||||||
:loading="revoking"
|
|
||||||
@click="handleRevoke"
|
@click="handleRevoke"
|
||||||
/>
|
>
|
||||||
|
<UIcon v-if="revoking" name="i-lucide-loader-2" class="animate-spin text-sm" />
|
||||||
|
Revoquer
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
|
|
||||||
<!-- Edit modal -->
|
<!-- Modal : Modifier -->
|
||||||
<UModal v-model:open="showEditModal">
|
<UModal v-model:open="showEditModal">
|
||||||
<template #content>
|
<template #content>
|
||||||
<div class="p-6 space-y-4">
|
<div class="p-6 space-y-4">
|
||||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">
|
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Modifier le mandat</h3>
|
||||||
Modifier le mandat
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Titre</label>
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Titre</label>
|
||||||
<UInput v-model="editData.title" />
|
<input v-model="editData.title" type="text" class="w-full rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-1">
|
||||||
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Origine</label>
|
||||||
|
<div class="relative">
|
||||||
|
<input
|
||||||
|
:value="editOriginSearch.query.value"
|
||||||
|
type="text"
|
||||||
|
class="w-full rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500"
|
||||||
|
placeholder="Rechercher un membre…"
|
||||||
|
@input="editOriginSearch.onInput(($event.target as HTMLInputElement).value)"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="editOriginSearch.results.value.length"
|
||||||
|
class="absolute z-10 mt-1 w-full bg-white dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-700 shadow-lg overflow-hidden"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-for="r in editOriginSearch.results.value"
|
||||||
|
:key="r.id"
|
||||||
|
class="w-full flex items-center gap-3 px-4 py-2 text-left text-sm hover:bg-gray-50 dark:hover:bg-gray-800"
|
||||||
|
@click="editOriginSearch.select(r)"
|
||||||
|
>
|
||||||
|
<UIcon name="i-lucide-user" class="text-gray-400 shrink-0" />
|
||||||
|
<span>{{ r.display_name || r.address }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Description</label>
|
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Description</label>
|
||||||
<UTextarea v-model="editData.description" :rows="4" />
|
<textarea v-model="editData.description" rows="4" class="w-full rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 resize-none" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||||
<UButton
|
<button class="px-4 py-2 text-sm text-gray-600 hover:text-gray-900" @click="showEditModal = false">Annuler</button>
|
||||||
label="Annuler"
|
<button
|
||||||
variant="ghost"
|
class="px-4 py-2 text-sm font-medium bg-primary-600 text-white rounded-xl hover:bg-primary-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||||
color="neutral"
|
:disabled="!editData.title?.trim() || saving"
|
||||||
@click="showEditModal = false"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
label="Enregistrer"
|
|
||||||
icon="i-lucide-save"
|
|
||||||
color="primary"
|
|
||||||
:loading="saving"
|
|
||||||
:disabled="!editData.title?.trim()"
|
|
||||||
@click="saveEdit"
|
@click="saveEdit"
|
||||||
/>
|
>
|
||||||
|
<UIcon v-if="saving" name="i-lucide-loader-2" class="animate-spin text-sm" />
|
||||||
|
Enregistrer
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
|
|
||||||
<!-- Delete confirmation modal -->
|
<!-- Modal : Supprimer -->
|
||||||
<UModal v-model:open="showDeleteConfirm">
|
<UModal v-model:open="showDeleteConfirm">
|
||||||
<template #content>
|
<template #content>
|
||||||
<div class="p-6 space-y-4">
|
<div class="p-6 space-y-4">
|
||||||
<h3 class="text-lg font-semibold text-red-600">
|
<h3 class="text-lg font-semibold text-red-600">Confirmer la suppression</h3>
|
||||||
Confirmer la suppression
|
|
||||||
</h3>
|
|
||||||
<p class="text-sm text-gray-600 dark:text-gray-400">
|
<p class="text-sm text-gray-600 dark:text-gray-400">
|
||||||
Etes-vous sur de vouloir supprimer ce mandat ? Cette action est irreversible.
|
Etes-vous sur de vouloir supprimer ce mandat ? Cette action est irreversible.
|
||||||
</p>
|
</p>
|
||||||
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
<div class="flex justify-end gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||||
<UButton
|
<button class="px-4 py-2 text-sm text-gray-600 hover:text-gray-900" @click="showDeleteConfirm = false">Annuler</button>
|
||||||
label="Annuler"
|
<button
|
||||||
variant="ghost"
|
class="px-4 py-2 text-sm font-medium bg-red-600 text-white rounded-xl hover:bg-red-700 flex items-center gap-2"
|
||||||
color="neutral"
|
:disabled="deleting"
|
||||||
@click="showDeleteConfirm = false"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
label="Supprimer"
|
|
||||||
icon="i-lucide-trash-2"
|
|
||||||
color="error"
|
|
||||||
:loading="deleting"
|
|
||||||
@click="handleDelete"
|
@click="handleDelete"
|
||||||
/>
|
>
|
||||||
|
<UIcon v-if="deleting" name="i-lucide-loader-2" class="animate-spin text-sm" />
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ const filteredMandates = computed(() => {
|
|||||||
|
|
||||||
// Filter by status group
|
// Filter by status group
|
||||||
if (activeStatus.value && statusGroupMap[activeStatus.value]) {
|
if (activeStatus.value && statusGroupMap[activeStatus.value]) {
|
||||||
const allowedStatuses = statusGroupMap[activeStatus.value]
|
const allowedStatuses = statusGroupMap[activeStatus.value]!
|
||||||
list = list.filter(m => allowedStatuses.includes(m.status))
|
list = list.filter(m => allowedStatuses.includes(m.status))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +95,8 @@ const filteredMandates = computed(() => {
|
|||||||
|
|
||||||
const typeLabel = (mandateType: string) => {
|
const typeLabel = (mandateType: string) => {
|
||||||
switch (mandateType) {
|
switch (mandateType) {
|
||||||
|
case 'statutory': return 'Statutaire'
|
||||||
|
case 'functional': return 'Fonctionnel'
|
||||||
case 'techcomm': return 'Comité technique'
|
case 'techcomm': return 'Comité technique'
|
||||||
case 'smith': return 'Forgeron'
|
case 'smith': return 'Forgeron'
|
||||||
case 'custom': return 'Personnalisé'
|
case 'custom': return 'Personnalisé'
|
||||||
@@ -154,14 +156,14 @@ async function handleCreate() {
|
|||||||
{{ opt.label }}
|
{{ opt.label }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<button
|
<NuxtLink
|
||||||
v-if="auth.isAuthenticated"
|
v-if="auth.isAuthenticated"
|
||||||
|
to="/mandates/new"
|
||||||
class="action-btn"
|
class="action-btn"
|
||||||
@click="showCreateModal = true"
|
|
||||||
>
|
>
|
||||||
<UIcon name="i-lucide-plus" class="text-xs" />
|
<UIcon name="i-lucide-plus" class="text-xs" />
|
||||||
<span>Nouveau</span>
|
<span>Nouveau</span>
|
||||||
</button>
|
</NuxtLink>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Main content: mandates list -->
|
<!-- Main content: mandates list -->
|
||||||
@@ -199,11 +201,11 @@ async function handleCreate() {
|
|||||||
<div class="mandate-onboarding__actions">
|
<div class="mandate-onboarding__actions">
|
||||||
<UButton
|
<UButton
|
||||||
v-if="auth.isAuthenticated"
|
v-if="auth.isAuthenticated"
|
||||||
|
to="/mandates/new"
|
||||||
label="Créer un premier mandat"
|
label="Créer un premier mandat"
|
||||||
icon="i-lucide-plus"
|
icon="i-lucide-plus"
|
||||||
color="primary"
|
color="primary"
|
||||||
size="sm"
|
size="sm"
|
||||||
@click="showCreateModal = true"
|
|
||||||
/>
|
/>
|
||||||
<UButton
|
<UButton
|
||||||
to="/protocols"
|
to="/protocols"
|
||||||
@@ -290,7 +292,7 @@ async function handleCreate() {
|
|||||||
:actions="[
|
:actions="[
|
||||||
{ label: 'Nouveau mandat', icon: 'i-lucide-plus', emit: 'create', primary: true },
|
{ label: 'Nouveau mandat', icon: 'i-lucide-plus', emit: 'create', primary: true },
|
||||||
]"
|
]"
|
||||||
@action="e => e === 'create' && (showCreateModal = true)"
|
@action="e => e === 'create' && navigateTo('/mandates/new')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Révocation -->
|
<!-- Révocation -->
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,9 @@
|
|||||||
*
|
*
|
||||||
* The extension signs <Bytes>{challenge}</Bytes> to match the backend verifier.
|
* The extension signs <Bytes>{challenge}</Bytes> to match the backend verifier.
|
||||||
*/
|
*/
|
||||||
|
// TODO: trustWallet — remplacer par postMessage vers l'iframe trustWallet (librodrome)
|
||||||
|
// Protocole prévu : window.postMessage({ type: 'LD_SIGN_REQUEST', address, challenge })
|
||||||
|
// → trustWallet répond { type: 'LD_SIGN_RESPONSE', signature }
|
||||||
async function _signWithExtension(address: string, challenge: string): Promise<string> {
|
async function _signWithExtension(address: string, challenge: string): Promise<string> {
|
||||||
const { web3Enable, web3FromAddress } = await import('@polkadot/extension-dapp')
|
const { web3Enable, web3FromAddress } = await import('@polkadot/extension-dapp')
|
||||||
const { stringToHex } = await import('@polkadot/util')
|
const { stringToHex } = await import('@polkadot/util')
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ export interface GroupMemberCreate {
|
|||||||
|
|
||||||
export const useGroupsStore = defineStore('groups', () => {
|
export const useGroupsStore = defineStore('groups', () => {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const orgs = useOrgsStore()
|
|
||||||
|
|
||||||
const list = ref<GroupSummary[]>([])
|
const list = ref<GroupSummary[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/**
|
|
||||||
* Mandates store: governance mandates and their lifecycle steps.
|
|
||||||
*
|
|
||||||
* Maps to the backend /api/v1/mandates endpoints.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface MandateStep {
|
export interface MandateStep {
|
||||||
id: string
|
id: string
|
||||||
mandate_id: string
|
mandate_id: string
|
||||||
@@ -20,10 +14,13 @@ export interface MandateStep {
|
|||||||
export interface Mandate {
|
export interface Mandate {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
|
origin_id: string | null
|
||||||
|
origin_display_name: string | null
|
||||||
description: string | null
|
description: string | null
|
||||||
mandate_type: string
|
mandate_type: string
|
||||||
status: string
|
status: string
|
||||||
mandatee_id: string | null
|
mandatee_id: string | null
|
||||||
|
mandatee_display_name: string | null
|
||||||
decision_id: string | null
|
decision_id: string | null
|
||||||
starts_at: string | null
|
starts_at: string | null
|
||||||
ends_at: string | null
|
ends_at: string | null
|
||||||
@@ -34,8 +31,10 @@ export interface Mandate {
|
|||||||
|
|
||||||
export interface MandateCreate {
|
export interface MandateCreate {
|
||||||
title: string
|
title: string
|
||||||
|
origin_id?: string | null
|
||||||
description?: string | null
|
description?: string | null
|
||||||
mandate_type: string
|
mandate_type: string
|
||||||
|
nomination_mode?: string
|
||||||
decision_id?: string | null
|
decision_id?: string | null
|
||||||
starts_at?: string | null
|
starts_at?: string | null
|
||||||
ends_at?: string | null
|
ends_at?: string | null
|
||||||
@@ -43,6 +42,7 @@ export interface MandateCreate {
|
|||||||
|
|
||||||
export interface MandateUpdate {
|
export interface MandateUpdate {
|
||||||
title?: string
|
title?: string
|
||||||
|
origin_id?: string | null
|
||||||
description?: string | null
|
description?: string | null
|
||||||
mandate_type?: string
|
mandate_type?: string
|
||||||
starts_at?: string | null
|
starts_at?: string | null
|
||||||
@@ -50,6 +50,7 @@ export interface MandateUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MandateStepCreate {
|
export interface MandateStepCreate {
|
||||||
|
step_order: number
|
||||||
step_type: string
|
step_type: string
|
||||||
title?: string | null
|
title?: string | null
|
||||||
description?: string | null
|
description?: string | null
|
||||||
@@ -71,31 +72,20 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
byStatus: (state) => {
|
byStatus: (state) => (status: string) => state.list.filter(m => m.status === status),
|
||||||
return (status: string) => state.list.filter(m => m.status === status)
|
activeMandates: (state): Mandate[] => state.list.filter(m => m.status === 'active'),
|
||||||
},
|
completedMandates: (state): Mandate[] => state.list.filter(m => m.status === 'completed'),
|
||||||
activeMandates: (state): Mandate[] => {
|
|
||||||
return state.list.filter(m => m.status === 'active')
|
|
||||||
},
|
|
||||||
completedMandates: (state): Mandate[] => {
|
|
||||||
return state.list.filter(m => m.status === 'completed')
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
/**
|
|
||||||
* Fetch all mandates with optional filters.
|
|
||||||
*/
|
|
||||||
async fetchAll(params?: { mandate_type?: string; status?: string }) {
|
async fetchAll(params?: { mandate_type?: string; status?: string }) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const query: Record<string, string> = {}
|
const query: Record<string, string> = {}
|
||||||
if (params?.mandate_type) query.mandate_type = params.mandate_type
|
if (params?.mandate_type) query.mandate_type = params.mandate_type
|
||||||
if (params?.status) query.status = params.status
|
if (params?.status) query.status = params.status
|
||||||
|
|
||||||
this.list = await $api<Mandate[]>('/mandates/', { query })
|
this.list = await $api<Mandate[]>('/mandates/', { query })
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this.error = err?.data?.detail || err?.message || 'Erreur lors du chargement des mandats'
|
this.error = err?.data?.detail || err?.message || 'Erreur lors du chargement des mandats'
|
||||||
@@ -104,13 +94,9 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a single mandate by ID with all its steps.
|
|
||||||
*/
|
|
||||||
async fetchById(id: string) {
|
async fetchById(id: string) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
this.current = await $api<Mandate>(`/mandates/${id}`)
|
this.current = await $api<Mandate>(`/mandates/${id}`)
|
||||||
@@ -121,19 +107,12 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new mandate.
|
|
||||||
*/
|
|
||||||
async create(payload: MandateCreate) {
|
async create(payload: MandateCreate) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const mandate = await $api<Mandate>('/mandates/', {
|
const mandate = await $api<Mandate>('/mandates/', { method: 'POST', body: payload })
|
||||||
method: 'POST',
|
|
||||||
body: payload,
|
|
||||||
})
|
|
||||||
this.list.unshift(mandate)
|
this.list.unshift(mandate)
|
||||||
return mandate
|
return mandate
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -144,18 +123,11 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Update an existing mandate.
|
|
||||||
*/
|
|
||||||
async update(id: string, data: MandateUpdate) {
|
async update(id: string, data: MandateUpdate) {
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const updated = await $api<Mandate>(`/mandates/${id}`, {
|
const updated = await $api<Mandate>(`/mandates/${id}`, { method: 'PUT', body: data })
|
||||||
method: 'PUT',
|
|
||||||
body: data,
|
|
||||||
})
|
|
||||||
if (this.current?.id === id) this.current = updated
|
if (this.current?.id === id) this.current = updated
|
||||||
const idx = this.list.findIndex(m => m.id === id)
|
const idx = this.list.findIndex(m => m.id === id)
|
||||||
if (idx >= 0) this.list[idx] = updated
|
if (idx >= 0) this.list[idx] = updated
|
||||||
@@ -166,12 +138,8 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a mandate.
|
|
||||||
*/
|
|
||||||
async delete(id: string) {
|
async delete(id: string) {
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
await $api(`/mandates/${id}`, { method: 'DELETE' })
|
await $api(`/mandates/${id}`, { method: 'DELETE' })
|
||||||
@@ -183,17 +151,11 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Advance the mandate to the next step in its workflow.
|
|
||||||
*/
|
|
||||||
async advance(id: string) {
|
async advance(id: string) {
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const updated = await $api<Mandate>(`/mandates/${id}/advance`, {
|
const updated = await $api<Mandate>(`/mandates/${id}/advance`, { method: 'POST' })
|
||||||
method: 'POST',
|
|
||||||
})
|
|
||||||
if (this.current?.id === id) this.current = updated
|
if (this.current?.id === id) this.current = updated
|
||||||
const idx = this.list.findIndex(m => m.id === id)
|
const idx = this.list.findIndex(m => m.id === id)
|
||||||
if (idx >= 0) this.list[idx] = updated
|
if (idx >= 0) this.list[idx] = updated
|
||||||
@@ -204,21 +166,12 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a step to a mandate.
|
|
||||||
*/
|
|
||||||
async addStep(id: string, step: MandateStepCreate) {
|
async addStep(id: string, step: MandateStepCreate) {
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const newStep = await $api<MandateStep>(`/mandates/${id}/steps`, {
|
const newStep = await $api<MandateStep>(`/mandates/${id}/steps`, { method: 'POST', body: step })
|
||||||
method: 'POST',
|
if (this.current?.id === id) this.current.steps.push(newStep)
|
||||||
body: step,
|
|
||||||
})
|
|
||||||
if (this.current?.id === id) {
|
|
||||||
this.current.steps.push(newStep)
|
|
||||||
}
|
|
||||||
return newStep
|
return newStep
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this.error = err?.data?.detail || err?.message || 'Erreur lors de l\'ajout de l\'etape'
|
this.error = err?.data?.detail || err?.message || 'Erreur lors de l\'ajout de l\'etape'
|
||||||
@@ -226,12 +179,8 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Assign a mandatee to the mandate.
|
|
||||||
*/
|
|
||||||
async assignMandatee(id: string, mandateeId: string) {
|
async assignMandatee(id: string, mandateeId: string) {
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const updated = await $api<Mandate>(`/mandates/${id}/assign`, {
|
const updated = await $api<Mandate>(`/mandates/${id}/assign`, {
|
||||||
@@ -248,17 +197,11 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Revoke the mandate.
|
|
||||||
*/
|
|
||||||
async revoke(id: string) {
|
async revoke(id: string) {
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { $api } = useApi()
|
const { $api } = useApi()
|
||||||
const updated = await $api<Mandate>(`/mandates/${id}/revoke`, {
|
const updated = await $api<Mandate>(`/mandates/${id}/revoke`, { method: 'POST' })
|
||||||
method: 'POST',
|
|
||||||
})
|
|
||||||
if (this.current?.id === id) this.current = updated
|
if (this.current?.id === id) this.current = updated
|
||||||
const idx = this.list.findIndex(m => m.id === id)
|
const idx = this.list.findIndex(m => m.id === id)
|
||||||
if (idx >= 0) this.list[idx] = updated
|
if (idx >= 0) this.list[idx] = updated
|
||||||
@@ -269,9 +212,6 @@ export const useMandatesStore = defineStore('mandates', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the current mandate.
|
|
||||||
*/
|
|
||||||
clearCurrent() {
|
clearCurrent() {
|
||||||
this.current = null
|
this.current = null
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
compatibilityDate: '2025-07-15',
|
compatibilityDate: '2025-07-15',
|
||||||
ssr: false,
|
ssr: false,
|
||||||
devtools: { enabled: true },
|
devtools: { enabled: false },
|
||||||
devServer: { port: 3002, host: '0.0.0.0' },
|
devServer: { port: 3002, host: '0.0.0.0' },
|
||||||
components: [{ path: '~/components', pathPrefix: false }],
|
components: [{ path: '~/components', pathPrefix: false }],
|
||||||
css: ['~/assets/css/moods.css'],
|
css: ['~/assets/css/moods.css'],
|
||||||
|
|||||||
Reference in New Issue
Block a user