Exemplo n.º 1
0
        public void DeleteAlbums(int[] albumIds)
        {
            try
            {
                foreach (int albumId in albumIds)
                {
                    try
                    {
                        IGalleryObject album = Factory.LoadAlbumInstance(albumId, false);

                        if (GalleryPage.IsUserAuthorized(SecurityActions.DeleteAlbum, album.Id))
                        {
                            album.Delete();
                        }
                    }
                    catch (GalleryServerPro.ErrorHandler.CustomExceptions.InvalidAlbumException) { }
                }
                HelperFunctions.PurgeCache();
            }
            catch (Exception ex)
            {
                AppErrorController.LogError(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        public void DeleteMediaObject(int mediaObjectId)
        {
            IGalleryObject mo = null;

            try
            {
                mo = Factory.LoadMediaObjectInstance(mediaObjectId);
                if (Utils.IsUserAuthorized(SecurityActions.DeleteMediaObject, mo.Parent.Id, mo.GalleryId, mo.IsPrivate))
                {
                    mo.Delete();
                    HelperFunctions.PurgeCache();
                }
            }
            catch (Exception ex)
            {
                if (mo != null)
                {
                    AppErrorController.LogError(ex, mo.GalleryId);
                }
                else
                {
                    AppErrorController.LogError(ex);
                }
                throw;
            }
        }
Exemplo n.º 3
0
        private bool btnOkClicked()
        {
            // User clicked 'Delete selected objects'.
            string[] selectedItems = RetrieveUserSelections();

            if (selectedItems.Length == 0)
            {
                // No objects were selected. Inform user and exit function.
                ucUserMessage.MessageTitle  = Resources.GalleryServerPro.Task_No_Objects_Selected_Hdr;
                ucUserMessage.MessageDetail = Resources.GalleryServerPro.Task_No_Objects_Selected_Dtl;
                ucUserMessage.Visible       = true;

                return(false);
            }

            if (!ValidateBeforeObjectDeletion(selectedItems))
            {
                return(false);
            }

            try
            {
                HelperFunctions.BeginTransaction();

                // Convert the string array of IDs to integers. Also assign whether each is an album or media object.
                // (Determined by the first character of each id's string: a=album; m=media object)
                foreach (string selectedItem in selectedItems)
                {
                    int  id     = Convert.ToInt32(selectedItem.Substring(1), CultureInfo.InvariantCulture);
                    char idType = Convert.ToChar(selectedItem.Substring(0, 1), CultureInfo.InvariantCulture);                     // 'a' or 'm'

                    if (idType == 'm')
                    {
                        IGalleryObject go = Factory.LoadMediaObjectInstance(id);
                        go.Delete();
                    }

                    if (idType == 'a')
                    {
                        IAlbum go = Factory.LoadAlbumInstance(id, false);
                        AlbumController.DeleteAlbum(go);
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();

            return(true);
        }
Exemplo n.º 4
0
 public void DeleteMediaObject(int mediaObjectId)
 {
     try
     {
         IGalleryObject mo = Factory.LoadMediaObjectInstance(mediaObjectId);
         if (GalleryPage.IsUserAuthorized(SecurityActions.DeleteMediaObject, mo.Parent.Id))
         {
             mo.Delete();
             HelperFunctions.PurgeCache();
         }
     }
     catch (Exception ex)
     {
         AppErrorController.LogError(ex);
         throw;
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Permanently deletes the specified media object from the file system and data store. No action is taken if the
        /// user does not have delete permission.
        /// </summary>
        /// <param name="id">The ID of the media object to be deleted.</param>
        //public HttpResponseMessage DeleteMediaItem(Entity.MediaItem mediaItem)
        public void Delete(int id)
        {
            IGalleryObject mo = null;

            try
            {
                mo = Factory.LoadMediaObjectInstance(id);
                var isUserAuthorized  = Utils.IsUserAuthorized(SecurityActions.DeleteMediaObject, mo.Parent.Id, mo.GalleryId, mo.IsPrivate, ((IAlbum)mo.Parent).IsVirtualAlbum);
                var isGalleryReadOnly = Factory.LoadGallerySetting(mo.GalleryId).MediaObjectPathIsReadOnly;
                if (!isUserAuthorized || isGalleryReadOnly)
                {
                    AppEventController.LogEvent(String.Format(CultureInfo.InvariantCulture, "Unauthorized access detected. The security system prevented a user from deleting media object {0}.", mo.Id), mo.GalleryId, EventType.Warning);

                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
                }

                mo.Delete();
                HelperFunctions.PurgeCache();
            }
            catch (InvalidMediaObjectException)
            {
                // HTTP specification says the DELETE method must be idempotent, so deleting a nonexistent item must have
                // the same effect as deleting an existing one. So we do nothing here and let the method return HttpStatusCode.OK.
            }
            catch (HttpResponseException)
            {
                throw;                 // Rethrow, since we've already logged it above
            }
            catch (Exception ex)
            {
                if (mo != null)
                {
                    AppEventController.LogError(ex, mo.GalleryId);
                }
                else
                {
                    AppEventController.LogError(ex);
                }

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
        public async Task <IActionResult> Delete(int id)
        {
            IGalleryObject mo = null;

            try
            {
                mo = Factory.LoadMediaObjectInstance(id);

                var isUserAuthorized = (await _authorizationService.AuthorizeAsync(User, mo, Operations.DeleteMediaObject)).Succeeded;
                //var isUserAuthorized = Utils.IsUserAuthorized(SecurityActions.DeleteMediaObject, mo.Parent.Id, mo.GalleryId, mo.IsPrivate, ((IAlbum)mo.Parent).IsVirtualAlbum);

                var isGalleryReadOnly = Factory.LoadGallerySetting(mo.GalleryId).MediaObjectPathIsReadOnly;
                if (!isUserAuthorized || isGalleryReadOnly)
                {
                    AppEventController.LogEvent($"Unauthorized access detected. The security system prevented a user from deleting media asset {mo.Id}.", mo.GalleryId, EventType.Warning);

                    return(Forbid());
                }

                mo.Delete();

                return(Ok($"Media asset {id} deleted..."));
            }
            catch (InvalidMediaObjectException)
            {
                // HTTP specification says the DELETE method must be idempotent, so deleting a nonexistent item must have
                // the same effect as deleting an existing one. So we do nothing here and let the method return HttpStatusCode.OK.
                return(Ok($"Media asset with ID {id} does not exist."));
            }
            catch (Exception ex)
            {
                if (mo != null)
                {
                    AppEventController.LogError(ex, mo.GalleryId);
                }
                else
                {
                    AppEventController.LogError(ex);
                }

                return(StatusCode(500, _exController.GetExString(ex)));
            }
        }
Exemplo n.º 7
0
        public void DeleteAlbums(int[] albumIds)
        {
            if (albumIds == null)
            {
                return;
            }

            IGalleryObject album = null;

            try
            {
                foreach (int albumId in albumIds)
                {
                    try
                    {
                        album = AlbumController.LoadAlbumInstance(albumId, false);

                        if (Utils.IsUserAuthorized(SecurityActions.DeleteAlbum, album.Id, album.GalleryId, album.IsPrivate))
                        {
                            album.Delete();
                        }
                    }
                    catch (GalleryServerPro.ErrorHandler.CustomExceptions.InvalidAlbumException) { }
                }
                HelperFunctions.PurgeCache();
            }
            catch (Exception ex)
            {
                if (album != null)
                {
                    AppErrorController.LogError(ex, album.GalleryId);
                }
                else
                {
                    AppErrorController.LogError(ex);
                }
                throw;
            }
        }