Commits

Anonymous committed 9518f24

Corrected #9 (BB issue tracker), and a null check in js when empty response is received

  • Participants
  • Parent commits 6e529aa

Comments (0)

Files changed (2)

File src/main/java/com/atlassian/jira/plugins/WhosLookin.java

 import com.atlassian.crowd.embedded.api.User;
 import com.atlassian.jira.bc.issue.IssueService;
 import com.atlassian.jira.issue.Issue;
+import com.atlassian.jira.issue.IssueManager;
 import com.atlassian.jira.security.JiraAuthenticationContext;
+import com.atlassian.jira.security.PermissionManager;
+import com.atlassian.jira.security.Permissions;
+import com.atlassian.jira.user.ApplicationUser;
 
 import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
 
     private final JiraAuthenticationContext jiraAuthenticationContext;
     private final WatchersService watchersService;
-    private final IssueService issueService;
-	private final WhosLookingConfiguration configuration;
+    private final WhosLookingConfiguration configuration;
+    private final PermissionManager permissionManager;
+    private final IssueManager issueManager;
 
-    public WhosLookin(JiraAuthenticationContext jiraAuthenticationContext, WatchersService watchersService, WhosLookingConfiguration configuration, IssueService issueService) {
+    public WhosLookin(JiraAuthenticationContext jiraAuthenticationContext, WatchersService watchersService, WhosLookingConfiguration configuration, IssueService issueService, PermissionManager permissionManager, IssueManager issueManager) {
         this.jiraAuthenticationContext = jiraAuthenticationContext;
         this.watchersService = watchersService;
 		this.configuration = configuration;
-        this.issueService = issueService;
+        this.permissionManager = permissionManager;
+        this.issueManager = issueManager;
     }
 
     /**
     public Response getUsersFromIssue(@PathParam("issue_key") String issueKey, @QueryParam("inforeground") Boolean inForeground, @QueryParam("firstcall") Boolean firstCall)
     {
         final User user = jiraAuthenticationContext.getLoggedInUser();
+        final ApplicationUser applicationUser = jiraAuthenticationContext.getUser();
+        final Issue issue = issueManager.getIssueObject(issueKey);
         if (firstCall == null)
         {
             firstCall = false;
         }
-    	if (user == null)
+    	if (user == null || issue == null)
         {
             return Response.status(Response.Status.ACCEPTED).build();
         }
-
-		if(this.configuration.isUserAuthorized(jiraAuthenticationContext))
+        if(permissionManager.hasPermission(Permissions.BROWSE, issue,applicationUser))
         {
-			watchersService.notifyUserWatchingIssue(user.getName(),user.getDisplayName(),issueKey,inForeground, firstCall);
-            IssueService.IssueResult issueResult = issueService.getIssue(user,issueKey);
-            Boolean issueChanged = false;
-            if (issueResult.isValid())
+            watchersService.notifyUserWatchingIssue(user.getName(),user.getDisplayName(),issueKey,inForeground, firstCall);
+            if(this.configuration.isUserAuthorized(jiraAuthenticationContext))
             {
+                Boolean issueChanged = false;
                 Watcher watcher = new Watcher(user.getName(),user.getDisplayName(), issueKey, System.currentTimeMillis(), inForeground, !firstCall);
-                Issue issue = issueResult.getIssue();
                 final Watcher currentWatcher = watchersService.findWatcher(issueKey,watcher);
                 if(currentWatcher != null)
-                	issueChanged = issue.getUpdated().getTime() > currentWatcher.getPageLoadedTime();
+                    issueChanged = issue.getUpdated().getTime() > currentWatcher.getPageLoadedTime();
+                return Response.ok(new Watchers(watchersService.getWatchersForIssueExcludingUser(issueKey,user.getName()),issueChanged, this.configuration)).build();
             }
-            return Response.ok(new Watchers(watchersService.getWatchersForIssueExcludingUser(issueKey,user.getName()),issueChanged, this.configuration)).build();
+            else
+            {
+                return Response.status(Response.Status.ACCEPTED).build();
+            }
         }
         else
         {

File src/main/resources/includes/whoslooking.js

         var parentElement;
         var currentChatURI=null;
 
+        if (null == response || response.length == 0){
+            return;
+        }
+
 		_chatURI = response.chatURI;
 		_backgroundRefreshInterval = response.backgroundRefreshInterval;
 		_refreshInterval = response.refreshInterval;
 
     return {
         pollForIssue: function() {
+            if (null == _issueKey || _issueKey.length == 0){
+                return;
+            }
             var ajaxOptions = _getAjaxOptions();
             ajaxOptions.type = "PUT";