### Eclipse Workspace Patch 1.0 #P org.eclipse.mylyn.jira.tests Index: src/org/eclipse/mylyn/jira/tests/core/JiraTaskDataHandlerTest.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.jira.tests/src/org/eclipse/mylyn/jira/tests/core/JiraTaskDataHandlerTest.java,v retrieving revision 1.13 diff -u -r1.13 JiraTaskDataHandlerTest.java --- src/org/eclipse/mylyn/jira/tests/core/JiraTaskDataHandlerTest.java 23 Sep 2009 02:00:45 -0000 1.13 +++ src/org/eclipse/mylyn/jira/tests/core/JiraTaskDataHandlerTest.java 23 Sep 2009 12:32:57 -0000 @@ -16,8 +16,10 @@ import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; import junit.framework.TestCase; @@ -54,6 +56,8 @@ import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskRelation; import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.mylyn.tests.util.TestUtil; +import org.eclipse.mylyn.tests.util.TestUtil.Credentials; import org.eclipse.mylyn.tests.util.TestUtil.PrivilegeLevel; /** @@ -754,4 +758,92 @@ return taskData; } + /** + * Add comment to a task which user doesn't have edit permission for. + * + * @throws Exception + */ + public void testPostTaskDataCommentWithoutEditPermission() throws Exception { + init(JiraTestConstants.JIRA_LATEST_URL, PrivilegeLevel.USER); + + JiraIssue issue = JiraTestUtil.createIssue(client, "testWithoutEditPermission"); + + TaskData taskData = dataHandler.getTaskData(repository, issue.getId(), new NullProgressMonitor()); + taskData.getRoot().getAttribute(JiraAttribute.SUMMARY.id()).setValue("new summary"); + taskData.getRoot().getAttribute(JiraAttribute.COMMENT_NEW.id()).setValue("comment"); + dataHandler.postTaskData(repository, taskData, buildChanged(taskData.getRoot(), JiraAttribute.SUMMARY, + JiraAttribute.COMMENT_NEW), new NullProgressMonitor()); + assertNull(taskData.getRoot().getAttribute(IJiraConstants.ATTRIBUTE_READ_ONLY)); + + taskData = dataHandler.getTaskData(repository, issue.getId(), new NullProgressMonitor()); + assertEquals("new summary", taskData.getRoot().getAttribute(JiraAttribute.SUMMARY.id()).getValue()); + ITask task = JiraTestUtil.createTask(repository, taskData.getTaskId()); + List comments = JiraTestUtil.getTaskComments(task); + assertEquals(1, comments.size()); + assertEquals("comment", comments.get(0).getText()); + assertNull(taskData.getRoot().getAttribute(IJiraConstants.ATTRIBUTE_READ_ONLY)); + + setUp(); + init(JiraTestConstants.JIRA_LATEST_URL, PrivilegeLevel.READ_ONLY); + + taskData = dataHandler.getTaskData(repository, issue.getId(), new NullProgressMonitor()); + assertNull(taskData.getRoot().getAttribute(IJiraConstants.ATTRIBUTE_READ_ONLY)); + + taskData.getRoot().getAttribute(JiraAttribute.COMMENT_NEW.id()).setValue("new comment"); + + dataHandler.postTaskData(repository, taskData, buildChanged(taskData.getRoot(), JiraAttribute.COMMENT_NEW), + new NullProgressMonitor()); + + taskData = dataHandler.getTaskData(repository, issue.getId(), new NullProgressMonitor()); + assertEquals("new summary", taskData.getRoot().getAttribute(JiraAttribute.SUMMARY.id()).getValue()); + task = JiraTestUtil.createTask(repository, taskData.getTaskId()); + comments = JiraTestUtil.getTaskComments(task); + assertEquals(2, comments.size()); + assertEquals("comment", comments.get(0).getText()); + assertEquals("new comment", comments.get(1).getText()); + assertNull(taskData.getRoot().getAttribute(IJiraConstants.ATTRIBUTE_READ_ONLY)); + } + + private Set buildChanged(TaskAttribute root, JiraAttribute... attrs) { + Set changed = new HashSet(); + for (JiraAttribute ja : attrs) { + changed.add(root.getAttribute(ja.id())); + } + return changed; + } + + /** + * Add comment to a task which user doesn't have edit permission for. + * + * @throws Exception + */ + public void testPostTaskDataAssignWithoutEditPermission() throws Exception { + init(JiraTestConstants.JIRA_LATEST_URL, PrivilegeLevel.USER); + + Credentials userCredentials = TestUtil.readCredentials(PrivilegeLevel.USER); + JiraIssue issue = JiraTestUtil.createIssue(client, "testWithoutEditPermission"); + + TaskData taskData = dataHandler.getTaskData(repository, issue.getId(), new NullProgressMonitor()); + taskData.getRoot().getAttribute(JiraAttribute.USER_ASSIGNED.id()).setValue("-1"); + + dataHandler.postTaskData(repository, taskData, buildChanged(taskData.getRoot(), JiraAttribute.USER_ASSIGNED), + new NullProgressMonitor()); + assertNull(taskData.getRoot().getAttribute(IJiraConstants.ATTRIBUTE_READ_ONLY)); + + setUp(); + init(JiraTestConstants.JIRA_LATEST_URL, PrivilegeLevel.READ_ONLY); + + taskData = dataHandler.getTaskData(repository, issue.getId(), new NullProgressMonitor()); + + taskData.getRoot().getAttribute(JiraAttribute.USER_ASSIGNED.id()).setValue(userCredentials.username); + + dataHandler.postTaskData(repository, taskData, buildChanged(taskData.getRoot(), JiraAttribute.USER_ASSIGNED), + new NullProgressMonitor()); + + taskData = dataHandler.getTaskData(repository, issue.getId(), new NullProgressMonitor()); + assertEquals(userCredentials.username, taskData.getRoot() + .getAttribute(JiraAttribute.USER_ASSIGNED.id()) + .getValue()); + } + } #P org.eclipse.mylyn.context.tests Index: src/org/eclipse/mylyn/context/tests/support/TestUtil.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.context.tests/src/org/eclipse/mylyn/context/tests/support/TestUtil.java,v retrieving revision 1.14 diff -u -r1.14 TestUtil.java --- src/org/eclipse/mylyn/context/tests/support/TestUtil.java 23 Sep 2009 00:55:45 -0000 1.14 +++ src/org/eclipse/mylyn/context/tests/support/TestUtil.java 23 Sep 2009 12:32:58 -0000 @@ -34,7 +34,7 @@ public static final String KEY_CREDENTIALS_FILE = "mylyn.credentials"; public enum PrivilegeLevel { - ANONYMOUS, GUEST, USER, ADMIN + ANONYMOUS, GUEST, USER, ADMIN, READ_ONLY }; public static class Credentials { @@ -91,6 +91,8 @@ return createCredentials(properties, realm + "guest.", "guest@mylyn.eclipse.org", defaultPassword); case USER: return createCredentials(properties, realm, "tests@mylyn.eclipse.org", defaultPassword); + case READ_ONLY: + return createCredentials(properties, realm, "read-only@mylyn.eclipse.org", defaultPassword); case ADMIN: return createCredentials(properties, realm + "admin.", "admin@mylyn.eclipse.org", null); } #P org.eclipse.mylyn.jira.core Index: src/org/eclipse/mylyn/internal/jira/core/JiraTaskDataHandler.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.jira.core/src/org/eclipse/mylyn/internal/jira/core/JiraTaskDataHandler.java,v retrieving revision 1.81 diff -u -r1.81 JiraTaskDataHandler.java --- src/org/eclipse/mylyn/internal/jira/core/JiraTaskDataHandler.java 18 Sep 2009 01:07:58 -0000 1.81 +++ src/org/eclipse/mylyn/internal/jira/core/JiraTaskDataHandler.java 23 Sep 2009 12:33:00 -0000 @@ -974,12 +974,44 @@ } else { String operationId = getOperationId(taskData); String newComment = getNewComment(taskData); - // do normal workflow all the time - if (!JiraRepositoryConnector.isClosed(issue) + Set changeIds = new HashSet(); + boolean handled = false; + + if (changedAttributes != null) { + for (TaskAttribute ta : changedAttributes) { + changeIds.add(ta.getId()); + } + } + + // if only comment was modified do not do the workflow + // otherwise do the whole workflow + if (!handled && changeIds.size() == 1 && changeIds.contains(TaskAttribute.COMMENT_NEW)) { + client.addCommentToIssue(issue, newComment, monitor); + handled = true; + } + + if (!handled && changeIds.contains(TaskAttribute.USER_ASSIGNED)) { + Set anythingElse = new HashSet(changeIds); + anythingElse.removeAll(Arrays.asList(TaskAttribute.USER_ASSIGNED, + TaskAttribute.USER_ASSIGNED_NAME, TaskAttribute.COMMENT_NEW)); + if (anythingElse.size() == 0) { + // no more changes, so that's a re-assign operation (we can't count on operationId == REASSIGN_OPERATION) + client.assignIssueTo(issue, JiraClient.ASSIGNEE_USER, getAssignee(taskData), newComment, + monitor); + handled = true; + } + } + + if (!handled && !JiraRepositoryConnector.isClosed(issue) && taskData.getRoot().getMappedAttribute(IJiraConstants.ATTRIBUTE_READ_ONLY) == null) { client.updateIssue(issue, newComment, monitor); - } else if (newComment.length() > 0) { + handled = true; + } + + // at last try to at least post the comment (if everything else failed) + if (!handled && newComment.length() > 0) { client.addCommentToIssue(issue, newComment, monitor); + handled = true; } postWorkLog(repository, client, taskData, issue, monitor); @@ -1022,6 +1054,15 @@ return newComment; } + private String getAssignee(TaskData taskData) { + String asignee = ""; //$NON-NLS-1$ + TaskAttribute attribute = taskData.getRoot().getMappedAttribute(TaskAttribute.USER_ASSIGNED); + if (attribute != null) { + asignee = taskData.getAttributeMapper().getValue(attribute); + } + return asignee; + } + private String getOperationId(TaskData taskData) { String operationId = ""; //$NON-NLS-1$ TaskAttribute attribute = taskData.getRoot().getMappedAttribute(TaskAttribute.OPERATION); #P org.eclipse.mylyn.tests.util Index: src/org/eclipse/mylyn/tests/util/TestUtil.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/TestUtil.java,v retrieving revision 1.5 diff -u -r1.5 TestUtil.java --- src/org/eclipse/mylyn/tests/util/TestUtil.java 23 Sep 2009 04:45:21 -0000 1.5 +++ src/org/eclipse/mylyn/tests/util/TestUtil.java 23 Sep 2009 12:33:01 -0000 @@ -28,7 +28,7 @@ public static final String KEY_CREDENTIALS_FILE = "mylyn.credentials"; public enum PrivilegeLevel { - ANONYMOUS, GUEST, USER, ADMIN + ANONYMOUS, GUEST, USER, ADMIN, READ_ONLY }; public static class Credentials { @@ -91,6 +91,8 @@ return createCredentials(properties, realm + "guest.", "guest@mylyn.eclipse.org", defaultPassword); case USER: return createCredentials(properties, realm, "tests@mylyn.eclipse.org", defaultPassword); + case READ_ONLY: + return createCredentials(properties, realm, "read-only@mylyn.eclipse.org", defaultPassword); case ADMIN: return createCredentials(properties, realm + "admin.", "admin@mylyn.eclipse.org", null); }