diff --git a/agenta-backend/agenta_backend/routers/app_router.py b/agenta-backend/agenta_backend/routers/app_router.py index 34f1145cd9..d4a54f16b5 100644 --- a/agenta-backend/agenta_backend/routers/app_router.py +++ b/agenta-backend/agenta_backend/routers/app_router.py @@ -50,9 +50,7 @@ if isCloudEE(): from agenta_backend.commons.services import db_manager_ee from agenta_backend.commons.services.selectors import ( - get_user_own_org, get_user_org_and_workspace_id, - get_org_default_workspace, ) # noqa pylint: disable-all from agenta_backend.commons.utils.permissions import ( check_action_access, @@ -220,9 +218,6 @@ async def create_app( Permission.CREATE_APPLICATION, ) - if payload.workspace_id is None: - payload.workspace_id = request.state.workspace_id - try: user_org_workspace_data = await get_user_org_and_workspace_id( request.state.user_id @@ -235,7 +230,7 @@ async def create_app( has_permission = await check_rbac_permission( user_org_workspace_data=user_org_workspace_data, - project_id=payload.project_id or request.state.project_id, + project_id=request.state.project_id, permission=Permission.CREATE_APPLICATION, ) logger.debug( @@ -252,8 +247,7 @@ async def create_app( app_db = await db_manager.create_app_and_envs( payload.app_name, - project_id=payload.project_id or request.state.project_id, - workspace_id=payload.workspace_id, + project_id=request.state.project_id, ) return CreateAppOutput(app_id=str(app_db.id), app_name=str(app_db.app_name)) except Exception as e: @@ -310,18 +304,16 @@ async def update_app( async def list_apps( request: Request, app_name: Optional[str] = None, - workspace_id: Optional[str] = None, ) -> List[App]: """ - Retrieve a list of apps filtered by app_name and org_id. + Retrieve a list of apps filtered by app_name. Args: app_name (Optional[str]): The name of the app to filter by. - org_id (Optional[str]): The ID of the organization to filter by. stoken_session (SessionContainer): The session container. Returns: - List[App]: A list of apps filtered by app_name and org_id. + List[App]: A list of apps filtered by app_name. Raises: HTTPException: If there was an error retrieving the list of apps. @@ -331,7 +323,6 @@ async def list_apps( project_id=request.state.project_id, user_uid=request.state.user_id, app_name=app_name, - workspace_id=workspace_id, ) return apps except Exception as e: @@ -491,12 +482,9 @@ async def create_app_and_variant_from_template( ) logger.debug("Step 3: Checking user has permission to create app") - project = await db_manager_ee.get_project_by_workspace( - workspace_id=payload.workspace_id - ) has_permission = await check_rbac_permission( user_org_workspace_data=user_org_workspace_data, - project_id=str(project.id), + project_id=request.state.project_id, permission=Permission.CREATE_APPLICATION, ) logger.debug( @@ -518,8 +506,7 @@ async def create_app_and_variant_from_template( app_name = payload.app_name.lower() app = await db_manager.fetch_app_by_name_and_parameters( app_name, - workspace_id=payload.workspace_id, - project_id=payload.project_id or request.state.project_id, + project_id=request.state.project_id, ) if app is not None: raise Exception( @@ -542,8 +529,7 @@ async def create_app_and_variant_from_template( app = await db_manager.create_app_and_envs( app_name=app_name, template_id=str(template_db.id), - project_id=payload.project_id or request.state.project_id, - workspace_id=payload.workspace_id, + project_id=request.state.project_id, ) logger.debug( diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index f9a9f20e2b..8f221ad47d 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -730,7 +730,6 @@ async def create_app_and_envs( app_name: str, template_id: Optional[str] = None, project_id: Optional[str] = None, - workspace_id: Optional[str] = None, ) -> AppDB: """ Create a new app with the given name and organization ID. @@ -747,10 +746,6 @@ async def create_app_and_envs( ValueError: If an app with the same name already exists. """ - if isCloudEE(): - project = await db_manager_ee.get_project_by_workspace(workspace_id) - project_id = str(project.id) - app = await fetch_app_by_name_and_parameters( app_name=app_name, project_id=project_id ) @@ -1213,7 +1208,6 @@ async def list_apps( project_id: str, user_uid: str, app_name: Optional[str] = None, - workspace_id: Optional[str] = None, ): """ Lists all the unique app names and their IDs from the database @@ -1233,13 +1227,10 @@ async def list_apps( elif isCloudEE(): if isCloudEE(): - project = await db_manager_ee.get_project_by_workspace( - workspace_id=workspace_id - ) user_org_workspace_data = await get_user_org_and_workspace_id(user_uid) # type: ignore has_permission = await check_rbac_permission( # type: ignore user_org_workspace_data=user_org_workspace_data, - project_id=str(project.id), + project_id=project_id, permission=Permission.VIEW_APPLICATION, # type: ignore ) logger.debug(f"User has Permission to list apps: {has_permission}") @@ -1251,7 +1242,7 @@ async def list_apps( async with engine.session() as session: result = await session.execute( - select(AppDB).filter_by(project_id=project.id) + select(AppDB).filter_by(project_id=project_id) ) apps = result.unique().scalars().all() return [converters.app_db_to_pydantic(app) for app in apps] @@ -2785,26 +2776,19 @@ async def update_app_variant( async def fetch_app_by_name_and_parameters( app_name: str, - workspace_id: Optional[str] = None, project_id: Optional[str] = None, ): """Fetch an app by its name and project identifier. Args: app_name (str): The name of the app - workspace_id (str, optional): The ID of the workspace. Defaults to None. project_id (str, optional): The ID of the project. Defaults to None. Returns: AppDB: the instance of the app """ - - if not project_id and (isCloudEE() and workspace_id is not None): - project = await db_manager_ee.get_project_by_workspace(workspace_id) - project_id = str(project.id) if project else None - if project_id is None: - raise ValueError("Either workspace_id or project_id must be provided.") + raise ValueError("project_id must be provided.") async with engine.session() as session: query = select(AppDB).filter_by( diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index ab3bf4a7ba..0e93534cc1 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -80,16 +80,11 @@ def cli(): @click.command() @click.option("--app-name", "--app_name", default=None) @click.option("--backend-host", "backend_host", default=None) -@click.option( - "--organisation-name", - "organisation_name", - default=None, - help="The name of the organisation", -) -def init(app_name: str, backend_host: str, organisation_name: str): - init_option = "Blank App" if backend_host != "" and app_name != "" else "" +def init(app_name: str, backend_host: str): """Initialize a new Agenta app with the template files.""" + init_option = "Blank App" if backend_host != "" and app_name != "" else "" + api_key = os.getenv("AGENTA_API_KEY") if not app_name: @@ -151,51 +146,9 @@ def init(app_name: str, backend_host: str, organisation_name: str): api_key=api_key if where_question == "On agenta cloud" else "", ) - # list of user organizations - user_organizations = [] - - # validate the api key if it is provided - if where_question == "On agenta cloud": - try: - key_prefix = api_key.split(".")[0] - client.validate_api_key(key_prefix=key_prefix) - except Exception as ex: - click.echo( - click.style( - f"Error: Unable to validate API key.\nError: {ex}", fg="red" - ) - ) - sys.exit(1) - # Make request to fetch user organizations after api key validation - try: - organizations = client.list_organizations() - if len(organizations) >= 1: - user_organizations = organizations - except Exception as ex: - click.echo(click.style(f"Error: {ex}", fg="red")) - sys.exit(1) - - organization = None - organization_choices = {} - if where_question == "On agenta cloud": - if not organisation_name: - organization_choices = { - f"{org.name}": org for org in user_organizations - } - which_organization = questionary.select( - "Which organization do you want to create the app for?", - choices=list(organization_choices.keys()), - ).ask() - organisation_name = which_organization - - organization = organization_choices.get(organisation_name) - # Get app_id after creating new app in the backend server try: - app_id = client.apps.create_app( - app_name=app_name, - organization_id=organization.id if organization else None, - ).app_id + app_id = client.apps.create_app(app_name=app_name).app_id except Exception as ex: click.echo(click.style(f"Error: {ex}", fg="red")) sys.exit(1) diff --git a/agenta-cli/agenta/client/backend/apps/client.py b/agenta-cli/agenta/client/backend/apps/client.py index 8caf7ae71e..b709a8538e 100644 --- a/agenta-cli/agenta/client/backend/apps/client.py +++ b/agenta-cli/agenta/client/backend/apps/client.py @@ -176,19 +176,17 @@ def list_apps( self, *, app_name: typing.Optional[str] = None, - workspace_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> typing.List[App]: """ - Retrieve a list of apps filtered by app_name and org_id. + Retrieve a list of apps filtered by app_name. Args: app_name (Optional[str]): The name of the app to filter by. - org_id (Optional[str]): The ID of the organization to filter by. stoken_session (SessionContainer): The session container. Returns: - List[App]: A list of apps filtered by app_name and org_id. + List[App]: A list of apps filtered by app_name. Raises: HTTPException: If there was an error retrieving the list of apps. @@ -197,8 +195,6 @@ def list_apps( ---------- app_name : typing.Optional[str] - workspace_id : typing.Optional[str] - request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -220,10 +216,7 @@ def list_apps( _response = self._client_wrapper.httpx_client.request( "apps", method="GET", - params={ - "app_name": app_name, - "workspace_id": workspace_id, - }, + params={"app_name": app_name}, request_options=request_options, ) try: @@ -255,15 +248,13 @@ def create_app( *, app_name: str, project_id: typing.Optional[str] = OMIT, - workspace_id: typing.Optional[str] = OMIT, - organization_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> CreateAppOutput: """ - Create a new app for a user or organization. + Create a new app for a user. Args: - payload (CreateApp): The payload containing the app name and organization ID (optional). + payload (CreateApp): The payload containing the app name. stoken_session (SessionContainer): The session container containing the user's session token. Returns: @@ -278,10 +269,6 @@ def create_app( project_id : typing.Optional[str] - workspace_id : typing.Optional[str] - - organization_id : typing.Optional[str] - request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -308,8 +295,6 @@ def create_app( json={ "app_name": app_name, "project_id": project_id, - "workspace_id": workspace_id, - "organization_id": organization_id, }, request_options=request_options, omit=OMIT, @@ -408,7 +393,7 @@ def update_app( request_options: typing.Optional[RequestOptions] = None, ) -> UpdateAppOutput: """ - Update an app for a user or organization. + Update an app for a user. Args: app_id (str): The ID of the app. @@ -587,8 +572,6 @@ def create_app_and_variant_from_template( template_id: str, env_vars: typing.Dict[str, str], project_id: typing.Optional[str] = OMIT, - workspace_id: typing.Optional[str] = OMIT, - organization_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> AppVariantResponse: """ @@ -614,10 +597,6 @@ def create_app_and_variant_from_template( project_id : typing.Optional[str] - workspace_id : typing.Optional[str] - - organization_id : typing.Optional[str] - request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -647,9 +626,7 @@ def create_app_and_variant_from_template( "app_name": app_name, "template_id": template_id, "project_id": project_id, - "workspace_id": workspace_id, "env_vars": env_vars, - "organization_id": organization_id, }, request_options=request_options, omit=OMIT, @@ -980,19 +957,17 @@ async def list_apps( self, *, app_name: typing.Optional[str] = None, - workspace_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> typing.List[App]: """ - Retrieve a list of apps filtered by app_name and org_id. + Retrieve a list of apps filtered by app_name. Args: app_name (Optional[str]): The name of the app to filter by. - org_id (Optional[str]): The ID of the organization to filter by. stoken_session (SessionContainer): The session container. Returns: - List[App]: A list of apps filtered by app_name and org_id. + List[App]: A list of apps filtered by app_name. Raises: HTTPException: If there was an error retrieving the list of apps. @@ -1001,8 +976,6 @@ async def list_apps( ---------- app_name : typing.Optional[str] - workspace_id : typing.Optional[str] - request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -1032,10 +1005,7 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "apps", method="GET", - params={ - "app_name": app_name, - "workspace_id": workspace_id, - }, + params={"app_name": app_name}, request_options=request_options, ) try: @@ -1067,15 +1037,13 @@ async def create_app( *, app_name: str, project_id: typing.Optional[str] = OMIT, - workspace_id: typing.Optional[str] = OMIT, - organization_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> CreateAppOutput: """ - Create a new app for a user or organization. + Create a new app for a user. Args: - payload (CreateApp): The payload containing the app name and organization ID (optional). + payload (CreateApp): The payload containing the app name. stoken_session (SessionContainer): The session container containing the user's session token. Returns: @@ -1090,10 +1058,6 @@ async def create_app( project_id : typing.Optional[str] - workspace_id : typing.Optional[str] - - organization_id : typing.Optional[str] - request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -1128,8 +1092,6 @@ async def main() -> None: json={ "app_name": app_name, "project_id": project_id, - "workspace_id": workspace_id, - "organization_id": organization_id, }, request_options=request_options, omit=OMIT, @@ -1236,7 +1198,7 @@ async def update_app( request_options: typing.Optional[RequestOptions] = None, ) -> UpdateAppOutput: """ - Update an app for a user or organization. + Update an app for a user. Args: app_id (str): The ID of the app. @@ -1431,8 +1393,6 @@ async def create_app_and_variant_from_template( template_id: str, env_vars: typing.Dict[str, str], project_id: typing.Optional[str] = OMIT, - workspace_id: typing.Optional[str] = OMIT, - organization_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> AppVariantResponse: """ @@ -1458,10 +1418,6 @@ async def create_app_and_variant_from_template( project_id : typing.Optional[str] - workspace_id : typing.Optional[str] - - organization_id : typing.Optional[str] - request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -1499,9 +1455,7 @@ async def main() -> None: "app_name": app_name, "template_id": template_id, "project_id": project_id, - "workspace_id": workspace_id, "env_vars": env_vars, - "organization_id": organization_id, }, request_options=request_options, omit=OMIT, diff --git a/agenta-web/src/contexts/app.context.tsx b/agenta-web/src/contexts/app.context.tsx index 625f435e59..548aa34f39 100644 --- a/agenta-web/src/contexts/app.context.tsx +++ b/agenta-web/src/contexts/app.context.tsx @@ -48,9 +48,7 @@ const useApps = () => { const {data, error, isLoading, mutate} = useSWR( !!user ? `${getAgentaApiUrl()}/api/apps?` + - (!isMockProjectId ? `project_id=${projectId}&` : "") + - (isDemo() ? `workspace_id=${selectedOrg?.default_workspace.id}&` : "") + - (isDemo() ? `org_id=${selectedOrg?.id}&` : "") + (!isMockProjectId ? `project_id=${projectId}&` : "") : null, !!user ? (isDemo() ? (selectedOrg?.id ? axiosFetcher : () => {}) : axiosFetcher) : null, {