Added document downloader control, icon, function
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DocumentDownloader.ascx.cs" CodeBehind="DocumentDownloader.ascx.cs" Inherits="Swarmops.Frontend.Controls.Base.DocumentDownloader" %>
|
||||
|
||||
<iframe id="<%=this.ClientID %>_iframe" style="display:none"></iframe>
|
||||
|
||||
<script>
|
||||
|
||||
function downloadDocument(docId, docName) {
|
||||
document.getElementById('<%=this.ClientID%>_iframe').src = '/Pages/v5/Support/DownloadUploadedDocument.aspx?DocId=docId&docName=' + encodeURIComponent(docName);
|
||||
};
|
||||
|
||||
</script>
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace Swarmops.Frontend.Controls.Base
|
||||
{
|
||||
public partial class DocumentDownloader : DataV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Swarmops.Frontend.Controls.Base {
|
||||
|
||||
|
||||
public partial class DocumentDownloader {
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
@@ -55,7 +55,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
string hasDoxString =
|
||||
"<img src='/Images/Icons/iconshock-search-256px.png' onmouseover=\\\"this.src='/Images/Icons/iconshock-search-hot-256px.png';\\\" onmouseout=\\\"this.src='/Images/Icons/iconshock-search-256px.png';\\\" baseid='{0}' class='LocalViewDox' style='cursor:pointer' height='20' width='20' />";
|
||||
"<img src='/Images/Icons/iconshock-search-256px.png' onmouseover=\\\"this.src='/Images/Icons/iconshock-search-hot-256px.png';\\\" onmouseout=\\\"this.src='/Images/Icons/iconshock-search-256px.png';\\\" data-docid='{0}' class='LocalViewDox' style='cursor:pointer' height='20' width='20' />" +
|
||||
"<img src='/Images/Icons/iconshock-download-240px.png' onmouseover=\\\"this.src='/Images/Icons/iconshock-download-hot-240px.png';\\\" onmouseout=\\\"this.src='/Images/Icons/iconshock-download-240px.png';\\\" data-docid='{0}' data-docname=\\\"{1}\\\" class='LocalDownloadDox' style='cursor:pointer' height='20' width='20' />";
|
||||
|
||||
foreach (VatReportItem item in items)
|
||||
{
|
||||
@@ -92,7 +93,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
if (transaction.Dependency != null || Documents.ForObject(transaction).Count > 0)
|
||||
{
|
||||
|
||||
element += String.Format(",\"dox\":\"" + hasDoxString + "\"", transaction.Identity);
|
||||
element += String.Format(",\"dox\":\"" + hasDoxString + "\"", transaction.Identity, CurrentOrganization.Name + " - " + report.DescriptionShort + " - " + Resources.Global.Financial_TransactionIdShort + " " + transaction.Identity.ToString("N2"));
|
||||
}
|
||||
|
||||
if (include)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
<Swarmops5:ExternalScripts Package="FancyBox" runat="server" ID="ScriptFancyBox"/>
|
||||
<Swarmops5:DocumentDownloader ID="DownloadSupport" runat="server"/>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
@@ -16,7 +17,11 @@
|
||||
$('span.loadingHeader').hide();
|
||||
|
||||
$(".LocalViewDox").click(function () {
|
||||
$("a.FancyBox_Gallery[data-fancybox='" + $(this).attr("baseid") + "']").first().click();
|
||||
$("a.FancyBox_Gallery[data-fancybox='" + $(this).attr("data-docid") + "']").first().click();
|
||||
});
|
||||
|
||||
$(".LocalDownloadDox").click(function() {
|
||||
downloadDocument($(this).attr("data-docid"), $(this).attr("data-docname"));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,15 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers {
|
||||
/// </remarks>
|
||||
protected global::Swarmops.Frontend.Controls.Meta.ExternalScripts ScriptFancyBox;
|
||||
|
||||
/// <summary>
|
||||
/// DownloadSupport control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::Swarmops.Frontend.Controls.Base.DocumentDownloader DownloadSupport;
|
||||
|
||||
/// <summary>
|
||||
/// PanelShowVatReports control.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Swarmops.Pages.v5.Support.DownloadUploadedDocument" Codebehind="DownloadUploadedDocument.aspx.cs" %>
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Mime;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Frontend;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Pages.v5.Support
|
||||
{
|
||||
public partial class DownloadUploadedDocument : DataV5Base
|
||||
{
|
||||
protected void Page_Load (object sender, EventArgs e)
|
||||
{
|
||||
string documentIdString = Request.QueryString["DocId"];
|
||||
int documentId = Int32.Parse (documentIdString);
|
||||
|
||||
string documentDownloadName = Request.QueryString["DocName"];
|
||||
documentDownloadName = documentDownloadName.Replace("\"", "'");
|
||||
|
||||
Document document = Document.FromIdentity (documentId);
|
||||
|
||||
//Orgid is needed to safely verify permission
|
||||
int orgId = 0; // initialize to invalid
|
||||
|
||||
bool hasPermission = false;
|
||||
string serverFileName = document.ServerFileName;
|
||||
|
||||
if (document.UploadedByPersonId == this.CurrentAuthority.Person.Identity)
|
||||
{
|
||||
hasPermission = true; // can always view documents you yourself uploaded
|
||||
}
|
||||
|
||||
if (CurrentOrganization.HasOpenLedgers)
|
||||
{
|
||||
hasPermission = true;
|
||||
}
|
||||
|
||||
|
||||
if (!hasPermission)
|
||||
{
|
||||
|
||||
|
||||
switch (document.DocumentType)
|
||||
{
|
||||
case DocumentType.FinancialTransaction:
|
||||
{
|
||||
/*
|
||||
//TODO: Get the orgId from foreign object
|
||||
if (this.CurrentAuthority.HasPermission(Permission.CanSeeEconomyDetails, orgId, -1, Authorization.Flag.ExactOrganization))
|
||||
{
|
||||
hasPermission = true;
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case DocumentType.ExpenseClaim:
|
||||
case DocumentType.InboundInvoice:
|
||||
case DocumentType.OutboundInvoice:
|
||||
{
|
||||
int budgetId = 0;
|
||||
|
||||
if (document.DocumentType == DocumentType.ExpenseClaim)
|
||||
{
|
||||
ExpenseClaim claim = (ExpenseClaim) document.ForeignObject;
|
||||
orgId = claim.Budget.OrganizationId;
|
||||
budgetId = claim.BudgetId;
|
||||
}
|
||||
else if (document.DocumentType == DocumentType.InboundInvoice)
|
||||
{
|
||||
InboundInvoice invoice = (InboundInvoice) document.ForeignObject;
|
||||
orgId = invoice.Budget.OrganizationId;
|
||||
budgetId = invoice.BudgetId;
|
||||
}
|
||||
else
|
||||
{
|
||||
OutboundInvoice invoice = (OutboundInvoice) document.ForeignObject;
|
||||
orgId = invoice.OrganizationId;
|
||||
budgetId = invoice.BudgetId;
|
||||
}
|
||||
|
||||
|
||||
FinancialAccount budget = FinancialAccount.FromIdentity(budgetId);
|
||||
|
||||
if (budget.OwnerPersonId == CurrentUser.Identity || budget.OwnerPersonId == 0)
|
||||
{
|
||||
hasPermission = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: Security leak - check CurrentOrganization against Document's org
|
||||
|
||||
if (
|
||||
CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.Financials,
|
||||
AccessType.Write)))
|
||||
{
|
||||
hasPermission = true;
|
||||
}
|
||||
/*
|
||||
if (this.CurrentAuthority.HasPermission(Permission.CanSeeEconomyDetails, orgId, -1, Authorization.Flag.ExactOrganization))
|
||||
{
|
||||
hasPermission = true;
|
||||
break;
|
||||
}*/
|
||||
|
||||
break;
|
||||
}
|
||||
case DocumentType.PaperLetter:
|
||||
{
|
||||
PaperLetter letter = (PaperLetter) document.ForeignObject;
|
||||
|
||||
if (letter.Recipient.Identity == CurrentUser.Identity)
|
||||
{
|
||||
hasPermission = true; // A letter to the viewer
|
||||
}
|
||||
/*
|
||||
// Otherwise, are there overriding permissions, if not addressed to him/her?
|
||||
|
||||
else if (!letter.Personal)
|
||||
{
|
||||
// Unpersonal paper letter, like a rally permit. Note that bank statements should
|
||||
// be considered personal as they contain donors' information in the transaction info.
|
||||
|
||||
if (this.CurrentAuthority.HasPermission(Permission.CanSeeInsensitivePaperLetters, letter.OrganizationId, -1, Authorization.Flag.Default))
|
||||
{
|
||||
hasPermission = true;
|
||||
}
|
||||
}
|
||||
else if (letter.ToPersonId == 0)
|
||||
{
|
||||
// Addressed to the organization, not to a specific person, but still personal.
|
||||
// Typical examples include political inquiries from private citizens written on
|
||||
// paper.
|
||||
|
||||
if (this.CurrentAuthority.HasPermission(Permission.CanSeeSensitivePaperLetters, letter.OrganizationId, -1, Authorization.Flag.Default))
|
||||
{
|
||||
hasPermission = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Addressed to a specific individual that is not the viewer, and it's personal.
|
||||
// INVOCATION OF THIS CODE IS A BREACH OF THE POSTAL SECRET and should ONLY EVER
|
||||
// be done for technical, not operational, reasons and preferably NEVER.
|
||||
|
||||
if (this.CurrentAuthority.HasPermission(Permission.CanBreachPostalSecretPaperLetters, letter.OrganizationId, -1, Authorization.Flag.Default))
|
||||
{
|
||||
hasPermission = true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case DocumentType.PersonPhoto:
|
||||
case DocumentType.Logo:
|
||||
case DocumentType.Artwork:
|
||||
{
|
||||
// These are public
|
||||
|
||||
hasPermission = true;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasPermission)
|
||||
{
|
||||
throw new Exception ("Access is not allowed");
|
||||
}
|
||||
|
||||
string contentType = string.Empty;
|
||||
|
||||
string clientFileNameLower = document.ClientFileName.ToLowerInvariant().Trim();
|
||||
string serverFileNameLower = document.ServerFileName.ToLowerInvariant().Trim();
|
||||
|
||||
if (clientFileNameLower.EndsWith (".pdf"))
|
||||
{
|
||||
contentType = MediaTypeNames.Application.Pdf;
|
||||
|
||||
if (!serverFileNameLower.EndsWith(".pdf"))
|
||||
{
|
||||
// Converted PDF, so cut filename to raw GUID length
|
||||
|
||||
serverFileName = serverFileName.Substring(0, serverFileName.Length - "-0001.png".Length);
|
||||
documentDownloadName += ".pdf";
|
||||
}
|
||||
}
|
||||
else if (clientFileNameLower == (".png"))
|
||||
{
|
||||
contentType = "image/png"; // why isn't this in MediaTypeNames?
|
||||
documentDownloadName += ".pdf";
|
||||
}
|
||||
else if (clientFileNameLower.EndsWith (".jpg") || clientFileNameLower.EndsWith(".jpeg"))
|
||||
{
|
||||
contentType = MediaTypeNames.Image.Jpeg;
|
||||
documentDownloadName += ".pdf";
|
||||
}
|
||||
else
|
||||
{
|
||||
int lastDot = clientFileNameLower.LastIndexOf('.');
|
||||
|
||||
if (lastDot > 0)
|
||||
{
|
||||
documentDownloadName += clientFileNameLower.Substring(lastDot); // Adds original client extension
|
||||
}
|
||||
}
|
||||
|
||||
string legacyMarker = string.Empty;
|
||||
|
||||
if (!File.Exists (Document.StorageRoot + serverFileName))
|
||||
{
|
||||
legacyMarker = "legacy/"; // for some legacy installations, all older files are placed here
|
||||
}
|
||||
|
||||
// TODO: If still doesn't exist, perhaps return a friendly error image instead?
|
||||
|
||||
if (!File.Exists (Document.StorageRoot + legacyMarker + serverFileName))
|
||||
{
|
||||
if (!Debugger.IsAttached) // if running live; ignore FNF errors when debugging
|
||||
{
|
||||
throw new FileNotFoundException(Document.StorageRoot + legacyMarker + serverFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Response.StatusCode = 404;
|
||||
Response.End();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Response.ContentType = contentType + "; filename=" + document.ClientFileName;
|
||||
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + documentDownloadName + "\"");
|
||||
Response.TransmitFile (Document.StorageRoot + legacyMarker + serverFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Swarmops.Pages.v5.Support {
|
||||
|
||||
|
||||
public partial class DownloadUploadedDocument {
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,13 @@
|
||||
<Compile Include="Controls\v5\Base\AjaxDropDown.ascx.designer.cs">
|
||||
<DependentUpon>AjaxDropDown.ascx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\v5\Base\DocumentDownloader.ascx.cs">
|
||||
<DependentUpon>DocumentDownloader.ascx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\v5\Base\DocumentDownloader.ascx.designer.cs">
|
||||
<DependentUpon>DocumentDownloader.ascx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\v5\Base\ProgressBarFake.ascx.cs">
|
||||
<DependentUpon>ProgressBarFake.ascx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
@@ -646,6 +653,13 @@
|
||||
<Compile Include="Pages\v5\Security\SetCurrentOrganization.aspx.designer.cs">
|
||||
<DependentUpon>SetCurrentOrganization.aspx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\v5\Support\DownloadUploadedDocument.aspx.cs">
|
||||
<DependentUpon>DownloadUploadedDocument.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Pages\v5\Support\DownloadUploadedDocument.aspx.designer.cs">
|
||||
<DependentUpon>DownloadUploadedDocument.aspx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\v5\Support\StreamUpload.aspx.cs">
|
||||
<DependentUpon>StreamUpload.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
@@ -761,6 +775,7 @@
|
||||
<Content Include="Controls\v5\Base\AjaxToggleSlider.ascx" />
|
||||
<Content Include="Controls\v5\Base\ComboGeographies.ascx" />
|
||||
<Content Include="Controls\v5\Base\AjaxDropDown.ascx" />
|
||||
<Content Include="Controls\v5\Base\DocumentDownloader.ascx" />
|
||||
<Content Include="Controls\v5\Base\DropDown.ascx" />
|
||||
<Content Include="Controls\v5\Base\FileUpload.ascx" />
|
||||
<Content Include="Controls\v5\Base\MainMenu.ascx" />
|
||||
@@ -817,6 +832,9 @@
|
||||
<Content Include="Images\Flags\tr-24px.png" />
|
||||
<Content Include="Images\Flags\tr-64px.png" />
|
||||
<Content Include="Images\Icons\expensify-icon-official.png" />
|
||||
<Content Include="Images\Icons\iconshock-download-240px.png" />
|
||||
<Content Include="Images\Icons\iconshock-download-96px.png" />
|
||||
<Content Include="Images\Icons\iconshock-download-hot-240px.png" />
|
||||
<Content Include="Images\Icons\iconshock-groups-docs-lists-64px.png" />
|
||||
<Content Include="Images\Icons\iconshock-invoice-256px.png" />
|
||||
<Content Include="Images\Icons\iconshock-pdf-128px.png" />
|
||||
@@ -1215,6 +1233,7 @@
|
||||
<Content Include="Pages\v5\Security\DatabaseUpgradeRequired.aspx" />
|
||||
<Content Include="Pages\v5\Security\Json-AccessibleOrganizationsTree.aspx" />
|
||||
<Content Include="Pages\v5\Security\SetCurrentOrganization.aspx" />
|
||||
<Content Include="Pages\v5\Support\DownloadUploadedDocument.aspx" />
|
||||
<Content Include="Pages\v5\Support\StreamUpload.aspx" />
|
||||
<Content Include="Pages\v5\Swarm\AddPerson.aspx" />
|
||||
<Content Include="Pages\v5\Swarm\Json-ListFindPeople.aspx" />
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
<add tagPrefix="Swarmops5" tagName="TreePositions" src="~/Controls/v5/Swarm/TreePositions.ascx" />
|
||||
<add tagPrefix="Swarmops5" tagName="ProgressBar" src="~/Controls/v5/Base/ProgressBar.ascx" />
|
||||
<add tagPrefix="Swarmops5" tagName="ProgressBarFake" src="~/Controls/v5/Base/ProgressBarFake.ascx" />
|
||||
<add tagPrefix="Swarmops5" tagName="DocumentDownloader" src="~/Controls/v5/Base/DocumentDownloader.ascx"/>
|
||||
</controls>
|
||||
</pages>
|
||||
</system.web>
|
||||
|
||||
Reference in New Issue
Block a user