mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
fix issue #156 - Issue attachments gone - error 500
This commit is contained in:
parent
df1e744fd6
commit
d243a42524
@ -47,7 +47,14 @@ public abstract class PullRequestChangeCommentPanel extends ProjectCommentPanel
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), getChange().getRequest().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getChange().getRequest().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManagePullRequests(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -72,13 +72,17 @@ public class DefaultAttachmentStorageManager implements AttachmentStorageManager
|
||||
}
|
||||
|
||||
private void permanentizeAttachmentStorage(File attachmentBase, String attachmentStorageUUID) {
|
||||
File tempAttachmentStorage = new File(attachmentBase, TEMP + "/" + attachmentStorageUUID);
|
||||
File permanentAttachmentStorage = getPermanentAttachmentStorage(attachmentBase, attachmentStorageUUID);
|
||||
if (tempAttachmentStorage.exists() && !permanentAttachmentStorage.exists()) {
|
||||
try {
|
||||
FileUtils.moveDirectory(tempAttachmentStorage, permanentAttachmentStorage);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (!permanentAttachmentStorage.exists()) {
|
||||
File tempAttachmentStorage = new File(attachmentBase, TEMP + "/" + attachmentStorageUUID);
|
||||
if (tempAttachmentStorage.exists()) {
|
||||
try {
|
||||
FileUtils.moveDirectory(tempAttachmentStorage, permanentAttachmentStorage);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
FileUtils.createDir(permanentAttachmentStorage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +143,14 @@ public abstract class CodeCommentPanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getComment().getProject(), getComment().getUUID());
|
||||
return new ProjectAttachmentSupport(getComment().getProject(), getComment().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageCodeComments(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -291,7 +298,14 @@ public abstract class CodeCommentPanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getComment().getProject(), getComment().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getComment().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageCodeComments(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -596,7 +610,14 @@ public abstract class CodeCommentPanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getComment().getProject(), getComment().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getComment().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageCodeComments(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -791,7 +791,14 @@ public class RevisionDiffPanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected ProjectAttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(projectModel.getObject(), uuid);
|
||||
return new ProjectAttachmentSupport(projectModel.getObject(), uuid) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageCodeComments(projectModel.getObject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -231,7 +231,14 @@ public abstract class IssueActivitiesPanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), getIssue().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getIssue().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageIssues(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -65,8 +65,14 @@ class IssueCommentedPanel extends GenericPanel<IssueComment> {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(IssueCommentedPanel.this.getComment().getIssue().getProject(),
|
||||
IssueCommentedPanel.this.getComment().getIssue().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), IssueCommentedPanel.this.getComment().getIssue().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageIssues(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -65,7 +65,14 @@ public abstract class IssueFieldChangePanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), getChange().getIssue().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getChange().getIssue().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageIssues(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -60,7 +60,14 @@ class IssueOpenedPanel extends GenericPanel<Issue> {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), getIssue().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getIssue().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageIssues(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -89,7 +89,14 @@ public abstract class NewIssueEditor extends FormComponentPanel<Issue> implement
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), issue.getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), issue.getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageIssues(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -39,6 +39,7 @@ import io.onedev.server.model.Project;
|
||||
import io.onedev.server.model.User;
|
||||
import io.onedev.server.model.support.issue.TransitionSpec;
|
||||
import io.onedev.server.model.support.issue.transitiontrigger.PressButtonTrigger;
|
||||
import io.onedev.server.security.SecurityUtils;
|
||||
import io.onedev.server.util.IssueUtils;
|
||||
import io.onedev.server.web.behavior.WebSocketObserver;
|
||||
import io.onedev.server.web.component.issue.IssueStateLabel;
|
||||
@ -135,7 +136,14 @@ public abstract class IssueOperationsPanel extends Panel {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), getIssue().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getIssue().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageIssues(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -16,4 +16,6 @@ public interface AttachmentSupport extends Serializable {
|
||||
|
||||
void deleteAttachemnt(String attachmentName);
|
||||
|
||||
boolean canDeleteAttachment();
|
||||
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<ul class="attachments list-unstyled">
|
||||
<li wicket:id="attachments" class="attachment image">
|
||||
<a wicket:id="select" title="Insert this image" class="insert"><img wicket:id="image"></img></a>
|
||||
<a wicket:id="delete" title="Remove this image" class="delete btn btn-default btn-block"><i class="fa fa-trash"></i> Remove</a>
|
||||
<a wicket:id="delete" title="Remove this image" class="delete btn btn-danger"><i class="fa fa-trash"></i> Remove</a>
|
||||
</li>
|
||||
</ul>
|
||||
</wicket:fragment>
|
||||
@ -45,7 +45,7 @@
|
||||
<a wicket:id="select" title="Insert link to this file" class="insert btn btn-block btn-default"><span wicket:id="file"></span></a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<a wicket:id="delete" title="Remove this file" class="delete btn btn-block btn-default"><i class="fa fa-trash"></i> Remove</a>
|
||||
<a wicket:id="delete" title="Remove this file" class="delete btn btn-danger"><i class="fa fa-trash"></i> Remove</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
@ -18,6 +18,7 @@ import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.wicket.Component;
|
||||
import org.apache.wicket.MetaDataKey;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
|
||||
import org.apache.wicket.markup.head.IHeaderResponse;
|
||||
@ -53,6 +54,7 @@ import io.onedev.server.git.BlobIdentFilter;
|
||||
import io.onedev.server.git.exception.GitException;
|
||||
import io.onedev.server.model.Project;
|
||||
import io.onedev.server.util.UrlUtils;
|
||||
import io.onedev.server.web.ajaxlistener.ConfirmClickListener;
|
||||
import io.onedev.server.web.behavior.ReferenceInputBehavior;
|
||||
import io.onedev.server.web.component.blob.folderpicker.BlobFolderPicker;
|
||||
import io.onedev.server.web.component.blob.picker.BlobPicker;
|
||||
@ -300,6 +302,18 @@ abstract class InsertUrlPanel extends Panel {
|
||||
|
||||
item.add(new AjaxLink<Void>("delete") {
|
||||
|
||||
@Override
|
||||
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
|
||||
super.updateAjaxAttributes(attributes);
|
||||
attributes.getAjaxCallListeners().add(new ConfirmClickListener("Do you really want to delete '" + attachmentName + "'?"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onConfigure() {
|
||||
super.onConfigure();
|
||||
setVisible(attachmentSupport.canDeleteAttachment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
attachmentSupport.deleteAttachemnt(attachmentName);
|
||||
@ -342,6 +356,12 @@ abstract class InsertUrlPanel extends Panel {
|
||||
|
||||
item.add(new AjaxLink<Void>("delete") {
|
||||
|
||||
@Override
|
||||
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
|
||||
super.updateAjaxAttributes(attributes);
|
||||
attributes.getAjaxCallListeners().add(new ConfirmClickListener("Do you really want to delete '" + attachmentName + "'?"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
attachmentSupport.deleteAttachemnt(attachmentName);
|
||||
|
||||
@ -228,12 +228,14 @@ body.fullscreen {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.insert-url .attachment.image {
|
||||
text-align: center;
|
||||
}
|
||||
.insert-url .attachment.image img {
|
||||
max-width: 100%;
|
||||
border-radius: 4px 4px 0 0 ;
|
||||
}
|
||||
.insert-url .attachment.image .btn {
|
||||
border-radius: 0 0 4px 4px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.insert-url .alert-info {
|
||||
|
||||
@ -453,7 +453,14 @@ public class SourceViewPanel extends BlobViewPanel implements Positionable, Sear
|
||||
|
||||
@Override
|
||||
protected ProjectAttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(context.getProject(), uuid);
|
||||
return new ProjectAttachmentSupport(context.getProject(), uuid) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManageCodeComments(context.getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -695,7 +695,14 @@ public class NewPullRequestPage extends ProjectPage implements CommentSupport {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(target.getProject(), getPullRequest().getUUID());
|
||||
return new ProjectAttachmentSupport(target.getProject(), getPullRequest().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManagePullRequests(target.getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -55,6 +55,7 @@ import io.onedev.server.model.support.pullrequest.changedata.PullRequestDescript
|
||||
import io.onedev.server.model.support.pullrequest.changedata.PullRequestReferencedFromCodeCommentData;
|
||||
import io.onedev.server.model.support.pullrequest.changedata.PullRequestReferencedFromIssueData;
|
||||
import io.onedev.server.model.support.pullrequest.changedata.PullRequestReferencedFromPullRequestData;
|
||||
import io.onedev.server.security.SecurityUtils;
|
||||
import io.onedev.server.web.behavior.WebSocketObserver;
|
||||
import io.onedev.server.web.component.markdown.AttachmentSupport;
|
||||
import io.onedev.server.web.component.project.comment.CommentInput;
|
||||
@ -285,7 +286,14 @@ public class PullRequestActivitiesPage extends PullRequestDetailPage {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), getPullRequest().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getPullRequest().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManagePullRequests(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -70,8 +70,14 @@ class PullRequestCommentedPanel extends GenericPanel<PullRequestComment> {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(PullRequestCommentedPanel.this.getComment().getProject(),
|
||||
PullRequestCommentedPanel.this.getComment().getRequest().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), PullRequestCommentedPanel.this.getComment().getRequest().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManagePullRequests(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -60,7 +60,14 @@ class PullRequestOpenedPanel extends GenericPanel<PullRequest> {
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getProject(), getPullRequest().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getPullRequest().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManagePullRequests(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,6 +13,7 @@ import io.onedev.server.OneDev;
|
||||
import io.onedev.server.entitymanager.UserManager;
|
||||
import io.onedev.server.model.Project;
|
||||
import io.onedev.server.model.User;
|
||||
import io.onedev.server.security.SecurityUtils;
|
||||
import io.onedev.server.web.component.markdown.AttachmentSupport;
|
||||
import io.onedev.server.web.component.modal.ModalPanel;
|
||||
import io.onedev.server.web.component.project.comment.CommentInput;
|
||||
@ -40,8 +41,14 @@ public abstract class CommentableOperationConfirmPanel extends OperationConfirmP
|
||||
|
||||
@Override
|
||||
protected AttachmentSupport getAttachmentSupport() {
|
||||
return new ProjectAttachmentSupport(getLatestUpdate().getRequest().getTargetProject(),
|
||||
getLatestUpdate().getRequest().getUUID());
|
||||
return new ProjectAttachmentSupport(getProject(), getLatestUpdate().getRequest().getUUID()) {
|
||||
|
||||
@Override
|
||||
public boolean canDeleteAttachment() {
|
||||
return SecurityUtils.canManagePullRequests(getProject());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -25,7 +25,7 @@ import io.onedev.server.web.component.markdown.AttachmentSupport;
|
||||
import io.onedev.server.web.download.AttachmentDownloadResource;
|
||||
import io.onedev.server.web.download.AttachmentDownloadResourceReference;
|
||||
|
||||
public class ProjectAttachmentSupport implements AttachmentSupport {
|
||||
public abstract class ProjectAttachmentSupport implements AttachmentSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user