|
11 | 11 | CognitionMacroExecutionLink, |
12 | 12 | ) |
13 | 13 | from ..enums import ( |
14 | | - AdminMacrosDisplay, |
15 | 14 | UserRoles, |
16 | 15 | MacroScope, |
17 | 16 | MacroType, |
|
22 | 21 | ) |
23 | 22 | from ..util import prevent_sql_injection, is_list_like |
24 | 23 | from . import project |
25 | | -from sqlalchemy import or_, and_ |
26 | 24 | from sqlalchemy.orm.attributes import flag_modified |
27 | 25 |
|
28 | 26 |
|
@@ -62,16 +60,13 @@ def get_with_nodes_and_edges(macro_id: str) -> Dict[str, Any]: |
62 | 60 |
|
63 | 61 | def get_overview_for_all_for_me( |
64 | 62 | user: User, |
65 | | - is_admin: bool, |
66 | 63 | project_id: Optional[str] = None, |
67 | 64 | only_production: bool = False, |
68 | 65 | ) -> List[CognitionMacro]: |
69 | 66 | project_item = project.get(project_id) if project_id else None |
70 | | - final_list = [] |
71 | | - final_list = __get_admin_macros_for_me( |
72 | | - user, is_admin, project_item, only_production |
73 | | - ) |
74 | | - final_list.extend(__get_org_macros_for_me(user, only_production)) |
| 67 | + if project_item and project_item.organization_id != user.organization_id: |
| 68 | + raise ValueError("Project doesn't belong to user org") |
| 69 | + final_list = list(__get_org_macros_for_me(user, only_production)) |
75 | 70 | if project_id: |
76 | 71 | final_list.extend(__get_project_macros_for_me(project_item, only_production)) |
77 | 72 | return final_list |
@@ -142,37 +137,6 @@ def macro_execution_finished( |
142 | 137 | ) |
143 | 138 |
|
144 | 139 |
|
145 | | -def __get_admin_macros_for_me( |
146 | | - user: User, is_admin: bool, project: CognitionProject, only_production: bool |
147 | | -) -> List[CognitionMacro]: |
148 | | - |
149 | | - if ( |
150 | | - not project |
151 | | - or not project.macro_config |
152 | | - or not (show := project.macro_config.get("show")) |
153 | | - ): |
154 | | - return [] |
155 | | - |
156 | | - if ( |
157 | | - (show == AdminMacrosDisplay.DONT_SHOW.value) |
158 | | - or (show == AdminMacrosDisplay.FOR_ADMINS.value and not is_admin) |
159 | | - or ( |
160 | | - show == AdminMacrosDisplay.FOR_ENGINEERS.value |
161 | | - and user.role != UserRoles.ENGINEER.value |
162 | | - and not is_admin |
163 | | - ) |
164 | | - ): |
165 | | - return [] |
166 | | - query = session.query(CognitionMacro).filter( |
167 | | - CognitionMacro.scope == MacroScope.ADMIN.value |
168 | | - ) |
169 | | - |
170 | | - if only_production: |
171 | | - query = query.filter(CognitionMacro.state == MacroState.PRODUCTION.value) |
172 | | - |
173 | | - return query.all() |
174 | | - |
175 | | - |
176 | 140 | def __get_org_macros_for_me(user: User, only_production: bool) -> List[CognitionMacro]: |
177 | 141 | query = session.query(CognitionMacro).filter( |
178 | 142 | CognitionMacro.scope == MacroScope.ORGANIZATION.value, |
@@ -272,29 +236,15 @@ def create_edge( |
272 | 236 | def delete_macros( |
273 | 237 | org_id: str, |
274 | 238 | ids: Iterable[str], |
275 | | - is_admin: bool, |
276 | 239 | user: User, |
277 | 240 | with_commit: bool = True, |
278 | | - # returns the ids that couldn't be deleted |
279 | 241 | ) -> List[str]: |
280 | | - # |
281 | 242 | query = session.query(CognitionMacro).filter( |
282 | 243 | CognitionMacro.id.in_(ids), |
283 | | - or_( |
284 | | - CognitionMacro.organization_id == org_id, |
285 | | - and_( |
286 | | - CognitionMacro.scope == MacroScope.ADMIN.value, |
287 | | - CognitionMacro.organization_id.is_(None), |
288 | | - ), |
289 | | - ), |
| 244 | + CognitionMacro.organization_id == org_id, |
290 | 245 | ) |
291 | | - # filter_org = |
292 | 246 | if user.role != UserRoles.ENGINEER.value: |
293 | | - # can only delete their own macros |
294 | 247 | query = query.filter(CognitionMacro.created_by == user.id) |
295 | | - if not is_admin: |
296 | | - # can't delete admin macros |
297 | | - query = query.filter(CognitionMacro.scope != MacroScope.ADMIN.value) |
298 | 248 | query.delete() |
299 | 249 | general.flush_or_commit(with_commit) |
300 | 250 |
|
@@ -551,7 +501,6 @@ def get_macro_execution_data_for_message_queue( |
551 | 501 | MacroType.DOCUMENT_MESSAGE_QUEUE.value, |
552 | 502 | MacroType.FOLDER_MESSAGE_QUEUE.value, |
553 | 503 | ]: |
554 | | - |
555 | 504 | raise ValueError(f"Macro with id {macro_id} not found or wrong type") |
556 | 505 | macro_id = prevent_sql_injection(macro_id, isinstance(macro_id, str)) |
557 | 506 | group_ids = [prevent_sql_injection(g, isinstance(g, str)) for g in group_ids] |
@@ -615,7 +564,6 @@ def get_macro_execution_data_for_message_queue( |
615 | 564 |
|
616 | 565 | result = general.execute_first(query) |
617 | 566 | if result and result[0]: |
618 | | - |
619 | 567 | project_ids = {e["meta_info"]["project_id"] for e in result[0]} |
620 | 568 | project_lookup = project.get_lookup_by_ids(project_ids) |
621 | 569 | if len(project_lookup) != len(project_ids): |
|
0 commit comments