Merge lp:~widelands-dev/widelands-website/wiki_no_delete into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 478
Proposed branch: lp:~widelands-dev/widelands-website/wiki_no_delete
Merge into: lp:widelands-website
Diff against target: 94 lines (+28/-4)
4 files modified
mainpage/admin.py (+12/-0)
wiki/admin.py (+2/-0)
wiki/models.py (+1/-0)
wiki/views.py (+13/-4)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/wiki_no_delete
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+334639@code.launchpad.net

Description of the change

Prevent deleting of wiki articles over the admin page by:

1. Disable the 'Action' selection box in https://wl.widelands.org/admin/wiki/article/
2. Remove permission 'delete' for model Article. This removes the 'Delete' button from the admin page detail view of an article. This change do not apply to users who already had the permission (the permission get not removed from the django model user_user_permission). To remove the permission from users who have this permission formerly, i have added the Django permission model to the admins interface. Deleting the permission over the admin will make sure Djangos orm is used.

Additionally:
1. Serve a HTTP404 if an article isn't found in backlinks view to prevent server errors
2. Reworked the logic of backlinks, because it didn't worked correct under some circumstances, e.g. if a copied url from browsers addressbar contain percent encoding and is pasted into the article. E.g. [[ Go back to main page | Main%20Page ]]

To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM - we can always do the more fancy stuff later

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Yes :-)

merged and deployed

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'mainpage/admin.py'
--- mainpage/admin.py 1970-01-01 00:00:00 +0000
+++ mainpage/admin.py 2017-12-03 12:34:33 +0000
@@ -0,0 +1,12 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""Get acces to additional models which are not set by Django by default.
5
6So Djangos orm is used when changing things, e.g. delete a permission.
7
8"""
9
10from django.contrib import admin
11from django.contrib.auth.models import Permission
12admin.site.register(Permission)
013
=== modified file 'wiki/admin.py'
--- wiki/admin.py 2016-12-19 07:33:38 +0000
+++ wiki/admin.py 2017-12-03 12:34:33 +0000
@@ -14,6 +14,8 @@
1414
1515
16class ArticleAdmin(admin.ModelAdmin):16class ArticleAdmin(admin.ModelAdmin):
17 # Do not show 'Action' to prevent deleting:
18 actions = None
17 search_fields = ['title']19 search_fields = ['title']
18 list_display = ('title', 'creator', 'last_update',)20 list_display = ('title', 'creator', 'last_update',)
19 list_filter = ('title',)21 list_filter = ('title',)
2022
=== modified file 'wiki/models.py'
--- wiki/models.py 2017-09-12 18:04:34 +0000
+++ wiki/models.py 2017-12-03 12:34:33 +0000
@@ -70,6 +70,7 @@
70 verbose_name = _(u'Article')70 verbose_name = _(u'Article')
71 verbose_name_plural = _(u'Articles')71 verbose_name_plural = _(u'Articles')
72 app_label = 'wiki'72 app_label = 'wiki'
73 default_permissions = ('change', 'add',)
7374
74 def get_absolute_url(self):75 def get_absolute_url(self):
75 if self.group is None:76 if self.group is None:
7677
=== modified file 'wiki/views.py'
--- wiki/views.py 2017-02-24 19:15:17 +0000
+++ wiki/views.py 2017-12-03 12:34:33 +0000
@@ -21,6 +21,7 @@
2121
22from wl_utils import get_real_ip22from wl_utils import get_real_ip
23import re23import re
24import urllib
2425
25# Settings26# Settings
26# lock duration in minutes27# lock duration in minutes
@@ -632,14 +633,19 @@
632 """633 """
633634
634 # Find old title(s) of this article635 # Find old title(s) of this article
635 this_article = Article.objects.get(title=title)636 this_article = get_object_or_404(Article, title=title)
636 changesets = this_article.changeset_set.all()637 changesets = this_article.changeset_set.all()
637 old_titles = []638 old_titles = []
638 for cs in changesets:639 for cs in changesets:
639 if cs.old_title and cs.old_title != title and cs.old_title not in old_titles:640 if cs.old_title and cs.old_title != title and cs.old_title not in old_titles:
640 old_titles.append(cs.old_title)641 old_titles.append(cs.old_title)
641642
642 search_title = [re.compile(r"\[\[\s*%s\s*\]\]" % title)]643 # Search for semantic wiki links. The regexpr was copied from there
644 # and slightly modified
645 search_title = [re.compile(r"\[\[\s*(%s)/?\s*(\|\s*.+?\s*)?\]\]" % title)]
646
647 # Search for links in MarkDown syntax, like [Foo](wiki/FooBar)
648 # The regexpr matches the title between '/' and ')'
643 search_title.append(re.compile(r"\/%s\)" % title))649 search_title.append(re.compile(r"\/%s\)" % title))
644650
645 # Search for current and previous titles651 # Search for current and previous titles
@@ -648,13 +654,16 @@
648 articles_all = Article.objects.all().exclude(title=title)654 articles_all = Article.objects.all().exclude(title=title)
649 for article in articles_all:655 for article in articles_all:
650 for regexp in search_title:656 for regexp in search_title:
651 match = regexp.search(article.content)657 # Need to unqoute the content to match
658 # e.g. [[ Back | Title%20of%20Page ]]
659 match = regexp.search(urllib.unquote(article.content))
652 if match:660 if match:
653 found_links.append({'title': article.title})661 found_links.append({'title': article.title})
654662
655 for old_title in old_titles:663 for old_title in old_titles:
656 if old_title in article.content:664 if old_title in article.content:
657 found_old_links.append({'old_title': old_title, 'title': article.title })665 found_old_links.append(
666 {'old_title': old_title, 'title': article.title })
658667
659 context = {'found_links': found_links,668 context = {'found_links': found_links,
660 'found_old_links': found_old_links,669 'found_old_links': found_old_links,

Subscribers

People subscribed via source and target branches