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

XWIKI-22433: Provide consistency in info / warning / error class usages in templates #3555

Draft
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

Sereza7
Copy link
Contributor

@Sereza7 Sereza7 commented Oct 11, 2024

Jira URL

https://jira.xwiki.org/browse/XWIKI-22433

Changes

Description

  • Updated all the vm hardcoded instances of colored message boxes
  • Updated the velocity macros to match the new kind of boxes and added a few to increase coverage and allow a correct conversion of hardcoded boxes.
  • Added a couple translations to populate the velocity macros.

Status

I made this table and categories with this order:

  • Contains a relevant instance of .<whatever>message. info--> warning -->error-->success
  • Github search order

(Table under the detail dropdown)

Part File Updated Self-reviewed
A styles.js
A LivedataFootnotes.vue
A passwd.vm
A changesdoc.vm
A loader.js
B extensionHistory.vm
B extension.vm
B distribution/macros.vm
B Extensions.xml
B Macros.xml
C Settings.xml
C OfficeImporterAdmin.xml
C LiveTableViewSheet.xml
C Admin.xml
C edit_macros.vm
D job_macros.vm
D children.vm
D import.js
D ExtensionBreakingQuestion.form.vm
D XClassBreakingQuestion.form.vm
E dashboard.js
E AttachmentGalleryPickerMacro.java
E OfficeImporter.xml
E XObjectDisplayerProvider.java
E CreateApplication.xml
F ClassEditSheet.xml
F CreateWiki.xml
F LiveTableEditSheet.xml
F flamingo/macros.vm
F editobject.vm
G job_status_json.vm
G uploadfailure.vm
G FilterStreamJobJSON.xml
G macroSelector.js
G macroEditor.js
H XWikiSkinsSheet.xml
H restore.vm
H AdminUsersSheet.xml
H InvitationCommon.xml
H ColorThemePropertyDisplayer.xml
I createinline.vm
I xwiki-office/plugin.js
I moveStatus.vm
I NotificationAlert.xml
I NotificationsMacro.xml
J VulnerabilityIndexer.java
J ConfigurableClass.xml
J flamingo/copy.vm
J templates/renameStatus.vm
J flamingo/renameStatus.vm

38 files updated.

Additional file changes

  • Application resources --> Contains a couple new keys to populate the velocity macros -- make them more consistent.
  • templates/macros.vm --> Contains the updated velocity macros to provide a macro for every situation.

2 files updated

38 + 2 => 40 files total

Screenshots & Video

The name of the file whose modifications are illustrated by the screenshots is above them. If there's only one screenshot, it's for the after state.

Invitations.xml
before
Screenshot from 2024-10-09 10-55-05
after
Screenshot from 2024-10-09 10-54-32

NotificationAlert.xml
Screenshot from 2024-10-09 16-39-46
moveStatus.vm
Screenshot from 2024-10-09 15-48-37
CreateWiki.xml
Screenshot from 2024-09-16 16-26-34
OfficeImporter.xml
Screenshot from 2024-09-16 13-46-43
flamingo/macros.vm
Screenshot from 2024-09-04 10-04-27

Executed Tests

Manual tests only. I did test most of the changes as much as I could on a local live instance. The changes are across a very large scope. From what I could see, adding a class to the item did not break docker tests.

Expected merging strategy

  • Prefers squash: Yes
  • Backport on branches:
    • None, relatively dangerous changes.

…es in templates

* Part B
* extensionHistory.vm
* extension.vm
* distribution/macros.vm
* template/macros.vm
* Extensions.xml
* AnnotationCode/Macros.xml
…es in templates

* Part C
* ExtensionSecurity/Admin.xml
* edit_macros.vm
* LiveTableViewSheet.xml
* OfficeImporterAdmin.xml
* Annotations/Settings.xml
…es in templates

* Part D
* job_macros.vm
* children.vm
* ExtensionBreakingQuestion.form.vm
* XClassBreakingQuestion.form.vm
…es in templates

* Misc - doubled icon regression
…es in templates

* Part E
* AttachmentGalleryPickerMacro.java fails with `You must inject a component role. Got [org.xwiki.rendering.internal.macro.message.WarningMessageMacro] at L.87`
…es in templates

* Part E
* OfficeImporter.xml
* XObjectDisplayerProvider.java (WIP)
* CreateApplication.xml
…es in templates

* Part F
* ClassEditSheet.xml
* CreateWiki.xml (partially tested)
* LiveTableEditSheet.xml
* macros.vm
* editobject.vm (WIP)
…es in templates

