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

Update page link before submitting page form #2636

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

charludo
Copy link
Contributor

@charludo charludo commented Feb 5, 2024

Short description

I had a bit of trouble reproducing the issue. The only way I could trigger it was by entering Firefox's Responsive Design Mode and enabling Touch Simulation (though I suspect this might also happen on real touch devices).

I don't think this is worth an entry in the change log, this really is an edge case.

Proposed changes

  • if the content form is submitted while we're still waiting on a response for slugify, prevent the submission, then trigger it again once the previous call completed.

Side effects

  • hopefully not

Resolved issues

Fixes: #2624


Pull Request Review Guidelines

@charludo charludo requested a review from a team as a code owner February 5, 2024 14:12
@charludo charludo linked an issue Feb 5, 2024 that may be closed by this pull request
Copy link

codeclimate bot commented Feb 5, 2024

Code Climate has analyzed commit 4113830 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 92.8% (50% is the threshold).

This pull request will bring the total coverage in the repository to 82.7% (0.0% change).

View more on Code Climate.

Copy link
Contributor

@seluianova seluianova left a comment

Choose a reason for hiding this comment

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

though I suspect this might also happen on real touch devices

Right, I was able to reproduce the issue using the touch screen.

As I can see now, the proposed changes fix that! 🚀
I think this can be applied to events and locations as well.

UPD.
And the same problem occurs when saving to draft or submitting for approval.

@charludo charludo force-pushed the fix/title-change-not-updating-link branch from 33516ef to 5082abf Compare February 21, 2024 09:21
@charludo
Copy link
Contributor Author

I think this can be applied to events and locations as well.

UPD. And the same problem occurs when saving to draft or submitting for approval.

Right, thanks for catching that!

I've added a more general solution.

Copy link
Contributor

@seluianova seluianova left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

Copy link
Contributor

@seluianova seluianova left a comment

Choose a reason for hiding this comment

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

Opps, sorry, I actually found one issue:
"Submit for approval" action has been broken for Observer
image
It can be reproduced, if Observer changes the page title.

@charludo
Copy link
Contributor Author

Opps, sorry, I actually found one issue: "Submit for approval" action has been broken for Observer
[...]
It can be reproduced, if Observer changes the page title.

Sorry for taking so long to get back to you.

Looks like this also happens on the develop branch, so it's unrelated to the changes. However, I think it might be intentional - @osmers, should Observers be able to change titles of pages they can edit?

If yes, I can open a new issue;
if no, I'd use this PR to set the field disabled for Observers, if that's all right with both of you.

@seluianova
Copy link
Contributor

Looks like this also happens on the develop branch, so it's unrelated to the changes

I have re-checked:
The error on the screen is reproduced on develop, so it's really unrelated.
But the action itself works on develop - I can submit a title change for approval now.

But right, if the title field should be disabled, it will solve the problem anyway :)

@charludo
Copy link
Contributor Author

But the action itself works on develop - I can submit a title change for approval now.

Ah, right. Then I guess it's not unrelated anymore, I'll look into it :D

@charludo charludo force-pushed the fix/title-change-not-updating-link branch from 5082abf to 4e56fdf Compare March 26, 2024 11:15
@charludo
Copy link
Contributor Author

Looks like this also happens on the develop branch, so it's unrelated to the changes

I have re-checked: The error on the screen is reproduced on develop, so it's really unrelated. But the action itself works on develop - I can submit a title change for approval now.

But right, if the title field should be disabled, it will solve the problem anyway :)

AH, I mistakenly thought Observers could not change the title, but in fact it's just that they can't directly change the link (so the automatic link update is, of course, not an issue at all here.

I've removed the submission prevention for "submit for approval".

@charludo charludo force-pushed the fix/title-change-not-updating-link branch from 4e56fdf to d501e5a Compare March 26, 2024 11:25
@osmers
Copy link

osmers commented Mar 26, 2024

Looks like this also happens on the develop branch, so it's unrelated to the changes

I have re-checked: The error on the screen is reproduced on develop, so it's really unrelated. But the action itself works on develop - I can submit a title change for approval now.
But right, if the title field should be disabled, it will solve the problem anyway :)

