def get_user_info(user): """Get the user information """ user = api.get_user(user) current = api.get_current_user() if api.is_anonymous(): return { "username": current.getUserName(), "authenticated": False, "roles": current.getRoles(), "api_url": api.url_for("plone.jsonapi.routes.users", username="******"), } # nothing to do if user is None: logger.warn("No user found for {}".format(user)) return None # plone user pu = user.getUser() info = { "username": user.getUserName(), "roles": user.getRoles(), "groups": pu.getGroups(), "authenticated": current == user, "api_url": api.url_for("bika.lims.jsonapi.v2.users", username=user.getId()), } for k, v in api.get_user_properties(user).items(): if api.is_date(v): v = api.to_iso_date(v) if not api.is_json_serializable(v): logger.warn( "User property '{}' is not JSON serializable".format(k)) continue info[k] = v return info
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 get_user_info(user): """Get the user information """ user = api.get_user(user) current = api.get_current_user() if api.is_anonymous(): return { "username": current.getUserName(), "authenticated": False, "roles": current.getRoles(), "api_url": api.url_for("plone.jsonapi.routes.users", username="******"), } # nothing to do if user is None: logger.warn("No user found for {}".format(user)) return None # plone user pu = user.getUser() info = { "username": user.getUserName(), "roles": user.getRoles(), "groups": pu.getGroups(), "authenticated": current == user, "api_url": api.url_for("bika.lims.jsonapi.v2.users", username=user.getId()), } for k, v in api.get_user_properties(user).items(): if api.is_date(v): v = api.to_iso_date(v) if not api.is_json_serializable(v): logger.warn("User property '{}' is not JSON serializable".format(k)) continue info[k] = v return info
def action(context, request, action=None, resource=None, uid=None): """Various HTTP POST actions """ # Fetch and call the action function of the API func_name = "{}_items".format(action) action_func = getattr(api, func_name, None) if action_func is None: api.fail(500, "API has no member named '{}'".format(func_name)) portal_type = api.resource_to_portal_type(resource) items = action_func(portal_type=portal_type, uid=uid) return { "count": len(items), "items": items, "url": api.url_for("bika.lims.jsonapi.v2.action", action=action), }
def action(context, request, action=None, resource=None, uid=None): """Various HTTP POST actions Case 1: /<uid> -> Return the full object immediately in the root of the JSON API response <Bika-Site>/@@API/v2/<uid> Case 2: /<action>/<uid> -> The actions (update, delete) will performed on the object identified by <uid> -> The actions (create) will use the <uid> as the parent folder <Bika-Site>/@@API/v2/<action>/<uid> Case 3: <resource>/<action> -> The "target" object will be located by a location given in the request body (uid, path, parent_path + id) -> The actions (cut, copy, update, delete) will performed on the target object -> The actions (create) will use the target object as the container <Bika-Site>/@@API/v2/<resource>/<action> Case 4: <resource>/<action>/<uid> -> The actions (cut, copy, update, delete) will performed on the object identified by <uid> -> The actions (create) will use the <uid> as the parent folder <Bika-Site>/@@API/v2/<resource>/<action> """ # Fetch and call the action function of the API func_name = "{}_items".format(action) action_func = getattr(api, func_name, None) if action_func is None: api.fail(500, "API has no member named '{}'".format(func_name)) portal_type = api.resource_to_portal_type(resource) items = action_func(portal_type=portal_type, uid=uid) return { "count": len(items), "items": items, "url": api.url_for("bika.lims.jsonapi.v2.action", action=action), }