/// <summary>
        /// Checks if the specified user can download the specified asset
        /// </summary>
        public static bool CanUserDownloadAsset(User user, Asset asset)
        {
            // Unrestricted assets don't need further checks
            if (!IsAssetRestricted(user, asset))
            {
                return(true);
            }

            // Can't authorise with a blank user
            if (user.IsNull)
            {
                return(false);
            }

            // ... or blank asset
            if (asset.IsNull)
            {
                return(false);
            }

            // Don't allow users to download unavailable assets
            // Super admins, BU admins and asset owners will still be able to download, as the
            // IsAssetRestricted() check above will return false for them.
            if (AssetManager.GetAssetStatusForUser(asset, user) != AssetStatus.Available)
            {
                return(false);
            }

            OrderItemFinder finder = new OrderItemFinder {
                UserId = user.UserId.GetValueOrDefault(-1), AssetId = asset.AssetId.GetValueOrDefault(-1)
            };
            OrderItem orderItem = OrderItem.FindOne(finder);

            if (orderItem.IsNull)
            {
                return(false);
            }

            switch (orderItem.OrderItemStatus)
            {
            case (OrderItemStatus.Preapproved):
            case (OrderItemStatus.Approved):
                return(true);

            default:
                return(false);
            }
        }
        private void Bind(int page)
        {
            // First get all of the items in the order
            OrderItemFinder finder = new OrderItemFinder {
                OrderId = CurrentOrderId
            };
            List <OrderItem> items = OrderItem.FindMany(finder);

            // Filter out those assets that are not accessible by the current user
            var validItems = (from item in items
                              where EntitySecurityManager.CanViewAssetInfo(CurrentUser, item.Asset)
                              select item);

            // Get the asset count
            int total = validItems.Count();

            // Set the page size
            SessionInfo.Current.UserSessionInfo.DownloadManagerPageSize = PageSize;

            // Bind the asset list to relevant page
            OrderItemsRepeater.DataSource = items;
            OrderItemsRepeater.DataBind();

            // Setup the top pager
            TopPager.CurrentPage = page;
            TopPager.PageSize    = PageSize;
            TopPager.ItemCount   = total;
            TopPager.CalculatePageCount();

            // Setup the bottom pager
            BottomPager.CurrentPage = TopPager.CurrentPage;
            BottomPager.PageSize    = TopPager.PageSize;
            BottomPager.ItemCount   = TopPager.ItemCount;
            BottomPager.CalculatePageCount();

            // Setup page variables
            CurrentPage = page;
            AssetCount  = total;
            TotalPages  = TopPager.PageCount;

            // Toggle no results panel
            OrderDetailsPanel.Visible = (items.Count > 0);
            EmptyOrderPanel.Visible   = (items.Count == 0);
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int assetId = GetRequiredQueryStringParameter("AssetId", "../Assets/AssetList.aspx");

                // Get the asset.  No need to check permissions
                // as the security module will have already checked it
                Asset asset = GetAsset(assetId);

                if (asset.IsNull)
                {
                    Response.Redirect("../Assets/AssetList.aspx", false);
                    return;
                }

                // Setup the audit trail link
                SiteUtils.SetHyperLink(CurrentUser, "Reports.AssetAuditTrail", string.Format("?AssetId={0}&Source=AssetStats", asset.AssetId), ViewAuditTrailHyperlink);

                // Update popularity rank
                AssetReportMapper.Instance.UpdateAssetPopularityRank(assetId);

                // Populate asset preview with this asset
                AssetPreview1.Asset = asset;

                // Populate asset info
                AssetReferenceLabel.Text        = asset.AssetId.ToString();
                AssetTypeLabel.Text             = asset.AssetType.Name;
                TitleLabel.Text                 = asset.Title;
                BrandLabel.Text                 = asset.Brand.Name;
                RestrictedDownloadLabel.Text    = EntitySecurityManager.IsAssetRestricted(CurrentUser, asset) ? "Yes" : "No";
                UsageRestrictionsLabel.Text     = asset.UsageRestrictions;
                UploadUserHyperLink.Text        = asset.UploadedByUserName;
                UploadUserHyperLink.NavigateUrl = "~/Admin/Users/UserForm.aspx?UserId=" + asset.UploadedByUserId;
                DateUploadedLabel.Text          = asset.UploadDate.ToString(Global.DateFormat);
                DatePublishedLabel.Text         = asset.PublishDate.ToString(Global.DateFormat);
                DateLastEditedLabel.Text        = asset.LastUpdate.ToString(Global.DateFormat);

                // Ensure empty cells have at least non-breaking space
                SiteUtils.PopulateBlankControl(TitleLabel);
                SiteUtils.PopulateBlankControl(UsageRestrictionsLabel);

                // Get total number of search hits
                AuditAssetSearchResultFinder finder1 = new AuditAssetSearchResultFinder();
                finder1.AssetId = asset.AssetId.GetValueOrDefault();
                TotalNumberOfSearchHitsLabel.Text = AuditAssetSearchResult.GetCount(finder1).ToString();

                // Get total number of views
                AuditAssetHistoryFinder finder2 = new AuditAssetHistoryFinder();
                finder2.AssetId              = asset.AssetId.GetValueOrDefault();
                finder2.AuditAssetAction     = AuditAssetAction.ViewedAssetDetail;
                TotalNumberOfViewsLabel.Text = AuditAssetHistory.GetCount(finder2).ToString();

                // Get total number of added to lightbox
                AuditAssetHistoryFinder finder3 = new AuditAssetHistoryFinder();
                finder3.AssetId                      = asset.AssetId.GetValueOrDefault();
                finder3.AuditAssetAction             = AuditAssetAction.AddedToLightbox;
                TotalNumberAddedToLightboxLabel.Text = AuditAssetHistory.GetCount(finder3).ToString();

                // Get total number of added to cart
                AuditAssetHistoryFinder finder4 = new AuditAssetHistoryFinder();
                finder4.AssetId                  = asset.AssetId.GetValueOrDefault();
                finder4.AuditAssetAction         = AuditAssetAction.AddedToCart;
                TotalNumberAddedToCartLabel.Text = AuditAssetHistory.GetCount(finder4).ToString();

                // Get total number of order requests
                OrderItemFinder finder5 = new OrderItemFinder();
                finder5.AssetId = asset.AssetId.GetValueOrDefault();
                TotalNumberOfOrderRequestsLabel.Text = OrderItem.GetCount(finder5).ToString();

                // Get total number of downloads
                AuditAssetHistoryFinder finder6 = new AuditAssetHistoryFinder();
                finder6.AssetId                  = asset.AssetId.GetValueOrDefault();
                finder6.AuditAssetAction         = AuditAssetAction.DownloadedAssetFile;
                TotalNumberOfDownloadsLabel.Text = AuditAssetHistory.GetCount(finder6).ToString();

                // Get total assets
                AssetFinder finder7    = new AssetFinder();
                int         assetCount = Asset.GetCount(finder7);

                // Display popularity based on downloads
                PopularityBasedOnDownloadsLabel.Text = string.Format("{0} / {1} assets", asset.PopularityRank, assetCount);

                // Open the panel specified in the querystring, or default to activity summary
                string panel = WebUtils.GetRequestParam("panel", Panels.ActivitySummary.ToString());
                TogglePanel(panel);
            }
        }