1. clone public plan and description
2. fixed orcid links on public entities
This commit is contained in:
parent
f4ff317c68
commit
50e38c6854
|
@ -15,6 +15,9 @@ public final class Permission {
|
||||||
public static String PublicBrowseDashboardStatistics = "PublicBrowseDashboardStatistics";
|
public static String PublicBrowseDashboardStatistics = "PublicBrowseDashboardStatistics";
|
||||||
public static String PublicSendContactSupport = "PublicSendContactSupport";
|
public static String PublicSendContactSupport = "PublicSendContactSupport";
|
||||||
public static String PublicBrowseReferenceType = "PublicBrowseReferenceType";
|
public static String PublicBrowseReferenceType = "PublicBrowseReferenceType";
|
||||||
|
public static String PublicClonePlan = "PublicClonePlan";
|
||||||
|
public static String PublicCloneDescription = "PublicCloneDescription";
|
||||||
|
|
||||||
//Elastic
|
//Elastic
|
||||||
public static String ManageElastic = "ManageElastic";
|
public static String ManageElastic = "ManageElastic";
|
||||||
//Queue Events
|
//Queue Events
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.opencdmp.model;
|
package org.opencdmp.model;
|
||||||
|
|
||||||
|
import org.opencdmp.commons.enums.ReferenceSourceType;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PublicReference {
|
public class PublicReference {
|
||||||
|
@ -19,6 +21,13 @@ public class PublicReference {
|
||||||
private String reference;
|
private String reference;
|
||||||
public static final String _reference = "reference";
|
public static final String _reference = "reference";
|
||||||
|
|
||||||
|
private String source;
|
||||||
|
public static final String _source = "source";
|
||||||
|
|
||||||
|
private ReferenceSourceType sourceType;
|
||||||
|
public static final String _sourceType = "sourceType";
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +67,22 @@ public class PublicReference {
|
||||||
public void setReference(String reference) {
|
public void setReference(String reference) {
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSource(String source) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceSourceType getSourceType() {
|
||||||
|
return sourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceType(ReferenceSourceType sourceType) {
|
||||||
|
this.sourceType = sourceType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.opencdmp.convention.ConventionService;
|
||||||
import org.opencdmp.data.ReferenceEntity;
|
import org.opencdmp.data.ReferenceEntity;
|
||||||
import org.opencdmp.model.PublicReference;
|
import org.opencdmp.model.PublicReference;
|
||||||
import org.opencdmp.model.PublicReferenceType;
|
import org.opencdmp.model.PublicReferenceType;
|
||||||
|
import org.opencdmp.model.reference.Reference;
|
||||||
import org.opencdmp.query.ReferenceTypeQuery;
|
import org.opencdmp.query.ReferenceTypeQuery;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -62,6 +63,8 @@ public class PublicReferenceBuilder extends BaseBuilder<PublicReference, Referen
|
||||||
if (fields.hasField(this.asIndexer(PublicReference._label))) m.setLabel(d.getLabel());
|
if (fields.hasField(this.asIndexer(PublicReference._label))) m.setLabel(d.getLabel());
|
||||||
if (fields.hasField(this.asIndexer(PublicReference._reference))) m.setReference(d.getReference());
|
if (fields.hasField(this.asIndexer(PublicReference._reference))) m.setReference(d.getReference());
|
||||||
if (fields.hasField(this.asIndexer(PublicReference._description))) m.setDescription(d.getDescription());
|
if (fields.hasField(this.asIndexer(PublicReference._description))) m.setDescription(d.getDescription());
|
||||||
|
if (fields.hasField(this.asIndexer(PublicReference._source))) m.setSource(d.getSource());
|
||||||
|
|
||||||
if (!typeFields.isEmpty() && typeItemsMap != null && typeItemsMap.containsKey(d.getTypeId())) m.setType(typeItemsMap.get(d.getTypeId()));
|
if (!typeFields.isEmpty() && typeItemsMap != null && typeItemsMap.containsKey(d.getTypeId())) m.setType(typeItemsMap.get(d.getTypeId()));
|
||||||
models.add(m);
|
models.add(m);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
|
||||||
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
|
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
|
||||||
import org.opencdmp.model.PlanUser;
|
import org.opencdmp.model.PlanUser;
|
||||||
import org.opencdmp.model.PlanValidationResult;
|
import org.opencdmp.model.PlanValidationResult;
|
||||||
|
import org.opencdmp.model.PublicPlan;
|
||||||
import org.opencdmp.model.builder.PlanUserBuilder;
|
import org.opencdmp.model.builder.PlanUserBuilder;
|
||||||
import org.opencdmp.model.builder.description.DescriptionBuilder;
|
import org.opencdmp.model.builder.description.DescriptionBuilder;
|
||||||
import org.opencdmp.model.builder.plan.PlanBuilder;
|
import org.opencdmp.model.builder.plan.PlanBuilder;
|
||||||
|
@ -91,6 +92,7 @@ import org.opencdmp.model.planblueprint.PlanBlueprint;
|
||||||
import org.opencdmp.model.planreference.PlanReferenceData;
|
import org.opencdmp.model.planreference.PlanReferenceData;
|
||||||
import org.opencdmp.model.reference.Reference;
|
import org.opencdmp.model.reference.Reference;
|
||||||
import org.opencdmp.model.referencetype.ReferenceType;
|
import org.opencdmp.model.referencetype.ReferenceType;
|
||||||
|
import org.opencdmp.model.result.QueryResult;
|
||||||
import org.opencdmp.query.*;
|
import org.opencdmp.query.*;
|
||||||
import org.opencdmp.service.actionconfirmation.ActionConfirmationService;
|
import org.opencdmp.service.actionconfirmation.ActionConfirmationService;
|
||||||
import org.opencdmp.service.description.DescriptionService;
|
import org.opencdmp.service.description.DescriptionService;
|
||||||
|
@ -125,6 +127,8 @@ import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.opencdmp.authorization.AuthorizationFlags.Public;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PlanServiceImpl implements PlanService {
|
public class PlanServiceImpl implements PlanService {
|
||||||
|
|
||||||
|
@ -568,10 +572,12 @@ public class PlanServiceImpl implements PlanService {
|
||||||
public void cloneDescription(UUID planId, Map<UUID, UUID> planDescriptionTemplateRemap, UUID descriptionId, UUID newPlanDescriptionTemplateId) throws InvalidApplicationException, IOException {
|
public void cloneDescription(UUID planId, Map<UUID, UUID> planDescriptionTemplateRemap, UUID descriptionId, UUID newPlanDescriptionTemplateId) throws InvalidApplicationException, IOException {
|
||||||
logger.debug("cloning description: {} with description: {}", descriptionId, planId);
|
logger.debug("cloning description: {} with description: {}", descriptionId, planId);
|
||||||
|
|
||||||
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(descriptionId)), Permission.CloneDescription);
|
PlanEntity descriptionPlan = this.queryFactory.query(PlanQuery.class).disableTracking().ids(planId).isActive(IsActive.Active).first();
|
||||||
|
|
||||||
|
if (!descriptionPlan.getAccessType().equals(PlanAccessType.Public)) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(descriptionId)), Permission.CloneDescription);
|
||||||
|
else this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(descriptionId)), Permission.PublicCloneDescription);
|
||||||
|
|
||||||
DescriptionEntity existing = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(descriptionId).isActive(IsActive.Active).first();
|
DescriptionEntity existing = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(descriptionId).isActive(IsActive.Active).first();
|
||||||
|
|
||||||
DescriptionEntity newDescription = new DescriptionEntity();
|
DescriptionEntity newDescription = new DescriptionEntity();
|
||||||
newDescription.setId(UUID.randomUUID());
|
newDescription.setId(UUID.randomUUID());
|
||||||
newDescription.setLabel(existing.getLabel());
|
newDescription.setLabel(existing.getLabel());
|
||||||
|
@ -673,12 +679,15 @@ public class PlanServiceImpl implements PlanService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Plan buildClone(ClonePlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, IOException, InvalidApplicationException {
|
public Plan buildClone(ClonePlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, IOException, InvalidApplicationException {
|
||||||
this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation( model.getId())), Permission.ClonePlan);
|
|
||||||
|
|
||||||
PlanEntity existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).ids(model.getId()).firstAs(fields);
|
PlanEntity existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(model.getId()).firstAs(fields);
|
||||||
|
|
||||||
if (!this.conventionService.isValidGuid(model.getId()) || existingPlanEntity == null)
|
if (!this.conventionService.isValidGuid(model.getId()) || existingPlanEntity == null)
|
||||||
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
|
if (!existingPlanEntity.getAccessType().equals(PlanAccessType.Public)) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation( model.getId())), Permission.ClonePlan);
|
||||||
|
else this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation( model.getId())), Permission.PublicClonePlan);
|
||||||
|
|
||||||
PlanEntity newPlan = new PlanEntity();
|
PlanEntity newPlan = new PlanEntity();
|
||||||
newPlan.setId(UUID.randomUUID());
|
newPlan.setId(UUID.randomUUID());
|
||||||
newPlan.setIsActive(IsActive.Active);
|
newPlan.setIsActive(IsActive.Active);
|
||||||
|
@ -711,6 +720,20 @@ public class PlanServiceImpl implements PlanService {
|
||||||
.isActive(IsActive.Active)
|
.isActive(IsActive.Active)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
UUID currentUserId = this.userScope.getUserId();
|
||||||
|
boolean currentUserIsInPlan = planUsers.stream().anyMatch(u -> u.getUserId() == currentUserId);
|
||||||
|
if (!currentUserIsInPlan) {
|
||||||
|
PlanUserEntity newUser = new PlanUserEntity();
|
||||||
|
newUser.setId(UUID.randomUUID());
|
||||||
|
newUser.setPlanId(newPlan.getId());
|
||||||
|
newUser.setUserId(currentUserId);
|
||||||
|
newUser.setRole(PlanUserRole.Owner);
|
||||||
|
newUser.setCreatedAt(Instant.now());
|
||||||
|
newUser.setUpdatedAt(Instant.now());
|
||||||
|
newUser.setIsActive(IsActive.Active);
|
||||||
|
|
||||||
|
this.entityManager.persist(newUser);
|
||||||
|
}
|
||||||
for (PlanUserEntity planUser : planUsers) {
|
for (PlanUserEntity planUser : planUsers) {
|
||||||
PlanUserEntity newUser = new PlanUserEntity();
|
PlanUserEntity newUser = new PlanUserEntity();
|
||||||
newUser.setId(UUID.randomUUID());
|
newUser.setId(UUID.randomUUID());
|
||||||
|
|
|
@ -69,6 +69,16 @@ permissions:
|
||||||
clients: [ ]
|
clients: [ ]
|
||||||
allowAnonymous: true
|
allowAnonymous: true
|
||||||
allowAuthenticated: true
|
allowAuthenticated: true
|
||||||
|
PublicClonePlan:
|
||||||
|
roles: [ ]
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: true
|
||||||
|
PublicCloneDescription:
|
||||||
|
roles: [ ]
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: true
|
||||||
BrowsePublicStatistics:
|
BrowsePublicStatistics:
|
||||||
roles: [ ]
|
roles: [ ]
|
||||||
clients: [ ]
|
clients: [ ]
|
||||||
|
|
|
@ -13,6 +13,7 @@ export enum AppPermission {
|
||||||
PublicBrowseDashboardStatistics = "PublicBrowseDashboardStatistics",
|
PublicBrowseDashboardStatistics = "PublicBrowseDashboardStatistics",
|
||||||
PublicSendContactSupport = "PublicSendContactSupport",
|
PublicSendContactSupport = "PublicSendContactSupport",
|
||||||
PublicBrowseReferenceType = "PublicBrowseReferenceType",
|
PublicBrowseReferenceType = "PublicBrowseReferenceType",
|
||||||
|
PublicClonePlan = "PublicClonePlan",
|
||||||
//Elastic
|
//Elastic
|
||||||
ManageElastic = "ManageElastic",
|
ManageElastic = "ManageElastic",
|
||||||
//Queue Events
|
//Queue Events
|
||||||
|
|
|
@ -248,7 +248,7 @@ export class PlanListingItemComponent extends BaseComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
canClonePlan(): boolean {
|
canClonePlan(): boolean {
|
||||||
return this.plan.authorizationFlags?.some(x => x === AppPermission.ClonePlan) || this.authentication.hasPermission(AppPermission.ClonePlan);
|
return this.plan.authorizationFlags?.some(x => x === AppPermission.ClonePlan) || this.authentication.hasPermission(AppPermission.ClonePlan) || (this.authentication.hasPermission(AppPermission.PublicClonePlan) && this.isPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
canFinalizePlan(): boolean {
|
canFinalizePlan(): boolean {
|
||||||
|
|
Loading…
Reference in New Issue