Beispiel #1
0
    protected override void CreateChildControls()
    {
        // Hide the control if there is no MediaLibrary
        if (MediaLibrary == null)
        {
            hidden         = true;
            Visible        = false;
            StopProcessing = true;
            return;
        }

        if (StopProcessing)
        {
            folderTree.StopProcessing     = true;
            fileDataSource.StopProcessing = true;
            UniPagerControl.PageControl   = null;
        }
        else
        {
            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(MediaLibrary, "Read"))
            {
                // Check 'Media gallery access' permission
                if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(MediaLibrary, "libraryaccess"))
                {
                    RaiseOnNotAllowed("libraryaccess");
                    return;
                }
            }

            base.CreateChildControls();
            InitializeInnerControls();
        }
    }
        public JsonResult Upload(string libraryName)
        {
            var dataContext = dataContextRetriever.Retrieve();

            if (!dataContext.EditMode)
            {
                throw new HttpException(403, "It is allowed to upload an image only when the page builder is in the edit mode.");
            }

            var library = MediaLibraryInfo.Provider.Get(libraryName, SiteContext.CurrentSiteID);

            if (library == null)
            {
                throw new InvalidOperationException($"The '{libraryName}' media library doesn't exist.");
            }

            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(library, "FileCreate", MembershipContext.AuthenticatedUser))
            {
                throw new HttpException(403, "You are not authorized to upload an image to the media library.");
            }

            var imageGuid = Guid.Empty;

            foreach (string requestFileName in Request.Files)
            {
                imageGuid = AddMediaFile(requestFileName, library);
            }

            return(Json(new { guid = imageGuid }));
        }
 /// <summary>
 /// Handle all the necessary actions performed while file info is imported into the DB.
 /// </summary>
 /// <param name="importAll">Indicates whether the all files should be imported at once</param>
 private void HandleFileImport(bool importAll)
 {
     // Check 'File create' permission
     if (MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filecreate"))
     {
         // Get set of file paths
         if (!string.IsNullOrEmpty(ImportFilePaths))
         {
             // Import single file
             if (importAll)
             {
                 // Import all files
                 HandleMultipleMediaFiles();
             }
             else
             {
                 HandleSingleMediaFile();
             }
         }
         else
         {
             // Inform user on error
             RaiseOnAction("importnofiles", null);
         }
     }
     else
     {
         RaiseOnAction("importerror", MediaLibraryHelper.GetAccessDeniedMessage("filecreate"));
     }
 }
    /// <summary>
    /// Initializes media file info.
    /// </summary>
    /// <param name="objectGuid">Media file GUID</param>
    /// <param name="siteName">Site name</param>
    private void metaDataEditor_InitializeObject(Guid objectGuid, string siteName)
    {
        // Get mediafile
        mediaFileInfo = MediaFileInfoProvider.GetMediaFileInfo(objectGuid, siteName);

        // If media file is not null
        if (mediaFileInfo != null)
        {
            MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(ValidationHelper.GetInteger(mediaFileInfo.FileLibraryID, 0));

            // Check permission 'FileModify'
            if (metaDataEditor.CheckPermissions && !MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "filemodify"))
            {
                RedirectToAccessDenied(GetString("metadata.errors.filemodify"));
            }

            // Fire event GetObjectExtension
            if (GetObjectExtension != null)
            {
                GetObjectExtension(mediaFileInfo.FileExtension);
            }
        }
        else
        {
            RedirectToInformation(GetString("editedobject.notexists"));
        }
    }
    /// <summary>
    /// Reload controls data.
    /// </summary>
    /// <param name="forceReload">Indicates if controls </param>
    public override void ReloadData(bool forceReload)
    {
        // Check media file permissions
        MediaLibraryInfo mli = (MediaLibraryInfo)MediaLibraryInfo;

        // Check authorization to filemodify or manage
        if ((mli != null) && ((MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "filemodify", CMSContext.CurrentUser) ||
                               MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "manage", CMSContext.CurrentUser)) || !CheckPermission))
        {
            Enabled = true;

            // Check if module 'Community' is loaded
            if (mli.LibraryGroupID > 0)
            {
                // Check 'GroupAdministrator' permission
                Enabled = (GroupInfo != null) && CMSContext.CurrentUser.IsGroupAdministrator(mli.LibraryGroupID);
            }
        }
        else
        {
            Enabled = false;
        }

        base.ReloadData(forceReload);
    }
    /// <summary>
    /// Initializes all the nested controls.
    /// </summary>
    private void SetupControls()
    {
        // Get media library info
        if (LibraryInfo != null)
        {
            ucMetaFile.ObjectID = LibraryInfo.LibraryID;
            ucMetaFile.SiteID   = LibraryInfo.LibrarySiteID;
            txtFolder.Enabled   = false;

            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, PERMISSION_MANAGE))
            {
                // Disable MetaFile uploader
                ucMetaFile.Enabled = false;
            }
        }
        else
        {
            ucMetaFile.ObjectID = 0;
            txtFolder.Enabled   = true;
        }
        ucMetaFile.ObjectType     = MediaLibraryObjectType.MEDIALIBRARY;
        ucMetaFile.Category       = MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL;
        ucMetaFile.OnAfterDelete += ucMetaFile_OnAfterDelete;
        ucMetaFile.OnAfterUpload += ucMetaFile_OnAfterUpload;
        ucMetaFile.ReloadData();
    }
