Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-09-01 17:25:25 +0000
committerKevin Sawicki2011-09-01 17:25:25 +0000
commit86e4ea89c0b6e131a4ac01b9a5a6e9407a7ca975 (patch)
tree61f60504d0a2bf628ee32ed3e949ca5009f8db47 /org.eclipse.mylyn.github.core
parenta5d6791cb9f17e09e100e2ed60cae59c67e6cc4c (diff)
downloadegit-github-86e4ea89c0b6e131a4ac01b9a5a6e9407a7ca975.tar.gz
egit-github-86e4ea89c0b6e131a4ac01b9a5a6e9407a7ca975.tar.xz
egit-github-86e4ea89c0b6e131a4ac01b9a5a6e9407a7ca975.zip
Only update Gists owned by currently authenticated user.
Mark description attribute as read only if not Gist owner. Change-Id: I9881830f60c37b353e3e0b431ecb2e757206c4b0 Signed-off-by: Kevin Sawicki <kevin@github.com>
Diffstat (limited to 'org.eclipse.mylyn.github.core')
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java39
1 files changed, 37 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
index 0f837584..2e9f9565 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
@@ -91,6 +91,8 @@ public class GistTaskDataHandler extends GitHubTaskDataHandler {
TaskAttribute description = GistAttribute.DESCRIPTION.getMetadata()
.create(data);
+ description.getMetaData().setReadOnly(
+ !isOwner(repository, gist.getUser()));
String gistDescription = gist.getDescription();
if (gistDescription != null)
mapper.setValue(description, gistDescription);
@@ -251,8 +253,10 @@ public class GistTaskDataHandler extends GitHubTaskDataHandler {
.getValue();
if (newComment.length() > 0)
service.createComment(taskData.getTaskId(), newComment);
-
- service.updateGist(gist);
+ String author = GistAttribute.AUTHOR.getMetadata().getValue(
+ taskData);
+ if (isOwner(repository, author))
+ service.updateGist(gist);
} catch (IOException e) {
throw new CoreException(GitHub.createWrappedStatus(e));
}
@@ -280,4 +284,35 @@ public class GistTaskDataHandler extends GitHubTaskDataHandler {
return true;
}
+
+ /**
+ * Is the given Gist author the same user as configured via the task
+ * repository's credentials?
+ *
+ * @param repository
+ * @param author
+ * @return true if owner, false otherwise
+ */
+ protected boolean isOwner(TaskRepository repository, User author) {
+ if (author == null)
+ return false;
+ return isOwner(repository, author.getLogin());
+ }
+
+ /**
+ * Is the given Gist author the same user as configured via the task
+ * repository's credentials?
+ *
+ * @param repository
+ * @param author
+ * @return true if owner, false otherwise
+ */
+ protected boolean isOwner(TaskRepository repository, String author) {
+ AuthenticationCredentials creds = repository
+ .getCredentials(AuthenticationType.REPOSITORY);
+ if (creds == null)
+ return false;
+ return author != null && author.length() > 0
+ && author.equals(creds.getUserName());
+ }
}

Back to the top