Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Create approving_user_url table

Revision ID: 69f7cc4f56d4
Revises: 33421c0590bb
Create Date: 2025-03-11 15:39:27.563567

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '69f7cc4f56d4'
down_revision: Union[str, None] = '33421c0590bb'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:

Check warning on line 21 in alembic/versions/2025_03_11_1539-69f7cc4f56d4_create_approving_user_url_table.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] alembic/versions/2025_03_11_1539-69f7cc4f56d4_create_approving_user_url_table.py#L21 <103>

Missing docstring in public function
Raw output
./alembic/versions/2025_03_11_1539-69f7cc4f56d4_create_approving_user_url_table.py:21:1: D103 Missing docstring in public function
op.create_table(
'approving_user_url',
sa.Column('id', sa.Integer(), nullable=False, primary_key=True),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('url_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), nullable=False, server_default=sa.text('now()')),
sa.ForeignKeyConstraint(['url_id'], ['urls.id'], ),
sa.UniqueConstraint('url_id', name='approving_user_url_uq_user_id_url_id')
)


def downgrade() -> None:

Check warning on line 33 in alembic/versions/2025_03_11_1539-69f7cc4f56d4_create_approving_user_url_table.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] alembic/versions/2025_03_11_1539-69f7cc4f56d4_create_approving_user_url_table.py#L33 <103>

Missing docstring in public function
Raw output
./alembic/versions/2025_03_11_1539-69f7cc4f56d4_create_approving_user_url_table.py:33:1: D103 Missing docstring in public function
op.drop_table('approving_user_url')
5 changes: 4 additions & 1 deletion api/routes/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ async def approve_source(
access_info: AccessInfo = Depends(get_access_info),
approval_info: FinalReviewApprovalInfo = FinalReviewApprovalInfo
) -> GetNextURLForFinalReviewOuterResponse:
next_source = await core.approve_and_get_next_source_for_review(approval_info)
next_source = await core.approve_and_get_next_source_for_review(
approval_info,
access_info=access_info
)
return GetNextURLForFinalReviewOuterResponse(next_source=next_source)
12 changes: 10 additions & 2 deletions collector_db/AsyncDatabaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collector_db.models import URL, URLErrorInfo, URLHTMLContent, Base, \
RootURL, Task, TaskError, LinkTaskURL, Batch, Agency, AutomatedUrlAgencySuggestion, \
UserUrlAgencySuggestion, AutoRelevantSuggestion, AutoRecordTypeSuggestion, UserRelevantSuggestion, \
UserRecordTypeSuggestion
UserRecordTypeSuggestion, ApprovingUserURL
from collector_manager.enums import URLStatus, CollectorType
from core.DTOs.GetNextRecordTypeAnnotationResponseInfo import GetNextRecordTypeAnnotationResponseInfo
from core.DTOs.GetNextRelevanceAnnotationResponseInfo import GetNextRelevanceAnnotationResponseInfo
Expand Down Expand Up @@ -1107,7 +1107,8 @@ async def approve_url(
url_id: int,
record_type: RecordType,
relevant: bool,
agency_id: Optional[int] = None
user_id: int,
agency_id: Optional[int] = None,
) -> None:

# Get URL
Expand Down Expand Up @@ -1135,3 +1136,10 @@ async def approve_url(
# If it does, do nothing

url.outcome = URLStatus.VALIDATED.value

approving_user_url = ApprovingUserURL(
user_id=user_id,
url_id=url_id
)

session.add(approving_user_url)
18 changes: 18 additions & 0 deletions collector_db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@
"AutoRelevantSuggestion", uselist=False, back_populates="url")
user_relevant_suggestions = relationship(
"UserRelevantSuggestion", back_populates="url")
approving_users = relationship(
"ApprovingUserURL", back_populates="url")

class ApprovingUserURL(Base):

Check warning on line 134 in collector_db/models.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/models.py#L134 <101>

Missing docstring in public class
Raw output
./collector_db/models.py:134:1: D101 Missing docstring in public class
__tablename__ = 'approving_user_url'
__table_args__ = (
UniqueConstraint(
"url_id",

Check failure on line 138 in collector_db/models.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/models.py#L138 <122>

continuation line missing indentation or outdented
Raw output
./collector_db/models.py:138:9: E122 continuation line missing indentation or outdented
name="approving_user_url_uq_user_id_url_id"),

Check failure on line 139 in collector_db/models.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] collector_db/models.py#L139 <122>

continuation line missing indentation or outdented
Raw output
./collector_db/models.py:139:9: E122 continuation line missing indentation or outdented
)

id = Column(Integer, primary_key=True)
user_id = Column(Integer, nullable=False)
url_id = Column(Integer, ForeignKey('urls.id'), nullable=False)
created_at = get_created_at_column()

# Relationships
url = relationship("URL", back_populates="approving_users")

class RootURL(Base):
__tablename__ = 'root_url_cache'
Expand Down
7 changes: 5 additions & 2 deletions core/AsyncCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from llm_api_logic.OpenAIRecordClassifier import OpenAIRecordClassifier
from pdap_api_client.AccessManager import AccessManager
from pdap_api_client.PDAPClient import PDAPClient
from security_manager.SecurityManager import AccessInfo
from util.helper_functions import get_from_env


Expand Down Expand Up @@ -213,12 +214,14 @@ async def get_next_source_for_review(self):

async def approve_and_get_next_source_for_review(
self,
approval_info: FinalReviewApprovalInfo
approval_info: FinalReviewApprovalInfo,
access_info: AccessInfo
):
await self.adb_client.approve_url(
url_id=approval_info.url_id,
record_type=approval_info.record_type,
relevant=approval_info.relevant,
agency_id=approval_info.agency_id
agency_id=approval_info.agency_id,
user_id=access_info.user_id
)
return await self.get_next_source_for_review()
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collector_db.DTOs.URLInfo import URLInfo
from collector_db.DTOs.URLMetadataInfo import URLMetadataInfo
from collector_db.enums import URLMetadataAttributeType, ValidationStatus, ValidationSource
from collector_db.models import URL
from collector_db.models import URL, ApprovingUserURL
from collector_manager.enums import URLStatus
from core.enums import BatchStatus, RecordType, SuggestionType
from tests.helpers.DBDataCreator import DBDataCreator
Expand Down Expand Up @@ -331,7 +331,8 @@
await adb_client.approve_url(
url_mapping.url_id,
record_type=RecordType.ARREST_RECORDS,
relevant=True
relevant=True,
user_id=1
)

# Confirm same agency id is listed as confirmed
Expand All @@ -344,3 +345,8 @@
assert url.relevant == True
assert url.outcome == URLStatus.VALIDATED.value

approving_user_urls = await adb_client.get_all(ApprovingUserURL)
assert len(approving_user_urls) == 1
assert approving_user_urls[0].user_id == 1
assert approving_user_urls[0].url_id == url_mapping.url_id

Check warning on line 352 in tests/test_automated/integration/collector_db/test_db_client.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] tests/test_automated/integration/collector_db/test_db_client.py#L352 <391>

blank line at end of file
Raw output
./tests/test_automated/integration/collector_db/test_db_client.py:352:1: W391 blank line at end of file