def update_luser_email_column( user, pk: int, workflow: models.Workflow, column: models.Column, ): """Update the field luser_email in the workflow. :param user: User making the request :param pk: Column ID to obtain the user id :param workflow: Workflow being manipulated. :param column: Column being used to update the luser field. :return: """ if not pk: # Empty pk, means reset the field. workflow.luser_email_column = None workflow.luser_email_column_md5 = '' workflow.lusers.set([]) workflow.save( update_fields=['luser_email_column', 'luser_email_column_md5']) return table_name = workflow.get_data_frame_table_name() # Get the column content emails = sql.get_rows(table_name, column_names=[column.name]) # Verify that the column as a valid set of emails incorrect_email = get_incorrect_email([row[column.name] for row in emails]) if incorrect_email: raise services.OnTaskWorkflowEmailError(message=_( 'Incorrect email addresses "{0}".').format(incorrect_email)) # Update the column workflow.luser_email_column = column workflow.save(update_fields=['luser_email_column']) # Calculate the MD5 value md5_hash = sql.get_text_column_hash(table_name, column.name) if workflow.luser_email_column_md5 == md5_hash: return # Change detected, run the update in batch mode workflow.luser_email_column_md5 = md5_hash workflow.save(update_fields=['luser_email_column_md5']) # Log the event with the status "preparing updating" log_item = workflow.log(user, models.Log.WORKFLOW_UPDATE_LUSERS) # Push the update of lusers to batch processing tasks.execute_operation.delay( operation_type=models.Log.WORKFLOW_UPDATE_LUSERS, user_id=user.id, workflow_id=workflow.id, log_id=log_item.id)
def _do_clone_workflow(workflow: Workflow) -> Workflow: """Clone the workflow. :param workflow: source workflow :return: Clone object """ new_workflow = Workflow( user=workflow.user, name=create_new_name( workflow.name, Workflow.objects.filter( Q(user=workflow.user) | Q(shared=workflow.user)), ), description_text=workflow.description_text, nrows=workflow.nrows, ncols=workflow.ncols, attributes=copy.deepcopy(workflow.attributes), query_builder_ops=copy.deepcopy(workflow.query_builder_ops), luser_email_column_md5=workflow.luser_email_column_md5, lusers_is_outdated=workflow.lusers_is_outdated) new_workflow.save() try: new_workflow.shared.set(list(workflow.shared.all())) new_workflow.lusers.set(list(workflow.lusers.all())) # Clone the columns for item_obj in workflow.columns.all(): do_clone_column_only(item_obj, new_workflow=new_workflow) # Update the luser_email_column if needed: if workflow.luser_email_column: new_workflow.luser_email_column = new_workflow.columns.get( name=workflow.luser_email_column.name, ) # Clone the DB table clone_table(workflow.get_data_frame_table_name(), new_workflow.get_data_frame_table_name()) # Clone actions for item_obj in workflow.actions.all(): do_clone_action(item_obj, new_workflow) for item_obj in workflow.views.all(): do_clone_view(item_obj, new_workflow) # Done! new_workflow.save() except Exception as exc: new_workflow.delete() raise exc return new_workflow