From 3f53a0ddba7418fc7e96d6c00d7a708cc1c18b3f Mon Sep 17 00:00:00 2001 From: Falkvinge Date: Mon, 30 Oct 2017 13:52:58 +0100 Subject: [PATCH] Added permissions to see outbound invoice documentation --- Site/Pages/v5/Support/StreamUpload.aspx.cs | 129 ++++++++++++--------- 1 file changed, 73 insertions(+), 56 deletions(-) diff --git a/Site/Pages/v5/Support/StreamUpload.aspx.cs b/Site/Pages/v5/Support/StreamUpload.aspx.cs index 11a6e501..d7733fe5 100644 --- a/Site/Pages/v5/Support/StreamUpload.aspx.cs +++ b/Site/Pages/v5/Support/StreamUpload.aspx.cs @@ -38,71 +38,86 @@ namespace Swarmops.Pages.v5.Support bool hasPermission = false; string serverFileName = document.ServerFileName; - switch (document.DocumentType) + if (CurrentOrganization.HasOpenLedgers) { - case DocumentType.FinancialTransaction: + hasPermission = true; + } + else + { + + + 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: - { - int budgetId = 0; - - if (document.DocumentType == DocumentType.ExpenseClaim) - { - ExpenseClaim claim = (ExpenseClaim) document.ForeignObject; - orgId = claim.Budget.OrganizationId; - budgetId = claim.BudgetId; } - else - { - InboundInvoice invoice = (InboundInvoice) document.ForeignObject; - orgId = invoice.Budget.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))) + case DocumentType.ExpenseClaim: + case DocumentType.InboundInvoice: + case DocumentType.OutboundInvoice: { - hasPermission = true; - } - /* + 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 + 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) @@ -137,17 +152,19 @@ namespace Swarmops.Pages.v5.Support hasPermission = true; } }*/ - } - break; - case DocumentType.PersonPhoto: - case DocumentType.Logo: - case DocumentType.Artwork: - { - // These are public + } + break; + case DocumentType.PersonPhoto: + case DocumentType.Logo: + case DocumentType.Artwork: + { + // These are public + + hasPermission = true; + } + break; - hasPermission = true; } - break; } if (!hasPermission)