|
60 | 60 | load_world_bank_dashboard_with_slices,
|
61 | 61 | load_world_bank_data,
|
62 | 62 | )
|
63 |
| -from .dashboard_utils import get_table |
64 | 63 |
|
65 | 64 | NEW_SECURITY_CONVERGE_VIEWS = (
|
66 | 65 | "Annotation",
|
|
73 | 72 | "SavedQuery",
|
74 | 73 | )
|
75 | 74 |
|
76 |
| -GAMMA_ROLE_PERMISSIONS = { |
77 |
| - "Gamma": [ |
78 |
| - ["menu_access", "List Users"], |
79 |
| - ["can_read", "SavedQuery"], |
80 |
| - ["can_write", "SavedQuery"], |
81 |
| - ["can_read", "CssTemplate"], |
82 |
| - ["can_write", "CssTemplate"], |
83 |
| - ["can_read", "ReportSchedule"], |
84 |
| - ["can_write", "ReportSchedule"], |
85 |
| - ["can_read", "AvailableDomains"], |
86 |
| - ["can_read", "Chart"], |
87 |
| - ["can_write", "Chart"], |
88 |
| - ["can_read", "Annotation"], |
89 |
| - ["can_write", "Annotation"], |
90 |
| - ["can_read", "Dataset"], |
91 |
| - ["can_read", "Dashboard"], |
92 |
| - ["can_write", "Dashboard"], |
93 |
| - ["can_read", "Database"], |
94 |
| - ["can_read", "Query"], |
95 |
| - ["can_this_form_post", "ResetMyPasswordView"], |
96 |
| - ["can_this_form_get", "ResetMyPasswordView"], |
97 |
| - ["can_this_form_post", "UserInfoEditView"], |
98 |
| - ["can_this_form_get", "UserInfoEditView"], |
99 |
| - ["can_userinfo", "UserDBModelView"], |
100 |
| - ["resetmypassword", "UserDBModelView"], |
101 |
| - ["can_get", "OpenApi"], |
102 |
| - ["can_show", "SwaggerView"], |
103 |
| - ["can_get", "MenuApi"], |
104 |
| - ["can_list", "AsyncEventsRestApi"], |
105 |
| - ["can_read", "AdvancedDataType"], |
106 |
| - ["can_invalidate", "CacheRestApi"], |
107 |
| - ["can_export", "Chart"], |
108 |
| - ["can_read", "DashboardFilterStateRestApi"], |
109 |
| - ["can_write", "DashboardFilterStateRestApi"], |
110 |
| - ["can_read", "DashboardPermalinkRestApi"], |
111 |
| - ["can_write", "DashboardPermalinkRestApi"], |
112 |
| - ["can_delete_embedded", "Dashboard"], |
113 |
| - ["can_get_embedded", "Dashboard"], |
114 |
| - ["can_export", "Dashboard"], |
115 |
| - ["can_read", "EmbeddedDashboard"], |
116 |
| - ["can_read", "Explore"], |
117 |
| - ["can_read", "ExploreFormDataRestApi"], |
118 |
| - ["can_write", "ExploreFormDataRestApi"], |
119 |
| - ["can_read", "ExplorePermalinkRestApi"], |
120 |
| - ["can_write", "ExplorePermalinkRestApi"], |
121 |
| - ["can_delete", "FilterSets"], |
122 |
| - ["can_list", "FilterSets"], |
123 |
| - ["can_edit", "FilterSets"], |
124 |
| - ["can_add", "FilterSets"], |
125 |
| - ["can_import_", "ImportExportRestApi"], |
126 |
| - ["can_export", "ImportExportRestApi"], |
127 |
| - ["can_export", "SavedQuery"], |
128 |
| - ["can_show", "DynamicPlugin"], |
129 |
| - ["can_list", "DynamicPlugin"], |
130 |
| - ["can_time_range", "Api"], |
131 |
| - ["can_query_form_data", "Api"], |
132 |
| - ["can_query", "Api"], |
133 |
| - ["can_this_form_post", "CsvToDatabaseView"], |
134 |
| - ["can_this_form_get", "CsvToDatabaseView"], |
135 |
| - ["can_this_form_post", "ExcelToDatabaseView"], |
136 |
| - ["can_this_form_get", "ExcelToDatabaseView"], |
137 |
| - ["can_this_form_post", "ColumnarToDatabaseView"], |
138 |
| - ["can_this_form_get", "ColumnarToDatabaseView"], |
139 |
| - ["can_get", "Datasource"], |
140 |
| - ["can_external_metadata", "Datasource"], |
141 |
| - ["can_external_metadata_by_name", "Datasource"], |
142 |
| - ["can_get_value", "KV"], |
143 |
| - ["can_store", "KV"], |
144 |
| - ["can_my_queries", "SqlLab"], |
145 |
| - ["can_created_dashboards", "Superset"], |
146 |
| - ["can_testconn", "Superset"], |
147 |
| - ["can_estimate_query_cost", "Superset"], |
148 |
| - ["can_explore", "Superset"], |
149 |
| - ["can_fetch_datasource_metadata", "Superset"], |
150 |
| - ["can_search_queries", "Superset"], |
151 |
| - ["can_save_dash", "Superset"], |
152 |
| - ["can_dashboard_permalink", "Superset"], |
153 |
| - ["can_warm_up_cache", "Superset"], |
154 |
| - ["can_request_access", "Superset"], |
155 |
| - ["can_datasources", "Superset"], |
156 |
| - ["can_available_domains", "Superset"], |
157 |
| - ["can_dashboard", "Superset"], |
158 |
| - ["can_annotation_json", "Superset"], |
159 |
| - ["can_created_slices", "Superset"], |
160 |
| - ["can_slice_json", "Superset"], |
161 |
| - ["can_profile", "Superset"], |
162 |
| - ["can_filter", "Superset"], |
163 |
| - ["can_validate_sql_json", "Superset"], |
164 |
| - ["can_slice", "Superset"], |
165 |
| - ["can_sqllab", "Superset"], |
166 |
| - ["can_log", "Superset"], |
167 |
| - ["can_recent_activity", "Superset"], |
168 |
| - ["can_tables", "Superset"], |
169 |
| - ["can_fave_slices", "Superset"], |
170 |
| - ["can_sqllab_viz", "Superset"], |
171 |
| - ["can_fave_dashboards", "Superset"], |
172 |
| - ["can_results", "Superset"], |
173 |
| - ["can_extra_table_metadata", "Superset"], |
174 |
| - ["can_schemas_access_for_file_upload", "Superset"], |
175 |
| - ["can_fave_dashboards_by_username", "Superset"], |
176 |
| - ["can_csv", "Superset"], |
177 |
| - ["can_add_slices", "Superset"], |
178 |
| - ["can_explore_json", "Superset"], |
179 |
| - ["can_sqllab_history", "Superset"], |
180 |
| - ["can_import_dashboards", "Superset"], |
181 |
| - ["can_sqllab_table_viz", "Superset"], |
182 |
| - ["can_stop_query", "Superset"], |
183 |
| - ["can_favstar", "Superset"], |
184 |
| - ["can_copy_dash", "Superset"], |
185 |
| - ["can_queries", "Superset"], |
186 |
| - ["can_user_slices", "Superset"], |
187 |
| - ["can_delete", "TableSchemaView"], |
188 |
| - ["can_post", "TableSchemaView"], |
189 |
| - ["can_expanded", "TableSchemaView"], |
190 |
| - ["can_get", "TabStateView"], |
191 |
| - ["can_post", "TabStateView"], |
192 |
| - ["can_migrate_query", "TabStateView"], |
193 |
| - ["can_put", "TabStateView"], |
194 |
| - ["can_activate", "TabStateView"], |
195 |
| - ["can_delete", "TabStateView"], |
196 |
| - ["can_delete_query", "TabStateView"], |
197 |
| - ["can_get", "TagView"], |
198 |
| - ["can_tagged_objects", "TagView"], |
199 |
| - ["can_post", "TagView"], |
200 |
| - ["can_delete", "TagView"], |
201 |
| - ["can_suggestions", "TagView"], |
202 |
| - ["can_read", "SecurityRestApi"], |
203 |
| - ["menu_access", "List Roles"], |
204 |
| - ["menu_access", "Action Log"], |
205 |
| - ["menu_access", "Access requests"], |
206 |
| - ["menu_access", "Home"], |
207 |
| - ["menu_access", "Annotation Layers"], |
208 |
| - ["menu_access", "Plugins"], |
209 |
| - ["menu_access", "Import Dashboards"], |
210 |
| - ["menu_access", "Alerts & Report"], |
211 |
| - ["menu_access", "Dashboards"], |
212 |
| - ["menu_access", "Charts"], |
213 |
| - ["menu_access", "SQL Editor"], |
214 |
| - ["menu_access", "Saved Queries"], |
215 |
| - ["menu_access", "Query Search"], |
216 |
| - ["menu_access", "Data"], |
217 |
| - ["menu_access", "Databases"], |
218 |
| - ["menu_access", "Datasets"], |
219 |
| - ["can_share_dashboard", "Superset"], |
220 |
| - ["can_share_chart", "Superset"], |
221 |
| - ], |
222 |
| - "schema_access_role": [["schema_access", "[examples].[temp_schema]"]], |
223 |
| - "dummy_role": [ |
224 |
| - ["datasource_access", "[examples].[wb_health_population](id:1)"], |
225 |
| - ["database_access", "[examples].(id:1)"], |
226 |
| - ], |
227 |
| -} |
228 |
| - |
229 | 75 |
|
230 | 76 | def get_perm_tuples(role_name):
|
231 | 77 | perm_set = set()
|
@@ -1757,54 +1603,6 @@ def test_views_are_secured(self):
|
1757 | 1603 | view_str = "\n".join([str(v) for v in unsecured_views])
|
1758 | 1604 | raise Exception(f"Some views are not secured:\n{view_str}")
|
1759 | 1605 |
|
1760 |
| - @patch("superset.utils.core.g") |
1761 |
| - @patch("superset.security.manager.g") |
1762 |
| - def test_get_permissions_gamma_user(self, mock_sm_g, mock_g): |
1763 |
| - session = db.session |
1764 |
| - role_name = "dummy_role" |
1765 |
| - gamma_user = security_manager.find_user(username="gamma") |
1766 |
| - security_manager.add_role(role_name) |
1767 |
| - dummy_role = security_manager.find_role(role_name) |
1768 |
| - gamma_user.roles.append(dummy_role) |
1769 |
| - |
1770 |
| - table = ( |
1771 |
| - db.session.query(SqlaTable) |
1772 |
| - .filter_by(table_name="wb_health_population") |
1773 |
| - .one() |
1774 |
| - ) |
1775 |
| - table_perm = table.perm |
1776 |
| - security_manager.add_permission_role( |
1777 |
| - dummy_role, |
1778 |
| - security_manager.find_permission_view_menu("datasource_access", table_perm), |
1779 |
| - ) |
1780 |
| - security_manager.add_permission_role( |
1781 |
| - dummy_role, |
1782 |
| - security_manager.find_permission_view_menu( |
1783 |
| - "database_access", table.database.perm |
1784 |
| - ), |
1785 |
| - ) |
1786 |
| - |
1787 |
| - session.commit() |
1788 |
| - |
1789 |
| - mock_g.user = mock_sm_g.user = security_manager.find_user("gamma") |
1790 |
| - with self.client.application.test_request_context(): |
1791 |
| - roles, permissions = security_manager.get_permissions(mock_g.user) |
1792 |
| - assert "dummy_role" in roles |
1793 |
| - assert "Gamma" in roles |
1794 |
| - assert sorted(roles["Gamma"]) == sorted(GAMMA_ROLE_PERMISSIONS["Gamma"]) |
1795 |
| - assert sorted(roles["schema_access_role"]) == sorted( |
1796 |
| - GAMMA_ROLE_PERMISSIONS["schema_access_role"] |
1797 |
| - ) |
1798 |
| - |
1799 |
| - assert len(permissions) == 2 |
1800 |
| - assert "[examples].(id:" in permissions["database_access"][0] |
1801 |
| - assert "[examples].[" in permissions["datasource_access"][0] |
1802 |
| - |
1803 |
| - # cleanup |
1804 |
| - gamma_user = security_manager.find_user(username="gamma") |
1805 |
| - gamma_user.roles.remove(security_manager.find_role(role_name)) |
1806 |
| - session.commit() |
1807 |
| - |
1808 | 1606 |
|
1809 | 1607 | class TestSecurityManager(SupersetTestCase):
|
1810 | 1608 | """
|
|
0 commit comments