Beispiel #7
0
    private void gridElem_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLowerCSafe())
        {
        case "edit":
            SelectedItemID = ValidationHelper.GetInteger(actionArgument, 0);
            RaiseOnEdit();
            break;

        case "delete":
            MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(ValidationHelper.GetInteger(actionArgument, 0));
            // Check 'Manage' permission
            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, PERMISSION_MANAGE))
            {
                ShowError(MediaLibraryHelper.GetAccessDeniedMessage(PERMISSION_MANAGE));
                return;
            }
            try
            {
                MediaLibraryInfoProvider.DeleteMediaLibraryInfo(ValidationHelper.GetInteger(actionArgument, 0));
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("Media library", "DELETEOBJ", ex, SiteContext.CurrentSiteID);

                ShowError(ex.Message, EventLogProvider.GetExceptionLogMessage(ex), null);
            }
            break;
        }

        RaiseOnAction(actionName, actionArgument);
    }
    /// <summary>
    /// UniGrid action buttons event handler.
    /// </summary>
    protected void GridOnAction(string actionName, object actionArgument)
    {
        // Process proper action
        switch (actionName.ToLower())
        {
        case "delete":
            if (this.IsMediaThumbnail)
            {
                // Delete thumbnail file
                if (this.LibraryInfo != null)
                {
                    // Check 'File delete' permission
                    if (MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(this.LibraryInfo, "filemodify"))
                    {
                        MediaFileInfoProvider.DeleteMediaFilePreview(CMSContext.CurrentSiteName, this.LibraryID, this.FileInfo.FilePath, false);

                        if (this.FileInfo != null)
                        {
                            SiteInfo si = SiteInfoProvider.GetSiteInfo(FileInfo.FileSiteID);
                            if (si != null)
                            {
                                // Log synchronization task
                                SynchronizationHelper.LogObjectChange(FileInfo, TaskTypeEnum.UpdateObject);
                            }

                            // Drop the cache dependencies
                            CacheHelper.TouchKeys(MediaFileInfoProvider.GetDependencyCacheKeys(this.FileInfo, true));
                        }
                    }
                    else
                    {
                        lblError.Text = MediaLibraryHelper.GetAccessDeniedMessage("filemodify");
                    }
                }

                // Ensure recent action is forgotten
                this.gridAttachments.ClearActions();
            }
            else
            {
                if (this.LibraryInfo != null)
                {
                    // Check 'File delete' permission
                    if (MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(this.LibraryInfo, "filedelete"))
                    {
                        // Delete Media File
                        if (this.FileInfo != null)
                        {
                            MediaFileInfoProvider.DeleteMediaFileInfo(this.FileInfo);
                        }
                    }
                }
            }

            // Force reload data
            ReloadData();
            break;
        }
    }
 private bool innermedia_GetModifyPermission(IDataContainer data)
 {
     if (mHasModify == null)
     {
         mHasModify = LibraryInfo != null?MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filemodify") : false;
     }
     return(mHasModify == true ? true : false);
 }
    public void RaisePostBackEvent(string eventArgument)
    {
        // Check 'Modify' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "manage"))
        {
            return;
        }

        string[] args = eventArgument.Split('|');

        if (args.Length == 2)
        {
            // Get info on currently selected item
            int permission = Convert.ToInt32(args[0]);
            int access     = Convert.ToInt32(args[1]);

            if (LibraryInfo != null)
            {
                // Update library permission access information
                switch (permission)
                {
                case 0:
                    LibraryInfo.FileCreate = ((SecurityAccessEnum)access);
                    break;

                case 2:
                    LibraryInfo.FileDelete = (SecurityAccessEnum)access;
                    break;

                case 4:
                    LibraryInfo.FileModify = ((SecurityAccessEnum)access);
                    break;

                case 1:
                    LibraryInfo.FolderCreate = (SecurityAccessEnum)access;
                    break;

                case 3:
                    LibraryInfo.FolderDelete = (SecurityAccessEnum)access;
                    break;

                case 5:
                    LibraryInfo.FolderModify = (SecurityAccessEnum)access;
                    break;

                case 6:
                    LibraryInfo.Access = (SecurityAccessEnum)access;
                    break;

                default:
                    break;
                }

                // Save changes to the library
                MediaLibraryInfoProvider.SetMediaLibraryInfo(LibraryInfo);
            }
        }
    }
