Skip to content

Commit

Permalink
fix: hibernate lazyloading exception on resource-child
Browse files Browse the repository at this point in the history
  • Loading branch information
StephGit committed Dec 24, 2024
1 parent 2781c58 commit 2649d0d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AMW_angular/io/src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class AuthService extends BaseService {
return (
this.restrictions()
.filter((entry) => entry.permission.name === permissionName)
.filter((entry) => entry.resourceGroupId === resourceGroupId)
.filter((entry) => entry.resourceGroupId === resourceGroupId || entry.resourceGroupId === null)
.map((entry) => entry.action)
.find((entry) => entry === Action.ALL || entry === action) !== undefined
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ResourceEditFunctionsComponent {
});

permissions = computed(() => {
if (this.authService.restrictions().length > 0) {
if (this.authService.restrictions().length > 0 && this.resource()) {
return {
canShowInstanceFunctions: this.authService.hasPermission(RESOURCE_PERM, Action.READ),
canShowSuperTypeFunctions: this.authService.hasPermission(RESOURCETYPE_PERM, Action.READ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
import ch.puzzle.itc.mobiliar.business.security.interceptor.HasPermission;
import ch.puzzle.itc.mobiliar.business.utils.Identifiable;
import ch.puzzle.itc.mobiliar.common.exception.NotFoundException;
import org.hibernate.Hibernate;

import javax.inject.Inject;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static ch.puzzle.itc.mobiliar.business.security.entity.Action.READ;

public class FunctionService implements GetFunctionUseCase, ListFunctionsUseCase {
public class FunctionService implements Serializable, GetFunctionUseCase, ListFunctionsUseCase {

@Inject
FunctionRepository functionRepository;
Expand Down Expand Up @@ -89,6 +91,10 @@ public List<AmwFunctionEntity> getAllOverwritableSupertypeFunctions(ResourceType
private Map<String, AmwFunctionEntity> getAllTypeAndSuperTypeFunctions(ResourceTypeEntity resourceTypeEntity) {
Map<String, AmwFunctionEntity> superTypeFunctions = new LinkedHashMap<>();
if (resourceTypeEntity != null) {
if (!Hibernate.isInitialized(resourceTypeEntity.getFunctions())) {
resourceTypeEntity = resourceTypeRepository.loadWithFunctionsAndMiksForId(resourceTypeEntity.getId());
}

for (AmwFunctionEntity function : resourceTypeEntity.getFunctions()) {
AmwFunctionEntity functionWithMik = functionRepository.getFunctionByIdWithMiksAndParentChildFunctions(function.getId());
superTypeFunctions.put(function.getName(), functionWithMik);
Expand Down

0 comments on commit 2649d0d

Please sign in to comment.