From 8b438308dd7110eee084586dafeef33769af2f5d Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Wed, 1 Nov 2023 23:21:26 +0000 Subject: [PATCH 1/8] add validation --- superset/tags/schemas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset/tags/schemas.py b/superset/tags/schemas.py index a391fd2b8055a..38676b42949e4 100644 --- a/superset/tags/schemas.py +++ b/superset/tags/schemas.py @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. from marshmallow import fields, Schema -from marshmallow.validate import Range +from marshmallow.validate import Length, Range from superset.dashboards.schemas import UserSchema @@ -58,7 +58,7 @@ class TaggedObjectEntityResponseSchema(Schema): class TagObjectSchema(Schema): - name = fields.String() + name = fields.String(validate=Length(min=1)) description = fields.String(required=False, allow_none=True) objects_to_tag = fields.List( fields.Tuple((fields.String(), fields.Int(validate=Range(min=1)))), From d024b555275dc5fca10d9a027d756b42e8d23ca2 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Thu, 2 Nov 2023 19:33:26 +0000 Subject: [PATCH 2/8] fix delete callback --- superset-frontend/src/pages/Tags/index.tsx | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/superset-frontend/src/pages/Tags/index.tsx b/superset-frontend/src/pages/Tags/index.tsx index e252e3d9f98c2..022b764275021 100644 --- a/superset-frontend/src/pages/Tags/index.tsx +++ b/superset-frontend/src/pages/Tags/index.tsx @@ -92,14 +92,20 @@ function TagList(props: TagListProps) { const initialSort = [{ id: 'changed_on_delta_humanized', desc: true }]; - function handleTagsDelete( - tags: Tag[], - callback: (text: string) => void, - error: (text: string) => void, - ) { + function handleTagsDelete(tags: Tag[]) { // TODO what permissions need to be checked here? - deleteTags(tags, callback, error); - refreshData(); + console.log(tags); + deleteTags( + tags, + (msg: string) => { + addSuccessToast(msg); + refreshData(); + }, + msg => { + addDangerToast(msg); + refreshData(); + }, + ); } const handleTagEdit = (tag: Tag) => { @@ -178,8 +184,6 @@ function TagList(props: TagListProps) { }, { Cell: ({ row: { original } }: any) => { - const handleDelete = () => - handleTagsDelete([original], addSuccessToast, addDangerToast); const handleEdit = () => handleTagEdit(original); return ( @@ -192,7 +196,7 @@ function TagList(props: TagListProps) { {original.dashboard_title}? } - onConfirm={handleDelete} + onConfirm={() => handleTagsDelete([original])} > {confirmDelete => ( - handleTagsDelete(tagsToDelete, addSuccessToast, addDangerToast); + handleTagsDelete(tagsToDelete); return ( <> From b02a4ebe763e503e778064d01ed941ede441a91d Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Thu, 2 Nov 2023 19:52:29 +0000 Subject: [PATCH 3/8] remove cl --- superset-frontend/src/pages/Tags/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/superset-frontend/src/pages/Tags/index.tsx b/superset-frontend/src/pages/Tags/index.tsx index 022b764275021..a66d7c7b61b0d 100644 --- a/superset-frontend/src/pages/Tags/index.tsx +++ b/superset-frontend/src/pages/Tags/index.tsx @@ -93,8 +93,6 @@ function TagList(props: TagListProps) { const initialSort = [{ id: 'changed_on_delta_humanized', desc: true }]; function handleTagsDelete(tags: Tag[]) { - // TODO what permissions need to be checked here? - console.log(tags); deleteTags( tags, (msg: string) => { From 7bd98e3a40eabfa22ebcad5630c7a111293c6e14 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Thu, 2 Nov 2023 21:03:12 +0000 Subject: [PATCH 4/8] ok --- .../src/features/tags/TagModal.tsx | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/features/tags/TagModal.tsx b/superset-frontend/src/features/tags/TagModal.tsx index fde448d4b48fd..613280d452d7d 100644 --- a/superset-frontend/src/features/tags/TagModal.tsx +++ b/superset-frontend/src/features/tags/TagModal.tsx @@ -222,10 +222,14 @@ const TagModal: React.FC = ({ name: tagName, objects_to_tag: [...dashboards, ...charts, ...savedQueries], }, - }).then(({ json = {} }) => { - refreshData(); - addSuccessToast(t('Tag updated')); - }); + }) + .then(({ json = {} }) => { + refreshData(); + addSuccessToast(t('Tag updated')); + }) + .catch(err => { + addDangerToast(err.message ? err.message : 'Error Updating Tag'); + }); } else { SupersetClient.post({ endpoint: `/api/v1/tag/`, @@ -234,10 +238,14 @@ const TagModal: React.FC = ({ name: tagName, objects_to_tag: [...dashboards, ...charts, ...savedQueries], }, - }).then(({ json = {} }) => { - refreshData(); - addSuccessToast(t('Tag created')); - }); + }) + .then(({ json = {} }) => { + refreshData(); + addSuccessToast(t('Tag created')); + }) + .catch(err => + addDangerToast(err.message ? err.message : 'Error Creating Tag'), + ); } onHide(); }; From 1b71aad844607105dbde55ae14a7e827d2fd8fb4 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Fri, 3 Nov 2023 13:15:09 -0400 Subject: [PATCH 5/8] Update superset-frontend/src/features/tags/TagModal.tsx Co-authored-by: Elizabeth Thompson --- superset-frontend/src/features/tags/TagModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/features/tags/TagModal.tsx b/superset-frontend/src/features/tags/TagModal.tsx index 613280d452d7d..17a6d057e80ff 100644 --- a/superset-frontend/src/features/tags/TagModal.tsx +++ b/superset-frontend/src/features/tags/TagModal.tsx @@ -228,7 +228,7 @@ const TagModal: React.FC = ({ addSuccessToast(t('Tag updated')); }) .catch(err => { - addDangerToast(err.message ? err.message : 'Error Updating Tag'); + addDangerToast(err.message || 'Error Updating Tag'); }); } else { SupersetClient.post({ From 61fb153d69449ed29da73f621d28de3a09d74130 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Fri, 3 Nov 2023 13:15:18 -0400 Subject: [PATCH 6/8] Update superset-frontend/src/features/tags/TagModal.tsx Co-authored-by: Elizabeth Thompson --- superset-frontend/src/features/tags/TagModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/features/tags/TagModal.tsx b/superset-frontend/src/features/tags/TagModal.tsx index 17a6d057e80ff..ed0d040431a1c 100644 --- a/superset-frontend/src/features/tags/TagModal.tsx +++ b/superset-frontend/src/features/tags/TagModal.tsx @@ -244,7 +244,7 @@ const TagModal: React.FC = ({ addSuccessToast(t('Tag created')); }) .catch(err => - addDangerToast(err.message ? err.message : 'Error Creating Tag'), + addDangerToast(err.message || 'Error Creating Tag'), ); } onHide(); From a1bad291056dc4b8b31bfd8a94e7026996088ae8 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Fri, 3 Nov 2023 18:10:08 +0000 Subject: [PATCH 7/8] added tet --- tests/integration_tests/tags/api_tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/integration_tests/tags/api_tests.py b/tests/integration_tests/tags/api_tests.py index e7f35c6b5d55b..33fa4902b26ca 100644 --- a/tests/integration_tests/tags/api_tests.py +++ b/tests/integration_tests/tags/api_tests.py @@ -485,6 +485,22 @@ def test_post_tag(self): ) assert tag is not None + @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") + def test_post_tag_no_name_400(self): + self.login(username="admin") + uri = f"api/v1/tag/" + dashboard = ( + db.session.query(Dashboard) + .filter(Dashboard.dashboard_title == "World Bank's Data") + .first() + ) + rv = self.client.post( + uri, + json={"name": "", "objects_to_tag": [["dashboard", dashboard.id]]}, + ) + + self.assertEqual(rv.status_code, 400) + @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") @pytest.mark.usefixtures("create_tags") def test_put_tag(self): From 9bc7bcbe8690627b5e1908b9b8bba261813b4b4b Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Sat, 4 Nov 2023 00:24:36 +0000 Subject: [PATCH 8/8] ok --- superset-frontend/src/features/tags/TagModal.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/superset-frontend/src/features/tags/TagModal.tsx b/superset-frontend/src/features/tags/TagModal.tsx index ed0d040431a1c..4339d69130792 100644 --- a/superset-frontend/src/features/tags/TagModal.tsx +++ b/superset-frontend/src/features/tags/TagModal.tsx @@ -243,9 +243,7 @@ const TagModal: React.FC = ({ refreshData(); addSuccessToast(t('Tag created')); }) - .catch(err => - addDangerToast(err.message || 'Error Creating Tag'), - ); + .catch(err => addDangerToast(err.message || 'Error Creating Tag')); } onHide(); };