Beispiel #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        RaiseOnCheckPermissions(PERMISSION_READ, this);

        if (!Visible)
        {
            EnableViewState = false;
        }

        if (MediaLibraryID > 0)
        {
            // Get information on current library
            permissionArray.Add("filecreate");
            permissionArray.Add("foldercreate");
            permissionArray.Add("filedelete");
            permissionArray.Add("folderdelete");
            permissionArray.Add("filemodify");
            permissionArray.Add("foldermodify");
            permissionArray.Add("libraryaccess");

            if ((ResLibrary != null) && (LibraryInfo != null))
            {
                // Retrieve permission matrix data
                QueryDataParameters parameters = new QueryDataParameters();
                parameters.Add("@ID", ResLibrary.ResourceID);
                parameters.Add("@LibraryID", MediaLibraryID);
                parameters.Add("@SiteID", LibraryInfo.LibrarySiteID);

                // Exclude generic roles from matrix
                string where = "(RoleName NOT IN ('_authenticated_', '_everyone_', '_notauthenticated_'))";

                if (permissionArray != null)
                {
                    where += " AND PermissionName IN (";
                    foreach (string permission in permissionArray)
                    {
                        where += "'" + permission + "',";
                    }
                    where  = where.TrimEnd(',');
                    where += ") ";
                }

                // Setup matrix control
                gridMatrix.QueryParameters = parameters;
                gridMatrix.WhereCondition  = where;
                gridMatrix.CssClass        = "permission-matrix";
                gridMatrix.OnItemChanged  += gridMatrix_OnItemChanged;

                // Check 'Modify' permission
                if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "manage"))
                {
                    Enable             = false;
                    gridMatrix.Enabled = false;
                    ShowError(String.Format(GetString("general.accessdeniedonpermissionname"), "Manage"));
                }
            }
        }
    }
    /// <summary>
    /// OnCheckPermissions event handler.
    /// </summary>
    private void elemEdit_OnCheckPermissions(string permissionType, CMSAdminControl sender)
    {
        MediaLibraryInfo mli = (MediaLibraryInfo)EditedObject;

        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            RedirectToAccessDenied("cms.medialibrary", "Read");
        }
    }
    private bool innermedia_GetModifyPermission(IDataContainer data)
    {
        if (mHasModify == null)
        {
            mHasModify = (LibraryInfo != null) && MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filemodify");
        }

        return(mHasModify.Value);
    }
