def test_admin_edits(self): settings.change({ 'open-editing': 'no', 'page-blacklist': '.*', 'parents-must-exist': 'yes' }) self.assertEquals(access.can_edit_page('foo/bar'), False) self.assertEquals(access.can_edit_page('foo/bar', is_admin=True), True)
def view_diff(r1, r2, user, is_admin): a = r1.revision_body if hasattr(r2, "revision_body"): b = r2.revision_body else: b = r2.body seqm = difflib.SequenceMatcher(None, a, b) output = [] for opcode, a0, a1, b0, b1 in seqm.get_opcodes(): if opcode == "equal": output.append(seqm.a[a0:a1]) elif opcode == "insert": output.append("<ins>" + seqm.b[b0:b1] + "</ins>") elif opcode == "delete": output.append("<del>" + seqm.a[a0:a1] + "</del>") elif opcode == "replace": output.append("<del>" + seqm.a[a0:a1] + "</del>") output.append("<ins>" + seqm.b[b0:b1] + "</ins>") else: raise RuntimeError, "unexpected opcode" data = { "r1": r1, "r2": r2, "r1updated": r1.updated if hasattr(r1, "updated") else r1.created, "r2updated": r2.updated if hasattr(r2, "updated") else r2.created, "page_title": r2.title, "diff_html": "".join(output), "user": user, "is_admin": is_admin, "can_edit": access.can_edit_page(r2.title, user, is_admin), } return render("diff.html", data)
def view_page(page, user=None, is_admin=False, revision=None): page = page.get_redirected() if page.title.startswith("Label:") and not page.body: page.body = DEFAULT_LABEL_BODY % {"title": page.title, "label": page.title[6:]} data = { "page": page, "is_admin": is_admin, "is_plain": page.get_property("format") == "plain", "can_edit": access.can_edit_page(page.title, user, is_admin), "page_labels": page.get_property("labels", []), "revision": revision, } # logging.debug(data) if settings.get("enable-map"): if page.get_property("map_label"): data["map_url"] = "/w/pages/map?label=" + util.uurlencode(page.get_property("map_label")) elif data["can_edit"] or page.geopt: data["map_url"] = "/w/map?page=" + util.uurlencode(page.title) if revision: logging.debug(u'Viewing page "%s" (revision %s)' % (data["page"].title, revision)) else: logging.debug(u'Viewing page "%s"' % data["page"].title) return render("view_page.html", data)
def show_page_history(page, user=None, is_admin=False): return render('history.html', { 'page_title': page.title, 'page': page, 'revisions': page.get_history(), 'can_edit': access.can_edit_page(page.title, user, is_admin), })
def view_diff(r1, r2, user, is_admin): a = r1.revision_body if hasattr(r2, 'revision_body'): b = r2.revision_body else: b = r2.body seqm = difflib.SequenceMatcher(None, a, b) output = [] for opcode, a0, a1, b0, b1 in seqm.get_opcodes(): if opcode == 'equal': output.append(seqm.a[a0:a1]) elif opcode == 'insert': output.append("<ins>" + seqm.b[b0:b1] + "</ins>") elif opcode == 'delete': output.append("<del>" + seqm.a[a0:a1] + "</del>") elif opcode == 'replace': output.append("<del>" + seqm.a[a0:a1] + "</del>") output.append("<ins>" + seqm.b[b0:b1] + "</ins>") else: raise RuntimeError, "unexpected opcode" data = { "r1": r1, "r2": r2, "r1updated": r1.updated if hasattr(r1, 'updated') else r1.created, "r2updated": r2.updated if hasattr(r2, 'updated') else r2.created, "page_title": r2.title, "diff_html": ''.join(output), "user": user, "is_admin": is_admin, 'can_edit': access.can_edit_page(r2.title, user, is_admin), } return render("diff.html", data)
def view_page(page, user=None, is_admin=False, revision=None): page = page.get_redirected() if page.title.startswith("Label:") and not page.body: page.body = DEFAULT_LABEL_BODY % {"title": page.title, "label": page.title[6:]} data = { 'page': page, 'is_admin': is_admin, 'is_plain': page.get_property('format') == 'plain', 'can_edit': access.can_edit_page(page.title, user, is_admin), 'page_labels': page.get_property('labels', []), 'revision': revision, } # logging.debug(data) if settings.get('enable-map'): if page.get_property('map_label'): data['map_url'] = '/w/pages/map?label=' + util.uurlencode(page.get_property('map_label')) elif data['can_edit'] or page.geopt: data['map_url'] = '/w/map?page=' + util.uurlencode(page.title) if revision: logging.debug(u'Viewing page "%s" (revision %s)' % (data['page'].title, revision)) else: logging.debug(u'Viewing page "%s"' % data['page'].title) return render('view_page.html', data)
def show_page_history(page, user=None, is_admin=False): return render( "history.html", { "page_title": page.title, "page": page, "revisions": page.get_history(), "can_edit": access.can_edit_page(page.title, user, is_admin), }, )
def edit_page(self, title, body=None): page = model.WikiContent.get_by_title(title) if body: page.body = body user = users.get_current_user() is_admin = users.is_current_user_admin() if not access.can_edit_page(title, user, is_admin): raise Forbidden if not body and not page.is_saved(): page.load_template(user, is_admin) self.reply(view.edit_page(page), 'text/html')
def post(self): """Processes requests to move the pointer. Expects arguments 'page_name' and 'll'.""" page = model.WikiContent.get_by_title(self.request.get('page_name')) if page is None: raise NotFound('Page not found.') if access.can_edit_page(page.title, users.get_current_user(), users.is_current_user_admin()): geo = self.request.get('lat') + ',' + self.request.get('lng') page.set_property('geo', geo) page.put() response = [l.strip() for l in page.get_property('geo').split(',')] self.reply(simplejson.dumps(response), 'application/json')
def post(self): title = urllib.unquote(str(self.request.get('name'))).decode('utf-8') if self.request.get('Preview'): self.edit_page(title, self.request.get('body')) return user = users.get_current_user() if not access.can_edit_page(title, user, users.is_current_user_admin()): raise Forbidden page = model.WikiContent.get_by_title(title) page.update(body=self.request.get('body'), author=user, delete=self.request.get('delete')) self.redirect('/' + urllib.quote(page.title.encode('utf-8').replace(' ', '_'))) taskqueue.add(url="/w/cache/purge", params={})
def post(self): title = urllib.unquote(str(self.request.get('name'))).decode('utf-8') if self.request.get('Preview'): self.edit_page(title, self.request.get('body')) return user = users.get_current_user() if not access.can_edit_page(title, user, users.is_current_user_admin()): raise Forbidden page = model.WikiContent.get_by_title(title) new_content = self.request.get('body') page.update(body=new_content, author=user, delete=self.request.get('delete')) memcache_key = 'Page:' + title memcache.set(memcache_key, new_content) self.redirect('/' + urllib.quote(page.title.encode('utf-8').replace(' ', '_')))
def test_logged_in_page_editing(self): alice = users.User('*****@*****.**') settings.change({'open-editing': 'no'}) self.assertFalse(access.can_edit_page("some page", user=None)) self.assertFalse(access.can_edit_page("some page", user=alice)) settings.change({'open-editing': 'yes'}) self.assertTrue(access.can_edit_page("some page", user=None)) self.assertTrue(access.can_edit_page("some page", user=alice)) settings.change({'open-editing': 'login'}) self.assertFalse(access.can_edit_page("some page", user=None)) self.assertTrue(access.can_edit_page("some page", user=alice))
def view_page(page, user=None, is_admin=False): page = page.get_redirected() data = { 'page': page, 'is_admin': is_admin, 'is_plain': page.get_property('format') == 'plain', 'can_edit': access.can_edit_page(page.title, user, is_admin), 'page_labels': page.get_property('labels', []), } logging.debug(data) if settings.get('enable-map'): if page.get_property('map_label'): data['map_url'] = '/w/pages/map?label=' + util.uurlencode(page.get_property('map_label')) elif data['can_edit'] or page.geopt: data['map_url'] = '/w/map?page=' + util.uurlencode(page.title) logging.debug(u'Viewing page "%s"' % data['page'].title) return render('view_page.html', data)
def test_admin_edits(self): settings.change({'open-editing': 'no', 'page-blacklist': '.*', 'parents-must-exist': 'yes'}) self.assertEquals(access.can_edit_page('foo/bar'), False) self.assertEquals(access.can_edit_page('foo/bar', is_admin=True), True)
def test_open_editing(self): self.assertEquals(access.can_edit_page('foo'), False) settings.change({'open-editing': 'yes'}) self.assertEquals(access.can_edit_page('foo'), True) settings.change({'page-blacklist': '^foo'}) self.assertEquals(access.can_edit_page('foo'), False)
def test_edit_orphan_page(self): settings.change({'open-editing': 'yes'}) self.assertEquals(access.can_edit_page('foo/bar'), True) settings.change({'parents-must-exist': 'yes'}) self.assertEquals(access.can_edit_page('foo/bar'), False)
def test_editor_access(self): user = users.User('*****@*****.**') self.assertEquals(access.can_edit_page('foo'), False) self.assertEquals(access.can_edit_page('foo', user), False) settings.change({'editors': user.email()}) self.assertEquals(access.can_edit_page('foo', user), True)
def test_edit_locked_page(self): """Make sure that locked pages aren't editable.""" model.WikiContent(title='foo', body='locked: yes\n---\n# foo').put() settings.change({'open-editing': 'yes', 'open-reading': 'yes'}) self.assertEquals(access.can_edit_page('foo', is_admin=False), False)
def test_edit_system_pages(self): self.assertEquals(access.can_edit_page('gaewiki:settings', is_admin=True), True) self.assertEquals(access.can_edit_page('gaewiki:settings', is_admin=False), False)
def test_edit_system_pages(self): self.assertEquals( access.can_edit_page('gaewiki:settings', is_admin=True), True) self.assertEquals( access.can_edit_page('gaewiki:settings', is_admin=False), False)