def clean(self) -> Dict: """Verify email values.""" form_data = super().clean() self.store_fields_in_dict([ ('subject', None), ('cc_email', ' '.join([ email.strip() for email in form_data['cc_email'].split() if email ])), ('bcc_email', ' '.join([ email.strip() for email in form_data['bcc_email'].split() if email ])) ]) incorrect_email = get_incorrect_email(form_data['cc_email'].split()) if incorrect_email: self.add_error( 'cc_email', _('Incorrect email value "{0}".').format(incorrect_email)) incorrect_email = get_incorrect_email(form_data['bcc_email'].split()) if incorrect_email: self.add_error( 'bcc_email', _('Incorrect email value "{0}".').format(incorrect_email)) return form_data
def clean(self) -> Dict: """Verify email values.""" form_data = super().clean() # Move data to the payload so that is ready to be used self.store_fields_in_dict([('send_confirmation', None), ('track_read', None)]) # Check if the values in the item_column are correct emails pcolumn = form_data['item_column'] try: column_data = sql.get_rows( self.action.workflow.get_data_frame_table_name(), column_names=[pcolumn.name]) incorrect_email = get_incorrect_email( [iname[0] for iname in column_data]) if incorrect_email: # column has incorrect email addresses self.add_error( 'item_column', _('Incorrect email address "{0}".').format( incorrect_email)) except TypeError: self.add_error( 'item_column', _('The column with email addresses has incorrect values.')) return form_data
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 _check_email_list(email_list_string: str) -> List[str]: """Verify that a space separated list of emails are correct. :param email_list_string: Space separated list of emails :return: List of verified email strings """ if email_list_string is None: return [] email_list = email_list_string.split() incorrect_email = get_incorrect_email(email_list) if incorrect_email: raise Exception( _('Invalid email address "{0}".').format(incorrect_email)) return email_list
def extra_validation(self, validated_data: Dict): """Validate the presence of certain fields.""" super().extra_validation(validated_data) action = validated_data['action'] payload = validated_data['payload'] item_column_name = payload.get('item_column') if not item_column_name: raise APIException( _('Personalized text need a column name in payload ' 'field item_column.')) item_column = action.workflow.columns.filter( name=item_column_name).first() if not item_column: raise APIException( _('Incorrect column name in field item_column.')) if action.action_type != models.Action.PERSONALIZED_TEXT: raise APIException(_('Incorrect type of action to schedule.')) subject = payload.get('subject') if not subject: raise APIException(_('Personalized text needs a subject.')) # Check if the values in the email column are correct emails try: column_data = sql.get_rows( action.workflow.get_data_frame_table_name(), column_names=[item_column.name]) incorrect_email = get_incorrect_email( [row[item_column.name] for row in column_data]) if incorrect_email: # column has incorrect email addresses raise APIException( _('Incorrect email value "{0}".').format(incorrect_email)) except TypeError: raise APIException( _('The column with email addresses has incorrect values.')) payload['item_column'] = item_column.id try: incorrect_email = get_incorrect_email([ email for email in payload.get('cc_email', '').split() if email ]) if incorrect_email: raise APIException( _('Incorrect email value "{0}".').format(incorrect_email)) except Exception: raise APIException( _('cc_email must be a space-separated list of emails.')) try: incorrect_email = get_incorrect_email([ email for email in payload.get('bcc_email', '').split() if email ]) if incorrect_email: raise APIException( _('Incorrect email value "{0}".').format(incorrect_email)) except Exception: raise APIException( _('bcc_email must be a space-separated list of emails.'))