Exemple #1
0
        /// <inheritdoc/>
        public string CreateMediaFolder(int librarySiteID, string libraryName, string folderName)
        {
            // Gets the media library
            string siteName        = SiteInfoProvider.GetSiteName(librarySiteID);
            var    existingLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryName, siteName);

            if (existingLibrary != null)
            {
                // Creates the "NewFolder" folder within the media library
                MediaLibraryInfoProvider.CreateMediaLibraryFolder(siteName, existingLibrary.LibraryID, folderName);
            }

            return(folderName);
        }
    /// <summary>
    /// Creates media folder. Called when the "Create folder" button is pressed.
    /// Expects the CreateMediaLibrary method to be run first.
    /// </summary>
    private bool CreateMediaFolder()
    {
        // Get media library
        MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName);

        if (library != null)
        {
            // Create new media folder object
            MediaLibraryInfoProvider.CreateMediaLibraryFolder(CurrentSiteName, library.LibraryID, "MyNewFolder", false);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Handles folder actions.
    /// </summary>
    public string ProcessFolderAction()
    {
        MediaLibraryInfo libInfo = MediaLibraryInfo.Provider.Get(LibraryID);

        if (libInfo != null)
        {
            if (Action.ToLowerCSafe().Trim() == "new")
            {
                if (CheckAdvancedPermissions)
                {
                    var currUser = MembershipContext.AuthenticatedUser;

                    // Not a global admin
                    if (!currUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
                    {
                        // Check 'CREATE' & 'MANAGE' permissions
                        if (!(currUser.IsAuthorizedPerResource("CMS.MediaLibrary", PERMISSION_MANAGE) || MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(libInfo, "foldercreate")))
                        {
                            ShowError(MediaLibraryHelper.GetAccessDeniedMessage("foldercreate"));
                            return(null);
                        }
                    }
                }
                // Check 'Folder create' permission
                else if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(libInfo, "foldercreate"))
                {
                    ShowError(MediaLibraryHelper.GetAccessDeniedMessage("foldercreate"));
                    return(null);
                }
            }
            else
            {
                // Check 'Folder modify' permission
                if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(libInfo, "foldermodify"))
                {
                    ShowError(MediaLibraryHelper.GetAccessDeniedMessage("foldermodify"));
                    return(null);
                }
            }

            SiteInfo si = SiteInfo.Provider.Get(libInfo.LibrarySiteID);
            if (si != null)
            {
                // Validate form entry
                string errMsg = ValidateForm(Action, si.SiteName);
                ErrorOccurred = !string.IsNullOrEmpty(errMsg);

                // If validation succeeded
                if (errMsg == "")
                {
                    try
                    {
                        // Update info only if folder was renamed
                        if (Path.EnsureForwardSlashes(FolderPath) != Path.EnsureForwardSlashes(mNewFolderPath))
                        {
                            if (Action.ToLowerCSafe().Trim() == "new")
                            {
                                // Create/Update folder according to action
                                MediaLibraryInfoProvider.CreateMediaLibraryFolder(si.SiteName, LibraryID, mNewFolderPath);
                            }
                            else
                            {
                                // Create/Update folder according to action
                                MediaLibraryInfoProvider.RenameMediaLibraryFolder(si.SiteName, LibraryID, FolderPath, mNewFolderPath);
                            }

                            // Refresh folder name
                            FolderPath = mNewFolderPath;
                            UpdateFolderName();

                            // Reload media library
                            if (OnFolderChange != null)
                            {
                                OnFolderChange(mNewTreePath);
                            }
                        }

                        // Inform the user on success
                        ShowChangesSaved();
                    }
                    catch (Exception ex)
                    {
                        // Display an error to the user
                        ShowError(GetString("general.erroroccurred") + " " + ex.Message);

                        mNewTreePath = null;
                    }
                }
                else
                {
                    // Display an error to the user
                    ShowError(errMsg);
                    mNewTreePath = null;
                }
            }
        }

        return(mNewTreePath);
    }
Exemple #4
0
    /// <summary>
    /// Handles folder actions.
    /// </summary>
    public string ProcessFolderAction()
    {
        MediaLibraryInfo libInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(this.LibraryID);

        if (libInfo != null)
        {
            if (this.Action.ToLower().Trim() == "new")
            {
                if (this.CheckAdvancedPermissions)
                {
                    CurrentUserInfo currUser = CMSContext.CurrentUser;

                    // Not a global admin
                    if (!currUser.IsGlobalAdministrator)
                    {
                        // Group library
                        bool isGroupLibrary = (libInfo.LibraryGroupID > 0);
                        if (!(isGroupLibrary && currUser.IsGroupAdministrator(libInfo.LibraryGroupID)))
                        {
                            // Checked resource name
                            string resource = (isGroupLibrary) ? "CMS.Groups" : "CMS.MediaLibrary";

                            // Check 'CREATE' & 'MANAGE' permissions
                            if (!(currUser.IsAuthorizedPerResource(resource, CMSAdminControl.PERMISSION_MANAGE) || MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(libInfo, "foldercreate")))
                            {
                                this.lblError.Text    = MediaLibraryHelper.GetAccessDeniedMessage("foldercreate");
                                this.lblError.Visible = true;
                                return(null);
                            }
                        }
                    }
                }
                // Check 'Folder create' permission
                else if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(libInfo, "foldercreate"))
                {
                    this.lblError.Text    = MediaLibraryHelper.GetAccessDeniedMessage("foldercreate");
                    this.lblError.Visible = true;
                    return(null);
                }
            }
            else
            {
                // Check 'Folder modify' permission
                if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(libInfo, "foldermodify"))
                {
                    this.lblError.Text    = MediaLibraryHelper.GetAccessDeniedMessage("foldermodify");
                    this.lblError.Visible = true;
                    return(null);
                }
            }

            SiteInfo si = SiteInfoProvider.GetSiteInfo(libInfo.LibrarySiteID);
            if (si != null)
            {
                // Validate form entry
                string errMsg = ValidateForm(this.Action, si.SiteName);
                this.ErrorOccurred = !string.IsNullOrEmpty(errMsg);

                // If validation suceeded
                if (errMsg == "")
                {
                    try
                    {
                        // Update info only if folder was renamed
                        if (MediaLibraryHelper.EnsurePath(FolderPath) != MediaLibraryHelper.EnsurePath(mNewFolderPath))
                        {
                            if (this.Action.ToLower().Trim() == "new")
                            {
                                // Create/Update folder according to action
                                MediaLibraryInfoProvider.CreateMediaLibraryFolder(si.SiteName, LibraryID, mNewFolderPath, false);
                            }
                            else
                            {
                                // Create/Update folder according to action
                                MediaLibraryInfoProvider.RenameMediaLibraryFolder(si.SiteName, LibraryID, FolderPath, mNewFolderPath, false);
                            }

                            // Inform the user on success
                            this.lblInfo.Text    = GetString("general.changessaved");
                            this.lblInfo.Visible = true;

                            // Refresh folder name
                            this.FolderPath = mNewFolderPath;
                            UpdateFolderName();

                            // Reload media library
                            if (OnFolderChange != null)
                            {
                                OnFolderChange(this.mNewTreePath);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // Display an error to the user
                        this.lblError.Text    = GetString("general.erroroccurred") + " " + ex.Message;
                        this.lblError.Visible = true;

                        this.mNewTreePath = null;
                    }
                }
                else
                {
                    // Display an error to the user
                    this.lblError.Text    = errMsg;
                    this.lblError.Visible = true;
                    this.mNewTreePath     = null;
                }
            }
        }

        return(this.mNewTreePath);
    }