Skip to content

Hotfix/is866 disable fake templates #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_application(config: dict):
setup_s3(app)
setup_storage(app)
setup_users(app)
setup_projects(app, enable_fake_data=True) # TODO: deactivate fakes i.e. debug=testing
setup_projects(app)
setup_studies_access(app)

if config['director']["enabled"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def setup(app: web.Application, *, enable_fake_data=False) -> bool:

:param app: main web application
:type app: web.Application
:param enable_fake_data: will inject some fake projects, defaults to False
:param enable_fake_data: if True it injects template projects under /data, defaults to False (USE ONLY FOR TESTING)
:param enable_fake_data: bool, optional
:return: False if subystem setup was skipped (e.g. explicitly disabled in config), otherwise True
:return: False if setup skips (e.g. explicitly disabled in config), otherwise True
:rtype: bool
"""
logger.debug("Setting up %s ...", __name__)
Expand Down Expand Up @@ -106,7 +106,6 @@ def setup(app: web.Application, *, enable_fake_data=False) -> bool:
app[APP_JSONSCHEMA_SPECS_KEY] = {CONFIG_SECTION_NAME: specs}

if enable_fake_data:
# TODO: inject data in database instead of keeping in memory!?
Fake.load_template_projects()

return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from aiohttp import web

from ..security_api import get_access_model, UserRole
from .projects_fakes import Fake


async def can_update_node_inputs(context):
Expand All @@ -20,11 +19,7 @@ async def can_update_node_inputs(context):
return False

# get current version
# TODO: unify call
if project_uuid in Fake.projects:
current_project = Fake.projects[project_uuid].data
else:
current_project = await db.get_user_project(user_id, project_uuid)
current_project = await db.get_user_project(user_id, project_uuid)

diffs = jsondiff.diff(current_project, updated_project)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .config import CONFIG_SECTION_NAME
from .projects_db import APP_PROJECT_DBAPI
from .projects_exceptions import ProjectNotFoundError
from .projects_fakes import Fake

BASE_UUID = uuidlib.UUID("71e0eb5e-0797-4469-89ba-00a0df4d338a")
TEMPLATE_PREFIX = "template-uuid"
Expand All @@ -44,9 +43,6 @@ def validate_project(app: web.Application, project: Dict):
async def get_project_for_user(request: web.Request, project_uuid, user_id) -> Dict:
await check_permission(request, "project.read")

if project_uuid in Fake.projects:
return Fake.projects[project_uuid].data

try:
db = request.config_dict[APP_PROJECT_DBAPI]
project = await db.get_user_project(user_id, project_uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .projects_exceptions import (ProjectInvalidRightsError,
ProjectNotFoundError)
from .projects_models import ProjectType, projects, user_to_projects
from .projects_fakes import Fake

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -189,7 +190,8 @@ async def load_user_projects(self, user_id: str) -> List[Dict]:

async def load_template_projects(self) -> List[Dict]:
log.info("Loading template projects")
projects_list = []
projects_list = [prj.data for prj in Fake.projects.values() if prj.template]

async with self.engine.acquire() as conn:
query = select([projects]).\
where(projects.c.type == ProjectType.TEMPLATE)
Expand All @@ -201,6 +203,10 @@ async def load_template_projects(self) -> List[Dict]:
return projects_list

async def get_template_project(self, project_uuid: str) -> Dict:
prj = Fake.projects.get(project_uuid)
if prj and prj.template:
return prj.data

template_prj = None
async with self.engine.acquire() as conn:
query = select([projects]).where(
Expand All @@ -219,6 +225,10 @@ async def get_user_project(self, user_id: str, project_uuid: str) -> Dict:
:return: schema-compliant project
:rtype: Dict
"""
prj = Fake.projects.get(project_uuid)
if prj and not prj.template:
return Fake.projects[project_uuid].data

log.info("Getting project %s for user %s", project_uuid, user_id)
async with self.engine.acquire() as conn:
joint_table = user_to_projects.join(projects)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .projects_db import APP_PROJECT_DBAPI
from .projects_exceptions import (ProjectInvalidRightsError,
ProjectNotFoundError)
from .projects_fakes import Fake

log = logging.getLogger(__name__)

Expand All @@ -30,12 +29,6 @@ async def create_projects(request: web.Request):
if template_uuid:
# create from template
template_prj = await db.get_template_project(template_uuid)

if not template_prj: # TODO: inject these projects in db instead!
for prj in Fake.projects.values():
if prj.template and prj.data['uuid']==template_uuid:
template_prj = prj.data
break
if not template_prj:
raise web.HTTPNotFound(reason="Invalid template uuid {}".format(template_uuid))

Expand Down Expand Up @@ -83,7 +76,6 @@ async def list_projects(request: web.Request):

projects_list = []
if ptype in ("template", "all"):
projects_list += [prj.data for prj in Fake.projects.values() if prj.template]
projects_list += await db.load_template_projects()

if ptype in ("user", "all"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ def load_isan_template_uuids():
async def get_template_project(app: web.Application, project_uuid: str):
# TODO: remove projects_ prefix from name
from .projects.projects_db import APP_PROJECT_DBAPI
from .projects.projects_fakes import Fake

db = app[APP_PROJECT_DBAPI]

# TODO: user search queries in DB instead
# BUG: ensure items in project_list have unique UUIDs
projects_list = [prj.data for prj in Fake.projects.values() if prj.template]
projects_list += await db.load_template_projects()
projects_list = await db.load_template_projects()

for prj in projects_list:
if prj.get('uuid') == project_uuid:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from simcore_service_webserver.db import setup_db
from simcore_service_webserver.login import setup_login
from simcore_service_webserver.projects import setup_projects
from simcore_service_webserver.projects.projects_handlers import Fake
from simcore_service_webserver.projects.projects_fakes import Fake
from simcore_service_webserver.rest import setup_rest
from simcore_service_webserver.security import setup_security
from simcore_service_webserver.security_roles import UserRole
Expand Down