Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync source page privacy settings with translated page #496

Merged
merged 3 commits into from
Dec 17, 2021

Conversation

zerolab
Copy link
Collaborator

@zerolab zerolab commented Dec 14, 2021

This PR fixes #317

it synchronizes the source page PageViewRestriction with the translated pages on translation creation and sync.

Scenarios covered:

Source Translation Action
Has privacy settings Doesn't have privacy settings Translated page privacy settings get created
Has changes to the privacy settings Has privacy settings Translated page privacy settings get updated
Has privacy settings removed Has privacy settings Translated page privacy settings removed
Has privacy settings removed Doesn't have privacy settings Noop

Note: if the source page privacy settings change, the translated page(s) privacy settings will only get updated after "sync translations"

@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2021

Codecov Report

Merging #496 (0741ae4) into main (297e5ed) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #496      +/-   ##
==========================================
+ Coverage   92.82%   92.92%   +0.09%     
==========================================
  Files          36       36              
  Lines        2983     3023      +40     
  Branches      467      477      +10     
==========================================
+ Hits         2769     2809      +40     
  Misses        114      114              
  Partials      100      100              
Impacted Files Coverage Δ
wagtail_localize/models.py 96.14% <100.00%> (+0.21%) ⬆️
wagtail_localize/views/update_translations.py 93.50% <100.00%> (+0.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 297e5ed...0741ae4. Read the comment docs.

wagtail_localize/models.py Show resolved Hide resolved
Comment on lines +917 to +922
if list(
original_restriction.groups.values_list("pk", flat=True)
) != list(translation_restriction.groups.values_list("pk", flat=True)):
translation_restriction.groups.set(
original_restriction.groups.all()
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are wemissing

should_save = True

in this last if block?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just for my own understanding, is the reason why we're doing this

should_save = False
if this != that:
    this = that
    should_save = True

if should_save:
    this.save()

pattern rather than just

this = that
this.save()

for performance reasons? (i.e: we're trying to minimise round trips to the DB)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it certainly is missing should_save = True.

The reason for this is that 2 or more of the conditions can be true.

e.g. when changing form the 'login' restriction to 'password', both the restriction_type and password attributes will have changed.

so we want a single save

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on missing should_save, we are not - 0741ae4#diff-a9c40e8134c27fd95a23649e865005e8a957dc24db0d423122655a565221d614R555-R565 - as groups are M2M

@zerolab zerolab merged commit 08272a9 into wagtail:main Dec 17, 2021
@zerolab zerolab deleted the feature/sync-page-restrictions branch December 17, 2021 14:34
@zerolab zerolab added this to the 1.1 milestone Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translations are not inheriting the source page privacy settings
3 participants