Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 2 additions & 54 deletions cognition_objects/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
CognitionMacroExecutionLink,
)
from ..enums import (
AdminMacrosDisplay,
UserRoles,
MacroScope,
MacroType,
Expand All @@ -22,7 +21,6 @@
)
from ..util import prevent_sql_injection, is_list_like
from . import project
from sqlalchemy import or_, and_
from sqlalchemy.orm.attributes import flag_modified


Expand Down Expand Up @@ -62,16 +60,11 @@ def get_with_nodes_and_edges(macro_id: str) -> Dict[str, Any]:

def get_overview_for_all_for_me(
user: User,
is_admin: bool,
project_id: Optional[str] = None,
only_production: bool = False,
) -> List[CognitionMacro]:
project_item = project.get(project_id) if project_id else None
final_list = []
final_list = __get_admin_macros_for_me(
user, is_admin, project_item, only_production
)
final_list.extend(__get_org_macros_for_me(user, only_production))
final_list = list(__get_org_macros_for_me(user, only_production))
if project_id:
final_list.extend(__get_project_macros_for_me(project_item, only_production))
return final_list
Expand Down Expand Up @@ -142,37 +135,6 @@ def macro_execution_finished(
)


def __get_admin_macros_for_me(
user: User, is_admin: bool, project: CognitionProject, only_production: bool
) -> List[CognitionMacro]:

if (
not project
or not project.macro_config
or not (show := project.macro_config.get("show"))
):
return []

if (
(show == AdminMacrosDisplay.DONT_SHOW.value)
or (show == AdminMacrosDisplay.FOR_ADMINS.value and not is_admin)
or (
show == AdminMacrosDisplay.FOR_ENGINEERS.value
and user.role != UserRoles.ENGINEER.value
and not is_admin
)
):
return []
query = session.query(CognitionMacro).filter(
CognitionMacro.scope == MacroScope.ADMIN.value
)

if only_production:
query = query.filter(CognitionMacro.state == MacroState.PRODUCTION.value)

return query.all()


def __get_org_macros_for_me(user: User, only_production: bool) -> List[CognitionMacro]:
query = session.query(CognitionMacro).filter(
CognitionMacro.scope == MacroScope.ORGANIZATION.value,
Expand Down Expand Up @@ -272,29 +234,15 @@ def create_edge(
def delete_macros(
org_id: str,
ids: Iterable[str],
is_admin: bool,
user: User,
with_commit: bool = True,
# returns the ids that couldn't be deleted
) -> List[str]:
#
query = session.query(CognitionMacro).filter(
CognitionMacro.id.in_(ids),
or_(
CognitionMacro.organization_id == org_id,
and_(
CognitionMacro.scope == MacroScope.ADMIN.value,
CognitionMacro.organization_id.is_(None),
),
),
CognitionMacro.organization_id == org_id,
)
# filter_org =
if user.role != UserRoles.ENGINEER.value:
# can only delete their own macros
query = query.filter(CognitionMacro.created_by == user.id)
if not is_admin:
# can't delete admin macros
query = query.filter(CognitionMacro.scope != MacroScope.ADMIN.value)
query.delete()
general.flush_or_commit(with_commit)

Expand Down
1 change: 0 additions & 1 deletion cognition_objects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def routing(

DEFAULT_MACRO_CONFIG = {
"enable": False,
"show": enums.AdminMacrosDisplay.DONT_SHOW.value,
}


Expand Down
7 changes: 0 additions & 7 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@ class MacroEdgeConditionType(Enum):


class MacroScope(Enum):
ADMIN = "ADMIN"
ORGANIZATION = "ORGANIZATION"
PROJECT = "PROJECT"

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


class AdminMacrosDisplay(Enum):
DONT_SHOW = "DONT_SHOW"
FOR_ADMINS = "FOR_ADMINS"
FOR_ENGINEERS = "FOR_ENGINEERS"
FOR_ALL = "FOR_ALL"


class FileCachingInitiator(Enum):
TMP_DOC_RETRIEVAL = "TMP_DOC_RETRIEVAL"
Expand Down
5 changes: 1 addition & 4 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,6 @@ class CognitionProject(Base):
max_file_size_mb = Column(Float, default=3.0)
useable_etl_configurations = Column(JSON)
max_folder_size_mb = Column(Float, default=20.0)
# holds e.g. show, admin macro setting etc.
macro_config = Column(JSON)
# options from <SVGIcon/> component - only visible with new UI selected (user setting)
icon = Column(String, default="IconBolt")
Expand Down Expand Up @@ -1775,13 +1774,12 @@ class CognitionMacro(Base):
UUID(as_uuid=True),
ForeignKey(f"{Tablenames.ORGANIZATION.value}.id", ondelete="CASCADE"),
index=True,
nullable=True, # ADMIN MACROS dont have a org_id
)
project_id = Column(
UUID(as_uuid=True),
ForeignKey(f"cognition.{Tablenames.PROJECT.value}.id", ondelete="CASCADE"),
index=True,
nullable=True, # ADMIN or ORGANIZATION MACROS dont have a project_id
nullable=True, # ORGANIZATION MACROS dont have a project_id
)
created_by = Column(
UUID(as_uuid=True),
Expand Down Expand Up @@ -1890,7 +1888,6 @@ class CognitionMacroExecutionLink(Base):
UUID(as_uuid=True),
ForeignKey(f"{Tablenames.ORGANIZATION.value}.id", ondelete="CASCADE"),
index=True,
nullable=True, # ADMIN MACROS dont have a org_id
)
execution_id = Column(
UUID(as_uuid=True),
Expand Down