Skip to content

Commit

Permalink
LPD-16000 Make sure to check supplier order
Browse files Browse the repository at this point in the history
  • Loading branch information
dsitu authored and brianchandotcom committed Feb 8, 2024
1 parent 75c39ea commit 5340196
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.liferay.commerce.model.CommerceOrder;
import com.liferay.commerce.product.model.CommerceChannel;
import com.liferay.commerce.product.service.CommerceChannelLocalService;
import com.liferay.commerce.service.CommerceOrderLocalService;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.configuration.module.configuration.ConfigurationProvider;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class CommerceOrderModelResourcePermissionLogic
public CommerceOrderModelResourcePermissionLogic(
AccountEntryLocalService accountEntryLocalService,
CommerceChannelLocalService commerceChannelLocalService,
CommerceOrderLocalService commerceOrderLocalService,
ConfigurationProvider configurationProvider,
GroupLocalService groupLocalService,
PortletResourcePermission portletResourcePermission,
Expand All @@ -49,6 +51,7 @@ public CommerceOrderModelResourcePermissionLogic(

_accountEntryLocalService = accountEntryLocalService;
_commerceChannelLocalService = commerceChannelLocalService;
_commerceOrderLocalService = commerceOrderLocalService;
_configurationProvider = configurationProvider;
_groupLocalService = groupLocalService;
_portletResourcePermission = portletResourcePermission;
Expand Down Expand Up @@ -476,23 +479,17 @@ private boolean _hasRoleAccountSupplier(
PermissionChecker permissionChecker, CommerceOrder commerceOrder)
throws PortalException {

CommerceChannel commerceChannel =
_commerceChannelLocalService.fetchCommerceChannelByGroupClassPK(
commerceOrder.getGroupId());

if ((commerceChannel != null) &&
(commerceChannel.getAccountEntryId() == 0)) {

return false;
}

List<AccountEntry> accountEntries =
_accountEntryLocalService.getUserAccountEntries(
permissionChecker.getUserId(), 0L, StringPool.BLANK,
new String[] {AccountConstants.ACCOUNT_ENTRY_TYPE_SUPPLIER},
QueryUtil.ALL_POS, QueryUtil.ALL_POS);

for (AccountEntry accountEntry : accountEntries) {
CommerceChannel commerceChannel =
_commerceChannelLocalService.fetchCommerceChannelByGroupClassPK(
commerceOrder.getGroupId());

if ((accountEntry.getAccountEntryId() ==
commerceChannel.getAccountEntryId()) &&
_userGroupRoleLocalService.hasUserGroupRole(
Expand All @@ -502,13 +499,37 @@ private boolean _hasRoleAccountSupplier(

return true;
}

for (long commerceOrderIds :
commerceOrder.getSupplierCommerceOrderIds()) {

CommerceOrder supplierCommerceOrder =
_commerceOrderLocalService.getCommerceOrder(
commerceOrderIds);

commerceChannel =
_commerceChannelLocalService.
fetchCommerceChannelByGroupClassPK(
supplierCommerceOrder.getGroupId());

if ((accountEntry.getAccountEntryId() ==
commerceChannel.getAccountEntryId()) &&
_userGroupRoleLocalService.hasUserGroupRole(
permissionChecker.getUserId(),
accountEntry.getAccountEntryGroupId(),
AccountRoleConstants.ROLE_NAME_ACCOUNT_SUPPLIER)) {

return true;
}
}
}

return false;
}

private final AccountEntryLocalService _accountEntryLocalService;
private final CommerceChannelLocalService _commerceChannelLocalService;
private final CommerceOrderLocalService _commerceOrderLocalService;
private final ConfigurationProvider _configurationProvider;
private final GroupLocalService _groupLocalService;
private final PortletResourcePermission _portletResourcePermission;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public class CommerceOrderModelResourcePermissionWrapper
consumer.accept(
new CommerceOrderModelResourcePermissionLogic(
_accountEntryLocalService, _commerceChannelLocalService,
_configurationProvider, _groupLocalService,
_portletResourcePermission, _userGroupRoleLocalService,
_commerceOrderLocalService, _configurationProvider,
_groupLocalService, _portletResourcePermission,
_userGroupRoleLocalService,
_workflowDefinitionLinkLocalService));
});
}
Expand Down

0 comments on commit 5340196

Please sign in to comment.