AH, I mistakenly thought Observers could not change the title, but in fact it's just that they can't directly change the link (so the automatic link update is, of course, not an issue at all here.

I've removed the submission prevention for "submit for approval".

I think it makes sense that observers can change the title of the page they are allowed to edit. Either they were given the rights to publish right away which means they are trusted to only do what's expected or they can only submit for review, in which case the changes to the title could be rejected if not wanted, right?

@seluianova
Copy link
Contributor

seluianova commented Mar 27, 2024

Observer can now submit a title change for approval (the same behavior as in develop) ✅
But the original problem remains for the "Submit for approval" action:

  • login as Author (the problem is that not only Observers submit changes for approval)
  • edit some page title
  • click 'Submit for approval' using the touch screen
    --> the page is saved with a new title, but the link is not updated

I mistakenly thought Observers could not change the title, but in fact it's just that they can't directly change the link

Actually it seems they can change a link directly (submit a link change for approval), I have just checked in develop.

@charludo charludo force-pushed the fix/title-change-not-updating-link branch from d501e5a to fbeb59d Compare April 29, 2024 13:18
@charludo
Copy link
Contributor Author

I mistakenly thought Observers could not change the title, but in fact it's just that they can't directly change the link

Actually it seems they can change a link directly (submit a link change for approval), I have just checked in develop.

Alright. I think everythin is working now the same as on develop, plus touch screens work. However, I have not fixed the underlying bug (which is that the slugify_ajax endpoint raises PermissionDenied for observers because they are not allowed to edit objects), but instead just moved the release of the submission lock to a finally() block. This way the fetch still throws an unhandled error, just like on develop.

I think we should either

  • keep the PermissionDenied but handle it "properly" (aka hide it / prevent logging to console), or
  • change the required permission in slugify_ajax.py to view_page etc.

I like the second option better, but wasn't sure if there's some unintended consequences.

@charludo charludo force-pushed the fix/title-change-not-updating-link branch from fbeb59d to 373c0e1 Compare April 29, 2024 13:29
@JoeyStk JoeyStk added bug Something isn't working prio: medium Should be scheduled in the forseeable future. labels May 3, 2024
Copy link
Contributor

@JoeyStk JoeyStk left a comment

Choose a reason for hiding this comment

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

Thank you very much! Looks really good! I really would like to have a test for this, but since we don't have JS tests yet, I think we can give it a pass

@charludo
Copy link
Contributor Author

charludo commented May 7, 2024

Thank you very much! Looks really good! I really would like to have a test for this, but since we don't have JS tests yet, I think we can give it a pass

Yes, fair 😅 Any suggestions on how to handle the PermissionDenied?

@JoeyStk
Copy link
Contributor

JoeyStk commented May 7, 2024

Oh sorry, I forgot to mention that. I also tend towards the second option. I think the PermissionDenied indicates that somewhere we have a logical thinking error in our permissions. I think changing the permission should be the right thing 🤔

@seluianova
Copy link
Contributor

seluianova commented May 7, 2024

change the required permission in slugify_ajax.py to view_page etc.

Sounds better to me, because if Observer has the right to modify the link directly, then modifying the link should also work for Observer through ajax. I think that would be more consistent.

@charludo charludo force-pushed the fix/title-change-not-updating-link branch from 373c0e1 to ebd42da Compare May 8, 2024 06:42
@charludo
Copy link
Contributor Author

charludo commented May 8, 2024

Alright, I've lowered the required permissions.

"Worst case" someone can generate a slug for a content objects they shouldn't - but since the function only returns the generated slug, not actually saves it, I think that's OK.

I have also let the client-side error handling in, just in case anything else occurs server-side we still release the submission lock.

@charludo charludo force-pushed the fix/title-change-not-updating-link branch 2 times, most recently from 8af7760 to 7f2d590 Compare May 8, 2024 07:53
@seluianova
Copy link
Contributor

seluianova commented May 13, 2024

"Worst case" someone can generate a slug for a content objects they shouldn't

This could be eliminated if we check for "cms.change_page_object" permission instead of "is user.role == Observer".
This will also make the check more accurate, because the slug can actually be edited when the user has permissions to a particular page and being an Observer is not enough.
But it will require some re-work of slugify_ajax() function. Not sure it's worth it, given the criticality of the original issue.

Smthg like:

request.user.has_perm("cms.change_page_object", object_instance.page)

But I don't insist here, let me know if you would prefer to keep the current implementation.

@charludo charludo force-pushed the fix/title-change-not-updating-link branch 3 times, most recently from 9161eae to 7220a42 Compare May 15, 2024 07:37
@charludo
Copy link
Contributor Author

"Worst case" someone can generate a slug for a content objects they shouldn't

This could be eliminated if we check for "cms.change_page_object" permission instead of "is user.role == Observer". This will also make the check more accurate, because the slug can actually be edited when the user has permissions to a particular page and being an Observer is not enough. But it will require some re-work of slugify_ajax() function. Not sure it's worth it, given the criticality of the original issue.

Smthg like:

request.user.has_perm("cms.change_page_object", object_instance.page)

But I don't insist here, let me know if you would prefer to keep the current implementation.

You're absolutely right, that makes a lot more sense. Tbh I completely forgot that checking permissions for a specific object is an option... 😅

@charludo charludo requested a review from seluianova May 15, 2024 07:51
@charludo charludo force-pushed the fix/title-change-not-updating-link branch 2 times, most recently from 3bc8dca to 2be6d88 Compare May 27, 2024 08:28
@charludo charludo requested a review from seluianova May 27, 2024 08:28
@seluianova seluianova self-assigned this May 27, 2024
@JoeyStk JoeyStk self-assigned this May 28, 2024
Copy link
Contributor

@seluianova seluianova left a comment

Choose a reason for hiding this comment

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

I've re-tested everything again and found no new problems except the one caused by removing the if-condition in the templates.
As soon as the if-s are returned, I think it's good to go 🤞
Thanks for tackling this tricky issue!

@charludo charludo force-pushed the fix/title-change-not-updating-link branch from 2be6d88 to 87a67ca Compare June 25, 2024 06:57
@charludo charludo force-pushed the fix/title-change-not-updating-link branch from 87a67ca to 4113830 Compare June 25, 2024 07:09
@charludo
Copy link
Contributor Author

I've re-tested everything again and found no new problems except the one caused by removing the if-condition in the templates. As soon as the if-s are returned, I think it's good to go 🤞 Thanks for tackling this tricky issue!

No, thank YOU for the thorough reviews and attention to detail!!

Seriously, without you, this PR might have solved the original issue, but would also have introduced multiple new bugs. Thank you 💛

@charludo charludo merged commit ec599d9 into develop Jun 25, 2024
5 checks passed
@charludo charludo deleted the fix/title-change-not-updating-link branch June 25, 2024 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working prio: medium Should be scheduled in the forseeable future.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Page link is not updated when changing title
4 participants