package controllers;

import models.Project;
import models.enumeration.ResourceType;
import models.resource.Resource;
import play.mvc.Result;
import play.mvc.Controller;

public class CommentApp extends Controller {
    public static Result delete(String type, String id) {
        Resource comment = Resource.get(ResourceType.getValue(type), id);

        if (comment.getType().equals(ResourceType.COMMIT_COMMENT)) {
            return CodeHistoryApp.deleteComment(comment.getProject().owner,
                    comment.getProject().name, comment.getContainer().getId(),
                    Long.valueOf(comment.getId()));
        }

        if (comment.getType().equals(ResourceType.PULL_REQUEST_COMMENT)) {
            return PullRequestCommentApp.deleteComment(Long.valueOf(id));
        }

        return badRequest();
    }
}

@@ -33,55 +33,29 @@
 els.
-Project;%0Aimport models.enumeration.ResourceType
+enumeration.Operation
 ;%0Aim
@@ -136,16 +136,94 @@
 troller;
+%0Aimport utils.AccessControl;%0A%0Aimport static models.enumeration.ResourceType.*;
 %0A%0Apublic
@@ -359,29 +359,16 @@
 rce.get(
-ResourceType.
 getValue
@@ -404,133 +404,52 @@
 ment
-.getType().equals(ResourceType.COMMIT_COMMENT)) %7B%0A            return CodeHistoryApp.deleteComment(comment.getProject().owner,
+ == null) %7B%0A            return badRequest();
 %0A   
@@ -449,32 +449,35 @@
 ();%0A        
+%7D%0A%0A
         
     comment.
@@ -468,120 +468,119 @@
     
-    comment.getProject().name, comment.getContainer().getId(),%0A                    Long.valueOf(comment.getId())
+if (!AccessControl.isAllowed(UserApp.currentUser(), comment, Operation.DELETE)) %7B%0A            return forbidden(
 );%0A 
@@ -589,35 +589,38 @@
      %7D%0A%0A        
-if 
+switch
 (comment.getType
@@ -625,29 +625,62 @@
 pe()
-.equals(ResourceType.
+) %7B%0A            case COMMIT_COMMENT:%0A            case 
 PULL
@@ -695,20 +695,17 @@
 _COMMENT
-)) %7B
+:
 %0A       
@@ -713,81 +713,88 @@
     
-return PullRequestC
+    c
 omment
-App
 .delete
-Comment(Long.valueOf(id));%0A        %7D%0A%0A
+();%0A                return ok();%0A            default:%0A        
     
@@ -814,20 +814,30 @@
 dRequest();%0A
+        %7D%0A
     %7D%0A%7D%0A

Remove dependency of CommentApp.delete on the other controllers.