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

Proposed by kaputtnik
Status: Merged
Merged at revision: 502
Proposed branch: lp:~widelands-dev/widelands-website/cleanup_ip_address_field
Merge into: lp:widelands-website
Diff against target: 429 lines (+87/-47)
16 files modified
pybb/admin.py (+1/-1)
pybb/forms.py (+1/-2)
pybb/migrations/0003_remove_post_user_ip.py (+19/-0)
pybb/models.py (+0/-1)
pybb/views.py (+1/-2)
templates/wiki/edit.html (+0/-1)
templates/wiki/history.html (+0/-4)
wiki/admin.py (+2/-8)
wiki/forms.py (+2/-6)
wiki/migrations/0003_auto_20180918_0836.py (+27/-0)
wiki/models.py (+7/-10)
wiki/views.py (+3/-5)
wlimages/admin.py (+1/-1)
wlimages/migrations/0003_remove_image_editor_ip.py (+19/-0)
wlimages/models.py (+3/-4)
wlimages/views.py (+1/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/cleanup_ip_address_field
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+356061@code.launchpad.net

Commit message

Remove the use of an IPAddressField from wiki, wlimages and pybb

Description of the change

As far i can see the IPAddressField was stored without a specific reason, except allowing to post anonymously, which we don't allow at all.

This branch removes that field from wiki, wlimages and pybb.

Removing this field from threadedcomments will be done in a different branch, because the changes are too big for this branch.

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

2 comments that might or might not need attention.

Revision history for this message
kaputtnik (franku) wrote :

Thanks for the review :-)

The classes are just used to show collapsed sections. They show up as "More options (Show)" like here: https://wl.widelands.org/admin/news/post/188/change/

Sorry for the remaining print statement. I'll remove it and merge this then.

505. By kaputtnik

removed superfluous print statement

Revision history for this message
kaputtnik (franku) wrote :

