Skip to content

Commit

Permalink
fixes #41 and #42 : use action semantics for 'are you sure?', and all…
Browse files Browse the repository at this point in the history
…ow bulk deletion of permissions, eg if orphaned
  • Loading branch information
danhaywood committed Oct 5, 2016
1 parent 33141e3 commit 8c887d6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 67 deletions.
3 changes: 2 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ Update your classpath by adding this dependency in your dom project's `pom.xml`:
<dependency>
<groupId>org.isisaddons.module.security</groupId>
<artifactId>isis-module-security-dom</artifactId>
<version>1.13.3</version>
<version>1.13.4</version>
</dependency>
----

Expand Down Expand Up @@ -682,6 +682,7 @@ Ideas for future features:

== Change Log

* `1.13.4` - released against Isis 1.13.0, closes link:https://github.com/isisaddons/isis-module-security/issues/41[#41] and link:https://github.com/isisaddons/isis-module-security/issues/42[#42]
* `1.13.3` - released against Isis 1.13.0, closes link:https://github.com/isisaddons/isis-module-security/issues/40[#40]
* `1.13.2` - released against Isis 1.13.0, closes link:https://github.com/isisaddons/isis-module-security/issues/39[#39]
* `1.13.1` - released against Isis 1.13.0, closes link:https://github.com/isisaddons/isis-module-security/issues/38[#38]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
import org.apache.isis.applib.annotation.DomainObject;
import org.apache.isis.applib.annotation.DomainObjectLayout;
import org.apache.isis.applib.annotation.Editing;
import org.apache.isis.applib.annotation.InvokeOn;
import org.apache.isis.applib.annotation.InvokedOn;
import org.apache.isis.applib.annotation.MemberGroupLayout;
import org.apache.isis.applib.annotation.MemberOrder;
import org.apache.isis.applib.annotation.Optionality;
import org.apache.isis.applib.annotation.Parameter;
import org.apache.isis.applib.annotation.ParameterLayout;
import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.annotation.Property;
import org.apache.isis.applib.annotation.PropertyLayout;
import org.apache.isis.applib.annotation.SemanticsOf;
import org.apache.isis.applib.annotation.Where;
import org.apache.isis.applib.services.actinvoc.ActionInvocationContext;
import org.apache.isis.applib.services.appfeat.ApplicationMemberType;
import org.apache.isis.applib.util.ObjectContracts;
import org.apache.isis.core.metamodel.services.appfeat.ApplicationFeature;
Expand Down Expand Up @@ -424,33 +424,27 @@ public static class FeatureFqnDomainEvent extends PropertyDomainEvent<String> {}
@MemberOrder(name="Feature", sequence = "5.1")
@Getter @Setter
private String featureFqn;
//endregion


//endregion

//region > delete (action)
public static class DeleteDomainEvent extends ActionDomainEvent {}