* Part G
* job_status_json.vm
* uploadfailure.vm
* FilterStreamJobJSON.xml
…es in templates

* Part J
* Added velocity macro to support the inline mode
@surli surli self-assigned this Oct 22, 2024
@@ -953,16 +953,44 @@ $html
### message
###

#macro(genericMessage $text $classAffix $iconName $prettyNameKey $isInline)
Copy link
Member

Choose a reason for hiding this comment

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

This is definitely missing some documentation: be aware that this macro will become public API. It needs docs, since etc. Unless you think it should only be internal, in which case it should be named _genericMessage. But still deserves doc.

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 2, 2024

Choose a reason for hiding this comment

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

Addressed in 6b9cce1 👍

$${\color{lightgreen}ADDRESSED}$$

&lt;div class="box errormessage xform"&gt;
{{/html}}

{{error cssClass="xform"}}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this xform here? for style only? My understanding is that the goal of the ticket was to simplify the usages of errormessage, so it feels a bit too complex than it should here?

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 2, 2024

Choose a reason for hiding this comment

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

Why do we need this xform here? for style only?

Yup, I want to minimize the changes in the actual content produced in order to minimize breaking customization and other features. I forgot the exact context here, but I don't want to break the form (style and functionality) just because I removed a class. Having this class is supported by the XWiki macro, so I figured it was okay to refactore things like that.

My understanding is that the goal of the ticket was to simplify the usages of errormessage

The goal of the PR is to factorize their code. This way, next time we update the message boxes, there won't be inconsistencies popping up everywhere (and this also fixes inconsistencies that popped up since we added icons with XWIKI-21452 :) ).
In order to do so, in all of the scripts here, I either use the new velocimacro, or the XWiki macro if possible.
$${\color{orange}ONGOING}$$

{{/html}}

{{error cssClass="xform"}}
{{html clean="false"}}
Copy link
Member

Choose a reason for hiding this comment

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

Hmm and why do we need the clean false here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right before starting the velocity macro, we closed the "current" html macro.
The only use of #maybeShowDeleteUserWarning is a few lines above, in #deleteUserModalContent. In this macro, we can see that the opening HTML block has the parameter clean="false". Since I do not want to break anything, the safest bet is to avoid cleaning the HTML in the content of the error XWiki macro too (It was already in a noncleaned HTML macro before).

Copy link
Member

Choose a reason for hiding this comment

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

the safest bet is to avoid cleaning the HTML in the content of the error XWiki macro too

that's a safest bet to avoid regression without performing a check, but I'm not sure it's a good solution or a good reflex to have: IMO using clean=false attribute in html macro should only be used for specific identified cases. It's quite possible I'm wrong, but I don't really see what we couldn't use clean true here. IMO it worth using clean true by default, and then checking manually the behaviour. Longer to test, for sure, but better for long term maintenance.

Copy link
Member

@tmortagne tmortagne Dec 3, 2024

Choose a reason for hiding this comment

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

Note that another potential reason to use clean="false" is performance, since the cleanup can be expensive.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm I didn't thought about that. Now I guess better be safe than fast in this specific condition? wdyt?

Copy link
Member

@tmortagne tmortagne Dec 4, 2024

Choose a reason for hiding this comment

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

Honestly, I don't have a strong opinion on either side. I guess it depends on how complex the content is and how often it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

File using clean="false" or clean=false position Modified Reason Step 1
AdminUsersSheet.xml inside macro content Yes (no reason found)
$${\color{red}TODO}$$
--
AdminUsersSheet.xml after macro content No backward compatibility of the maybeShowDeleteUserWarning velocimacro.
LiveTableEditSheet.xml inside macro content Yes (no reason found)
$${\color{red}TODO}$$
--
CreateWiki.xml before macro content ( x2 ) No We don't create HTML that is correct inside this macro alone (elements are opened but closed only in another HTML macro).
CreateWiki.xml after macro content ( x2 ) No We don't create HTML that is correct inside this macro alone (elements are not opened but closed only here).
InvitationCommon.xml inside macro content Yes, remove the HTML block
$${\color{lightgreen}Done}$$
This is not even HTML syntax (with standard values of translations)
InvitationCommon.xml after macro content Yes, but just add wiki=false
$${\color{lightgreen}Done}$$
We want to set the same HTML macro context as before the macro (see L133). In order to do so, we should have both wiki=false and clean=false
ExtensionBreakingQuestion.form.vm before macro content $${\color{lightgreen}Done}$$ We don't create HTML that is correct inside this macro alone (elements are opened but closed only in another HTML macro).
ExtensionBreakingQuestion.form.vm after macro content $${\color{lightgreen}Done}$$ We don't create HTML that is correct inside this macro alone (elements are not opened but closed only here)
ExtensionBreakingQuestion.form.vm inside macro content $${\color{lightgreen}Done}$$ --
XClassBreakingQuestion.form.vm before macro content $${\color{lightgreen}Done}$$ We don't create HTML that is correct inside this macro alone (elements are opened but closed only in another HTML macro).
XClassBreakingQuestion.form.vm after macro content $${\color{lightgreen}Done}$$ We don't create HTML that is correct inside this macro alone (elements are not opened but closed only here)
XClassBreakingQuestion.form.vm inside macro content $${\color{lightgreen}Done}$$ --

