def _signup_create_user(self, values): """ create a new user from the template user """ get_param = self.env['ir.config_parameter'].sudo().get_param template_user_id = literal_eval( get_param('auth_signup.template_user_id', 'False')) template_user = self.browse(template_user_id) assert template_user.exists(), 'Signup: invalid template user' # check that uninvited users may sign up if 'partner_id' not in values: if not literal_eval( get_param('auth_signup.allow_uninvited', 'False')): raise SignupError( _('Signup is not allowed for uninvited users')) assert values.get('login'), "Signup: no login given for new user" assert values.get('partner_id') or values.get( 'name'), "Signup: no name or partner given for new user" # create a copy of the template user (attached to a specific partner_id if given) values['active'] = True try: with self.env.cr.savepoint(): return template_user.with_context( no_reset_password=True).copy(values) except Exception as e: # copy may failed if asked login is not available. raise SignupError(ustr(e))
def _unsubscribe_check(self, text): url = "/groups/unsubscribe/{}/{}/{}".format(self.mailing_list.id, self.partner.id, self.token) r = self.url_open(url) body = ustr(r.content) # normalize space to make matching simpler self.assertIn(text, u' '.join(body.split()))
def get_preprocessor_error(self, stderr, source=None): """Improve and remove sensitive information from sass/less compilator error messages""" error = misc.ustr(stderr).split('Load paths')[0].replace( ' Use --trace for backtrace.', '') if 'Cannot load compass' in error: error += "Maybe you should install the compass gem using this extra argument:\n\n" \ " $ sudo gem install compass --pre\n" error += "This error occured while compiling the bundle '%s' containing:" % self.name for asset in self.stylesheets: if isinstance(asset, PreprocessedCSS): error += '\n - %s' % (asset.url if asset.url else '<inline sass>') return error
def simple_vat_check(self, country_code, vat_number): ''' Check the VAT number depending of the country. http://sima-pc.com/nif.php ''' if not ustr(country_code).encode('utf-8').isalpha(): return False check_func_name = 'check_vat_' + country_code check_func = getattr(self, check_func_name, None) or getattr(vatnumber, check_func_name, None) if not check_func: # No VAT validation available, default to check that the country code exists if country_code.upper() == 'EU': # Foreign companies that trade with non-enterprises in the EU # may have a VATIN starting with "EU" instead of a country code. return True country_code = _eu_country_vat_inverse.get(country_code, country_code) return bool(self.env['res.country'].search([('code', '=ilike', country_code)])) return check_func(vat_number)
def check_vat_mx(self, vat): ''' Mexican VAT verification Verificar RFC México ''' # we convert to 8-bit encoding, to help the regex parse only bytes vat = ustr(vat).encode('iso8859-1') m = self.__check_vat_mx_re.match(vat) if not m: #No valid format return False try: ano = int(m.group('ano')) if ano > 30: ano = 1900 + ano else: ano = 2000 + ano datetime.date(ano, int(m.group('mes')), int(m.group('dia'))) except ValueError: return False # Valid format and valid date return True
def compile_css(self, cmd, source): """Sanitizes @import rules, remove duplicates @import rules, then compile""" imports = [] def sanitize(matchobj): ref = matchobj.group(2) line = '@import "%s"%s' % (ref, matchobj.group(3)) if '.' not in ref and line not in imports and not ref.startswith( ('.', '/', '~')): imports.append(line) return line msg = "Local import '%s' is forbidden for security reasons." % ref _logger.warning(msg) self.css_errors.append(msg) return '' source = re.sub(self.rx_preprocess_imports, sanitize, source) try: compiler = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) except Exception: msg = "Could not execute command %r" % cmd[0] _logger.error(msg) self.css_errors.append(msg) return '' result = compiler.communicate(input=source.encode('utf-8')) if compiler.returncode: cmd_output = ''.join(misc.ustr(result)) if not cmd_output: cmd_output = "Process exited with return code %d\n" % compiler.returncode error = self.get_preprocessor_error(cmd_output, source=source) _logger.warning(error) self.css_errors.append(error) return '' compiled = result[0].strip().decode('utf8') return compiled