1.在jforum-custom.conf中加入一行:
attachments.anonymous=false
2.修改net.jforum.view.forum.PostAction.java的downloadAttach():
將
if ((SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED) &&
!SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD))
|| (!SessionFacade.isLogged() && !SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_ANONYMOUS))) {
this.setTemplateName(TemplateKeys.POSTS_CANNOT_DOWNLOAD);
this.context.put("message", I18n.getMessage("Attachments.featureDisabled"));
return;
}
改為
if ((SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED) &&
!SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD))) {
this.setTemplateName(TemplateKeys.POSTS_CANNOT_DOWNLOAD);
this.context.put("message", I18n.getMessage("Attachments.featureDisabled"));
return;
}
if (!SessionFacade.isLogged() && !SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_ANONYMOUS)) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
原先的程式碼是不管設定為不啟用附加檔案及未登入且有設定禁止匿名下載附加檔案時都顯示同一個錯誤訊息,我們把它分開成兩個狀況,在未登入且有設定禁止匿名下載附加檔案時先導到登入畫面,通過登入驗證後再下載檔案。