&lt;div class="box errormessage"&gt;$errorMessage&lt;/div&gt;
{{/html}}

{{error}}{{html clean="false"}}$errorMessage{{/html}}{/error}}
Copy link
Member

Choose a reason for hiding this comment

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

The clean false doesn't sound accurate here. I don't understand why we'd need it.

Copy link
Member

Choose a reason for hiding this comment

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

Also we probably miss escaping

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 2, 2024

Choose a reason for hiding this comment

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

The clean false doesn't sound accurate here. I don't understand why we'd need it.

The clean false was there before. I don't want to break things by removing it.

Also we probably miss escaping

We could add it 👍
This is a change unrelated to refactoring, I'll need to check that it doesn't break anything when adding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The clean false was there before. I don't want to break things by removing it.

I looked further to understand better what this $errorMessage is. It seems to have been copied from ClassEditSheet. The place where it was set in this other template is not anymore in this one, and AFAIU, it's always an empty value so the code we're updating is never reached.

IMO we could probably remove it without it impacting the result of this template in any meaningful way.

AFAICS the content of the errorMessage (if there's some) would be something similar to:
platform.appwithinminutes.classEditorDuplicateFieldNameError=The class has two fields with the same name: {0}. This is plain xwiki syntax, no specific HTML, so we can remove the HTML macro from here, just make sure we escape the translation for XML.

Addressed in 8d2d174 👍
$${\color{lightgreen}ADDRESSED}$$

#end
#info("$infoFooterContent
$formContent")
Copy link
Member

Choose a reason for hiding this comment

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

hmmm you should really add a comment if the carriage return is on purpose here

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 2, 2024

Choose a reason for hiding this comment

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

I just checked it again and it doesn't seem to me like this is needed. I just figured out it wouldn't hurt since it's HTML syntax, and it makes it a bit more readable.
$${\color{orange}ONGOING}$$

&lt;div class="box successmessage"&gt;
Done.
&lt;/div&gt;
#success('Done.')
Copy link
Member

Choose a reason for hiding this comment

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

We're missing translations in that file it seems. Might worth adding a comment / creating ticket if there's none.

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 3, 2024

Choose a reason for hiding this comment

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

Addressed in 87fe4a4 👍
$${\color{lightgreen}ADDRESSED}$$

* Note that the exact context this content is rendered in is not fixed, using the XWiki macro
* would have ended up in unstable behaviour.
*#
#macro (warningWithExtraClass $text $extraClass)
Copy link
Member

Choose a reason for hiding this comment

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

Preferable use name starting with _ if it's not supposed to become public. Now I'm a bit surprised that you don't need that elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I'm a bit surprised that you don't need that elsewhere.

It's the only place where both:

  • I couldn't make it work with XWiki Macro (I tried for an especially long time for this one ^^')
  • We needed the cssClass argument.

Since it's the only place with this very specific need, I figured it wasn't worth creating and exposing a cssClass argument for all the standard macros.
The extra CSS class, even when using XWiki Macro, is rarely used (at least in XWiki Standard).

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 3, 2024

Choose a reason for hiding this comment

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

Preferable use name starting with _ if it's not supposed to become public.

My bad, addressed in
f75a44c 👍

$${\color{lightgreen}ADDRESSED}$$

## TODO: we do not escape this string because we inject some HTML code. We should improve it.
$services.localization.render('admin.ooserver.options.source', ['&lt;span class="monospace"&gt;xwiki.properties&lt;/span&gt;'])
&lt;/span&gt;
## TODO: we do not escape this string because we inject some HTML code. We should improve it.
Copy link
Member

Choose a reason for hiding this comment

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

@michitux might be good to have your input on this...

Copy link
Contributor

Choose a reason for hiding this comment

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

