def before_new_version(self, page): user = web.ctx.site.get_user() account = user and user.get_account() if account and account.is_blocked(): raise ValidationException( 'Your account has been suspended. You are not allowed to make any edits.' ) if page.key.startswith('/a/') or page.key.startswith('/authors/'): if page.type.key == '/type/author': return books = web.ctx.site.things({ 'type': '/type/edition', 'authors': page.key }) books = books or web.ctx.site.things({ 'type': '/type/work', 'authors': { 'author': { 'key': page.key } } }) if page.type.key == '/type/delete' and books: raise ValidationException( 'This Author page cannot be deleted as %d record(s) still reference this id. Please remove or reassign before trying again. Referenced by: %s' % (len(books), books)) elif page.type.key != '/type/author' and books: raise ValidationException( 'Changing type of author pages is not allowed.')
def before_new_version(self, page): user = web.ctx.site.get_user() account = user and user.get_account() if account and account.is_blocked(): raise ValidationException( "Your account has been suspended. You are not allowed to make any edits." ) if page.type.key == '/type/library': bad = list(page.find_bad_ip_ranges(page.ip_ranges or "")) if bad: raise ValidationException('Bad IPs: ' + '; '.join(bad)) if page.key.startswith('/a/') or page.key.startswith('/authors/'): if page.type.key == '/type/author': return books = web.ctx.site.things({ "type": "/type/edition", "authors": page.key }) books = books or web.ctx.site.things({ "type": "/type/work", "authors": { "author": { "key": page.key } } }) if page.type.key == '/type/delete' and books: raise ValidationException( "Deleting author pages is not allowed.") elif page.type.key != '/type/author' and books: raise ValidationException( "Changing type of author pages is not allowed.")
def before_new_version(self, page): if page.type.key == '/type/library': bad = list(page.find_bad_ip_ranges(page.ip_ranges or "")) if bad: raise ValidationException('Bad IPs: ' + '; '.join(bad)) if page.key.startswith('/a/') or page.key.startswith('/authors/'): if page.type.key == '/type/author': return books = web.ctx.site.things({ "type": "/type/edition", "authors": page.key }) books = books or web.ctx.site.things({ "type": "/type/work", "authors": { "author": { "key": page.key } } }) if page.type.key == '/type/delete' and books: raise ValidationException( "Deleting author pages is not allowed.") elif page.type.key != '/type/author' and books: raise ValidationException( "Changing type of author pages is not allowed.")
def _prevent_ocaid_deletion(self, edition): # Allow admins to modify ocaid user = accounts.get_current_user() if user and (user.is_admin() or user.is_librarian()): return # read ocaid from form data try: ocaid = [ id['value'] for id in edition.get('identifiers', []) if id['name'] == 'ocaid' ][0] except IndexError: ocaid = None # 'self.edition' is the edition doc from the db and 'edition' is the doc from formdata if (self.edition and self.edition.get('ocaid') and self.edition.get('ocaid') != ocaid): logger.warn( "Attempt to change ocaid of %s from %r to %r.", self.edition.key, self.edition.get('ocaid'), ocaid, ) raise ValidationException( "Changing Internet Archive ID is not allowed.")
def _compile_template(name, text): text = web.safestr(_stringify(text)) try: return web.template.Template(text, filter=web.websafe, filename=name) except (web.template.ParseError, SyntaxError) as e: print('Template parsing failed for ', name, file=web.debug) import traceback traceback.print_exc() raise ValidationException("Template parsing failed: " + str(e))
def before_new_version(self, page): user = web.ctx.site.get_user() account = user and user.get_account() if account and account.is_blocked(): raise ValidationException("Your account has been suspended. You are not allowed to make any edits.") if page.type.key == '/type/library': bad = list(page.find_bad_ip_ranges(page.ip_ranges or "")) if bad: raise ValidationException('Bad IPs: ' + '; '.join(bad)) if page.key.startswith('/a/') or page.key.startswith('/authors/'): if page.type.key == '/type/author': return books = web.ctx.site.things({"type": "/type/edition", "authors": page.key}) books = books or web.ctx.site.things({"type": "/type/work", "authors": {"author": {"key": page.key}}}) if page.type.key == '/type/delete' and books: raise ValidationException("This Author page cannot be deleted as %d record(s) still reference this id. Please remove or reassign before trying again. Referenced by: %s" % (len(books), books)) elif page.type.key != '/type/author' and books: raise ValidationException("Changing type of author pages is not allowed.")