Merge remote-tracking branch 'origin/master' into production

This commit is contained in:
Konstantinos Triantafyllou 2024-06-03 12:30:17 +03:00
commit 26c1b51adc
13 changed files with 87 additions and 67 deletions

View File

@ -29,7 +29,7 @@
<dependency> <!-- this dependency includes dependency to uoa-authorization-library -->
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-admin-tools-library</artifactId>
<version>1.0.10</version>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>

View File

@ -234,8 +234,6 @@ function uniqueIndexes() {
db.stakeholder.createIndex( { "alias": 1 }, { unique: true } );
}
// use monitordb;
upperCaseEnumValues();
addHeightInIndicators();
addVisibility();

View File

@ -52,8 +52,6 @@ function addFooterHelpTextForPortalType(portalType) {
}
}
// use monitordb;
addHomePageInPortalType("funder");
addFooterDivIdForPortalType("funder");
addFooterHelpTextForPortalType("funder");

View File

@ -176,7 +176,5 @@ function addFundingStreamInDefaultMSCA() {
}
}
// use monitordb;
statsProfileOfIndicatorsAsVariable();
addFundingStreamInDefaultMSCA();

View File

@ -12,5 +12,12 @@ function deleteIndexParameters() {
})
}
// use irish-prod;
function addCopyWithDefaultValue() {
/* Set default profiles with copy: false */
db.stakeholder.updateMany({defaultId: null, copy: {$exists: false}}, {$set: {copy: false}});
/* Set not default profiles with copy: true */
db.stakeholder.updateMany({defaultId: {$ne: null}, copy: {$exists: false}}, {$set: {copy: true}});
}
deleteIndexParameters();
addCopyWithDefaultValue();

View File

@ -1,13 +1,12 @@
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
import eu.dnetlib.uoamonitorservice.dto.copy;
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
import eu.dnetlib.uoamonitorservice.dto.copy;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import eu.dnetlib.uoamonitorservice.service.CommonService;
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -16,7 +15,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@CrossOrigin(origins = "*")
@ -25,11 +23,13 @@ public class StakeholderController {
private final PortalService portalService;
private final StakeholderService stakeholderService;
private final CommonService commonService;
@Autowired
public StakeholderController(PortalService portalService, StakeholderService stakeholderService) {
public StakeholderController(PortalService portalService, StakeholderService stakeholderService, CommonService commonService) {
this.portalService = portalService;
this.stakeholderService = stakeholderService;
this.commonService = commonService;
}
@PreAuthorize("isAuthenticated()")
@ -89,7 +89,7 @@ public class StakeholderController {
public StakeholderFull getStakeholder(@PathVariable("alias") String alias) {
StakeholderFull stakeholder = this.stakeholderService.getFullStakeholder(this.stakeholderService.findByAlias(alias));
if (stakeholder == null) {
throw new ForbiddenException("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
this.commonService.unauthorized("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
}
return stakeholder;
}

View File

@ -102,7 +102,7 @@ public class CategoryService {
this.updateChildren(category);
category = this.save(category);
} else {
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -113,7 +113,7 @@ public class CategoryService {
}
this.addCategory(topic, category.getId());
} else {
throw new ForbiddenException("You are not authorized to create a category in stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to create a category in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category);
@ -145,8 +145,9 @@ public class CategoryService {
throw new EntityNotFoundException("Some subCategories dont exist in the category with id " + category.getId());
}
} else {
throw new ForbiddenException("You are not authorized to reorder subCategories in category with id: " + category.getId());
this.commonService.unauthorized("You are not authorized to reorder subCategories in category with id: " + category.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, Category defaultCategory, List<String> defaultSubCategories) {
@ -171,7 +172,7 @@ public class CategoryService {
}
this.dao.delete(category);
} else {
throw new ForbiddenException("Delete category: You are not authorized to delete category with id: " + category.getId());
this.commonService.unauthorized("Delete category: You are not authorized to delete category with id: " + category.getId());
}
}
@ -205,8 +206,9 @@ public class CategoryService {
category.update(this.save(new Category(category)));
return category;
} else {
throw new ForbiddenException("Change category visibility: You are not authorized to update category with id: " + category.getId());
this.commonService.unauthorized("Change category visibility: You are not authorized to update category with id: " + category.getId());
}
return null;
}
public CategoryFull changeVisibility(String type, String alias, Category category, Visibility visibility, Boolean propagate) {

View File

@ -1,5 +1,7 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.handlers.UnauthorizedException;
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
import eu.dnetlib.uoamonitorservice.generics.Common;
@ -69,4 +71,12 @@ public class CommonService {
});
return ids;
}
public void unauthorized(String message) {
if(authorizationService.getAaiId() != null) {
throw new ForbiddenException(message);
} else {
throw new UnauthorizedException(message);
}
}
}

View File

@ -1,6 +1,5 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.entities.Section;
@ -82,7 +81,7 @@ public class IndicatorService {
this.updateChildren(indicator);
indicator = this.save(indicator);
} else {
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -90,7 +89,7 @@ public class IndicatorService {
this.createChildren(section, indicator);
this.addIndicator(section, indicator.getId());
} else {
throw new ForbiddenException("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
}
}
return indicator;
@ -128,7 +127,7 @@ public class IndicatorService {
}
this.dao.delete(indicator);
} else {
throw new ForbiddenException("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
this.commonService.unauthorized("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
}
}
@ -157,7 +156,8 @@ public class IndicatorService {
indicator.setVisibility(visibility);
return this.save(indicator);
} else {
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
}
return null;
}
}

View File

@ -103,7 +103,7 @@ public class SectionService {
this.createChildren(subCategory, new Section(section), -1);
});
} else {
throw new ForbiddenException("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
}
}
@ -115,7 +115,7 @@ public class SectionService {
this.updateChildren(section);
section = this.save(section);
} else {
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -123,7 +123,7 @@ public class SectionService {
this.createChildren(subCategory, section, index);
this.addSection(subCategory, section.getId(), index);
} else {
throw new ForbiddenException("You are not authorized to create a section in stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to create a section in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section);
@ -168,8 +168,9 @@ public class SectionService {
throw new EntityNotFoundException("Some indicators dont exist in the section with id " + section.getId());
}
} else {
throw new ForbiddenException("You are not authorized to reorder indicators in section with id: " + section.getId());
this.commonService.unauthorized("You are not authorized to reorder indicators in section with id: " + section.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, Section defaultSection, List<String> defaultIndicators) {
@ -194,7 +195,7 @@ public class SectionService {
}
this.dao.delete(section);
} else {
throw new ForbiddenException("Delete section: You are not authorized to delete section with id: " + section.getId());
this.commonService.unauthorized("Delete section: You are not authorized to delete section with id: " + section.getId());
}
}
@ -238,7 +239,8 @@ public class SectionService {
section.update(this.save(new Section(section)));
return section;
} else {
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + section.getId());
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + section.getId());
}
return null;
}
}

