Skip to content

Commit e41ab93

Browse files
Merge remote-tracking branch 'origin/dev' into use-auto-scroll
2 parents a0f4907 + d3cb492 commit e41ab93

File tree

4 files changed

+5
-68
lines changed

4 files changed

+5
-68
lines changed

cognition_objects/macro.py

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
CognitionMacroExecutionLink,
1212
)
1313
from ..enums import (
14-
AdminMacrosDisplay,
1514
UserRoles,
1615
MacroScope,
1716
MacroType,
@@ -22,7 +21,6 @@
2221
)
2322
from ..util import prevent_sql_injection, is_list_like
2423
from . import project
25-
from sqlalchemy import or_, and_
2624
from sqlalchemy.orm.attributes import flag_modified
2725

2826

@@ -62,16 +60,13 @@ def get_with_nodes_and_edges(macro_id: str) -> Dict[str, Any]:
6260

6361
def get_overview_for_all_for_me(
6462
user: User,
65-
is_admin: bool,
6663
project_id: Optional[str] = None,
6764
only_production: bool = False,
6865
) -> List[CognitionMacro]:
6966
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))
7570
if project_id:
7671
final_list.extend(__get_project_macros_for_me(project_item, only_production))
7772
return final_list
@@ -142,37 +137,6 @@ def macro_execution_finished(
142137
)
143138

144139

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-
176140
def __get_org_macros_for_me(user: User, only_production: bool) -> List[CognitionMacro]:
177141
query = session.query(CognitionMacro).filter(
178142
CognitionMacro.scope == MacroScope.ORGANIZATION.value,
@@ -272,29 +236,15 @@ def create_edge(
272236
def delete_macros(
273237
org_id: str,
274238
ids: Iterable[str],
275-
is_admin: bool,
276239
user: User,
277240
with_commit: bool = True,
278-
# returns the ids that couldn't be deleted
279241
) -> List[str]:
280-
#
281242
query = session.query(CognitionMacro).filter(
282243
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,
290245
)
291-
# filter_org =
292246
if user.role != UserRoles.ENGINEER.value:
293-
# can only delete their own macros
294247
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)
298248
query.delete()
299249
general.flush_or_commit(with_commit)
300250

@@ -551,7 +501,6 @@ def get_macro_execution_data_for_message_queue(
551501
MacroType.DOCUMENT_MESSAGE_QUEUE.value,
552502
MacroType.FOLDER_MESSAGE_QUEUE.value,
553503
]:
554-
555504
raise ValueError(f"Macro with id {macro_id} not found or wrong type")
556505
macro_id = prevent_sql_injection(macro_id, isinstance(macro_id, str))
557506
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(
615564

616565
result = general.execute_first(query)
617566
if result and result[0]:
618-
619567
project_ids = {e["meta_info"]["project_id"] for e in result[0]}
620568
project_lookup = project.get_lookup_by_ids(project_ids)
621569
if len(project_lookup) != len(project_ids):

cognition_objects/project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def routing(
170170

171171
DEFAULT_MACRO_CONFIG = {
172172
"enable": False,
173-
"show": enums.AdminMacrosDisplay.DONT_SHOW.value,
174173
}
175174

176175

enums.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,6 @@ class MacroEdgeConditionType(Enum):
847847

848848

849849
class MacroScope(Enum):
850-
ADMIN = "ADMIN"
851850
ORGANIZATION = "ORGANIZATION"
852851
PROJECT = "PROJECT"
853852

@@ -870,12 +869,6 @@ class MacroExecutionLinkAction(Enum):
870869
UPDATE = "UPDATE"
871870

872871

873-
class AdminMacrosDisplay(Enum):
874-
DONT_SHOW = "DONT_SHOW"
875-
FOR_ADMINS = "FOR_ADMINS"
876-
FOR_ENGINEERS = "FOR_ENGINEERS"
877-
FOR_ALL = "FOR_ALL"
878-
879872

880873
class FileCachingInitiator(Enum):
881874
TMP_DOC_RETRIEVAL = "TMP_DOC_RETRIEVAL"

models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,6 @@ class CognitionProject(Base):
12501250
max_file_size_mb = Column(Float, default=3.0)
12511251
useable_etl_configurations = Column(JSON)
12521252
max_folder_size_mb = Column(Float, default=20.0)
1253-
# holds e.g. show, admin macro setting etc.
12541253
macro_config = Column(JSON)
12551254
# options from <SVGIcon/> component - only visible with new UI selected (user setting)
12561255
icon = Column(String, default="IconBolt")
@@ -1776,13 +1775,12 @@ class CognitionMacro(Base):
17761775
UUID(as_uuid=True),
17771776
ForeignKey(f"{Tablenames.ORGANIZATION.value}.id", ondelete="CASCADE"),
17781777
index=True,
1779-
nullable=True, # ADMIN MACROS dont have a org_id
17801778
)
17811779
project_id = Column(
17821780
UUID(as_uuid=True),
17831781
ForeignKey(f"cognition.{Tablenames.PROJECT.value}.id", ondelete="CASCADE"),
17841782
index=True,
1785-
nullable=True, # ADMIN or ORGANIZATION MACROS dont have a project_id
1783+
nullable=True, # ORGANIZATION MACROS dont have a project_id
17861784
)
17871785
created_by = Column(
17881786
UUID(as_uuid=True),
@@ -1891,7 +1889,6 @@ class CognitionMacroExecutionLink(Base):
18911889
UUID(as_uuid=True),
18921890
ForeignKey(f"{Tablenames.ORGANIZATION.value}.id", ondelete="CASCADE"),
18931891
index=True,
1894-
nullable=True, # ADMIN MACROS dont have a org_id
18951892
)
18961893
execution_id = Column(
18971894
UUID(as_uuid=True),

0 commit comments

Comments
 (0)