Commit 583e8de6 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Remove only users having no VOSpace child nodes.

parent 0d7a917f
Loading
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -1336,6 +1336,25 @@ class DbConnector(object):
        try:
            conn = self.getConnection()
            cursor = conn.cursor(cursor_factory = RealDictCursor)
            username = self.getUserName(userId)
            userNodePath = "/" + username
            cursor.execute("""
                SELECT count(*) > 1 AS child_nodes
                FROM node 
                WHERE creator_id = %s
                AND path <@ text2ltree(id_from_vos_path(%s)::text);
                """,
                (userId, userNodePath,))
            result = cursor.fetchall()[0]["child_nodes"]
        except Exception:
            if not conn.closed:
                conn.rollback()
            raise
        else:
            if result:
                return False
            else:
                try:
                    cursor.execute("""
                        DELETE FROM users
                        WHERE user_id = %s;
+9 −2
Original line number Diff line number Diff line
@@ -108,7 +108,14 @@ class UserRPCServer(RedisRPCServer):
                             "errorMsg": errorMsg }
                return response
            else:
                if result:
                    response = { "responseType": "USER_DEL_DONE" }
                else:
                    errorMsg = "The user cannot be removed because its VOSpace node has child nodes."
                    self.logger.error(errorMsg)
                    response = { "responseType": "ERROR",
                                 "errorCode": 4,
                                 "errorMsg": errorMsg }
        elif requestBody["requestType"] == "USER_SEARCH":
            searchStr = requestBody["searchStr"]
            try:
@@ -127,7 +134,7 @@ class UserRPCServer(RedisRPCServer):
            errorMsg = "Unkown request type."
            self.logger.error(errorMsg)
            response = { "responseType": "ERROR",
                         "errorCode": 4,
                         "errorCode": 5,
                         "errorMsg": errorMsg }
        return response