Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesSetting Read and Write Permissions on a Child Directory in a Custom Module?Setting Read and Write Permissions on a Child Directory in a Custom Module?
Previous
 
Next
New Post
4/7/2018 9:59 PM
 

Hi,

I'm refactoring an old module originally written for DNN 5 and upgraded to DNN 7.  It uses the FileSystemUtils.GetRoles feature to set a permission (read/write) on a given folder in the module directory.  I understand that FolderManager has additional functionality and am seeking code samples / suggestion on how best to refactor the following:

public static System.Web.UI.WebControls.DropDownList GetFolderDDL(System.Web.UI.WebControls.DropDownList ddl, DirectoryInfo ChildDirectory, DotNetNuke.Entities.Portals.PortalSettings portalSettings, int portalId, string folder, FolderPermissionInfo permissionsInfo, IFolderInfo folderInfo)

        {

            string readRoles;

            string writeRoles;

            PortalInfo portalInfo = new PortalInfo();

           

            if (ChildDirectory == null)

            {

                ChildDirectory = new DirectoryInfo(portalSettings.HomeDirectoryMapPath);

                ddl.Items.Clear();

                System.Web.UI.WebControls.ListItem rootItem = new System.Web.UI.WebControls.ListItem();

                rootItem.Text = "Root";

                rootItem.Value = String.Empty;

                readRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles("", portalSettings.PortalId, "READ");

                writeRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles("", portalSettings.PortalId, "WRITE");

 

                if ((DotNetNuke.Security.PortalSecurity.IsInRoles(readRoles) || (DotNetNuke.Security.PortalSecurity.IsInRoles(writeRoles))))

                {

                    ddl.Items.Add(rootItem);

                }

 

            }

            DirectoryInfo currentDir = ChildDirectory;

            DirectoryInfo[] childDirs;

            string parentFolderName;

 

            parentFolderName = ChildDirectory.FullName.Substring(portalSettings.HomeDirectoryMapPath.Length);

 

            currentDir = ChildDirectory;

            childDirs = currentDir.GetDirectories();

 

            foreach (DirectoryInfo dir in childDirs)

            {

 

                System.Web.UI.WebControls.ListItem folderItem = new System.Web.UI.WebControls.ListItem();

                string itemText = parentFolderName.Replace(@"\", "/") + "/" + dir.Name;

                if (itemText.StartsWith("/"))

                    itemText = itemText.Remove(0, 1);

                if (itemText.EndsWith("/"))

                    itemText = itemText.Remove(itemText.Length - 1, 1);

 

                //readRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles(itemText, portalSettings.PortalId, "READ");

                readRoles = FolderPermissionController.GetFolderPermissionsCollectionByFolder(portalId, folder).ToString();

                

                //writeRoles = DotNetNuke.Common.Utilities.FileSystemUtils.GetRoles(itemText, portalSettings.PortalId, "WRITE");

                writeRoles = FolderPermissionController.SaveFolderPermissions(folderInfo);

                if ((DotNetNuke.Security.PortalSecurity.IsInRoles(readRoles) || (DotNetNuke.Security.PortalSecurity.IsInRoles(writeRoles))))

                {

                    folderItem.Text = itemText;

                    folderItem.Value = itemText + "/";

                    ddl.Items.Add(folderItem);

                }

                if (dir.GetDirectories().Length > 0)

                    ddl = GetFolderDDL(ddl, dir, portalSettings, portalId, folder, folderInfo);

 

            }

            return ddl;

        }

 

You'll note that I experimented with the FolderPermissionController.SaveFolder feature.  However, I'm uncertain whether this is considered best practice for DNN 9?  Greatly appreciate advice and guidance.

 

Thanks,

Sid

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesSetting Read and Write Permissions on a Child Directory in a Custom Module?Setting Read and Write Permissions on a Child Directory in a Custom Module?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out