Ejemplo n.º 1
0
 /// <summary>
 /// Updates the file rules.
 /// </summary>
 /// <param name="filePermission">The file access permission.</param>
 /// <param name="fileRule">The file rule.</param>
 /// <returns>FileAccessRules.</returns>
 public virtual SQLFileAccessRules UpdateFileRules(SQLFileAccessRules filePermission, SQLAccessRule fileRule)
 {
     filePermission.Copy     = HasPermission(fileRule.Copy);
     filePermission.Download = HasPermission(fileRule.Download);
     filePermission.Edit     = HasPermission(fileRule.Edit);
     filePermission.Read     = HasPermission(fileRule.Read);
     return(filePermission);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates the folder rules.
 /// </summary>
 /// <param name="filePermission">The file access permission.</param>
 /// <param name="folderRule">The folder rule.</param>
 /// <returns>FileAccessRules.</returns>
 public virtual SQLFileAccessRules UpdateFolderRules(SQLFileAccessRules filePermission, SQLAccessRule folderRule)
 {
     filePermission.Copy         = HasPermission(folderRule.Copy);
     filePermission.Edit         = HasPermission(folderRule.Edit);
     filePermission.EditContents = HasPermission(folderRule.EditContents);
     filePermission.Read         = HasPermission(folderRule.Read);
     filePermission.Upload       = HasPermission(folderRule.Upload);
     return(filePermission);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the file permission details for specified file/ folder.
        /// </summary>
        /// <param name="location">The path.</param>
        /// <param name="name">The name.</param>
        /// <param name="isFile">if set to <c>true</c> [is file].</param>
        /// <returns>FileAccessRules.</returns>
        public virtual SQLFileAccessRules GetFilePermission(string location, string name, bool isFile)
        {
            SQLFileAccessRules FilePermission = new SQLFileAccessRules();

            if (isFile)
            {
                string nameExtension = Path.GetExtension(name).ToLower();
                foreach (SQLAccessRule fileRule in AccessRules.Rules)
                {
                    if (!string.IsNullOrEmpty(fileRule.Path) && Path.HasExtension(fileRule.Path) && (fileRule.Role == null || fileRule.Role == AccessRules.Role))
                    {
                        var pathExtension = Path.GetExtension(fileRule.Path).ToLower();
                        if (fileRule.Path.IndexOf("*.*") > -1)
                        {
                            string parentPath = fileRule.Path.Substring(0, fileRule.Path.IndexOf("*.*"));
                            if (location.IndexOf(GetPath(AccessRules.RootPath + parentPath)) == 0 || parentPath == "")
                            {
                                FilePermission = UpdateFileRules(FilePermission, fileRule);
                            }
                        }
                        else if (fileRule.Path.IndexOf("*.") > -1)
                        {
                            string parentPath = fileRule.Path.Substring(0, fileRule.Path.IndexOf("*."));
                            if ((GetPath(AccessRules.RootPath + parentPath) == location || parentPath == "") && nameExtension == pathExtension)
                            {
                                FilePermission = UpdateFileRules(FilePermission, fileRule);
                            }
                        }
                        else if (GetPath(AccessRules.RootPath + fileRule.Path) == (location + name))
                        {
                            FilePermission = UpdateFileRules(FilePermission, fileRule);
                        }
                    }
                }
                return(FilePermission);
            }
            else
            {
                foreach (SQLAccessRule folderRule in AccessRules.Rules)
                {
                    if (folderRule.Path != null && !Path.HasExtension(folderRule.Path) && (folderRule.Role == null || folderRule.Role == AccessRules.Role))
                    {
                        if (folderRule.Path.IndexOf("*") > -1)
                        {
                            string parentPath = folderRule.Path.Substring(0, folderRule.Path.IndexOf("*"));
                            if ((location + name).IndexOf(GetPath(AccessRules.RootPath + parentPath)) == 0 || parentPath == "")
                            {
                                FilePermission = UpdateFolderRules(FilePermission, folderRule);
                            }
                        }
                        else if (GetPath(AccessRules.RootPath + folderRule.Path) == (location + name) || GetPath(AccessRules.RootPath + folderRule.Path) == (location + name + "\\"))
                        {
                            FilePermission = UpdateFolderRules(FilePermission, folderRule);
                        }
                        else if ((location + name).IndexOf(GetPath(AccessRules.RootPath + folderRule.Path)) == 0)
                        {
                            FilePermission.Edit         = HasPermission(folderRule.EditContents);
                            FilePermission.EditContents = HasPermission(folderRule.EditContents);
                        }
                    }
                }
                FilePermission.Download = false;
                return(FilePermission);
            }
        }