Skip to content

Commit

Permalink
fix: accessControl fields should exist in database
Browse files Browse the repository at this point in the history
- fix 3.8 migration script
- add null checks to prevent NPE

gravitee-io/issues#8320
  • Loading branch information
phiz71 committed Aug 16, 2022
1 parent 2c6d772 commit ff1872e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
Expand Up @@ -12,3 +12,11 @@ pages.find({ excluded_groups: { $exists: true, $not: { $size: 0 } } }).forEach((
pages.replaceOne({ _id: page._id }, page);
}
);

pages.updateMany(
{ accessControls: { $exists: false } },
{ $set: { excludedAccessControls: false, accessControls: [] } },
{
upsert: false,
}
);
Expand Up @@ -702,22 +702,24 @@ private void removeGroupFromPages(String groupId, Date updatedDate, String apiId
}
final List<Page> apiPages = this.pageRepository.search(criteriaBuilder.build());
for (Page page : apiPages) {
Set<AccessControl> accessControlsToRemove = page
.getAccessControls()
.stream()
.filter(
accessControl ->
(
AccessControlReferenceType.GROUP.name().equals(accessControl.getReferenceType()) &&
accessControl.getReferenceId().equals(groupId)
)
)
.collect(Collectors.toSet());
if (page.getAccessControls() != null) {
Set<AccessControl> accessControlsToRemove = page
.getAccessControls()
.stream()
.filter(
accessControl ->
(
AccessControlReferenceType.GROUP.name().equals(accessControl.getReferenceType()) &&
accessControl.getReferenceId().equals(groupId)
)
)
.collect(Collectors.toSet());

if (!accessControlsToRemove.isEmpty()) {
page.setUpdatedAt(updatedDate);
page.getAccessControls().removeAll(accessControlsToRemove);
this.pageRepository.update(page);
if (!accessControlsToRemove.isEmpty()) {
page.setUpdatedAt(updatedDate);
page.getAccessControls().removeAll(accessControlsToRemove);
this.pageRepository.update(page);
}
}
}
} catch (TechnicalException ex) {
Expand Down
Expand Up @@ -2261,12 +2261,16 @@ private PageEntity convert(Page page) {
pageEntity.setAccessControls(PageServiceImpl.convertToEntities(page.getAccessControls()));

if (page.isExcludedAccessControls() && Visibility.PRIVATE.name().equals(page.getVisibility())) {
List<String> excludedGroups = page
.getAccessControls()
.stream()
.filter(accessControl -> AccessControlReferenceType.GROUP.name().equals(accessControl.getReferenceType()))
.map(accessControl -> accessControl.getReferenceId())
.collect(toList());
List<String> excludedGroups = emptyList();
if (page.getAccessControls() != null) {
excludedGroups =
page
.getAccessControls()
.stream()
.filter(accessControl -> AccessControlReferenceType.GROUP.name().equals(accessControl.getReferenceType()))
.map(accessControl -> accessControl.getReferenceId())
.collect(toList());
}
pageEntity.setExcludedGroups(excludedGroups);
}

Expand Down

0 comments on commit ff1872e

Please sign in to comment.