@Action(
domainEvent = DeleteDomainEvent.class
semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE,
domainEvent = DeleteDomainEvent.class,
invokeOn = InvokeOn.OBJECT_AND_COLLECTION
)
@MemberOrder(sequence = "1")
public ApplicationRole delete(
@Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Are you sure?")
final Boolean areYouSure) {
public ApplicationRole delete() {
final ApplicationRole owningRole = getRole();
container.removeIfNotAlready(this);
return owningRole;
}
public String validateDelete(final Boolean areYouSure) {
return not(areYouSure) ? "Please confirm this action": null;
}

static boolean not(final Boolean areYouSure) {
return areYouSure == null || !areYouSure;
return actionInvocationContext.getInvokedOn() == InvokedOn.OBJECT ? owningRole : null;
}
//endregion

//region > equals, hashCode, compareTo, toString
private final static String propertyNames = "role, featureType, featureFqn, mode";

Expand Down Expand Up @@ -510,6 +504,9 @@ public String apply(final ApplicationPermission input) {
@javax.inject.Inject
DomainObjectContainer container;

@javax.inject.Inject
ActionInvocationContext actionInvocationContext;

@javax.inject.Inject
ApplicationFeatureRepositoryDefault applicationFeatureRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,35 +641,25 @@ public static class DeleteDomainEvent extends ActionDomainEvent {}

@Action(
domainEvent = DeleteDomainEvent.class,
semantics = SemanticsOf.NON_IDEMPOTENT
semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE
)
@MemberOrder(sequence = "1")
public List<ApplicationRole> delete(
@Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Are you sure?")
final Boolean areYouSure) {
public List<ApplicationRole> delete() {
getUsers().clear();
final List<ApplicationPermission> permissions = getPermissions();
for (final ApplicationPermission permission : permissions) {
permission.delete(areYouSure);
permission.delete();
}
container.flush();
container.removeIfNotAlready(this);
container.flush();
return applicationRoleRepository.allRoles();
}

public String disableDelete(final Boolean areYouSure) {
public String disableDelete() {
return isAdminRole() ? "Cannot delete the admin role" : null;
}

public String validateDelete(final Boolean areYouSure) {
return not(areYouSure) ? "Please confirm this action": null;
}

static boolean not(final Boolean areYouSure) {
return areYouSure == null || !areYouSure;
}
//endregion

//region > isAdminRole (programmatic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,32 +364,17 @@ public static class DeleteDomainEvent extends ActionDomainEvent {}

@Action(
domainEvent = DeleteDomainEvent.class,
semantics = SemanticsOf.NON_IDEMPOTENT
semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE
)
@MemberOrder(sequence = "1")
public List<ApplicationTenancy> delete(
@Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Are you sure?")
final Boolean areYouSure) {
public List<ApplicationTenancy> delete() {
for (final ApplicationUser user : getUsers()) {
user.updateTenancy(null);
}
container.removeIfNotAlready(this);
container.flush();
return applicationTenancyRepository.allTenancies();
}

public String validateDelete(final Boolean areYouSure) {
return not(areYouSure) ? "Please confirm this action": null;
}

public Boolean default0Delete() {
return Boolean.FALSE;
}

static boolean not(final Boolean areYouSure) {
return areYouSure == null || !areYouSure;
}
//endregion

//region > compareTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,32 +874,18 @@ public static class DeleteDomainEvent extends ActionDomainEvent {}

@Action(
domainEvent = DeleteDomainEvent.class,
semantics = SemanticsOf.NON_IDEMPOTENT
semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE
)
@MemberOrder(sequence = "1")
public List<ApplicationUser> delete(
@Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Are you sure?")
final Boolean areYouSure) {
public List<ApplicationUser> delete() {
container.removeIfNotAlready(this);
container.flush();
return applicationUserRepository.allUsers();
}

public String validateDelete(final Boolean areYouSure) {
return not(areYouSure) ? "Please confirm this action": null;
}
public Boolean default0Delete() {
return Boolean.FALSE;
}

public String disableDelete(final Boolean areYouSure) {
public String disableDelete() {
return isAdminUser()? "Cannot delete the admin user": null;
}

static boolean not(final Boolean areYouSure) {
return areYouSure == null || !areYouSure;
}
//endregion

//region > PermissionSet (programmatic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ protected void execute(ExecutionContext executionContext) {
ApplicationRole.class,
"name",
"description");

// // for adhoc testing of #42
// newMemberPermissions(
// ApplicationPermissionRule.ALLOW,
// ApplicationPermissionMode.CHANGING,
// ApplicationUser.class,
// "orphanedUpdateEmailAddress",
// "orphanedUpdatePhoneNumber",
// "orphanedUpdateFaxNumber");

}

}
6 changes: 5 additions & 1 deletion webapp/src/main/webapp/WEB-INF/viewer_wicket.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ isis.viewer.wicket.datePickerPattern=dd-mm-yy

#isis.viewer.wicket.suppressSignUp=true
#isis.viewer.wicket.suppressPasswordReset=true
#isis.viewer.wicket.suppressRememberMe=true

#isis.viewer.wicket.rememberMe.supprress=true
isis.viewer.wicket.rememberMe.encryptionKey=securityDemoEncryptionKey


#isis.viewer.wicket.disableModalDialogs=true


Expand Down

0 comments on commit 8c887d6

Please sign in to comment.