Beispiel #14
0
    void librarySecurity_OnCheckPermissions(string permissionType, CMSAdminControl sender)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(QueryHelper.GetInteger("libraryid", 0));

        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            CMSPage.RedirectToCMSDeskAccessDenied("cms.medialibrary", "Read");
        }
    }
    /// <summary>
    /// Edit file event handler.
    /// </summary>
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        // Check 'File modify' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filemodify"))
        {
            ShowError(MediaLibraryHelper.GetAccessDeniedMessage("filemodify"));

            SetupFile();
            return;
        }

        FileInfo fi = CMS.IO.FileInfo.New(MediaFileInfoProvider.GetMediaFilePath(CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder, FilePath));

        if ((fi != null) && (LibraryInfo != null))
        {
            if (FileInfo != null)
            {
                FileInfo.FileModifiedWhen = DateTime.Now;
                // Set media file info
                FileInfo.FileSize = fi.Length;
                if (ImageHelper.IsImage(FileInfo.FileExtension))
                {
                    ImageHelper ih = new ImageHelper();
                    ih.LoadImage(File.ReadAllBytes(fi.FullName));
                    FileInfo.FileImageWidth  = ih.ImageWidth;
                    FileInfo.FileImageHeight = ih.ImageHeight;
                }
                FileInfo.FileTitle       = txtEditTitle.Text.Trim();
                FileInfo.FileDescription = txtEditDescription.Text.Trim();

                // Save
                MediaFileInfoProvider.SetMediaFileInfo(FileInfo);

                // Remove old thumbnails
                MediaFileInfoProvider.DeleteMediaFileThumbnails(FileInfo);

                // Inform user on success
                ShowConfirmation(GetString("media.refresh.success"));

                SetupTexts();

                SetupFile();
                pnlUpdateGeneral.Update();

                SetupPreview();
                pnlUpdatePreviewDetails.Update();

                SetupEdit();
                pnlUpdateFileInfo.Update();

                SetupVersions(false);
                pnlUpdateVersions.Update();

                RaiseOnAction("rehighlightitem", Path.GetFileName(FileInfo.FilePath));
            }
        }
    }
Beispiel #16
0
    private void librarySecurity_OnCheckPermissions(string permissionType, CMSAdminControl sender)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryId);

        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            RedirectToAccessDenied("cms.medialibrary", "Read");
        }
    }
    /// <summary>
    /// Page_Load event handler.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        MediaLibraryInfo mli = (MediaLibraryInfo)EditedObject;

        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            RedirectToAccessDenied("cms.medialibrary", "Read");
        }

        elemEdit.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(elemEdit_OnCheckPermissions);
        elemEdit.MediaLibraryID      = mli.LibraryID;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(QueryHelper.GetInteger("libraryid", 0));

        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            RedirectToCMSDeskAccessDenied("cms.medialibrary", "Read");
        }
        EditedObject = mli;

        elemEdit.MediaLibraryID      = mli.LibraryID;
        elemEdit.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(elemEdit_OnCheckPermissions);
    }
