From 1ec8c37fcb795b8176956f89e362d7e3e289fb34 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:59:27 -0600 Subject: [PATCH 01/12] Update constants.py --- OpenOversight/app/utils/constants.py | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenOversight/app/utils/constants.py b/OpenOversight/app/utils/constants.py index 91e2e6fb9..9e18fc817 100644 --- a/OpenOversight/app/utils/constants.py +++ b/OpenOversight/app/utils/constants.py @@ -44,7 +44,6 @@ ENCODING_UTF_8 = "utf-8" FILE_TYPE_HTML = "html" FILE_TYPE_PLAIN = "plain" -SAVED_UMASK = os.umask(0o077) # Ensure the file is read/write by the creator only # File Name Constants SERVICE_ACCOUNT_FILE = "service_account_key.json" From bc9829e3aa23b6b459ac3a36909bbf5d5cf59c92 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:05:03 -0600 Subject: [PATCH 02/12] Update constants.py --- OpenOversight/app/utils/constants.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/OpenOversight/app/utils/constants.py b/OpenOversight/app/utils/constants.py index 9e18fc817..61c2aaa74 100644 --- a/OpenOversight/app/utils/constants.py +++ b/OpenOversight/app/utils/constants.py @@ -1,6 +1,3 @@ -import os - - # Cache Key Constants KEY_DEPT_ALL_ASSIGNMENTS = "all_department_assignments" KEY_DEPT_ALL_INCIDENTS = "all_department_incidents" From 9b9e8d0717d7453f1a855939b6c00714b8dbe334 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:05:13 -0600 Subject: [PATCH 03/12] Update database.py --- OpenOversight/app/models/database.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index 6ffd345a5..d09666e8e 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -136,7 +136,7 @@ class Department(BaseModel, TrackUpdates): __table_args__ = (UniqueConstraint("name", "state", name="departments_name_state"),) def __repr__(self): - return f"" + return f"" def to_custom_dict(self): return { @@ -279,6 +279,14 @@ class Officer(BaseModel, TrackUpdates): CheckConstraint("gender in ('M', 'F', 'Other')", name="gender_options"), ) + def __repr__(self): + if self.unique_internal_identifier: + return ( + f"" + ) + return f"" + def full_name(self): if self.middle_initial: middle_initial = ( @@ -339,14 +347,6 @@ def currently_on_force(self): return "Yes" if most_recent.resign_date is None else "No" return "Uncertain" - def __repr__(self): - if self.unique_internal_identifier: - return ( - f"" - ) - return f"" - class Salary(BaseModel, TrackUpdates): __tablename__ = "salaries" @@ -365,7 +365,7 @@ class Salary(BaseModel, TrackUpdates): is_fiscal_year = db.Column(db.Boolean, index=False, unique=False, nullable=False) def __repr__(self): - return f"" @property def total_pay(self) -> float: @@ -433,7 +433,7 @@ class Unit(BaseModel, TrackUpdates): ) def __repr__(self): - return f"Unit: {self.description}" + return f"" class Face(BaseModel, TrackUpdates): @@ -485,7 +485,7 @@ class Face(BaseModel, TrackUpdates): __table_args__ = (UniqueConstraint("officer_id", "img_id", name="unique_faces"),) def __repr__(self): - return f"" + return f"" class Image(BaseModel, TrackUpdates): From e41ebe79b348b196c09f9e9d1056611f632cd7ba Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:05:55 -0600 Subject: [PATCH 04/12] Update views.py --- OpenOversight/app/main/views.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OpenOversight/app/main/views.py b/OpenOversight/app/main/views.py index 29ae06537..6c5fb10d8 100644 --- a/OpenOversight/app/main/views.py +++ b/OpenOversight/app/main/views.py @@ -1,4 +1,3 @@ -import os import re import sys from datetime import datetime @@ -124,9 +123,6 @@ ) -# Ensure the file is read/write by the creator only -SAVED_UMASK = os.umask(0o077) - sitemap_endpoints = [] From 17ba963299140ce209bd931141e4bfb0cade3c16 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:25:14 -0600 Subject: [PATCH 05/12] Update database.py --- OpenOversight/app/models/database.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index d09666e8e..c367d7b78 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -136,7 +136,7 @@ class Department(BaseModel, TrackUpdates): __table_args__ = (UniqueConstraint("name", "state", name="departments_name_state"),) def __repr__(self): - return f"" + return f"" def to_custom_dict(self): return { @@ -365,7 +365,7 @@ class Salary(BaseModel, TrackUpdates): is_fiscal_year = db.Column(db.Boolean, index=False, unique=False, nullable=False) def __repr__(self): - return f"" + return f"" @property def total_pay(self) -> float: @@ -512,7 +512,7 @@ class Image(BaseModel, TrackUpdates): ) def __repr__(self): - return f"" + return f"" incident_links = db.Table( @@ -656,6 +656,9 @@ class Link(BaseModel, TrackUpdates): author = db.Column(db.String(255), nullable=True) has_content_warning = db.Column(db.Boolean, nullable=False, default=False) + def __repr__(self): + return f"" + @validates("url") def validate_url(self, key, url): return url_validator(url) @@ -704,6 +707,9 @@ class Incident(BaseModel, TrackUpdates): "Department", backref=db.backref("incidents", cascade_backrefs=False), lazy=True ) + def __repr__(self): + return f"" + class User(UserMixin, BaseModel): __tablename__ = "users" From 4c7dc89527db840b7b01f2fc5493416f1b30cc82 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:25:22 -0600 Subject: [PATCH 06/12] Add tests --- OpenOversight/tests/test_models.py | 20 +++++++++++++++----- OpenOversight/tests/test_utils.py | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/OpenOversight/tests/test_models.py b/OpenOversight/tests/test_models.py index 8919ba4c1..8e5ade98c 100644 --- a/OpenOversight/tests/test_models.py +++ b/OpenOversight/tests/test_models.py @@ -30,7 +30,7 @@ def test_department_repr(mockdata): department = Department.query.first() assert ( repr(department) - == f"" + == f"" ) @@ -141,6 +141,11 @@ def test_assignment_repr(mockdata): ) +def test_incident_repr(mockdata): + incident = Incident.query.first() + assert repr(incident) == f"" + + def test_job_repr(mockdata): job = Job.query.first() assert repr(job) == f"" @@ -148,17 +153,17 @@ def test_job_repr(mockdata): def test_image_repr(mockdata): image = Image.query.first() - assert repr(image) == f"" + assert repr(image) == f"" def test_face_repr(mockdata): face = Face.query.first() - assert repr(face) == f"" + assert repr(face) == f"" def test_unit_repr(mockdata): unit = Unit.query.first() - assert repr(unit) == f"Unit: {unit.description}" + assert repr(unit) == f"" def test_user_repr(mockdata): @@ -168,7 +173,12 @@ def test_user_repr(mockdata): def test_salary_repr(mockdata): salary = Salary.query.first() - assert repr(salary) == f"" + + +def test_link_repr(mockdata): + link = Link.query.first() + assert repr(link) == f"" def test_password_not_printed(mockdata): diff --git a/OpenOversight/tests/test_utils.py b/OpenOversight/tests/test_utils.py index 99bf113f0..ee3104082 100644 --- a/OpenOversight/tests/test_utils.py +++ b/OpenOversight/tests/test_utils.py @@ -212,7 +212,7 @@ def test_user_cannot_submit_invalid_file_extension(mockdata): def test_unit_choices(mockdata): unit_choices_result = [str(x) for x in unit_choices()] - assert "Unit: Bureau of Organized Crime" in unit_choices_result + assert "" in unit_choices_result @upload_s3_patch From d1a231a6069ee99e7e0ca419bd83c68679f3ce74 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:39:38 -0600 Subject: [PATCH 07/12] Assignment --- OpenOversight/app/models/database.py | 8 ++++---- OpenOversight/tests/test_models.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index c367d7b78..b60ad5a9a 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -406,7 +406,7 @@ class Assignment(BaseModel, TrackUpdates): resign_date = db.Column(db.Date, index=True, unique=False, nullable=True) def __repr__(self): - return f"" + return f"" @property def start_date_or_min(self): @@ -656,13 +656,13 @@ class Link(BaseModel, TrackUpdates): author = db.Column(db.String(255), nullable=True) has_content_warning = db.Column(db.Boolean, nullable=False, default=False) - def __repr__(self): - return f"" - @validates("url") def validate_url(self, key, url): return url_validator(url) + def __repr__(self): + return f"" + class Incident(BaseModel, TrackUpdates): __tablename__ = "incidents" diff --git a/OpenOversight/tests/test_models.py b/OpenOversight/tests/test_models.py index 8e5ade98c..77fef7cd3 100644 --- a/OpenOversight/tests/test_models.py +++ b/OpenOversight/tests/test_models.py @@ -137,7 +137,7 @@ def test_assignment_repr(mockdata): assignment = Assignment.query.first() assert ( repr(assignment) - == f"" + == f"" ) From 5002bbfcf9338e94a50856f4a634d585393d345e Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:46:22 -0600 Subject: [PATCH 08/12] description, note --- OpenOversight/app/models/database.py | 6 ++++++ OpenOversight/tests/test_models.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index b60ad5a9a..e46694c3c 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -212,6 +212,9 @@ class Note(BaseModel, TrackUpdates): officer_id = db.Column(db.Integer, db.ForeignKey("officers.id", ondelete="CASCADE")) officer = db.relationship("Officer", back_populates="notes") + def __repr__(self): + return f"" + class Description(BaseModel, TrackUpdates): __tablename__ = "descriptions" @@ -221,6 +224,9 @@ class Description(BaseModel, TrackUpdates): text_contents = db.Column(db.Text()) officer_id = db.Column(db.Integer, db.ForeignKey("officers.id", ondelete="CASCADE")) + def __repr__(self): + return f"" + class Officer(BaseModel, TrackUpdates): __tablename__ = "officers" diff --git a/OpenOversight/tests/test_models.py b/OpenOversight/tests/test_models.py index 77fef7cd3..344a23738 100644 --- a/OpenOversight/tests/test_models.py +++ b/OpenOversight/tests/test_models.py @@ -10,6 +10,7 @@ from OpenOversight.app.models.database import ( Assignment, Department, + Description, Face, Image, Incident, @@ -17,6 +18,7 @@ LicensePlate, Link, Location, + Note, Officer, Salary, Unit, @@ -181,6 +183,19 @@ def test_link_repr(mockdata): assert repr(link) == f"" +def test_note_repr(mockdata): + note = Note.query.first() + assert repr(note) == f"" + + +def test_description_repr(mockdata): + description = Description.query.first() + assert ( + repr(description) + == f"" + ) + + def test_password_not_printed(mockdata): """Validate that password fields cannot be directly accessed.""" user = User(password="bacon") From 12ec3d8691dfb609d6581ceaaee398f23483523a Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:49:51 -0600 Subject: [PATCH 09/12] license plate --- OpenOversight/app/models/database.py | 3 +++ OpenOversight/tests/test_models.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index e46694c3c..48f7a7bdf 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -650,6 +650,9 @@ class LicensePlate(BaseModel, TrackUpdates): def validate_state(self, key, state): return state_validator(state) + def __repr__(self): + return f"" + class Link(BaseModel, TrackUpdates): __tablename__ = "links" diff --git a/OpenOversight/tests/test_models.py b/OpenOversight/tests/test_models.py index 344a23738..c6ba54242 100644 --- a/OpenOversight/tests/test_models.py +++ b/OpenOversight/tests/test_models.py @@ -196,6 +196,14 @@ def test_description_repr(mockdata): ) +def test_license_plate_repr(mockdata): + license_plate = LicensePlate.query.first() + assert ( + repr(license_plate) + == f"" + ) + + def test_password_not_printed(mockdata): """Validate that password fields cannot be directly accessed.""" user = User(password="bacon") From 99fc259bc833fa1f642977cc44bfd62a7be3cf80 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:59:12 -0600 Subject: [PATCH 10/12] Update database.py --- OpenOversight/app/models/database.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index 48f7a7bdf..babc74774 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -198,7 +198,7 @@ class Job(BaseModel, TrackUpdates): ) def __repr__(self): - return f"" + return f"" def __str__(self): return self.job_title @@ -288,10 +288,10 @@ class Officer(BaseModel, TrackUpdates): def __repr__(self): if self.unique_internal_identifier: return ( - f"" ) - return f"" + return f"" def full_name(self): if self.middle_initial: From 27d7f1877820d95f7c4a8b79101a3d38ade5bb71 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:01:30 -0600 Subject: [PATCH 11/12] Update test_models.py --- OpenOversight/tests/test_models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenOversight/tests/test_models.py b/OpenOversight/tests/test_models.py index c6ba54242..09b4c60cd 100644 --- a/OpenOversight/tests/test_models.py +++ b/OpenOversight/tests/test_models.py @@ -95,7 +95,7 @@ def test_officer_repr(session): ).first() assert ( - repr(officer_uii) == f"" ) @@ -109,7 +109,7 @@ def test_officer_repr(session): ).first() assert ( - repr(officer_no_uii) == f"" ) @@ -120,7 +120,7 @@ def test_officer_repr(session): assert ( repr(officer_no_mi) - == f"" ) @@ -150,7 +150,7 @@ def test_incident_repr(mockdata): def test_job_repr(mockdata): job = Job.query.first() - assert repr(job) == f"" + assert repr(job) == f"" def test_image_repr(mockdata): From c9b95c3c9a99b94e6c7faad08764c96708b9a1fc Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:10:30 -0600 Subject: [PATCH 12/12] Update --- OpenOversight/app/models/database.py | 2 +- OpenOversight/tests/test_models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index babc74774..2924ac664 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -291,7 +291,7 @@ def __repr__(self): f"" ) - return f"" + return f"" def full_name(self): if self.middle_initial: diff --git a/OpenOversight/tests/test_models.py b/OpenOversight/tests/test_models.py index 09b4c60cd..4f49e35cf 100644 --- a/OpenOversight/tests/test_models.py +++ b/OpenOversight/tests/test_models.py @@ -109,7 +109,7 @@ def test_officer_repr(session): ).first() assert ( - repr(officer_no_uii) == f"" )