Jump to content

How to UNassign user from a task?


Alex Sknarin

Recommended Posts

Hi,

You essentially have to delete the user assignment, here's a function below that removes all users given a specific task_id, it might not be exactly what you need since you might only want to remove a specific user but this should point you in the right direction.

 

# Assumes a session is already established

def unassing_users_from_task(task_id):

	# Queries users assigned to a task
    users_assigned_to_tasks = session.query(
      'select assignments.context_id from User '
      'where assignments any (context_id = "{0}")'.format(task_id)
    )

    for user in users_assigned_to_tasks:
      assignments = user['assignments']
      for assignment in assignments:
        if assignment['context_id'] == task_id:
          session.delete(assignment)
    
    # Remember to use session.commit() I would only do this if you had in fact removed an assignment.
    session.commit()

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...