Beispiel #19
0
    private void libraryElem_OnCheckPermissions(string permissionType, CMSAdminControl sender)
    {
        MediaLibraryInfo MediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryId);

        if (permissionType.ToLowerCSafe() == "read")
        {
            // Check 'Read' permission
            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(MediaLibrary, permissionType))
            {
                RedirectToAccessDenied("cms.medialibrary", "Read");
            }
        }
    }
    /// <summary>
    /// Returns a value indicating whether the current user is authorized to manage the edited media library.
    /// </summary>
    private bool CheckPermissions()
    {
        if (LibraryInfo != null)
        {
            return(MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "Manage"));
        }
        if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.MediaLibrary", "Manage"))
        {
            return(true);
        }

        return(false);
    }
    private void formMediaFileCustomFields_OnBeforeSave(object sender, EventArgs e)
    {
        // Check 'File modify' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filemodify"))
        {
            ShowError(MediaLibraryHelper.GetAccessDeniedMessage("filemodify"));

            DisplayCustomFields(true);
            formMediaFileCustomFields.StopProcessing = true;

            // Update form
            SetupEdit();
        }
    }
 /// <summary>
 /// On item changed event.
 /// </summary>
 private void gridMatrix_OnItemChanged(object sender, int roleId, int permissionId, bool allow)
 {
     // Check 'Modify' permission
     if (MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "manage"))
     {
         if (allow)
         {
             MediaLibraryRolePermissionInfoProvider.AddRoleToLibrary(roleId, MediaLibraryID, permissionId);
         }
         else
         {
             MediaLibraryRolePermissionInfoProvider.RemoveRoleFromLibrary(roleId, MediaLibraryID, permissionId);
         }
     }
 }
 /// <summary>
 /// Check perrmissions for selected library.
 /// </summary>
 private bool CheckPermissions()
 {
     // If mFiles is empty handle directory copy/move
     if (String.IsNullOrEmpty(Files) && !mAllFiles)
     {
         if (Action.ToLower().Trim() == "copy")
         {
             // Check 'Folder create' permission
             if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "foldercreate"))
             {
                 lblError.Text = MediaLibraryHelper.GetAccessDeniedMessage("foldercreate");
                 return(false);
             }
         }
         else
         {
             // Check 'Folder modify' permission
             if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "foldermodify"))
             {
                 lblError.Text = MediaLibraryHelper.GetAccessDeniedMessage("foldermodify");
                 return(false);
             }
         }
     }
     else
     {
         if (Action.ToLower().Trim() == "copy")
         {
             // Check 'File create' permission
             if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filecreate"))
             {
                 lblError.Text = MediaLibraryHelper.GetAccessDeniedMessage("filecreate");
                 return(false);
             }
         }
         else
         {
             // Check 'File modify' permission
             if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filemodify"))
             {
                 lblError.Text = MediaLibraryHelper.GetAccessDeniedMessage("filemodify");
                 return(false);
             }
         }
     }
     return(true);
 }
    /// <summary>
    /// Returns a value indicating whether the current user is authorized to manage the edited media library.
    /// </summary>
    private bool CheckPermissions()
    {
        if (LibraryInfo != null)
        {
            return(MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "Manage"));
        }
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.MediaLibrary", "Manage"))
        {
            return(true);
        }
        if ((MediaLibraryGroupID > 0) && (CMSContext.CurrentUser.IsGroupAdministrator(MediaLibraryGroupID)))
        {
            return(true);
        }

        return(false);
    }
 /// <summary>
 /// Setup preview values.
 /// </summary>
 private void SetupPreview()
 {
     if ((FileInfo != null) && (LibraryInfo != null))
     {
         fileUplPreview.EnableUpdate      = MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(LibraryInfo, "filemodify");
         fileUplPreview.StopProcessing    = false;
         fileUplPreview.IsLiveSite        = IsLiveSite;
         fileUplPreview.LibraryFolderPath = FolderPath;
         fileUplPreview.LibraryID         = LibraryInfo.LibraryID;
         fileUplPreview.MediaFileID       = FileID;
         fileUplPreview.FileInfo          = FileInfo;
         fileUplPreview.ReloadData();
     }
     else
     {
         plcPreview.Visible = false;
     }
 }
Beispiel #26
0
    protected void Page_Load(object sender, EventArgs e)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(QueryHelper.GetInteger("libraryid", 0));

        EditedObject = mli;

        // Check 'Read' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            CMSPage.RedirectToCMSDeskAccessDenied("cms.medialibrary", "Read");
        }

        // Check 'Manage' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Manage"))
        {
            this.librarySecurity.Enable = false;
        }

        this.librarySecurity.MediaLibraryID      = QueryHelper.GetInteger("libraryid", 0);
        this.librarySecurity.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(librarySecurity_OnCheckPermissions);
    }
