From 12c49b285a6afd355eb6e9c5c1e9b85316377dd9 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sun, 17 Sep 2017 17:35:47 +0200 Subject: [PATCH] Fix page permissions and fix migration when on sqlite backend --- club/migrations/0010_auto_20170912_2028.py | 6 ++-- core/models.py | 2 +- core/operations.py | 32 ++++++++++++++++++++++ core/urls.py | 10 +++---- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 core/operations.py diff --git a/club/migrations/0010_auto_20170912_2028.py b/club/migrations/0010_auto_20170912_2028.py index d80a4cb6..06cad259 100644 --- a/club/migrations/0010_auto_20170912_2028.py +++ b/club/migrations/0010_auto_20170912_2028.py @@ -2,7 +2,9 @@ from __future__ import unicode_literals from django.db import migrations, models + from club.models import Club +from core.operations import PsqlRunOnly def generate_club_pages(apps, schema_editor): @@ -32,7 +34,7 @@ class Migration(migrations.Migration): name='page', field=models.OneToOneField(related_name='club', blank=True, null=True, to='core.Page'), ), - migrations.RunSQL('SET CONSTRAINTS ALL IMMEDIATE', reverse_sql=migrations.RunSQL.noop), + PsqlRunOnly('SET CONSTRAINTS ALL IMMEDIATE', reverse_sql=migrations.RunSQL.noop), migrations.RunPython(generate_club_pages), - migrations.RunSQL(migrations.RunSQL.noop, reverse_sql='SET CONSTRAINTS ALL IMMEDIATE'), + PsqlRunOnly(migrations.RunSQL.noop, reverse_sql='SET CONSTRAINTS ALL IMMEDIATE'), ] diff --git a/core/models.py b/core/models.py index f7972863..b9dda65f 100644 --- a/core/models.py +++ b/core/models.py @@ -893,7 +893,7 @@ class Page(models.Model): ) def can_be_edited_by(self, user): - if self.is_club_page and self.club.can_be_edited_by(user): + if hasattr(self, 'club') and self.club.can_be_edited_by(user): # Override normal behavior for clubs return True return False diff --git a/core/operations.py b/core/operations.py new file mode 100644 index 00000000..fedc1cde --- /dev/null +++ b/core/operations.py @@ -0,0 +1,32 @@ +# -*- coding:utf-8 -* +# +# Copyright 2016,2017 +# - Sli +# +# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, +# http://ae.utbm.fr. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License a published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple +# Place - Suite 330, Boston, MA 02111-1307, USA. +# +# + +from django.db import connection, migrations + + +class PsqlRunOnly(migrations.RunSQL): + + def _run_sql(self, schema_editor, sqls): + if connection.vendor == 'postgresql': + super(PsqlRunOnly, self)._run_sql(schema_editor, sqls) diff --git a/core/urls.py b/core/urls.py index 27a63070..a056b4b7 100644 --- a/core/urls.py +++ b/core/urls.py @@ -87,9 +87,9 @@ urlpatterns = [ url(r'^page/$', PageListView.as_view(), name='page_list'), url(r'^page/create$', PageCreateView.as_view(), name='page_new'), url(r'^page/(?P[0-9]*)/delete$', PageDeleteView.as_view(), name='page_delete'), - url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/edit$', PageEditView.as_view(), name='page_edit'), - url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/prop$', PagePropView.as_view(), name='page_prop'), - url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/hist$', PageHistView.as_view(), name='page_hist'), - url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/rev/(?P[0-9]+)/', PageRevView.as_view(), name='page_rev'), - url(r'^page/(?P[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])/$', PageView.as_view(), name='page'), + url(r'^page/(?P([/a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])+)/edit$', PageEditView.as_view(), name='page_edit'), + url(r'^page/(?P([/a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])+)/prop$', PagePropView.as_view(), name='page_prop'), + url(r'^page/(?P([/a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])+)/hist$', PageHistView.as_view(), name='page_hist'), + url(r'^page/(?P([/a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])+)/rev/(?P[0-9]+)/', PageRevView.as_view(), name='page_rev'), + url(r'^page/(?P([/a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])+)/$', PageView.as_view(), name='page'), ]