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

IBX-952: Added chosen Location to Translation Choice form #1885

Merged
merged 3 commits into from
Sep 15, 2021

Conversation

barw4
Copy link
Member

@barw4 barw4 commented Sep 2, 2021

Question Answer
Tickets IBX-952
Bug fix? yes
New feature? no
BC breaks? no
Tests pass? yes
Doc needed? no
License GPL-2.0

We should consider the Location we are actually in to load the required languages as the user might not have access to main Location but have access to secondary one.

Related ezplatform-page-builder PR: https://github.com/ezsystems/ezplatform-page-builder/pull/826.

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

Copy link
Contributor

@mikadamczyk mikadamczyk left a comment

Choose a reason for hiding this comment

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

I would say that because the user might not have access to the main location we should not treat it like a secure fallback. If in any of those cases location will be null then an error will occur.

@@ -85,7 +91,11 @@ function (Language $language) {
$this->contentInfo,
[
(new Target\Builder\VersionBuilder())->translateToAnyLanguageOf($languagesCodes)->build(),
$this->locationService->loadLocation($this->contentInfo->mainLocationId),
$this->locationService->loadLocation(
$this->location !== null
Copy link
Contributor

Choose a reason for hiding this comment

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

If we will have a location there is a need to reload it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this ChoiceLoader is not a service, it's initialized with the form so it shouldn't really be a problem.

Copy link
Contributor

@mikadamczyk mikadamczyk Sep 3, 2021

Choose a reason for hiding this comment

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

ContentEditTranslationChoiceLoader is a service. Of course, we could reload but what for? It looks not so good

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is indeed a service then sure we shouldn't store it as a property 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@mikadamczyk It's not a service. It's built on demand, just like most choice loaders do.

I guess the issue could be that the current user does not have access to a Location in current context, hence the reload. I do think though that it should be skipped if it's passed directly - relying on implicit security check would be bad anyway.

Copy link
Contributor

@mikadamczyk mikadamczyk Sep 3, 2021

Choose a reason for hiding this comment

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

As we agreed, it is incorrectly registered as a service

@@ -50,14 +54,16 @@ public function __construct(
?ContentInfo $contentInfo,
LookupLimitationsTransformer $lookupLimitationsTransformer,
array $languageCodes,
LocationService $locationService
LocationService $locationService,
?Location $location
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
?Location $location
?Location $location = null

Copy link
Contributor

@Steveb-p Steveb-p Sep 3, 2021

Choose a reason for hiding this comment

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

Does it make sense to always require this parameter and drop the LocationService dependency as a result?

Copy link
Contributor

Choose a reason for hiding this comment

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

Aside from BC, I think this would be a good idea.

@webhdx
Copy link
Contributor

webhdx commented Sep 3, 2021

@mikadamczyk You are right, this is not fixing the root issue, only decreases chances of happening. Anyway this is still a valid PR because it makes the form being closer to actual context and not just rely on possibly completely different Location.

Copy link
Contributor

@Steveb-p Steveb-p left a comment

Choose a reason for hiding this comment

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

There are 2 questions posted in comments that I'd like to have answered before merging:

  1. Do we reload the Location object internally, if it has been passed directly via constructor?
  2. Do we expect to make $location argument mandatory in Choice Loader? If yes, then should we deprecate $locationService argument (as it's only purpose was to do the loading)?

Additionally, should we remove the ChoiceLoader service, as it should not (and cannot) be used as a service? If yes, then should it be a separate PR, or should we do so immediately?

@barw4
Copy link
Member Author

barw4 commented Sep 3, 2021

@Steveb-p
when it comes to question 1 I think we can skip reloading the Location, the same Location is still checked when accessing this content before.
2: Mandatory with null as a default or without null? Based on the parts in system where this service is called, we cannot guarantee we will have Location instead of null. If that's a null we won't really be able to load limitations for the given content, that's why we could help ourselves with mainLocationId which in fact should be loaded.

@barw4 barw4 requested a review from Steveb-p September 3, 2021 13:52
@Steveb-p
Copy link
Contributor

Steveb-p commented Sep 3, 2021

@Steveb-p
when it comes to question 1 I think we can skip reloading the Location, the same Location is still checked when accessing this content before.
2: Mandatory with null as a default or without null? Based on the parts in system where this service is called, we cannot guarantee we will have Location instead of null. If that's a null we won't really be able to load limitations for the given content, that's why we could help ourselves with mainLocationId which in fact should be loaded.

  1. Yeah, it's impossible to get to that location (see what I did there...?) without getting Location in current site access / user context. So it should be skipped.
  2. null as default, because we can't make it mandatory without a BC break. In terms of future direction that we could go is making it mandatory to pass Location from calling code (i.e. when constructing the ChoiceLoader in question). This would then lead to removal of LocationService dependency in ChoiceLoader itself - instead developers would use LocationService in calling code as necessary.

🧙‍♂️ Summoning @alongosz for architecture design decision

Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

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

@Steveb-p

  1. null as default, because we can't make it mandatory without a BC break. In terms of future direction that we could go is making it mandatory to pass Location from calling code (i.e. when constructing the ChoiceLoader in question). This would then lead to removal of LocationService dependency in ChoiceLoader itself - instead developers would use LocationService in calling code as necessary.

Summoning @alongosz for architecture design decision

@Steveb-p I'm not really following what happens here, but from the clean code POV if you were to introduce Location value so you can entirely drop dependency on LocationService and costly loading of Repository data, I would always support that.

That said, it of course depends on the required changes to the calling code. If this is used only within the scope we see in the PR - it should be fine. If it's used elsewhere, then depends on such diff as well.

@sonarcloud
Copy link

sonarcloud bot commented Sep 9, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@bogusez bogusez self-assigned this Sep 13, 2021
@mikadamczyk mikadamczyk merged commit 5ab572d into 2.3 Sep 15, 2021
@mikadamczyk mikadamczyk deleted the ibx-952-fix-translation-list-loader branch September 15, 2021 13:51
@barw4
Copy link
Member Author

barw4 commented Sep 15, 2021

Merged into master: c6b97ae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

7 participants