Problem/Motivation

content_translation_view_access() is invoked as an implementation of hook_ENTITY_TYPE_access(), but it is not an implementation of this hook.

Proposed resolution

Rename the function. However, there are other functions that have a name in the same format, such as content_translation_add_access().

Remaining tasks

User interface changes

None.

API changes

Function renames, but no functional changes.

Issues blocked by this one:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Status: Active » Needs review
FileSize
3.06 KB
Xano’s picture

Status: Needs review » Needs work

The last submitted patch, 1: drupal_2200333_1.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
xjm’s picture

Could we make these names a bit less ambiguous? I'd say hasFooAccess() if they were method names.

Edit: Or maybe content_translation_check_foo_access()?

Gábor Hojtsy’s picture

check...access is fine. I don't have a strong opinion either way. The current patch is equally fine with me.

Xano’s picture

FileSize
3.09 KB

Updated as per #5. For those who wonder why the tests never caught this problem, the answer is that core never uses entity access for views' view operation, or at least no code that is executed during tests does. #2200229: Use entity access for Views UI routes will fix that.

Xano’s picture

Priority: Normal » Major

Bumping to major for xjm.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

ha. :P I'm not sure it's actually major, but it sure is weird.

Let's add explicit test coverage for this as well as the implicit coverage coming in #2200229: Use entity access for Views UI routes.

Xano’s picture

FileSize
15.88 KB

This is what I've come up with so far, but I am a little stuck as to how to test this properly. There are four variables that influence how view access is determined, for instance, and writing tests that covers all possible permutations is going to be a hell of a lot of work with all the expectations that will need to be configured.

Any ideas?

YesCT’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +D8MI

adding link to doc about tests for someone that wants to pick this up.
--
needs review to trigger testbot.
it is still needs work for test coverage.

Status: Needs review » Needs work

The last submitted patch, 10: drupal_2200333_10.patch, failed testing.

YesCT’s picture

Xano and I talked about this.

Xano is going to post a little bit more to make clear what needs to be done.

Gábor Hojtsy’s picture

So you could maybe write a test for this with invoking the view access and then expecting an exception? Or would that entirely fail? Without the fix that would fail. Looks like the problem overall is this is never invoked in core. ?!

Xano’s picture

FileSize
16.05 KB

Re-roll.

So you could maybe write a test for this with invoking the view access and then expecting an exception? Or would that entirely fail? Without the fix that would fail. Looks like the problem overall is this is never invoked in core. ?!

Well, the functions must at the very least be renamed to prevent this collission. The reason nobody noticed this before, is that no code ever used entity access for Views, which is what invokes hook_ENTITY_TYPE_access(). See #2200229: Use entity access for Views UI routes for this.

Xano’s picture

For the record, and this is what I talked to @webchick and @YesCT about last night, this patch requires MUCH more work, because the test methods are complex and can be executed following many different scenarios. I have absolutely no interest in adding test coverage for this code, and I'd like this to be simply renamed, so I can move along and fix #2200229: Use entity access for Views UI routes, and integrate everything other access control and entity operations issues.

I understand the desire for test coverage, but I will not add it, so unless someone else steps up and provides full coverage (half coverage is no coverage), the request for tests blocks more important issues while the actual problem can be fixed easily.

plach’s picture

The current issue is blocking a ton of other more important work, so I don't think it's worth to hold that up just to provide additional coverage, which I completely agree is badly needed. The patch in #1 is ok and it's pretty obvious that it won't introduce any regression as it's just renaming a bunch of functions that may even be deprecated after #2155787: Introduce more flexible access control for content translation operations. The only risk we have here is we are introducing other name clashes, but I guess @xano already properly checked this is not the case :)

Since we are in the middle of a big sprint, I suggest to file a major follow-up to add test-coverage for these (semi-unused) API functions and let @xano go on with the stuff he's working on. If none will show up to work on that I'll do it myself prior to the first D8 stable release, I promise.

Xano’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
3.18 KB

@plach and I talked this through and he, as the Content Translation maintainer, agrees that renaming the functions does not cause a regression and allows more pressing issues to be fixed. We also agreed on creating a follow-up to add the test coverage and possibly refactor the code, which I posted at #2227307: Add test coverage for the content_translation_access_*() methods.

The attached patch is a re-roll of #1, and simply changes the function names to prevent any hook collisions.

plach’s picture

Tentatively marking RTBC to get feedback from committers, please see #17-#18.

plach’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/content_translation/content_translation.module
@@ -262,7 +262,7 @@ function content_translation_view_access(EntityInterface $entity, $langcode, Acc
-function content_translation_add_access(EntityInterface $entity, Language $source = NULL, Language $target = NULL) {
+function content_translation_access_add(EntityInterface $entity, Language $source = NULL, Language $target = NULL) {

@@ -279,7 +279,7 @@ function content_translation_add_access(EntityInterface $entity, Language $sourc
-function content_translation_edit_access(EntityInterface $entity, Language $language = NULL) {
+function content_translation_access_edit(EntityInterface $entity, Language $language = NULL) {

@@ -295,7 +295,7 @@ function content_translation_edit_access(EntityInterface $entity, Language $lang
-function content_translation_delete_access(EntityInterface $entity, Language $language = NULL) {
+function content_translation_access_delete(EntityInterface $entity, Language $language = NULL) {

Why do we have these unused and untested functions anyway?

If we do need to provide them then they should be tested. And this issue should add that test coverage.

Xano’s picture

Are we seriously blocking progress on other more pressing access control issues, just because these functions were poorly designed and untested to begin with? The patch only fixes a problem. It doesn’t cause a regression.

Xano’s picture

Status: Needs work » Needs review
FileSize
5.12 KB

This patch removes all unused functions and moves the only used function to its caller, which has extensive coverage through \Drupal\content_translation\Tests\ContentTranslationUITest, \Drupal\content_translation\Tests\ContentTranslationWorkflowsTest, and \Drupal\content_translation\Tests\ContentTranslationSyncImageTest.

Status: Needs review » Needs work

The last submitted patch, 23: drupal_2200333_23.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
5.04 KB
1.43 KB
plach’s picture

Assigned: Unassigned » alexpott
Status: Needs review » Reviewed & tested by the community
Issue tags: +language-content, +sprint

@Xano told me @alexpott is fine with removing the unused functions and merge the offending one directly in the caller. The failures in #23 show that this change is extensively covered so I think we should be good now.

Let's try again :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
git ac https://drupal.org/files/issues/drupal_2200333_25.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5158  100  5158    0     0   3699      0  0:00:01  0:00:01 --:--:--  6840
error: patch failed: core/modules/content_translation/content_translation.module:251
error: core/modules/content_translation/content_translation.module: patch does not apply
Xano’s picture

Status: Needs work » Needs review
FileSize
5.12 KB

Re-roll.

Xano’s picture

Status: Needs review » Reviewed & tested by the community

RTBC if the tests pass.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed b3df95c and pushed to 8.x. Thanks!

  • Commit b3df95c on 8.x by alexpott:
    Issue #2200333 by Xano: Content_translation_view_access() is invoked as...
Gábor Hojtsy’s picture

Issue tags: -sprint, -Needs reroll

Superb, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.