def __init__(self, context): self._catalog = api.get_tool("portal_catalog") self._bika_catalog = api.get_tool("bika_catalog") self._bika_analysis_catalog = api.get_tool("bika_analysis_catalog") self._bika_setup_catalog = api.get_tool("bika_setup_catalog") self._catalogs = { "portal_catalog": self._catalog, "bika_catalog": self._bika_catalog, "bika_analysis_catalog": self._bika_analysis_catalog, "bika_setup_catalog": self._bika_setup_catalog, }
def login(context, request): """ Login Route Login route to authenticate a user against Plone. """ # extract the data __ac_name = request.get("__ac_name", None) __ac_password = request.get("__ac_password", None) logger.info("*** LOGIN %s ***" % __ac_name) if __ac_name is None: api.fail(400, "__ac_name is missing") if __ac_password is None: api.fail(400, "__ac_password is missing") acl_users = api.get_tool("acl_users") # XXX hard coded acl_users.credentials_cookie_auth.login() # XXX amin user won't be logged in if I use this approach # acl_users.login() # response = request.response # acl_users.updateCredentials(request, response, __ac_name, __ac_password) if api.is_anonymous(): api.fail(401, "Invalid Credentials") # return the JSON in the same format like the user route return get(context, request, username=__ac_name)
def logout(context, request): """ Logout Route """ logger.info("*** LOGOUT ***") acl_users = api.get_tool("acl_users") acl_users.logout(request) return {"url": api.url_for("bika.lims.jsonapi.v2.users"), "success": True}
def logout(context, request): """ Logout Route """ logger.info("*** LOGOUT ***") acl_users = api.get_tool("acl_users") acl_users.logout(request) return { "url": api.url_for("bika.lims.jsonapi.v2.users"), "success": True }
def update_sample(content, record): """ Custom code for updating a sample because of special requirements for storage location and sample type. :param content: The sample object that has to be modified :param record: This object has a dictionary, items, that has the values that are to be changed. :return: The updated sample object """ # set and unset the storage locations for k, v in record.items(): if k == 'StorageLocation': storage_location_results = search(portal_type='StoragePosition', Title=v) if not storage_location_results: storage_location_results = search( portal_type='StoragePosition', uid=v) storage_location = storage_location_results and get_object( storage_location_results[0]) or None wf_tool = get_tool("portal_workflow") location_status = wf_tool.getStatusOf( 'bika_storageposition_workflow', storage_location) if location_status and location_status.get("review_state", None) == "available": current_location = content.getStorageLocation() if current_location: doActionFor(current_location, 'liberate') # assign the sample to the storage location content.setStorageLocation(storage_location) sample_status = wf_tool.getStatusOf('bika_sample_workflow', content) if sample_status and sample_status.get( "review_state", None) == "sample_received": doActionFor(storage_location, 'occupy') else: doActionFor(storage_location, 'reserve') if k == 'SampleType': sample_type_results = search(portal_type="SampleType", title=v) if not sample_type_results: sample_type_results = search(portal_type="SampleType", uid=v) sample_type = sample_type_results and get_object( sample_type_results[0]) or None if isinstance(sample_type, tuple): sample_type = sample_type[0] content.setSampleType(sample_type) return content