The changes are applied, but not committed yet. Will do it this evening...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pybb/admin.py'
2--- pybb/admin.py 2017-04-29 19:52:28 +0000
3+++ pybb/admin.py 2018-10-03 20:25:29 +0000
4@@ -84,7 +84,7 @@
5 ),
6 (_('Additional options'), {
7 'classes': ('collapse',),
8- 'fields': (('created', 'updated'), 'user_ip')
9+ 'fields': (('created', 'updated'),)
10 }
11 ),
12 (_('Message'), {
13
14=== modified file 'pybb/forms.py'
15--- pybb/forms.py 2018-04-07 09:48:02 +0000
16+++ pybb/forms.py 2018-10-03 20:25:29 +0000
17@@ -25,7 +25,6 @@
18 self.user = kwargs.pop('user', None)
19 self.topic = kwargs.pop('topic', None)
20 self.forum = kwargs.pop('forum', None)
21- self.ip = kwargs.pop('ip', None)
22 super(AddPostForm, self).__init__(*args, **kwargs)
23
24 if self.topic:
25@@ -54,7 +53,7 @@
26 topic_is_new = False
27 topic = self.topic
28
29- post = Post(topic=topic, user=self.user, user_ip=self.ip,
30+ post = Post(topic=topic, user=self.user,
31 markup=self.cleaned_data['markup'],
32 body=self.cleaned_data['body'])
33 post.save(*args, **kwargs)
34
35=== added file 'pybb/migrations/0003_remove_post_user_ip.py'
36--- pybb/migrations/0003_remove_post_user_ip.py 1970-01-01 00:00:00 +0000
37+++ pybb/migrations/0003_remove_post_user_ip.py 2018-10-03 20:25:29 +0000
38@@ -0,0 +1,19 @@
39+# -*- coding: utf-8 -*-
40+# Generated by Django 1.11.12 on 2018-10-02 19:31
41+from __future__ import unicode_literals
42+
43+from django.db import migrations
44+
45+
46+class Migration(migrations.Migration):
47+
48+ dependencies = [
49+ ('pybb', '0002_auto_20161001_2046'),
50+ ]
51+
52+ operations = [
53+ migrations.RemoveField(
54+ model_name='post',
55+ name='user_ip',
56+ ),
57+ ]
58
59=== modified file 'pybb/models.py'
60--- pybb/models.py 2018-04-08 14:40:17 +0000
61+++ pybb/models.py 2018-10-03 20:25:29 +0000
62@@ -203,7 +203,6 @@
63 body = models.TextField(_('Message'))
64 body_html = models.TextField(_('HTML version'))
65 body_text = models.TextField(_('Text version'))
66- user_ip = models.GenericIPAddressField(_('User IP'), default='')
67 hidden = models.BooleanField(_('Hidden'), blank=True, default=False)
68
69 class Meta:
70
71=== modified file 'pybb/views.py'
72--- pybb/views.py 2018-04-08 14:40:17 +0000
73+++ pybb/views.py 2018-10-03 20:25:29 +0000
74@@ -20,7 +20,6 @@
75 from pybb import settings as pybb_settings
76 from pybb.orm import load_related
77
78-from wl_utils import get_real_ip
79 from check_input.models import SuspiciousInput
80
81 try:
82@@ -154,7 +153,7 @@
83 quote = quote_text(post.body, post.user, 'markdown')
84
85 form = build_form(AddPostForm, request, topic=topic, forum=forum,
86- user=request.user, ip=get_real_ip(request),
87+ user=request.user,
88 initial={'markup': 'markdown', 'body': quote})
89
90 if form.is_valid():
91
92=== modified file 'templates/wiki/edit.html'
93--- templates/wiki/edit.html 2017-01-15 12:03:04 +0000
94+++ templates/wiki/edit.html 2018-10-03 20:25:29 +0000
95@@ -77,7 +77,6 @@
96 {{ form.content_type }}
97 {{ form.object_id }}
98 {{ form.action }}
99- {{ form.user_ip }}
100
101 <div>
102 <input id="id_preview" type="button" value="{% trans "Preview" %}" />
103
104=== modified file 'templates/wiki/history.html'
105--- templates/wiki/history.html 2016-04-26 16:10:04 +0000
106+++ templates/wiki/history.html 2018-10-03 20:25:29 +0000
107@@ -99,11 +99,7 @@
108 {{ change.modified|custom_date:user }}
109 </td>
110 <td>
111- {% if change.is_anonymous_change %}
112- {{ change.editor_ip }}
113- {% else %}
114 {{ change.editor|user_link }}
115- {% endif %}
116 </td>
117 <td class="italic">
118 {% if change.comment %}'{{ change.comment }}'{% endif %}
119
120=== modified file 'wiki/admin.py'
121--- wiki/admin.py 2017-12-03 11:43:47 +0000
122+++ wiki/admin.py 2018-10-03 20:25:29 +0000
123@@ -21,11 +21,7 @@
124 list_filter = ('title',)
125 ordering = ['-last_update']
126 fieldsets = (
127- (None, {'fields': ('title', 'content', 'markup')}),
128- ('Creator', {'fields': ('creator', 'creator_ip'),
129- 'classes': ('collapse', 'wide')}),
130- # ('Group', {'fields': ('object_id', 'content_type'),
131- # 'classes': ('collapse', 'wide')}),
132+ (None, {'fields': ('title', 'content', 'creator', 'markup')}),
133 )
134 raw_id_fields = ('creator',)
135 inlines = [InlineImages]
136@@ -41,13 +37,11 @@
137 list_filter = ('article__title',)
138 ordering = ('-modified',)
139 fieldsets = (
140- ('Article', {'fields': ('article',)}),
141+ ('Article', {'fields': ('article', 'editor')}),
142 ('Differences', {'fields': ('old_title', 'old_markup',
143 'content_diff')}),
144 ('Other', {'fields': ('comment', 'modified', 'revision', 'reverted'),
145 'classes': ('collapse', 'wide')}),
146- ('Editor', {'fields': ('editor', 'editor_ip'),
147- 'classes': ('collapse', 'wide')}),
148 )
149 raw_id_fields = ('editor',)
150
151
152=== modified file 'wiki/forms.py'
153--- wiki/forms.py 2017-04-29 19:56:32 +0000
154+++ wiki/forms.py 2018-10-03 20:25:29 +0000
155@@ -22,7 +22,6 @@
156 summary = forms.CharField(widget=forms.Textarea)
157
158 comment = forms.CharField(required=False)
159- user_ip = forms.CharField(widget=forms.HiddenInput)
160
161 content_type = forms.ModelChoiceField(
162 queryset=ContentType.objects.all(),
163@@ -35,8 +34,7 @@
164
165 class Meta:
166 model = Article
167- exclude = ('creator', 'creator_ip',
168- 'group', 'created_at', 'last_update')
169+ exclude = ('creator', 'group', 'created_at', 'last_update')
170
171 def clean_title(self):
172 """Check for some errors regarding the title:
173@@ -92,7 +90,6 @@
174
175 def save(self, *args, **kwargs):
176 # 0 - Extra data
177- editor_ip = self.cleaned_data['user_ip']
178 comment = self.cleaned_data['comment']
179
180 # 2 - Save the Article
181@@ -102,7 +99,6 @@
182 editor = getattr(self, 'editor', None)
183 group = getattr(self, 'group', None)
184 if self.is_new:
185- article.creator_ip = editor_ip
186 if editor is not None:
187 article.creator = editor
188 article.group = group
189@@ -113,6 +109,6 @@
190 # 4 - Create new revision
191 changeset = article.new_revision(
192 self.old_content, self.old_title, self.old_markup,
193- comment, editor_ip, editor)
194+ comment, editor)
195
196 return article, changeset
197
198=== added file 'wiki/migrations/0003_auto_20180918_0836.py'
199--- wiki/migrations/0003_auto_20180918_0836.py 1970-01-01 00:00:00 +0000
200+++ wiki/migrations/0003_auto_20180918_0836.py 2018-10-03 20:25:29 +0000
201@@ -0,0 +1,27 @@
202+# -*- coding: utf-8 -*-
203+# Generated by Django 1.11.12 on 2018-09-18 08:36
204+from __future__ import unicode_literals
205+
206+from django.db import migrations
207+
208+
209+class Migration(migrations.Migration):
210+
211+ dependencies = [
212+ ('wiki', '0002_auto_20161218_1056'),
213+ ]
214+
215+ operations = [
216+ migrations.AlterModelOptions(
217+ name='article',
218+ options={'default_permissions': ('change', 'add'), 'ordering': ['title'], 'verbose_name': 'Article', 'verbose_name_plural': 'Articles'},
219+ ),
220+ migrations.RemoveField(
221+ model_name='article',
222+ name='creator_ip',
223+ ),
224+ migrations.RemoveField(
225+ model_name='changeset',
226+ name='editor_ip',
227+ ),
228+ ]
229
230=== modified file 'wiki/models.py'
231--- wiki/models.py 2018-05-02 06:33:13 +0000
232+++ wiki/models.py 2018-10-03 20:25:29 +0000
233@@ -53,8 +53,6 @@
234 null=True, blank=True)
235 creator = models.ForeignKey(User, verbose_name=_('Article Creator'),
236 null=True)
237- creator_ip = models.GenericIPAddressField(_('IP Address of the Article Creator'),
238- blank=True, null=True)
239 created_at = models.DateTimeField(default=datetime.now)
240 last_update = models.DateTimeField(blank=True, null=True)
241
242@@ -93,7 +91,7 @@
243 return self.images.all()
244
245 def new_revision(self, old_content, old_title, old_markup,
246- comment, editor_ip, editor):
247+ comment, editor):
248 """Create a new ChangeSet with the old content."""
249
250 content_diff = diff(self.content, old_content)
251@@ -101,7 +99,6 @@
252 cs = ChangeSet.objects.create(
253 article=self,
254 comment=comment,
255- editor_ip=editor_ip,
256 editor=editor,
257 old_title=old_title,
258 old_markup=old_markup,
259@@ -109,10 +106,10 @@
260
261 return cs
262
263- def revert_to(self, revision, editor_ip, editor=None):
264+ def revert_to(self, revision, editor=None):
265 """Revert the article to a previuos state, by revision number."""
266 changeset = self.changeset_set.get(revision=revision)
267- changeset.reapply(editor_ip, editor)
268+ changeset.reapply(editor)
269
270 def compare(self, from_revision, to_revision):
271 """Compares to revisions of this article."""
272@@ -139,10 +136,9 @@
273
274 article = models.ForeignKey(Article, verbose_name=_(u"Article"))
275
276- # Editor identification -- logged or anonymous
277+ # Editor identification -- logged
278 editor = models.ForeignKey(User, verbose_name=_(u'Editor'),
279 null=True)
280- editor_ip = models.GenericIPAddressField(_(u"IP Address of the Editor"))
281
282 # Revision number, starting from 1
283 revision = models.IntegerField(_(u"Revision Number"))
284@@ -185,7 +181,7 @@
285 def is_anonymous_change(self):
286 return self.editor is None
287
288- def reapply(self, editor_ip, editor):
289+ def reapply(self, editor):
290 """Return the Article to this revision."""
291
292 # XXX Would be better to exclude reverted revisions
293@@ -218,7 +214,8 @@
294 old_content=old_content, old_title=old_title,
295 old_markup=old_markup,
296 comment='Reverted to revision #%s' % self.revision,
297- editor_ip=editor_ip, editor=editor)
298+ editor=editor
299+ )
300
301 self.save()
302
303
304=== modified file 'wiki/views.py'
305--- wiki/views.py 2018-04-08 14:40:17 +0000
306+++ wiki/views.py 2018-10-03 20:25:29 +0000
307@@ -300,15 +300,13 @@
308 return redirect(new_article)
309
310 elif request.method == 'GET':
311- user_ip = get_real_ip(request)
312
313 # TODO(Franku): Never worked IMHO
314 # lock = cache.get(title, None)
315 # if lock is None:
316 # lock = ArticleEditLock(title, request)
317 # lock.create_message(request)
318-
319- initial = {'user_ip': user_ip}
320+ initial = {}
321 if group_slug is not None:
322 initial.update({'content_type': group_ct.id,
323 'object_id': group.id})
324@@ -493,9 +491,9 @@
325 except Article.DoesNotExist:
326 # No existing article found -> reverting possible
327 if request.user.is_authenticated:
328- article.revert_to(revision, get_real_ip(request), request.user)
329+ article.revert_to(revision, request.user)
330 else:
331- article.revert_to(revision, get_real_ip(request))
332+ article.revert_to(revision)
333 return redirect(article)
334 # An article with this name exists
335 messages.error(
336
337=== modified file 'wlimages/admin.py'
338--- wlimages/admin.py 2016-12-13 18:28:51 +0000
339+++ wlimages/admin.py 2018-10-03 20:25:29 +0000
340@@ -31,7 +31,7 @@
341 actions = [delete_with_file]
342 fieldsets = (
343 (None, {'fields': ('image', 'name', 'date_submitted', 'revision')}),
344- (_('Upload data:'), {'fields': ('user', 'editor_ip')}),
345+ (_('Uploaded by:'), {'fields': ('user',)}),
346 (_('Content object:'), {
347 'fields': (('content_type', 'content_object'), 'object_id')}),
348 )
349
350=== added file 'wlimages/migrations/0003_remove_image_editor_ip.py'
351--- wlimages/migrations/0003_remove_image_editor_ip.py 1970-01-01 00:00:00 +0000
352+++ wlimages/migrations/0003_remove_image_editor_ip.py 2018-10-03 20:25:29 +0000
353@@ -0,0 +1,19 @@
354+# -*- coding: utf-8 -*-
355+# Generated by Django 1.11.12 on 2018-09-18 09:01
356+from __future__ import unicode_literals
357+
358+from django.db import migrations
359+
360+
361+class Migration(migrations.Migration):
362+
363+ dependencies = [
364+ ('wlimages', '0002_remove_image_url'),
365+ ]
366+
367+ operations = [
368+ migrations.RemoveField(
369+ model_name='image',
370+ name='editor_ip',
371+ ),
372+ ]
373
374=== modified file 'wlimages/models.py'
375--- wlimages/models.py 2016-12-13 18:28:51 +0000
376+++ wlimages/models.py 2018-10-03 20:25:29 +0000
377@@ -24,6 +24,7 @@
378 def create(self, **keyw):
379 """Makes sure that no image/revision pair is already in the
380 database."""
381+
382 if 'name' not in keyw or 'revision' not in keyw:
383 raise IntegrityError('needs name and revision as keywords')
384
385@@ -32,12 +33,12 @@
386
387 return super(ImageManager, self).create(**keyw)
388
389- def create_and_save_image(self, user, image, content_type, object_id, ip):
390+ def create_and_save_image(self, user, image, content_type, object_id):
391 # Use Django's get_valid_name() to get a safe filename
392 storage = FileSystemStorage()
393 safe_filename = storage.get_valid_name(image.name)
394 im = self.create(content_type=content_type, object_id=object_id,
395- user=user, revision=1, name=image.name, editor_ip=ip)
396+ user=user, revision=1, name=image.name)
397 path = '%swlimages/%s' % (MEDIA_ROOT, safe_filename)
398
399 destination = open(path, 'wb')
400@@ -69,8 +70,6 @@
401
402 # User Field
403 user = models.ForeignKey(User)
404- editor_ip = models.GenericIPAddressField(
405- _('IP address'), null=True, blank=True)
406
407 # Date Fields
408 date_submitted = models.DateTimeField(
409
410=== modified file 'wlimages/views.py'
411--- wlimages/views.py 2018-04-03 05:18:03 +0000
412+++ wlimages/views.py 2018-10-03 20:25:29 +0000
413@@ -4,7 +4,6 @@
414 from django.shortcuts import get_object_or_404, render
415
416 from models import Image
417-from wl_utils import get_real_ip
418 from forms import UploadImageForm
419
420
421@@ -31,7 +30,7 @@
422 form = UploadImageForm(request.POST, request.FILES)
423 if form.is_valid(): # All validation rules pass
424 Image.objects.create_and_save_image(user=request.user, image=request.FILES['imagename'],
425- content_type=ContentType.objects.get(pk=content_type), object_id=object_id, ip=get_real_ip(request))
426+ content_type=ContentType.objects.get(pk=content_type), object_id=object_id)
427 return HttpResponseRedirect(next) # Redirect after POST
428 else:
429 form = UploadImageForm() # An unbound form

Subscribers

People subscribed via source and target branches