View File

@ -40,7 +40,7 @@ public class StakeholderService {
}
public Stakeholder findByPath(String stakeholderId) {
if(stakeholderId.equals("-1")) {
if (stakeholderId.equals("-1")) {
return null;
}
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
@ -81,10 +81,9 @@ public class StakeholderService {
}
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
if (this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder)) {
if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
if(defaultStakeholder != null) {
if (defaultStakeholder != null) {
return new StakeholderFull(stakeholder,
defaultStakeholder.getTopics().stream()
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
@ -95,15 +94,12 @@ public class StakeholderService {
stakeholder.getTopics().stream()
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
.collect(Collectors.toList()));
} else {
return null;
}
}
public Stakeholder buildStakeholder(Stakeholder stakeholder, String copyId) {
if(stakeholder.getDefaultId() == null) {
if (stakeholder.getDefaultId() == null) {
stakeholder.setCopy(false);
if(copyId == null) {
if (copyId == null) {
stakeholder.setTopics(new ArrayList<>());
} else {
Stakeholder copyFrom = this.findByPath(copyId);
@ -111,9 +107,9 @@ public class StakeholderService {
}
} else {
stakeholder.setTopics(new ArrayList<>());
if(stakeholder.isCopy()) {
if (stakeholder.isCopy()) {
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
if(defaultStakeholder != null) {
if (defaultStakeholder != null) {
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
}
}
@ -131,9 +127,9 @@ public class StakeholderService {
});
stakeholder.setTopics(new ArrayList<>());
} else {
if(old.getTopics().isEmpty() && old.getDefaultId() != null) {
if (old.getTopics().isEmpty() && old.getDefaultId() != null) {
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
if(defaultStakeholder != null) {
if (defaultStakeholder != null) {
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
}
}
@ -158,8 +154,9 @@ public class StakeholderService {
throw new EntityNotFoundException("Some topics dont exist in the stakeholder with id " + stakeholder.getId());
}
} else {
throw new ForbiddenException("You are not authorized to reorder topics in stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to reorder topics in stakeholder with id: " + stakeholder.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, List<String> defaultTopics) {
@ -181,8 +178,9 @@ public class StakeholderService {
this.dao.delete(id);
return stakeholder.getAlias();
} else {
throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
this.commonService.unauthorized("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
}
return null;
}
public StakeholderFull changeVisibility(StakeholderFull stakeholder, Visibility visibility, Boolean propagate) {
@ -196,8 +194,9 @@ public class StakeholderService {
stakeholder.update(this.save(new Stakeholder(stakeholder)));
return stakeholder;
} else {
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
return null;
}
public StakeholderFull changeVisibility(Stakeholder stakeholder, Visibility visibility, Boolean propagate) {

View File

@ -112,7 +112,7 @@ public class SubCategoryService {
this.updateChildren(subCategory);
subCategory = this.save(subCategory);
} else {
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -120,7 +120,7 @@ public class SubCategoryService {
this.createChildren(category, subCategory);
this.addSubCategory(category, subCategory.getId());
} else {
throw new ForbiddenException("You are not authorized to create a subCategory in stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to create a subCategory in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
@ -153,8 +153,9 @@ public class SubCategoryService {
this.moveIndicatorChildren(stakeholder, subCategory, moveIndicator);
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
} else {
throw new ForbiddenException("You are not authorized to move indicators in subCategory with id: " + subCategory.getId());
this.commonService.unauthorized("You are not authorized to move indicators in subCategory with id: " + subCategory.getId());
}
return null;
}
public void moveIndicatorChildren(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, MoveIndicator moveIndicator) {
@ -191,8 +192,9 @@ public class SubCategoryService {
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
}
} else {
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
this.commonService.unauthorized("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
}
return null;
}
public SubCategoryFull reorderCharts(Stakeholder stakeholder, SubCategory subCategory, List<String> charts) {
@ -206,8 +208,9 @@ public class SubCategoryService {
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
}
} else {
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
this.commonService.unauthorized("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
}
return null;
}
public void reorderChildrenNumbers(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List<String> defaultSections) {
@ -245,7 +248,7 @@ public class SubCategoryService {
}
this.dao.delete(subCategory);
} else {
throw new ForbiddenException("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
this.commonService.unauthorized("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
}
}
@ -282,8 +285,9 @@ public class SubCategoryService {
subCategory.update(this.save(new SubCategory(subCategory)));
return subCategory;
} else {
throw new ForbiddenException("Change subCategory visibility: You are not authorized to update subCategory with id: " + subCategory.getId());
this.commonService.unauthorized("Change subCategory visibility: You are not authorized to update subCategory with id: " + subCategory.getId());
}
return null;
}
public SubCategoryFull changeVisibility(String type, String alias, SubCategory subCategory, Visibility visibility, Boolean propagate) {

View File

@ -94,7 +94,7 @@ public class TopicService {
this.updateChildren(topic);
topic = this.save(topic);
} else {
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if(this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -102,7 +102,7 @@ public class TopicService {
this.createChildren(stakeholder, topic);
this.addTopic(stakeholder, topic.getId());
} else {
throw new ForbiddenException("You are not authorized to create a topic in stakeholder with id: " + stakeholder.getId());
this.commonService.unauthorized("You are not authorized to create a topic in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic);
@ -132,8 +132,9 @@ public class TopicService {
throw new EntityNotFoundException("Some categories dont exist in the topic with id " + topic.getId());
}
} else {
throw new ForbiddenException("You are not authorized to reorder categories in topic with id: " + topic.getId());
this.commonService.unauthorized("You are not authorized to reorder categories in topic with id: " + topic.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, Topic defaultTopic, List<String> defaultCategories) {
@ -158,7 +159,7 @@ public class TopicService {
}
this.dao.delete(topic);
} else {
throw new ForbiddenException("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
this.commonService.unauthorized("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
}
}
@ -192,8 +193,9 @@ public class TopicService {
topic.update(this.save(new Topic(topic)));
return topic;
} else {
throw new ForbiddenException("Change topic visibility: You are not authorized to update topic with id: " + topic.getId());
this.commonService.unauthorized("Change topic visibility: You are not authorized to update topic with id: " + topic.getId());
}
return null;
}
public TopicFull changeVisibility(String type, String alias, Topic topic, Visibility visibility, Boolean propagate) {