Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
98296f86
Unverified
Kaydet (Commit)
98296f86
authored
Nis 26, 2019
tarafından
Carlton Gibson
Kaydeden (comit)
Mariusz Felisiak
Nis 27, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #30351 -- Handled pre-existing permissions in proxy model permissions data migration.
Regression in
181fb601
.
üst
08a4ee06
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
5 deletions
+55
-5
0011_update_proxy_permissions.py
.../contrib/auth/migrations/0011_update_proxy_permissions.py
+25
-5
2.2.1.txt
docs/releases/2.2.1.txt
+5
-0
test_migrations.py
tests/auth_tests/test_migrations.py
+25
-0
No files found.
django/contrib/auth/migrations/0011_update_proxy_permissions.py
Dosyayı görüntüle @
98296f86
from
django.db
import
migrations
import
sys
from
django.core.management.color
import
color_style
from
django.db
import
migrations
,
transaction
from
django.db.models
import
Q
from
django.db.models
import
Q
from
django.db.utils
import
IntegrityError
WARNING
=
"""
A problem arose migrating proxy model permissions for {old} to {new}.
Permission(s) for {new} already existed.
Codenames Q: {query}
Ensure to audit ALL permissions for {old} and {new}.
"""
def
update_proxy_model_permissions
(
apps
,
schema_editor
,
reverse
=
False
):
def
update_proxy_model_permissions
(
apps
,
schema_editor
,
reverse
=
False
):
...
@@ -7,6 +20,7 @@ def update_proxy_model_permissions(apps, schema_editor, reverse=False):
...
@@ -7,6 +20,7 @@ def update_proxy_model_permissions(apps, schema_editor, reverse=False):
Update the content_type of proxy model permissions to use the ContentType
Update the content_type of proxy model permissions to use the ContentType
of the proxy model.
of the proxy model.
"""
"""
style
=
color_style
()
Permission
=
apps
.
get_model
(
'auth'
,
'Permission'
)
Permission
=
apps
.
get_model
(
'auth'
,
'Permission'
)
ContentType
=
apps
.
get_model
(
'contenttypes'
,
'ContentType'
)
ContentType
=
apps
.
get_model
(
'contenttypes'
,
'ContentType'
)
for
Model
in
apps
.
get_models
():
for
Model
in
apps
.
get_models
():
...
@@ -24,10 +38,16 @@ def update_proxy_model_permissions(apps, schema_editor, reverse=False):
...
@@ -24,10 +38,16 @@ def update_proxy_model_permissions(apps, schema_editor, reverse=False):
proxy_content_type
=
ContentType
.
objects
.
get_for_model
(
Model
,
for_concrete_model
=
False
)
proxy_content_type
=
ContentType
.
objects
.
get_for_model
(
Model
,
for_concrete_model
=
False
)
old_content_type
=
proxy_content_type
if
reverse
else
concrete_content_type
old_content_type
=
proxy_content_type
if
reverse
else
concrete_content_type
new_content_type
=
concrete_content_type
if
reverse
else
proxy_content_type
new_content_type
=
concrete_content_type
if
reverse
else
proxy_content_type
Permission
.
objects
.
filter
(
try
:
permissions_query
,
with
transaction
.
atomic
():
content_type
=
old_content_type
,
Permission
.
objects
.
filter
(
)
.
update
(
content_type
=
new_content_type
)
permissions_query
,
content_type
=
old_content_type
,
)
.
update
(
content_type
=
new_content_type
)
except
IntegrityError
:
old
=
'{}_{}'
.
format
(
old_content_type
.
app_label
,
old_content_type
.
model
)
new
=
'{}_{}'
.
format
(
new_content_type
.
app_label
,
new_content_type
.
model
)
sys
.
stdout
.
write
(
style
.
WARNING
(
WARNING
.
format
(
old
=
old
,
new
=
new
,
query
=
permissions_query
)))
def
revert_proxy_model_permissions
(
apps
,
schema_editor
):
def
revert_proxy_model_permissions
(
apps
,
schema_editor
):
...
...
docs/releases/2.2.1.txt
Dosyayı görüntüle @
98296f86
...
@@ -59,3 +59,8 @@ Bugfixes
...
@@ -59,3 +59,8 @@ Bugfixes
* Increased the default timeout when using ``Watchman`` to 5 seconds to prevent
* Increased the default timeout when using ``Watchman`` to 5 seconds to prevent
falling back to ``StatReloader`` on larger projects and made it customizable
falling back to ``StatReloader`` on larger projects and made it customizable
via the ``DJANGO_WATCHMAN_TIMEOUT`` environment variable (:ticket:`30361`).
via the ``DJANGO_WATCHMAN_TIMEOUT`` environment variable (:ticket:`30361`).
* Fixed a regression in Django 2.2 that caused a crash when migrating
permissions for proxy models if the target permissions already existed. For
example, when a permission had been created manually or a model had been
migrated from concrete to proxy (:ticket:`30351`).
tests/auth_tests/test_migrations.py
Dosyayı görüntüle @
98296f86
...
@@ -4,6 +4,7 @@ from django.apps import apps
...
@@ -4,6 +4,7 @@ from django.apps import apps
from
django.contrib.auth.models
import
Permission
,
User
from
django.contrib.auth.models
import
Permission
,
User
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.models
import
ContentType
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.utils
import
captured_stdout
from
.models
import
Proxy
,
UserProxy
from
.models
import
Proxy
,
UserProxy
...
@@ -152,3 +153,27 @@ class ProxyModelWithSameAppLabelTests(TestCase):
...
@@ -152,3 +153,27 @@ class ProxyModelWithSameAppLabelTests(TestCase):
user
=
User
.
_default_manager
.
get
(
pk
=
user
.
pk
)
user
=
User
.
_default_manager
.
get
(
pk
=
user
.
pk
)
for
permission
in
[
self
.
default_permission
,
self
.
custom_permission
]:
for
permission
in
[
self
.
default_permission
,
self
.
custom_permission
]:
self
.
assertTrue
(
user
.
has_perm
(
'auth_tests.'
+
permission
.
codename
))
self
.
assertTrue
(
user
.
has_perm
(
'auth_tests.'
+
permission
.
codename
))
def
test_migrate_with_existing_target_permission
(
self
):
"""
Permissions may already exist:
- Old workaround was to manually create permissions for proxy models.
- Model may have been concrete and then converted to proxy.
Output a reminder to audit relevant permissions.
"""
proxy_model_content_type
=
ContentType
.
objects
.
get_for_model
(
Proxy
,
for_concrete_model
=
False
)
Permission
.
objects
.
create
(
content_type
=
proxy_model_content_type
,
codename
=
'add_proxy'
,
name
=
'Can add proxy'
,
)
Permission
.
objects
.
create
(
content_type
=
proxy_model_content_type
,
codename
=
'display_proxys'
,
name
=
'May display proxys information'
,
)
with
captured_stdout
()
as
stdout
:
update_proxy_permissions
.
update_proxy_model_permissions
(
apps
,
None
)
self
.
assertIn
(
'A problem arose migrating proxy model permissions'
,
stdout
.
getvalue
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment