Skip to content

Commit 765ca08

Browse files
Hotfix permission batch (#187)
* improved permission receival * embedding force update * PR fix potential no results --------- Co-authored-by: andhreljaKern <[email protected]>
1 parent cb5bab5 commit 765ca08

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

business_objects/embedding.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,18 +772,31 @@ def update_embedding_state_failed(
772772

773773

774774
def update_embedding_state_waiting(
775-
project_id: str, embedding_id: str, with_commit: bool = False
775+
project_id: str,
776+
embedding_id: str,
777+
with_commit: bool = False,
778+
force_update: bool = False,
776779
) -> None:
777780
__update_embedding_state(
778-
project_id, embedding_id, enums.EmbeddingState.WAITING.value, with_commit
781+
project_id,
782+
embedding_id,
783+
enums.EmbeddingState.WAITING.value,
784+
with_commit,
785+
force_update,
779786
)
780787

781788

782789
def __update_embedding_state(
783-
project_id: str, embedding_id: str, state: str, with_commit=False
790+
project_id: str,
791+
embedding_id: str,
792+
state: str,
793+
with_commit: bool = False,
794+
force_update: bool = False,
784795
) -> None:
785796
embedding_item = get(project_id, embedding_id)
786-
if embedding_item and not embedding_item.state == enums.EmbeddingState.FAILED.value:
797+
if embedding_item and (
798+
not embedding_item.state == enums.EmbeddingState.FAILED.value or force_update
799+
):
787800
embedding_item.state = state
788801
general.flush_or_commit(with_commit)
789802

cognition_objects/integration.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,23 @@ def get_sharepoint_permissions_by_integration_id(
278278
ON x.id = s.id
279279
"""
280280
return session.execute(query).all()
281+
282+
283+
def get_distinct_item_ids_for_all_permissions(
284+
integration_id: str,
285+
) -> List[str]:
286+
integration_id = prevent_sql_injection(
287+
integration_id, isinstance(integration_id, str)
288+
)
289+
query = f"""SELECT DISTINCT x.object_id
290+
FROM (
291+
SELECT json_array_elements_text(permissions) permission_id, MAX(object_id::TEXT) object_id
292+
FROM integration.sharepoint
293+
WHERE integration_id = '{integration_id}'
294+
GROUP BY 1
295+
) x;"""
296+
results = session.execute(query).all()
297+
if not results:
298+
return []
299+
300+
return [row[0] for row in results if row and row[0]]

0 commit comments

Comments
 (0)