def worker_cleanup(self, user_id, worker_id):
     """
     Deletes the worker and all associated data from the database as well
     as the socket directory.
     """
     with self._engine.begin() as conn:
         socket_rows = conn.execute(cl_worker_socket.select().where(
             and_(
                 cl_worker_socket.c.user_id == user_id,
                 cl_worker_socket.c.worker_id == worker_id,
             ))).fetchall()
         for socket_row in socket_rows:
             self._cleanup_socket(socket_row.socket_id)
         conn.execute(cl_worker_socket.delete().where(
             and_(
                 cl_worker_socket.c.user_id == user_id,
                 cl_worker_socket.c.worker_id == worker_id,
             )))
         conn.execute(cl_worker_run.delete().where(
             and_(cl_worker_run.c.user_id == user_id,
                  cl_worker_run.c.worker_id == worker_id)))
         conn.execute(cl_worker_dependency.delete().where(
             and_(
                 cl_worker_dependency.c.user_id == user_id,
                 cl_worker_dependency.c.worker_id == worker_id,
             )))
         conn.execute(cl_worker.delete().where(
             and_(cl_worker.c.user_id == user_id,
                  cl_worker.c.worker_id == worker_id)))
 def worker_cleanup(self, user_id, worker_id):
     """
     Deletes the worker and all associated data from the database as well
     as the socket directory.
     """
     with self._engine.begin() as conn:
         socket_rows = conn.execute(
             cl_worker_socket.select()
                 .where(and_(cl_worker_socket.c.user_id == user_id,
                             cl_worker_socket.c.worker_id == worker_id))
         ).fetchall()
         for socket_row in socket_rows:
             self._cleanup_socket(socket_row.socket_id)
         conn.execute(cl_worker_socket.delete()
                      .where(and_(cl_worker_socket.c.user_id == user_id,
                                  cl_worker_socket.c.worker_id == worker_id)))   
         conn.execute(cl_worker_run.delete()
                      .where(and_(cl_worker_run.c.user_id == user_id,
                                  cl_worker_run.c.worker_id == worker_id)))      
         conn.execute(cl_worker_dependency.delete()
                      .where(and_(cl_worker_dependency.c.user_id == user_id,
                                  cl_worker_dependency.c.worker_id == worker_id)))      
         conn.execute(cl_worker.delete()
                      .where(and_(cl_worker.c.user_id == user_id,
                                  cl_worker.c.worker_id == worker_id)))
Exemple #3
0
 def has_reply_permission(self, user_id, worker_id, socket_id):
     """
     Checks whether the given user running a worker with the given ID can
     reply on the socket with the given ID. Used to prevent a user from
     impersonating a worker from another user and replying to its messages.
     """
     with self._engine.begin() as conn:
         row = conn.execute(cl_worker_socket.select().where(
             and_(cl_worker_socket.c.user_id == user_id,
                  cl_worker_socket.c.worker_id == worker_id,
                  cl_worker_socket.c.socket_id == socket_id))).fetchone()
         if row:
             return True
         return False
 def has_reply_permission(self, user_id, worker_id, socket_id):
     """
     Checks whether the given user running a worker with the given ID can
     reply on the socket with the given ID. Used to prevent a user from
     impersonating a worker from another user and replying to its messages.
     """
     with self._engine.begin() as conn:
         row = conn.execute(
             cl_worker_socket.select()
                 .where(and_(cl_worker_socket.c.user_id == user_id,
                             cl_worker_socket.c.worker_id == worker_id,
                             cl_worker_socket.c.socket_id == socket_id))
         ).fetchone()
         if row:
             return True
         return False