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

OBPIH-5768 Add request approval supported activity to the Location do… #4277

Merged
merged 6 commits into from
Sep 15, 2023

Conversation

kchelstowski
Copy link
Collaborator

…main

Either can be merged and for now use ROLE_APPOVER for user to check if it works fine, or do not merge and wait for the OBPIH-5799 to replace the role with REQUEST_APPROVER or whatever it will be.

// Don't allow to set REQUEST_APPROVAL activity if there are not any users that
// have Request Approver location role for this location
// TODO: Replace ROLE_APPROVER with the ROLE_REQUEST_APPROVER when OBPIH-5799 is done
if (activities?.contains(ActivityCode.REQUEST_APPROVAL.id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was it meant to be a validator? I thought it was a message to inform the user that he has to do this after adding this supported activity to the location

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I apologize, I was confused because of many different versions that we were speaking about, but I've consulted with Katarzyna and she confirmed this could be just a message, not a validation.
I fixed that part.

@@ -64,7 +64,9 @@ enum ActivityCode {

AUTOSAVE('AUTOSAVE'),

NONE('NONE')
NONE('NONE'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you put it at the end?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved

@@ -114,6 +114,10 @@ class LocationController {
}
flash.message = "${warehouse.message(code: 'default.updated.message', args: [warehouse.message(code: 'location.label', default: 'Location'), locationInstance.id])}"

if (locationInstance.supportedActivities.contains(ActivityCode.REQUEST_APPROVAL.id)) {
flash.message += " ${g.message(code: 'location.supportedActivities.noRequestApprovers', default: 'You must add one or several Approvers to the location to support the requests approval workflow. Go to users list to add an Approver.')}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you confirm that the component where flash.message is rendered does not render HTML?
Because my first thought was to have a messages.properties label

location.supportedActivities.noRequestApprovers=You must add one or several Approvers to the location to support the requests approval workflow. Go to <a href="{0}">users list</a> to add an Approver.

and inject the link with an argument

 flash.message += " ${g.message(code: 'location.supportedActivities.noRequestApprovers', default: 'You must add one or several Approvers to the location to support the requests approval workflow. Go to users list to add an Approver.', args: ["https://somelink...."])}"

Comment on lines 115 to 116
flash.message = []
flash.message.add([code: 'default.updated.message', args: [warehouse.message(code: 'location.label', default: 'Location'), locationInstance.id]])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can it be done without initializing empty array? I mean merging those two lines into one:

flash.message = [[code: 'default.updated.message', args: [warehouse.message(code: 'location.label', default: 'Location'), locationInstance.id]]]

<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
<g:renderMessage />
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this solution since rendering messages with HTML tags doesn't work well in Grails 1. The first situation that came to my mind was the message after logging in with incorrect credentials. (This message works on Grails 3 - the same code, without any changes) 👍👍

* by default takes the value stored in flash.message.
* accepts data like: String, List<String>, Map<code: string, args: obj>, List<Map<code: string, args: obj>>
*/
class RenderMessageTagLib {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@drodzewicz I am not sure if this is a good place for this tag lib (if there is need for a new tag lib). I wonder if this rather should be in the MessageTagLib.

@@ -1456,6 +1457,7 @@ location.bgColor.label=Background color
location.fgColor.label=Foreground color
location.bgColor.invalid.matchingcolor=Colors cannot be the same
location.supportedActivities.invalid.supportedActivities=You cannot set supported activity NONE in combination with other supported activities
location.supportedActivities.noRequestApprovers=You must add one or several Approvers to the location to support the requests approval workflow. Go to <a href="{0}">users list</a> to add an Approver.
Copy link
Member

Choose a reason for hiding this comment

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

"one or more approvers to the location to support the requisition approval workflow."

<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
<warehouse:renderMessage />
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain the reason for this?

Copy link
Member

Choose a reason for hiding this comment

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

Using a join(".") in the controller might allow us to avoid this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you explain the reason for this?

The reason for that was to be able to include a link inside the message. This has nothing to do with the dot.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The reason behind creating this taglib util function for rendering messages is because when translating labels in the controller and passing them using flash.messages it would either escape the HTML or render the HTML as a string.

So as a solution we want to pass to the flash.message all of the arguments needed for rendering the translated label and let the g.message handle the rendering.

I implemented this <warehouse:renderMessage /> taglib function in a way so it would be possible to render either a single message or a list of messages.
We can also both pass a normal string or, as I mentioned before, all of the arguments for rendering message.properties labels like code, args, default

@@ -589,7 +589,7 @@ default.qtyPerUom.label=Qty per UoM
default.pricePerUom.label=Price per UoM
default.upload.label=Upload {0}
default.uploaded.message={0} uploaded
default.updated.message={0} updated
default.updated.message={0} updated.
Copy link
Member

Choose a reason for hiding this comment

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

Periods. We don't need no stinkin' periods.

image

]
if (locationInstance.supportedActivities.contains(ActivityCode.REQUEST_APPROVAL.id)) {
flash.message.add([code: 'location.supportedActivities.noRequestApprovers', args: [g.createLink(controller: "user", action: "list")]])
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding a period to the message, just add a join(".") here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The comma isn't necessary anymore since the message is rendered in the new line like
image

Previously @kchelstowski must have added the comma to separate both messages since they were rendered in the same line.

@@ -64,6 +64,8 @@ enum ActivityCode {

AUTOSAVE('AUTOSAVE'),

REQUEST_APPROVAL('REQUEST_APPROVAL'),
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we use APPROVE_REQUEST above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly I have not seen this before. I checked it and it seems to be existing, but not having any effect 🤔 so we could potentially use it.
It's also displayed as Approve requisition - I saw your comments in @alannadolny 's ticket and I am a bit confused. In tickets it was supposed to be named with "Request" and you suggest that it should be "Requisition" instead of "Request".
So would it mean this activity code should be also renamed from APPROVE_REQUEST to APPROVE_REQUISITION?

I think we should not mix "Requisition" and "Request", so the question is, what is the path we want to follow?

Copy link
Collaborator

@awalkowiak awalkowiak left a comment

Choose a reason for hiding this comment

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

@drodzewicz There are still some pending requests (If everything is fixed, @kchelstowski you have green light to merge this one)

@awalkowiak awalkowiak merged commit 19bf7ec into develop Sep 15, 2023
3 checks passed
@awalkowiak awalkowiak deleted the OBPIH-5798 branch September 15, 2023 12:05
kchelstowski added a commit that referenced this pull request Oct 31, 2023
#4277)

* OBPIH-5768 Add request approval supported activity to the Location domain

* OBPIH-5798 Remove validation for request approval supported activity, and instead return an information message

* OBPIH-5798 Render list of messages using flash.messages

* OBPIH-5798 Create RenderMessageTagLib which handles rendering of messages passed by flash.message

* OBPIH-5798 Move renderMessage to MessageTagLib

* OBPIH-5798 Use APPROVE_REQUEST Activity code instead of REQUEST_APPROVAL

---------

Co-authored-by: Darek Rodzewicz <DRodzewicz@gmail.com>
(cherry picked from commit 19bf7ec)
jmiranda added a commit that referenced this pull request Nov 1, 2023
…APPROVE_REQUEST activity (#4364)

* OBPIH-5768 Add request approval supported activity to the Location do… (#4277)

* OBPIH-5768 Add request approval supported activity to the Location domain

* OBPIH-5798 Remove validation for request approval supported activity, and instead return an information message

* OBPIH-5798 Render list of messages using flash.messages

* OBPIH-5798 Create RenderMessageTagLib which handles rendering of messages passed by flash.message

* OBPIH-5798 Move renderMessage to MessageTagLib

* OBPIH-5798 Use APPROVE_REQUEST Activity code instead of REQUEST_APPROVAL

---------

Co-authored-by: Darek Rodzewicz <DRodzewicz@gmail.com>
(cherry picked from commit 19bf7ec)

* OBGM-714 Fixed i18n code used to alert user to add approvers (cherry-picked re: OBPIH-5768)

* OBGM-714 Removed unnecessary newline

---------

Co-authored-by: jmiranda <jcm62@columbia.edu>
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.

None yet

5 participants