From 7ab5ff78828bd119766efa4260f1090a3f2a71dc Mon Sep 17 00:00:00 2001 From: Marty Bode Date: Mon, 6 May 2024 13:48:32 -0400 Subject: [PATCH 1/8] flag user submitted sources for approval --- regular_api_checks.py | 16 ++++++++++++++-- resources/DataSources.py | 15 +++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/regular_api_checks.py b/regular_api_checks.py index 8946109d..b5a2b8aa 100644 --- a/regular_api_checks.py +++ b/regular_api_checks.py @@ -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(): @@ -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", diff --git a/resources/DataSources.py b/resources/DataSources.py index 50fdb48e..dde9a2c3 100644 --- a/resources/DataSources.py +++ b/resources/DataSources.py @@ -142,6 +142,7 @@ def post(self) -> Dict[str, str]: "approval_status", "airtable_uid", "airtable_source_last_modified", + "test_flag", ] column_names = "" @@ -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."} From 8dbd773216eef0f838f9bf036580c1a2dd2f1d6f Mon Sep 17 00:00:00 2001 From: Marty Bode Date: Mon, 13 May 2024 13:57:11 -0400 Subject: [PATCH 2/8] linting --- regular_api_checks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regular_api_checks.py b/regular_api_checks.py index b5a2b8aa..a50dd8d1 100644 --- a/regular_api_checks.py +++ b/regular_api_checks.py @@ -92,7 +92,7 @@ def test_create_data_source(): json={"name": "test", "record_type": "test", "test_flag": True}, ) - assert response.json()['message'] == 'Data source added successfully.' + assert response.json()["message"] == "Data source added successfully." def test_create_user_data_source(): From 2033c59799059364107ffa0e349b483254739c1b Mon Sep 17 00:00:00 2001 From: bonjarlow Date: Thu, 27 Jun 2024 11:42:00 -0400 Subject: [PATCH 3/8] prepend https:// if not in source_url --- client/src/components/SearchResultCard.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/src/components/SearchResultCard.vue b/client/src/components/SearchResultCard.vue index d662c30e..6357de81 100644 --- a/client/src/components/SearchResultCard.vue +++ b/client/src/components/SearchResultCard.vue @@ -149,7 +149,11 @@ 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; + if (!/^https?:\/\//i.test(url)) { + url = 'https://' + url; + } + window.open(url, '_blank'); }, formatDate: formatDateForSearchResults, }, From 99684aee0fa152eb4ea94b90dac3a62918fafd8e Mon Sep 17 00:00:00 2001 From: bonjarlow Date: Thu, 27 Jun 2024 11:42:30 -0400 Subject: [PATCH 4/8] explicitly load_env --- middleware/initialize_psycopg2_connection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/middleware/initialize_psycopg2_connection.py b/middleware/initialize_psycopg2_connection.py index 6b6e1966..367494e6 100644 --- a/middleware/initialize_psycopg2_connection.py +++ b/middleware/initialize_psycopg2_connection.py @@ -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() -> ( @@ -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( From 3f36716f82d7295d37ecf6403a7fb24882112786 Mon Sep 17 00:00:00 2001 From: Josh <30379833+josh-chamberlain@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:41:55 -0400 Subject: [PATCH 5/8] Update CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a03d45d8..a001991c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ /client/ @joshuagraber -* @mbodeantor +* @josh-chamberlain From f5fe049144cc720ccb7068da94146813afe65f44 Mon Sep 17 00:00:00 2001 From: bonjarlow Date: Thu, 27 Jun 2024 16:54:30 -0400 Subject: [PATCH 6/8] extract regex to commented function --- client/src/components/SearchResultCard.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/components/SearchResultCard.vue b/client/src/components/SearchResultCard.vue index 6357de81..a267a563 100644 --- a/client/src/components/SearchResultCard.vue +++ b/client/src/components/SearchResultCard.vue @@ -150,10 +150,16 @@ export default { }, openSource() { 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)) { - url = 'https://' + url; + return url = 'https://' + url; } - window.open(url, '_blank'); + return url; }, formatDate: formatDateForSearchResults, }, From 6cd4ad0026400c66dc794fc35d609511bb4bbc7c Mon Sep 17 00:00:00 2001 From: bonjarlow Date: Thu, 27 Jun 2024 16:59:36 -0400 Subject: [PATCH 7/8] space and tab mixing fixed --- client/src/components/SearchResultCard.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/components/SearchResultCard.vue b/client/src/components/SearchResultCard.vue index a267a563..3400210a 100644 --- a/client/src/components/SearchResultCard.vue +++ b/client/src/components/SearchResultCard.vue @@ -149,13 +149,13 @@ export default { this.$router.push(`/data-sources/${this.dataSource.airtable_uid}`); }, openSource() { - let url = this.dataSource.source_url; - // ensure URL is treated as an absolute path - url = this.prepend_protocol_if_none(url) + 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 + prepend_protocol_if_none(url) { + // add 'https://' if the URL does not have a protocol if (!/^https?:\/\//i.test(url)) { return url = 'https://' + url; } From f48a195060ea2a5f3d85bde0d14c216e452225fe Mon Sep 17 00:00:00 2001 From: bonjarlow Date: Thu, 27 Jun 2024 17:02:37 -0400 Subject: [PATCH 8/8] space and tab mixing fixed... again --- client/src/components/SearchResultCard.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/SearchResultCard.vue b/client/src/components/SearchResultCard.vue index 3400210a..17ea31b6 100644 --- a/client/src/components/SearchResultCard.vue +++ b/client/src/components/SearchResultCard.vue @@ -149,7 +149,7 @@ export default { this.$router.push(`/data-sources/${this.dataSource.airtable_uid}`); }, openSource() { - let url = this.dataSource.source_url; + 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');