Problem/Motivation
There is an error message on LocalTaskItemForm page "Notice: Undefined index: #format in Drupal\filter\Element\TextFormat::processFormat() (line 188 of core/modules/filter/src/Element/TextFormat.php).". If I am right this appears when a user/local translator uses a text format (format of translation) but doesn't have a permission for it (for instance - full_html).
Proposed resolution
Add a permission check for a current user before adding it into the list of allowed formats. Possibly we should add a fallback to different (accessible) text format if passed one is not available? However, it seems Drupal does it for us too if we do not set allowed formats at all.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | do_not_allow_text-2685579-19-interdiff.txt | 7.87 KB | mbovan |
| #19 | do_not_allow_text-2685579-19.patch | 10.57 KB | mbovan |
| #17 | no_permission.png | 38.34 KB | mbovan |
| #17 | do_not_allow_text-2685579-17-interdiff.txt | 13.03 KB | mbovan |
| #17 | do_not_allow_text-2685579-17.patch | 9.52 KB | mbovan |
Comments
Comment #2
mbovan commentedThis patch fixes the error notice. Do we need to set a fallback format here or it's not necessary?
Probably we should extend LocalTranslatorTest to check for full_html format as well.
Comment #3
berdirIf the user doesn't have access to the format, then we must not use a textfield with format.
Comment #4
berdirIn fact, users shouldn't even be allowed to see the content at all then, but considering that we send it out to translators, I'm not sure how to handle this. Maybe we shouldn't show it and don't allow to accept such job items.
Imagine someone using the php input filter, then you could inject PHP code into the site.
Comment #5
berdirComment #6
mbovan commentedIf a user has permission for e.g. PHP filter, then it's fine to display - even if it can be a security issue (the responsibility is on the admin user)?
Disabling the content/text-field from editing and displaying a warning message that explains that chosen (original) text format is not allowed for a user can be an option for the next patch?
Comment #7
mbovan commentedAs discussed, implemented similar to how it's done in node module.
Comment #8
berdirAdditionally to disabling the reject/finish buttons, we need to disable being able to accept this at all. You might need to store the value of this in a global $form_state key, if any is FALSE, save as completed must not be shown.
You can simplify this a bit with $format->access('use')
I think they can still see the content then? Which is what we want to prevent. See how TextFormat uses filter_form_access_denied()
Since we don't allow to save anyway, it should be safe to switch out the text completely with a similar explanation that additionally says that it's not possible to accept this job item.
Comment #9
mbovan commentedRe #8.3: There is fallback to filter_form_access_denied() with this message when we specify allowed formats and format...
Updated the message and set "Save as completed" to be hidden in this case.
I left the source content visible in order to not repeat the message. Also, user might get (edit) permission at some point...

Comment #10
berdirComment #11
berdirDuplicate the message is exactly what we need. Or show that in the source and keep translation empty, that works too.
Comment #12
mbovan commentedI thought in a way: "This is just a text format permission problem". At some point user can get it and be able to translate the content from the field...
Anyway, moved the message to source and left translation disabled and blank.
Comment #13
berdirYes, what should happen with the translator is a problem.
See #1415234: Deal with text format permissions and security. text formats, security and permissions are never an easy problem. We've had that critical open since we started TMGMT. This is a good step towards solving that. #2688419: To create a continuous job you must have admin tmgmt permission was another part of the puzzle.
Comment #15
mbovan commentedRerolled.
Comment #16
berdirOh. I didn't notice that you did this (only) in the local translator.
I'm actually not sure if we need this for the local translator at all. It will be quite common that they will be asked to translate content that they would not have permissions to, including formats. There is 1-2 problems for them, however: a) preview and b) auto-accept.
So for now, lets do this in this issue:
* Implement the same logic for reviewers, do not allow save as completed
* Simplify the logic again for local translator, simply do not use a text format if the user does not have access, display as a plain text field.
To solve the problems mentioned above, I discussed that with mIro and we agreed on this (new issue, possibly use #1415234: Deal with text format permissions and security for that): A new setting in tmgmt that lists all text formats and allows to check them. If nothing is selected, nothing is checked. If some are checked and a given job has a format that is not in the list of checked formats, do not provide preview links (directly in tmgmt_content) and skip auto-accept.
Comment #17
mbovan commentedOk. Here is the updated patch.
I moved to logic from LocalTranslator to JobItemReviewForm (reviewer). LocalTranslator can see the translation content in a text field (there is a default fallback to plain_text format).
Comment #18
berdirClose
can we move this to the review test? I recently spent quite some time to remove methods from this test class as it is very long and slow (which means it can not be executed in parallel on testbot)
that's a button, not a link? I don't think that would fail right now.
you should do a positive check for the button now here, an assertRaw() or so.
since we don't use #type text_format then, we won't use the plain text format, we won't have a format at all then.
like the example above, assertNo*() only asserts are dangerous as they can easily assert something that never exists (e.g. you could have a typo in the string that you're looking for, so it would never match).
Instead, try to do a positive match. text_formt fields have a different, nested structure. So you can verify that you do not have that here but only a normal textfield.
Comment #19
mbovan commentedThis should address all the points above.
Comment #21
berdirDidn't do a lot of testing but this looks good now I think.