Skip to content

Commit

Permalink
Merge pull request #344 from Police-Data-Accessibility-Project/dev
Browse files Browse the repository at this point in the history
v1 dev → main
  • Loading branch information
maxachis authored Jul 2, 2024
2 parents e4a6760 + 6622599 commit e4f08c2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
12 changes: 11 additions & 1 deletion client/src/components/SearchResultCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ export default {
this.$router.push(`/data-sources/${this.dataSource.airtable_uid}`);
},
openSource() {
window.open(this.dataSource.source_url, '_blank');
let url = this.dataSource.source_url;
// ensure URL is treated as an absolute path
url = this.prepend_protocol_if_none(url)
window.open(url, '_blank');
},
prepend_protocol_if_none(url) {
// add 'https://' if the URL does not have a protocol
if (!/^https?:\/\//i.test(url)) {
return url = 'https://' + url;
}
return url;
},
formatDate: formatDateForSearchResults,
},
Expand Down
2 changes: 2 additions & 0 deletions middleware/initialize_psycopg2_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from psycopg2.extensions import connection as PgConnection
from typing import Union, Dict, List
from dotenv import load_dotenv


def initialize_psycopg2_connection() -> (
Expand All @@ -17,6 +18,7 @@ def initialize_psycopg2_connection() -> (
:return: A psycopg2 connection object if successful, or a dictionary with a count of 0 and an empty data list upon failure.
"""
try:
load_dotenv()
DO_DATABASE_URL = os.getenv("DO_DATABASE_URL")

return psycopg2.connect(
Expand Down
16 changes: 14 additions & 2 deletions regular_api_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,20 @@ def test_create_data_source():
response = requests.post(
f"{BASE_URL}/data-sources",
headers=HEADERS,
json={"name": "test", "record_type": "test"},
json={"name": "test", "record_type": "test", "test_flag": True},
)

assert response.json() == True
assert response.json()["message"] == "Data source added successfully."


def test_create_user_data_source():
response = requests.post(
f"{BASE_URL}/data-sources",
headers=HEADERS,
json={"name": "test", "record_type": "test", "approval_status": "intake"},
)

assert response.json()["message"] == "Data source added successfully."


def test_update_data_source():
Expand Down Expand Up @@ -301,6 +311,8 @@ def main():
"test_quicksearch_media_bulletin_pennsylvania_results",
"test_data_source_by_id",
"test_data_sources",
"test_create_data_source",
"test_create_user_data_source",
"test_update_data_source",
"test_data_sources_approved",
"test_data_source_by_id_approved",
Expand Down
15 changes: 9 additions & 6 deletions resources/DataSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def post(self) -> Dict[str, str]:
"approval_status",
"airtable_uid",
"airtable_source_last_modified",
"test_flag",
]

column_names = ""
Expand All @@ -157,15 +158,17 @@ def post(self) -> Dict[str, str]:
now = datetime.now().strftime("%Y-%m-%d")
airtable_uid = str(uuid.uuid4())

column_names += (
"approval_status, url_status, data_source_created, airtable_uid"
)
column_values += f"False, '[\"ok\"]', '{now}', '{airtable_uid}'"
if "approval_status" not in data:
column_names += "approval_status, "
column_values += "'intake', "
column_names += "url_status, data_source_created, airtable_uid"
column_values += f"'[\"ok\"]', '{now}', '{airtable_uid}'"

sql_query = f"INSERT INTO data_sources ({column_names}) VALUES ({column_values}) RETURNING *"

cursor.execute(sql_query)
self.psycopg2_connection.commit()
if "test_flag" not in data:
cursor.execute(sql_query)
self.psycopg2_connection.commit()

return {"message": "Data source added successfully."}

Expand Down

0 comments on commit e4f08c2

Please sign in to comment.