misc fixes + updates:
[mir.git] / source / mircoders / accesscontrol / AccessControl.java
index fcfb3dc..7e15db7 100755 (executable)
@@ -39,6 +39,7 @@ import mircoders.entity.EntityUsers;
 
 public class AccessControl {
   private UserAccessControl user;
+  private GeneralAccessControl general;
   protected LoggerWrapper logger = new LoggerWrapper("Global.AccessControl");
   protected MirPropertiesConfiguration configuration;
 
@@ -47,6 +48,7 @@ public class AccessControl {
       configuration = MirPropertiesConfiguration.instance();
 
       user = new UserAccessControl(configuration.getVector("AccessControl.SuperUsers"));
+      general = new GeneralAccessControl();
     }
     catch (Throwable t) {
       throw new RuntimeException(t.toString());
@@ -57,6 +59,40 @@ public class AccessControl {
     return user;
   }
 
+  public GeneralAccessControl general() {
+    return general;
+  }
+
+  public class GeneralAccessControl {
+    public boolean mayDeleteArticles(EntityUsers aSubject) {
+      return configuration.getString("Mir.Localizer.Admin.AllowDeleteArticle", "0").equals("1");
+    }
+
+    public void assertMayDeleteArticles(EntityUsers aSubject) throws AuthorizationExc, AuthorizationFailure {
+      try {
+        if (!mayDeleteArticles(aSubject))
+          throw new AuthorizationExc("not allowed to delete articles");
+      }
+      catch (Throwable t) {
+        throw new AuthorizationFailure(t);
+      }
+    }
+
+    public boolean mayDeleteComments(EntityUsers aSubject) {
+      return configuration.getString("Mir.Localizer.Admin.AllowDeleteComment", "0").equals("1");
+    }
+
+    public void assertMayDeleteComments(EntityUsers aSubject) throws AuthorizationExc, AuthorizationFailure {
+      try {
+        if (!mayDeleteArticles(aSubject))
+          throw new AuthorizationExc("not allowed to delete comments");
+      }
+      catch (Throwable t) {
+        throw new AuthorizationFailure(t);
+      }
+    }
+  }
+
   public class UserAccessControl {
     private List superusers;
 
@@ -128,8 +164,6 @@ public class AccessControl {
       catch (Throwable t) {
         throw new AuthorizationFailure(t);
       }
-
     }
-
   }
 }