Skip to content

OBGM-551 Unable to Place PO#4129

Merged
awalkowiak merged 2 commits intofeature/upgrade-to-grails-3.3.10from
OBGM-551
Jun 30, 2023
Merged

OBGM-551 Unable to Place PO#4129
awalkowiak merged 2 commits intofeature/upgrade-to-grails-3.3.10from
OBGM-551

Conversation

@alannadolny
Copy link
Collaborator

Roles passed from the application.yaml weren't properly compared with the values from getEffectiveRoles(user) (it always returned false, so we didn't have appropriate privileges to perform actions).

boolean canApproveOrder(Order order, User userInstance) {
if (isApprovalRequired(order)) {
List<RoleType> defaultRoleTypes = grailsApplication.config.openboxes.purchasing.approval.defaultRoleTypes
.collect { RoleType."$it" }
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 first try to define it as defaultRoleTypes: [org.pih.warehouse.core.RoleType.ROLE_APPROVER] instead of "ROLE_APPROVER" in the application.yml? If that will work this should be the change. Otherwise, if that won't work, then I think we should discuss it in the tech huddle. The change to string in the applicaiton.yml was a quick temporary hotfix.

Copy link
Member

Choose a reason for hiding this comment

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

Also, if that does not work I recommend we change the enum lookup from

RoleType."$it"

to

RoleType.valueOf(it)

Copy link
Member

Choose a reason for hiding this comment

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

Actually an even better way to do this would be to use the approach suggested here https://grails.org/blog/2016-08-31.html

Either inject the value into the class

@Value('${openboxes.purchasing.approval.defaultRoleTypes:[RoleType.ROLE_APPROVER]}')
List<RoleType> defaultRoleTypes

or pull the property from the config object

List<RoleType> defaultRoleTypes = grailsApplication.config.getProperty("openboxes.purchasing.approval.defaultRoleTypes", List, [RoleType.ROLE_APPROVER])

Unfortunately neither of these approaches seem to coerce the object into the proper type List.

So let's just use the collect { return RoleType.valueOf(it) } approach.

boolean canApproveOrder(Order order, User userInstance) {
if (isApprovalRequired(order)) {
List<RoleType> defaultRoleTypes = grailsApplication.config.openboxes.purchasing.approval.defaultRoleTypes
.collect { RoleType."$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, if that does not work I recommend we change the enum lookup from

RoleType."$it"

to

RoleType.valueOf(it)

@alannadolny alannadolny requested a review from awalkowiak June 30, 2023 09:06
@awalkowiak awalkowiak merged commit d14c1e8 into feature/upgrade-to-grails-3.3.10 Jun 30, 2023
@awalkowiak awalkowiak deleted the OBGM-551 branch June 30, 2023 09:28
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