Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Use EntityRestrict alone instead of Restrict
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jun 30, 2015
1 parent 821d4ca commit 4c26110
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 0 additions & 2 deletions zanata-model/src/main/java/org/zanata/model/HProject.java
Expand Up @@ -63,7 +63,6 @@
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.seam.annotations.security.Restrict;
import org.zanata.annotation.EntityRestrict;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
Expand Down Expand Up @@ -93,7 +92,6 @@
typeClass = LocaleIdType.class)

})
@Restrict
@EntityRestrict({ INSERT, UPDATE, DELETE })
@Setter
@Getter
Expand Down
Expand Up @@ -62,7 +62,6 @@
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Indexed;
import org.jboss.seam.annotations.security.Restrict;
import org.zanata.annotation.EntityRestrict;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
Expand All @@ -78,7 +77,6 @@
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@TypeDef(name = "entityStatus", typeClass = EntityStatusType.class)
@Restrict
@EntityRestrict({ INSERT, UPDATE, DELETE })
@Indexed
@Access(AccessType.FIELD)
Expand Down
@@ -1,6 +1,7 @@
package org.zanata.security;

import java.util.Arrays;
import java.util.List;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
Expand Down Expand Up @@ -62,19 +63,16 @@ public void preRemove(Object entity) {
isEntityRestricted(Object entity, EntityAction action) {
EntityRestrict entityRestrict =
entity.getClass().getAnnotation(EntityRestrict.class);
Restrict restrict = entity.getClass().getAnnotation(Restrict.class);
if (restrict != null) {
if (entityRestrict != null) {
if (Arrays.asList(entityRestrict.value()).contains(action)) {
return true; // restricted
} else {
return false; // not restricted
}
if (entityRestrict != null) {
List<EntityAction> restrictedActions = Arrays.asList(
entityRestrict.value());
if (restrictedActions.isEmpty() || restrictedActions.contains(action)) {
return true; // restricted
} else {
return true; // restricted, just not specifically
return false; // not restricted
}
} else {
return false; // not restricted
return false; // restricted, just not specifically
}
}

Expand Down

0 comments on commit 4c26110

Please sign in to comment.