public void RemoveAssetFromLightbox(int lightboxId, int assetId, string additionalNotes) { Lightbox lb = GetLightboxById(lightboxId); if (EntitySecurityManager.CanManageLightbox(User, lb)) { if (LightboxContainsAsset(lb, assetId)) { foreach (LightboxAsset lba in lb.GetLightboxAssetList()) { if (lba.AssetId == assetId) { LightboxAsset.Delete(lba.LightboxAssetId); AuditLogManager.LogAssetAction(assetId, User, AuditAssetAction.RemovedFromLightbox); string notes = string.Format("Removed AssetId: {0} from LightboxId: {1}", assetId, lightboxId); if (!StringUtils.IsBlank(additionalNotes)) { notes += string.Format(". {0}", additionalNotes); } AuditLogManager.LogUserAction(User, AuditUserAction.RemoveFromLightbox, notes); } } } } else { m_Logger.DebugFormat("User: {0} (UserId: {1}) tried to remove AssetId: {2} from LightboxId: {3} but couldn't due to insufficient permissions to manage ths lightbox", User.FullName, User.UserId, assetId, lightboxId); } }
/// <summary> /// Delete asset and update audit log /// </summary> /// <param name="user">The user deleting the asset</param> /// <param name="assetId">The ID of the asset to be deleted</param> public static void DeleteAsset(User user, int assetId) { m_Logger.DebugFormat("DeleteAsset: {0}", assetId); Asset asset = Asset.Get(assetId); if (asset.IsNull) { return; } asset.IsDeleted = true; Asset.Update(asset); m_Logger.Debug(" -Flagged asset as deleted"); // Update the audit log AuditLogManager.LogAssetAction(asset, user, AuditAssetAction.DeleteAsset); AuditLogManager.LogUserAction(user, AuditUserAction.DeleteAsset, string.Format("Deleted Asset with AssetId: {0}", asset.AssetId)); m_Logger.Debug(" -Updated audit log"); // Delete asset files DeleteAssetFiles(asset, asset.AssetFilePath.Path); // Delete asset bitmaps folder AssetBitmapGroupManager.DeleteAssetBitmapsFolder(asset); // Delete all asset categories AssetCategory.DeleteAllByAssetId(assetId); }
/// <summary> /// Adds a copy of the lightbox asset to the lightbox, if it does not contain the asset /// </summary> public void AddAssetToLightbox(Lightbox lightbox, LightboxAsset lightboxAsset) { if (!lightbox.IsNull && !lightboxAsset.IsNull) { if (EntitySecurityManager.CanManageLightbox(User, lightbox)) { if (!LightboxContainsAsset(lightbox, lightboxAsset.AssetId)) { LightboxAsset lba = LightboxAsset.New(); lba.LightboxId = lightbox.LightboxId.GetValueOrDefault(); lba.AssetId = lightboxAsset.AssetId; lba.Notes = lightboxAsset.Notes; lba.CreateDate = DateTime.Now; LightboxAsset.Update(lba); AuditLogManager.LogAssetAction(lightboxAsset.AssetId, User, AuditAssetAction.AddedToLightbox); AuditLogManager.LogUserAction(User, AuditUserAction.AddToLightbox, string.Format("Added AssetId: {0} to LightboxId: {1}", lightboxAsset.AssetId, lightbox.LightboxId.GetValueOrDefault())); } } else { m_Logger.DebugFormat("User: {0} (UserId: {1}) tried to add AssetId: {2} to LightboxId: {3} but couldn't due to insufficient permissions to manage ths lightbox", User.FullName, User.UserId, lightboxAsset.AssetId, lightbox.LightboxId.GetValueOrDefault()); } } }
public static void ReplaceAssetFile(Asset asset, BinaryFile file, bool notify, User uploadUser) { m_Logger.DebugFormat("ReplaceAssetFile() - AssetId: {0}", asset.AssetId); // Will save the asset file, increment version, etc AssetFileManager.SaveAssetFile(asset, file, notify); if (asset.AssetPublishStatus == AssetPublishStatus.PendingApproval) { // The asset is still in a workflow, which we need to cancel and re-submit // Get the most recent workflow and perform relevant actions on it if (asset.AssetWorkflowList.Count > 0) { // Get the most recent workflow AssetWorkflow assetWorkflow = asset.AssetWorkflowList[0]; // Cancel it WorkflowManager.CancelWorkflow(assetWorkflow); m_Logger.DebugFormat("Cancelled AssetWorkflow - AssetWorkflowId: {0}", assetWorkflow.AssetWorkflowId); // Resubmit it WorkflowManager.SubmitAssetToWorkflow(asset, uploadUser); m_Logger.DebugFormat("Resubmitted asset to workflow. AssetId: {0}", asset.AssetId); } } AuditLogManager.LogAssetAction(asset, uploadUser, AuditAssetAction.ReplacedAssetFile); AuditLogManager.LogUserAction(uploadUser, AuditUserAction.ReplacedAssetFile, string.Format("Replaced asset file of AssetId: {0}", asset.AssetId)); }
public void RemoveCartItemFromCart(Cart cart) { Cart.Delete(cart.CartId); AuditLogManager.LogAssetAction(cart.AssetId, User, AuditAssetAction.RemovedFromCart); AuditLogManager.LogUserAction(User, AuditUserAction.RemoveFromCart, string.Format("Removed AssetId: {0} from cart", cart.AssetId)); m_CartItems = null; }
/// <summary> /// Remove the cart item for the specified asset from the user's cart /// </summary> public void RemoveAssetFromCart(int assetId) { foreach (Cart cart in CartList) { if (cart.AssetId == assetId) { Cart.Delete(cart.CartId); AuditLogManager.LogAssetAction(assetId, User, AuditAssetAction.RemovedFromCart); AuditLogManager.LogUserAction(User, AuditUserAction.RemoveFromCart, string.Format("Removed AssetId: {0} from cart", assetId)); } } m_CartItems = null; }
/// <summary> /// Empties the specified user's cart /// </summary> /// <param name="log">Boolean value specifying whether the asset and user logs should be updated</param> public void EmptyCart(bool log) { foreach (Cart cartItem in CartList) { Cart.Delete(cartItem.CartId); if (log) { AuditLogManager.LogAssetAction(cartItem.AssetId, User, AuditAssetAction.RemovedFromCart, "User emptied cart"); AuditLogManager.LogUserAction(User, AuditUserAction.EmptyCart, string.Format("User emptied cart. Removed AssetId: {0} from cart", cartItem.AssetId)); } } m_CartItems = null; }
/// <summary> /// Adds the asset with the specified ID to the user's cart. /// </summary> public void AddAssetToCart(int assetId) { if (CartContainsAsset(assetId)) { return; } Cart cart = Cart.New(); cart.UserId = User.UserId.GetValueOrDefault(); cart.AssetId = assetId; cart.DateAdded = DateTime.Now; Cart.Update(cart); AuditLogManager.LogAssetAction(assetId, User, AuditAssetAction.AddedToCart); AuditLogManager.LogUserAction(User, AuditUserAction.AddToCart, string.Format("Added AssetId: {0} to cart", assetId)); m_CartItems = null; }
/// <summary> /// Delegates an asset to another user /// </summary> /// <param name="asset">The asset to be delegated</param> /// <param name="newContactEmail">The email address of the user to which the asset should be delegated. This must be an upload user or above.</param> /// <exception cref="InvalidAssetDelegationException">Thrown if the specified email address does not belong to a valid user, or if belongs to a user without upload permissions</exception> private static void DelegateAsset(Asset asset, string newContactEmail) { if (StringUtils.IsBlank(newContactEmail)) { throw new InvalidAssetDelegationException("System Error: Contact Email is blank", asset, User.Empty); } // First get the user we are delegating to User user = User.GetByEmail(newContactEmail); // Ensure we have a valid user if (user.IsNull) { throw new InvalidAssetDelegationException("Email address does not belong to a valid user", asset, user); } // Ensure the user is at least an upload user if (user.UserRoleId < Convert.ToInt32(UserRole.UploadUser)) { throw new InvalidAssetDelegationException("Email address does not belong to a user with upload permissions", asset, user); } // Otherwise, user is valid, so re-assign the asset asset.UploadedByUserId = user.UserId.GetValueOrDefault(); asset.ContactEmail = user.Email; // Save it Asset.Update(asset); // Log it AuditLogManager.LogAssetAction(asset, user, AuditAssetAction.SavedAsset, "Asset was delegated to this user"); m_Logger.DebugFormat("Asset with AssetId: {0} delegated to user: {1}", asset.AssetId, user.FullName); // Fire email notification if (AssetDelegated != null) { AssetDelegatedEventArgs e = new AssetDelegatedEventArgs(asset, user); AssetDelegated(null, e); } }
private void LogUploadedAsset(Asset asset, string notes) { AuditLogManager.LogAssetAction(asset, UploadedBy, AuditAssetAction.UploadedAsset, notes); AuditLogManager.LogUserAction(UploadedBy, AuditUserAction.UploadAsset, string.Format("Uploaded {0} asset - AssetId: {1}. {2}", asset.AssetType.Name, asset.AssetId, notes)); }
/// <summary> /// Creates an order from the user's cart. /// </summary> public static Order CreateOrderFromCart(User user) { // Create new cart manager for easy access to cart CartManager cm = new CartManager(user); // Ensure that the cart contains orderable items ValidateCart(cm.CartList, user); // Create the order Order order = Order.New(); order.UserId = user.UserId.GetValueOrDefault(); order.OrderDate = DateTime.Now; // Ensure there's no order items Debug.Assert(order.OrderItemList.Count == 0); // Now add the cart items to it foreach (Cart cartItem in cm.CartList) { Asset asset = cartItem.Asset; // Get the asset status for the cart item AssetStatus assetStatus = AssetManager.GetAssetStatusForUser(asset, user); // Only add assets that are actually available // (Ignore withdrawn and expired assets) if (assetStatus == AssetStatus.Available) { // Set the order item status based on whether the item is restricted or not bool isRestricted = EntitySecurityManager.IsAssetRestricted(user, asset); // Create new order item OrderItem orderItem = OrderItem.New(); // Order items that are for restricted assets are set to awaiting approval // and need to be approved by the user who uploaded them by default // (though this can change, and be reassigned to the BU admin or superadmin, // as per the workflow and scheduled scripts) if (isRestricted) { orderItem.OrderItemStatus = OrderItemStatus.AwaitingApproval; orderItem.AssignedToUserId = asset.UploadedByUser.GetOrderItemApproverUserId(); } else { orderItem.OrderItemStatus = OrderItemStatus.Preapproved; orderItem.AssignedToUserId = null; } orderItem.AssetId = cartItem.AssetId; orderItem.Notes = cartItem.Notes; orderItem.RequiredByDate = cartItem.RequiredByDate; orderItem.CreateDate = DateTime.Now; order.OrderItemList.Add(orderItem); } } // Save the order SaveOrder(order); // Log which assets were ordered foreach (OrderItem orderItem in order.OrderItemList) { AuditLogManager.LogAssetAction(orderItem.AssetId, user, AuditAssetAction.Ordered, string.Format("OrderId: {0}", orderItem.OrderId)); } // Log order against user AuditLogManager.LogUserAction(user, AuditUserAction.OrderAssets, string.Format("Placed order, with OrderId: {0} containing {1} assets", order.OrderId, order.OrderItemList.Count)); // Remove the items from the cart cm.EmptyCart(false); // Complete the order if all items have been processed if (AllOrderItemsProcessed(order)) { // Nothing in the order required approval, so automatically complete it CompleteOrder(order); } else { // Fire event if (OrderCreated != null) { OrderCreated(null, new OrderEventArgs(order)); } } return(order); }
public static void ProcessOrderItems(EntityList <OrderItem> orderItems, User user) { if (orderItems.Count == 0) { throw new SystemException("No order items"); } // Ensure that we have valid items ValidateOrderItemsForProcessing(orderItems); // Get the parent of the first order (all order items should be from the same order) Order order = orderItems[0].Order; // Create list to hold processed items EntityList <OrderItem> processedOrderItems = new EntityList <OrderItem>(); // Flag to tell us whether we need to fire the 'order completion' event bool notifyIfComplete = false; // Iterate through all of the processed order items and save changes to database foreach (OrderItem orderItem in orderItems) { if (orderItem.IsDirty) { notifyIfComplete = true; } // Update database OrderItem.Update(orderItem); // Save comments foreach (OrderItemComment orderItemComment in orderItem.NewOrderItemCommentList) { // Save the comment OrderItemComment.Update(orderItemComment); // Fire event so user gets notified that a new comment has been made if (NewAdminOrderItemComment != null) { NewAdminOrderItemComment(null, new OrderItemCommentEventArgs(order, orderItemComment)); } } // All new comments saved orderItem.NewOrderItemCommentList.Clear(); switch (orderItem.OrderItemStatus) { case (OrderItemStatus.Approved): // Order items which are approved are processed so add these to the processedOrderItems list processedOrderItems.Add(orderItem); // Log that a request for this asset was approved in the asset audit history AuditLogManager.LogAssetAction(orderItem.AssetId, user, AuditAssetAction.ApprovedForDownload, string.Format("Approved for download for OrderId: {0} made by {1}", orderItem.OrderId, order.User.FullName)); // Log in user audit AuditLogManager.LogUserAction(user, AuditUserAction.AuthoriseOrder, string.Format("Approved request for asset with AssetId: {0} for download in OrderId: {1} made by {2} (UserId: {3})", orderItem.AssetId, orderItem.OrderId, order.User.FullName, order.User.UserId)); break; case (OrderItemStatus.Rejected): // Order items which are rejected are processed so add these to the processedOrderItems list processedOrderItems.Add(orderItem); // Log that a request for this asset was rejected in the asset audit history AuditLogManager.LogAssetAction(orderItem.AssetId, user, AuditAssetAction.RejectedForDownload, string.Format("Rejected for download for OrderId: {0} made by {1}. Reason: {2}", orderItem.OrderId, order.User.FullName, orderItem.LastComment)); // Log in user audit AuditLogManager.LogUserAction(user, AuditUserAction.AuthoriseOrder, string.Format("Rejected request for asset with AssetId: {0} for download in OrderId: {1} made by {2} (UserId: {3})", orderItem.AssetId, orderItem.OrderId, order.User.FullName, order.User.UserId)); break; } } // Complete the order if everything has been processed if (AllOrderItemsProcessed(order)) { CompleteOrder(order); } else { // Otherwise, fire the order items processed event to trigger // any notifications to this user that order items have been processed. // We only want to fire this if order items have actually been changed though // so we look through the order items and check that at least one is dirty if (notifyIfComplete) { if (OrderItemsProcessed != null) { OrderItemsProcessed(null, new OrderItemEventArgs(order, processedOrderItems)); } } } // Update user audit with how many order items were processed in which order AuditLogManager.LogUserAction(user, AuditUserAction.AuthoriseOrder, string.Format("Processed {0} items in order with OrderId: {1}", processedOrderItems.Count, order.OrderId)); }