wip mifosx-195 add/remove READ_{reportName} permissions when add/remove non-core reports

This commit is contained in:
John Woodlock
2013-04-17 12:23:55 +01:00
parent e5b0c31200
commit 3001cc3582
3 changed files with 68 additions and 39 deletions
@@ -243,4 +243,9 @@ public class Report extends AbstractPersistable<Long> {
"Validation errors exist.", dataValidationErrors);
}
}
public String getReportName() {
return reportName;
}
}
@@ -16,6 +16,9 @@ import org.mifosplatform.infrastructure.dataqueries.domain.ReportRepository;
import org.mifosplatform.infrastructure.dataqueries.exception.ReportNotFoundException;
import org.mifosplatform.infrastructure.dataqueries.serialization.ReportCommandFromApiJsonDeserializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.domain.Permission;
import org.mifosplatform.useradministration.domain.PermissionRepository;
import org.mifosplatform.useradministration.exception.PermissionNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,15 +36,18 @@ public class ReportWritePlatformServiceImpl implements
private final PlatformSecurityContext context;
private final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private final ReportRepository reportRepository;
private final PermissionRepository permissionRepository;
@Autowired
public ReportWritePlatformServiceImpl(
final PlatformSecurityContext context,
final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer,
final ReportRepository reportRepository) {
final ReportRepository reportRepository,
final PermissionRepository permissionRepository) {
this.context = context;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.reportRepository = reportRepository;
this.permissionRepository = permissionRepository;
}
@Transactional
@@ -54,8 +60,10 @@ public class ReportWritePlatformServiceImpl implements
this.fromApiJsonDeserializer.validate(command.json());
final Report report = Report.fromJson(command);
final Permission permission = new Permission("report",
report.getReportName(), "READ");
this.reportRepository.save(report);
this.permissionRepository.save(permission);
return new CommandProcessingResultBuilder()
.withCommandId(command.commandId())
@@ -109,8 +117,15 @@ public class ReportWritePlatformServiceImpl implements
"error.msg.cant.delete.core.report",
"Core Reports Can't be Deleted", "");
}
final Permission permission = this.permissionRepository.findOneByCode("READ" + "_" + report.getReportName());
if (permission == null) {
throw new PermissionNotFoundException("READ" + "_" + report.getReportName());
}
this.reportRepository.delete(report);
this.permissionRepository.delete(permission);
return new CommandProcessingResultBuilder().withEntityId(reportId)
.build();
@@ -15,51 +15,60 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
@Table(name = "m_permission")
public class Permission extends AbstractPersistable<Long> {
@Column(name = "grouping", nullable = false, length = 45)
private final String grouping;
@Column(name = "grouping", nullable = false, length = 45)
private final String grouping;
@Column(name = "code", nullable = false, length = 100)
private final String code;
@Column(name = "code", nullable = false, length = 100)
private final String code;
@SuppressWarnings("unused")
@Column(name = "entity_name", nullable = true, length = 100)
private final String entityName;
@SuppressWarnings("unused")
@Column(name = "entity_name", nullable = true, length = 100)
private final String entityName;
@SuppressWarnings("unused")
@Column(name = "action_name", nullable = true, length = 100)
private final String actionName;
@SuppressWarnings("unused")
@Column(name = "action_name", nullable = true, length = 100)
private final String actionName;
@Column(name = "can_maker_checker", nullable = false)
private boolean canMakerChecker;
@Column(name = "can_maker_checker", nullable = false)
private boolean canMakerChecker;
protected Permission() {
this.grouping = null;
this.code = null;
this.entityName = null;
this.actionName = null;
this.canMakerChecker = false;
}
public Permission(final String grouping, final String entityName,
final String actionName) {
this.grouping = grouping;
this.entityName = entityName;
this.actionName = actionName;
this.code = actionName + "_" + entityName;
this.canMakerChecker = false;
}
public boolean hasCode(final String checkCode) {
return this.code.equalsIgnoreCase(checkCode);
}
protected Permission() {
this.grouping = null;
this.entityName = null;
this.actionName = null;
this.code = null;
this.canMakerChecker = false;
}
public String getCode() {
return this.code;
}
public boolean hasCode(final String checkCode) {
return this.code.equalsIgnoreCase(checkCode);
}
public boolean hasMakerCheckerEnabled() {
return this.canMakerChecker;
}
public String getCode() {
return this.code;
}
public String getGrouping() {
return this.grouping;
}
public boolean hasMakerCheckerEnabled() {
return this.canMakerChecker;
}
public boolean enableMakerChecker(final boolean canMakerChecker) {
final boolean isUpdatedValueSame = (this.canMakerChecker == canMakerChecker);
this.canMakerChecker = canMakerChecker;
return !isUpdatedValueSame;
}
public String getGrouping() {
return this.grouping;
}
public boolean enableMakerChecker(final boolean canMakerChecker) {
final boolean isUpdatedValueSame = (this.canMakerChecker == canMakerChecker);
this.canMakerChecker = canMakerChecker;
return !isUpdatedValueSame;
}
}