Beispiel #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryId);

        EditedObject = mli;

        // Check 'Read' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            RedirectToAccessDenied("cms.medialibrary", "Read");
        }

        // Check 'Manage' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Manage"))
        {
            librarySecurity.Enable = false;
        }

        librarySecurity.MediaLibraryID      = libraryId;
        librarySecurity.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(librarySecurity_OnCheckPermissions);
    }
Beispiel #28
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        MediaLibraryInfo libInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(this.LibraryID);

        if (libInfo != null)
        {
            // Check 'Folder delete' permission
            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(libInfo, "folderdelete"))
            {
                this.lblError.Text    = MediaLibraryHelper.GetAccessDeniedMessage("folderdelete");
                this.lblError.Visible = true;
                return;
            }

            try
            {
                // Delete folder and all files within
                MediaLibraryInfoProvider.DeleteMediaLibraryFolder(CMSContext.CurrentSiteName, this.LibraryID, this.FolderPath, false);

                // Get path of the parent folder of the currently deleted folder
                this.FolderPath           = DirectoryHelper.CombinePath(this.LibraryFolder, this.FolderPath);
                this.mDeletedFolderParent = this.FolderPath.Remove(this.FolderPath.LastIndexOf("\\"));

                // Let the parent control know the folder was deleted
                if (OnFolderDeleted != null)
                {
                    OnFolderDeleted(this.mDeletedFolderParent);
                }

                this.lblError.Visible = false;
            }
            catch (Exception ex)
            {
                // Display an error to the user
                this.lblError.Text    = GetString("general.erroroccurred") + " " + ex.Message;
                this.lblError.Visible = true;
            }
        }
    }
Beispiel #29
0
        public object Upload(string libraryName)
        {
            var dataContext = dataContextRetriever.Retrieve();

            if (!dataContext.EditMode)
            {
                return(StatusCode(403, new ObjectResult("It is allowed to upload an image only when the page builder is in the edit mode.")));
            }

            var library = MediaLibraryInfo.Provider.Get(libraryName, SiteContext.CurrentSiteID);

            if (library == null)
            {
                return(NotFound($"The '{libraryName}' media library doesn't exist."));
            }

            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(library, "FileCreate", MembershipContext.AuthenticatedUser))
            {
                return(StatusCode(403, new ObjectResult("You are not authorized to upload an image to the media library.")));
            }

            var imageGuid = Guid.Empty;

            foreach (var requestFile in Request.Form.Files)
            {
                var failedValidationResult = ImageUploaderHelper.ValidateUploadedFile(requestFile);

                if (failedValidationResult != null)
                {
                    return(failedValidationResult);
                }

                imageGuid = AddMediaFile(requestFile, library);
            }

            return(new { guid = imageGuid });
        }
    void gridElem_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLower())
        {
        case "edit":
            this.SelectedItemID = ValidationHelper.GetInteger(actionArgument, 0);
            this.RaiseOnEdit();
            break;

        case "delete":
            MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(ValidationHelper.GetInteger(actionArgument, 0));
            // Check 'Manage' permission
            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, CMSAdminControl.PERMISSION_MANAGE))
            {
                this.lblError.Text    = MediaLibraryHelper.GetAccessDeniedMessage(CMSAdminControl.PERMISSION_MANAGE);
                this.lblError.Visible = true;
                return;
            }
            try
            {
                MediaLibraryInfoProvider.DeleteMediaLibraryInfo(ValidationHelper.GetInteger(actionArgument, 0));
            }
            catch (Exception ex)
            {
                EventLogProvider eventLog = new EventLogProvider();
                eventLog.LogEvent("Media library", "DELETEOBJ", ex, CMSContext.CurrentSiteID);

                this.lblError.Text    = ex.Message;
                this.lblError.ToolTip = EventLogProvider.GetExceptionLogMessage(ex);
                this.lblError.Visible = true;
            }
            break;
        }

        this.RaiseOnAction(actionName, actionArgument);
    }