We have the workaround that is quite verbose that you first get the translation with a parameter placeholder like __VALUE__, apply HTML escaping, and then replace that placeholder with the HTML. For a better solution, we're lacking the APIs that were discussed quite some time ago but not implemented yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 4b60a92 👍
Here is what this looks like on my local instance
image
$${\color{lightgreen}ADDRESSED}$$

@@ -17,15 +17,16 @@
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
## ---------------------------------------------------------------------------
##!source.syntax=xwiki/2.1
Copy link
Member

Choose a reason for hiding this comment

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

That's a big change... why exactly do you need that? Can't just use the velocity macros?

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 3, 2024

Choose a reason for hiding this comment

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

Where possible I wanted to still use the XWiki macro, which is still the most standard way. It looked like it was easy enough here to change the default syntax of this template and wrap most things in a velocity macro so that I could use the XWiki macro when needed.

I can revert those changes and use the velocimacro if you confirm that it'd be better 👍

Copy link
Member

@tmortagne tmortagne Dec 3, 2024

Choose a reason for hiding this comment

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

I don't have anything against moving to xwiki/2.1 in general, but you need to keep in mind that the behavior is very different, especially regarding dealing with new lines and stuff like this. It's most probably more dangerous than you think.

Copy link
Contributor Author

@Sereza7 Sereza7 Dec 9, 2024

Choose a reason for hiding this comment

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

Reverted the changes.
In order to use the velocimacro here, I had to upgrade the internal one to feature the two secondary parameters of the XWiki macro.

See changes in 161d3d0

Tested on a local instance:
Screenshot from 2024-12-09 16-06-46
$${\color{lightgreen}ADDRESSED}$$

@@ -17,15 +17,19 @@
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
## ---------------------------------------------------------------------------
##!source.syntax=xwiki/2.1
Copy link
Member

Choose a reason for hiding this comment

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

Same here, not a big fan of that move...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted it in 20b86ef 👍
$${\color{lightgreen}DONE}$$

Copy link
Member

@surli surli left a comment

Choose a reason for hiding this comment

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

Manual tests only. I did test most of the changes as much as I could on a local live instance. The changes are across a very large scope. From what I could see, adding a class to the item did not break docker tests.

Frankly given the size of the changes that's not enough. IMO you should at least perform following check:

  1. ensure that all tests in xwiki-platform-web are passing (we already have PageTests in there)
  2. ensure that all tests in xwiki-platform-flamingo-skin-test-docker are passing
  3. you performed changes in AWM / Administration / Extension: I would run the docker tests there too: it's a bit more optional but better be safe.

Not doing this means that there's a high risk we get CI failures and you need to urgently fix stuff...

…es in templates

* Updated the velociMacros
** Added comments on the message boxes macros.
** Set the genericMessage as an internal macro.
…es in templates

* Added a reference to the newly created issue for translations
…es in templates

* Set the warningWithExtraClass velocimacro as internal.
@@ -17,15 +17,16 @@
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
## ---------------------------------------------------------------------------
##!source.syntax=xwiki/2.1
{{velocity}}
#template('job/question/macros.vm')
Copy link
Member

Choose a reason for hiding this comment

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

If you move to wiki syntax, you should probably move to {{template name="job/question/macros.vm" output="false"/}} (but outside the Velocity macro IMO).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not an object anymore since I reverted those changes in regards to #3555 (comment)

$${\color{lightgreen}ADDRESSED}$$

@@ -17,15 +17,19 @@
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
## ---------------------------------------------------------------------------
##!source.syntax=xwiki/2.1
{{velocity}}
#template('job/question/macros.vm')

Copy link
Member

Choose a reason for hiding this comment

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

Those empty lines are going to cause actual, visual, new lines in the final HTML, which is not what you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your help on this. Mostly because of the dangerouseness you pointed out, I decided to revert my changes on both these files and go with the alternative solution of upgrading the velocimacro.
See more at #3555 (comment)

$${\color{lightgreen}ADDRESSED}$$

…es in templates

* Part C
* Removed the TODO and implemented the solution described by Michael
…es in templates

* Fixed an inconsistency in the velocimacro compared to the XWiki macro.
@Sereza7 Sereza7 marked this pull request as draft December 9, 2024 13:15
…es in templates

* Part F
* Escaped the errorMessage
* removed the useless HTML macro.
…es in templates

* Part D
* Updated the internal velocimacro to also take into account equivalents to rarely used XWikiMacro parameters.
…es in templates

* Part D
* Reverted the change of syntax for XClassBreakingQuestion.form.vm
…es in templates

* Fixed changes unrelated to the ticket for this PR.
…es in templates

* Fixed incorrect HTML context in the content of the error macro.
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.

4 participants