def clean(self): """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 ])), ('export_wf', None) ]) all_correct = all( is_correct_email(email) for email in form_data['cc_email'].split()) if not all_correct: self.add_error( 'cc_email', _('Field needs a space-separated list of emails.'), ) all_correct = all( is_correct_email(email) for email in form_data['bcc_email'].split()) if not all_correct: self.add_error( 'bcc_email', _('Field needs a space-separated list of emails.'), ) return form_data
def clean(self): """Verify that the date is correct.""" form_data = super().clean() self.store_fields_in_dict([ ('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 ])) ]) if not all( is_correct_email(email) for email in form_data['cc_email'].split()): self.add_error( 'cc_email', _('This field must be a comma-separated list of emails.')) if not all( is_correct_email(email) for email in form_data['bcc_email'].split()): self.add_error( 'bcc_email', _('This field must be a comma-separated list of emails.')) return form_data
def clean(self): """Verify email values.""" form_data = super().clean() # Move data to the payload so that is ready to be used self.action_info['subject'] = form_data['subject'] self.action_info['item_column'] = form_data['email_column'] self.action_info['cc_email'] = [ email.strip() for email in form_data['cc_email'].split(',') if email ] self.action_info['bcc_email'] = [ email.strip() for email in form_data['bcc_email'].split(',') if email ] self.action_info['confirm_items'] = form_data['confirm_items'] self.action_info['send_confirmation'] = form_data['send_confirmation'] self.action_info['track_read'] = form_data['track_read'] self.action_info['export_wf'] = form_data['export_wf'] # Check if the values in the email column are correct emails try: column_data = get_rows( self.action.workflow.get_data_frame_table_name(), column_names=[self.action_info['item_column']]) if not all(is_correct_email(iname[0]) for iname in column_data): # column has incorrect email addresses self.add_error( 'email_column', _('The column with email addresses has incorrect values.'), ) except TypeError: self.add_error( 'email_column', _('The column with email addresses has incorrect values.'), ) all_correct = all( is_correct_email(email) for email in self.action_info['cc_email']) if not all_correct: self.add_error( 'cc_email', _('Field needs a comma-separated list of emails.'), ) all_correct = all( is_correct_email(email) for email in self.action_info['bcc_email']) if not all_correct: self.add_error( 'bcc_email', _('Field needs a comma-separated list of emails.'), ) return form_data
def extra_validation(self, validated_data): """Validate the presence of certain fields.""" act, execute, column, exclude, payload = super().extra_validation( validated_data) if act.action_type != 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.')) if not column: raise APIException(_('Personalized text needs an item_column')) # Check if the values in the email column are correct emails try: column_data = get_rows( act.workflow.get_data_frame_table_name(), column_names=[column.name]) if not all( is_correct_email(row[column.name]) for row in column_data ): # column has incorrect email addresses raise APIException( _('The column with email addresses has incorrect values.')) except TypeError: raise APIException( _('The column with email addresses has incorrect values.')) try: if not all( is_correct_email(email_val) for email_val in payload.get('cc_email', []) if email_val ): raise APIException( _('cc_email must be a comma-separated list of emails.')) except TypeError: raise APIException( _('cc_email must be a comma-separated list of emails.')) try: if not all( is_correct_email(email) for email in payload.get('bcc_email', []) if email ): raise APIException( _('bcc_email must be a comma-separated list of emails.')) except TypeError: raise APIException( _('bcc_email must be a comma-separated list of emails.')) return act, execute, column, exclude, payload
def scheduled_email_action_data_is_correct(action, cleaned_data): """Verify email action data. Verify the integrity of a ScheduledAction object with a Personalised_text type. The function returns a list of pairs (field name, message) with the errors, or [] if no error has been found. :param action: Action object to use for scheduling :param cleaned_data: :return: List of pairs (field name, error) or [] if correct """ pair_list = [] item_column = cleaned_data['item_column'] # Verify the correct time pair_list.extend(scheduled_action_data_is_correct(cleaned_data)) # Check if the values in the email column are correct emails try: column_data = get_rows(action.workflow.get_data_frame_table_name(), column_names=[item_column.name]) if not all(is_correct_email(row['email']) for row in column_data): # column has incorrect email addresses pair_list.append( ('item_column', _('The column with email addresses has incorrect values.')), ) except TypeError: pair_list.append( ('item_column', _('The column with email addresses has incorrect values.')), ) if not all( is_correct_email(email) for email in cleaned_data['cc_email'].split(',') if email): pair_list.append( ('cc_email', _('This field must be a comma-separated list of emails.')), ) if not all( is_correct_email(email) for email in cleaned_data['bcc_email'].split(',') if email): pair_list.append( ('bcc_email', _('This field must be a comma-separated list of emails.')), ) return pair_list
def clean(self): form_data = super().clean() self.store_fields_in_dict([('item_column', form_data['item_column'].name), ('confirm_items', None)]) item_column = self.cleaned_data['item_column'] # Check if the values in the email column are correct emails try: column_data = get_rows( self.action.workflow.get_data_frame_table_name(), column_names=[item_column.name]) if not all( is_correct_email(row[item_column.name]) for row in column_data): # column has incorrect email addresses self.add_error( 'item_column', _('The column with email addresses has incorrect values.')) except TypeError: self.add_error( 'item_column', _('The column with email addresses has incorrect values.')) if self.instance and not form_data['confirm_items']: self.instance.exclude_values = [] return form_data
def clean(self): """Verify email values.""" form_data = super().clean() # Move data to the payload so that is ready to be used self.store_fields_in_dict([('item_column', None), ('confirm_items', None), ('send_confirmation', None), ('track_read', None)]) # Check if the values in the email column are correct emails try: column_data = get_rows( self.action.workflow.get_data_frame_table_name(), column_names=[self._FormWithPayload__form_info['item_column']]) if not all(is_correct_email(iname[0]) for iname in column_data): # column has incorrect email addresses self.add_error( 'item_column', _('The column with email addresses has incorrect values.'), ) except TypeError: self.add_error( 'item_column', _('The column with email addresses has incorrect values.'), ) return form_data
def clean(self) -> Dict: """Verify recipient email value""" form_data = super().clean() self.store_field_in_dict('email_to') if not is_correct_email(form_data['email_to']): self.add_error('email_to', _('Field needs a valid email address.')) return form_data
def _check_cc_lists(cc_email_list: List[str], bcc_email_list: List[str]): """Verify that the cc lists are correct. :param cc_email_list: List of emails to use in CC :param bcc_email_list: List of emails to use in BCC :return: Nothing or exception """ # Set the cc_email_list and bcc_email_list to the right values if cc_email_list is None: cc_email_list = [] if bcc_email_list is None: bcc_email_list = [] # Check that cc and bcc contain list of valid email addresses if not all(is_correct_email(email) for email in cc_email_list): raise Exception(_('Invalid email address in cc email')) if not all(is_correct_email(email) for email in bcc_email_list): raise Exception(_('Invalid email address in bcc email'))
def clean(self): """Process errors and add them to the form.""" form_data = super().clean() self.store_field_in_dict('email_to') if not is_correct_email(form_data['email_to']): self.add_error('email_to', _('This field must be a valid email address.')) return form_data
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]) if not all( is_correct_email(row[item_column.name]) for row in column_data ): # column has incorrect email addresses raise APIException( _('The column with email addresses has incorrect values.')) except TypeError: raise APIException( _('The column with email addresses has incorrect values.')) payload['item_column'] = item_column.id try: if not all( is_correct_email(email) for email in payload.get('cc_email', '').split() if email ): raise APIException( _('cc_email must be a space-separated list of emails.')) except Exception: raise APIException( _('cc_email must be a space-separated list of emails.')) try: if not all( is_correct_email(email) for email in payload.get('bcc_email', '').split() if email ): raise APIException( _('bcc_email must be a space-separated list of emails.')) except Exception: raise APIException( _('bcc_email must be a space-separated list of emails.'))
def assign_luser_column( request: HttpRequest, pk: Optional[int] = None, workflow: Optional[Workflow] = None, column: Optional[Column] = None, ) -> JsonResponse: """Render the view to assign the luser column. AJAX view to assign the column with id PK to the field luser_email_column and calculate the hash :param request: HTTP request :param pk: Column id :return: JSON data """ if workflow.nrows == 0: messages.error( request, _('Workflow has no data. ' + 'Go to "Manage table data" to upload data.'), ) return JsonResponse({'html_redirect': reverse('action:index')}) if not pk: # Empty pk, means reset the field. workflow.luser_email_column = None workflow.luser_email_column_md5 = '' workflow.lusers.set([]) workflow.save() return JsonResponse({'html_redirect': ''}) table_name = workflow.get_data_frame_table_name() # Get the column content emails = get_rows(table_name, column_names=[column.name]) # Verify that the column as a valid set of emails if not all(is_correct_email(row[column.name]) for row in emails): messages.error( request, _('The selected column does not contain email addresses.'), ) return JsonResponse({'html_redirect': ''}) # Update the column workflow.luser_email_column = column workflow.save() # Calculate the MD5 value md5_hash = get_text_column_hash(table_name, column.name) if workflow.luser_email_column_md5 != md5_hash: # Change detected, run the update in batch mode workflow.luser_email_column_md5 = md5_hash # Log the event with the status "preparing updating" log_item = workflow.log(request.user, Log.WORKFLOW_UPDATE_LUSERS) # Push the update of lusers to batch processing workflow_update_lusers_task.delay(request.user.id, workflow.id, log_item.id) workflow.lusers_is_outdated = False workflow.save() messages.success( request, _('The list of workflow users will be updated shortly.'), ) return JsonResponse({'html_redirect': ''})