Exemple #1
0
        public void RestoreDeleted(SecurityObject undeletedBy)
        {
            using (var context = new OnlineFilesEntities())
                if (!(context.FileSecurities.AsNoTracking().Any(x => undeletedBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.CanDelete)))
                {
                    throw new SecurityException("Not Authorized.");
                }

            IsDeleted   = false;
            DeletedDt   = DateTime.Now;
            DeletedById = undeletedBy.SecurityObjectId;
        }
Exemple #2
0
        public void RestoreDeleted(SecurityObject undeletedBy)
        {
            List <FolderSecurity> perm;

            using (var context = new OnlineFilesEntities())
                perm = context.FolderSecurities.AsNoTracking().Where(d => d.fk_FolderId == pk_FolderId).ToList();

            if (perm.Any(d => d.canDelete && undeletedBy.mySecurityGroups.Contains(d.SecurityObjectId)))
            {
                IsDeleted   = false;
                DeletedDt   = DateTime.Now;
                DeletedById = undeletedBy.SecurityObjectId;
            }
            else
            {
                throw new SecurityException("Not Authorized.");
            }
        }
Exemple #3
0
        public static File Rename(Guid?fileId, Guid?folderId, string name, SecurityObject createdBy)
        {
            using (var context = new OnlineFilesEntities())
            {
                if (folderId == null)
                {
                    throw new Exception("Bad Guid.");
                }

                var folder = context.Folders
                             .Include(x => x.FolderSecurities)
                             .FirstOrDefault(d => d.pk_FolderId == folderId);
                if (folder == null)
                {
                    throw new Exception("Folder Not Found.");
                }

                if (!folder.FolderSecurities.Any(x => createdBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.canCreateFiles))
                {
                    throw new SecurityException("No Access.");
                }

                var filechk = context.Files
                              .Include(x => x.FileSecurities)
                              .FirstOrDefault(d => d.Name == name);
                if (filechk != null)
                {
                    throw new Exception("File Name already used.");
                }
                var file = context.Files
                           .Include(x => x.FileSecurities)
                           .FirstOrDefault(d => d.pk_FileId == fileId);
                if (file != null)
                {
                    file.Name = name;
                }

                context.Files.AddOrUpdate(file);
                context.SaveChanges();

                return(file);
            }
        }
 public WebDavSqlStoreItemLockInstance(SecurityObject so, string path, WebDavLockScope lockscope, WebDavLockType locktype, string owner, double? requestedlocktimeout, Guid? token, XmlDocument requestdocument, int depth, IWebDavStoreItemLock lockSystem, DateTime? createdate = null)
     : base(path, lockscope, locktype, owner, requestedlocktimeout, token, requestdocument, depth, lockSystem, createdate)
 {
     SoOwner = so;
 }
        public static File Rename(Guid? fileId, Guid? folderId, string name, SecurityObject createdBy)
        {
            using (var context = new OnlineFilesEntities())
            {
                if (folderId == null)
                    throw new Exception("Bad Guid.");

                var folder = context.Folders
                    .Include(x => x.FolderSecurities)
                    .FirstOrDefault(d => d.pk_FolderId == folderId);
                if (folder == null)
                    throw new Exception("Folder Not Found.");

                if (!folder.FolderSecurities.Any(x => createdBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.canCreateFiles))
                    throw new SecurityException("No Access.");

                var filechk = context.Files
                    .Include(x => x.FileSecurities)
                    .FirstOrDefault(d => d.Name == name);
                if (filechk != null)
                    throw new Exception("File Name already used.");
                var file = context.Files
                    .Include(x => x.FileSecurities)
                    .FirstOrDefault(d => d.pk_FileId == fileId);
                if (file != null)
                    file.Name = name;

                context.Files.AddOrUpdate(file);
                context.SaveChanges();

                return file;
            }
        }
        /// <summary>
        ///     Creates a new File Object.
        /// </summary>
        /// <param name="folderId"></param>
        /// <param name="name"></param>
        /// <param name="createdBy"></param>
        /// <param name="inheritSecurity"></param>
        /// <returns></returns>
        public static File Create(Guid? folderId, string name, SecurityObject createdBy, bool inheritSecurity = true)
        {
            using (var context = new OnlineFilesEntities())
            {
                if (folderId == null)
                    throw new Exception("Bad Guid.");

                var folder = context.Folders
                    .Include(x => x.FolderSecurities)
                    .FirstOrDefault(d => d.pk_FolderId == folderId);
                if (folder == null)
                    throw new Exception("Folder Not Found.");

                if (!folder.FolderSecurities.Any(x => createdBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.canCreateFiles))
                    throw new SecurityException("No Access.");


                var file = new File
                {
                    fk_FolderId = (Guid) folderId,
                    IsDeleted = false,
                    isRevisioned = true,
                    Name = name,
                    MimeType = MimeMapping.GetMimeMapping(name),
                    CreatedById = createdBy.SecurityObjectId,
                    CreateDt = DateTime.Now,
                    OwnerId = createdBy.SecurityObjectId
                };
                context.Files.Add(file);
                context.SaveChanges();

                FileSecurity fileSecurity = new FileSecurity
                {
                    CanDelete = true,
                    canRead = true,
                    canWrite = true,
                    fk_FileId = file.pk_FileId,
                    SecurityObjectId = createdBy.SecurityObjectId
                };
                context.FileSecurities.Add(fileSecurity);
                context.SaveChanges();

                foreach (FolderSecurity security in folder.FolderSecurities)
                {
                    fileSecurity = context.FileSecurities.FirstOrDefault(d => d.SecurityObjectId == security.SecurityObjectId && d.fk_FileId == file.pk_FileId);
                    if (fileSecurity == null)
                    {
                        fileSecurity = new FileSecurity
                        {
                            CanDelete = security.canDelete,
                            canRead = security.canListObjects,
                            canWrite = security.canCreateFiles,
                            fk_FileId = file.pk_FileId,
                            SecurityObjectId = security.SecurityObjectId
                        };
                        context.FileSecurities.Add(fileSecurity);
                    }
                    else
                    {
                        fileSecurity.CanDelete = security.canDelete;
                        fileSecurity.canRead = security.canListObjects;
                        fileSecurity.canWrite = security.canCreateFiles;
                    }
                }


                context.SaveChanges();
                return file;
            }
        }
        public void RestoreDeleted(SecurityObject undeletedBy)
        {
            using (var context = new OnlineFilesEntities())
                if (!(context.FileSecurities.AsNoTracking().Any(x => undeletedBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.CanDelete)))
                    throw new SecurityException("Not Authorized.");

            IsDeleted = false;
            DeletedDt = DateTime.Now;
            DeletedById = undeletedBy.SecurityObjectId;
        }
Exemple #8
0
        /// <summary>
        ///     Creates a new File Object.
        /// </summary>
        /// <param name="folderId"></param>
        /// <param name="name"></param>
        /// <param name="createdBy"></param>
        /// <param name="inheritSecurity"></param>
        /// <returns></returns>
        public static File Create(Guid?folderId, string name, SecurityObject createdBy, bool inheritSecurity = true)
        {
            using (var context = new OnlineFilesEntities())
            {
                if (folderId == null)
                {
                    throw new Exception("Bad Guid.");
                }

                var folder = context.Folders
                             .Include(x => x.FolderSecurities)
                             .FirstOrDefault(d => d.pk_FolderId == folderId);
                if (folder == null)
                {
                    throw new Exception("Folder Not Found.");
                }

                if (!folder.FolderSecurities.Any(x => createdBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.canCreateFiles))
                {
                    throw new SecurityException("No Access.");
                }


                var file = new File
                {
                    fk_FolderId  = (Guid)folderId,
                    IsDeleted    = false,
                    isRevisioned = true,
                    Name         = name,
                    MimeType     = MimeMapping.GetMimeMapping(name),
                    CreatedById  = createdBy.SecurityObjectId,
                    CreateDt     = DateTime.Now,
                    OwnerId      = createdBy.SecurityObjectId
                };
                context.Files.Add(file);
                context.SaveChanges();

                FileSecurity fileSecurity = new FileSecurity
                {
                    CanDelete        = true,
                    canRead          = true,
                    canWrite         = true,
                    fk_FileId        = file.pk_FileId,
                    SecurityObjectId = createdBy.SecurityObjectId
                };
                context.FileSecurities.Add(fileSecurity);
                context.SaveChanges();

                foreach (FolderSecurity security in folder.FolderSecurities)
                {
                    fileSecurity = context.FileSecurities.FirstOrDefault(d => d.SecurityObjectId == security.SecurityObjectId && d.fk_FileId == file.pk_FileId);
                    if (fileSecurity == null)
                    {
                        fileSecurity = new FileSecurity
                        {
                            CanDelete        = security.canDelete,
                            canRead          = security.canListObjects,
                            canWrite         = security.canCreateFiles,
                            fk_FileId        = file.pk_FileId,
                            SecurityObjectId = security.SecurityObjectId
                        };
                        context.FileSecurities.Add(fileSecurity);
                    }
                    else
                    {
                        fileSecurity.CanDelete = security.canDelete;
                        fileSecurity.canRead   = security.canListObjects;
                        fileSecurity.canWrite  = security.canCreateFiles;
                    }
                }


                context.SaveChanges();
                return(file);
            }
        }
        public void RestoreDeleted(SecurityObject undeletedBy)
        {
            List<FolderSecurity> perm;
            using (var context = new OnlineFilesEntities())
                perm = context.FolderSecurities.AsNoTracking().Where(d => d.fk_FolderId == pk_FolderId).ToList();

            if (perm.Any(d => d.canDelete && undeletedBy.mySecurityGroups.Contains(d.SecurityObjectId)))
            {
                IsDeleted = false;
                DeletedDt = DateTime.Now;
                DeletedById = undeletedBy.SecurityObjectId;
            }
            else
            {
                throw new SecurityException("Not Authorized.");
            }
        }
        /// <summary>
        /// Creates a new Folder object.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parentFolderGuid"></param>
        /// <param name="createdBy"></param>
        /// <param name="inheritSecurity"></param>
        /// <param name="isSystemCreate"></param>
        /// <returns></returns>
        public static Folder Create(string name, Guid? parentFolderGuid, SecurityObject createdBy, bool inheritSecurity = true, bool isSystemCreate = false)
        {
            using (var context = new OnlineFilesEntities())
            {
                //Get Folder object for parent folder
                Folder parentFolder = context.Folders
                    .Include(x => x.CatalogCollection)
                    .Include(x => x.FolderSecurities)
                    .FirstOrDefault(d => d.pk_FolderId == parentFolderGuid);

                if (!isSystemCreate)
                    if (!(parentFolder.FolderSecurities.Any(x => createdBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.canCreateFolders)))
                        throw new SecurityException("Not Authorized.");


                //Check Name
                name = parentFolder.CheckFolderName(name);

                //If Parent Folder is null, throw exception
                if (parentFolder == null)
                    throw new Exception("Folder is null");


                //Create Folder
                Folder f = new Folder
                {
                    fk_ParentFolderId = parentFolderGuid,
                    Name = name,
                    CreateDt = DateTime.Now,
                    fk_CatalogCollectionId = parentFolder.fk_CatalogCollectionId,
                    Win32FileAttribute = (int)FileAttributes.Directory,
                    IsDeleted = false,
                    DeletedDt = null,
                    DeletedBy = null,
                    OwnerId = createdBy.SecurityObjectId,
                    CreatedById = createdBy.SecurityObjectId
                };
                try
                {
                    context.Folders.Add(f);
                    context.SaveChanges();
                    var pfs = new FolderSecurity()
                    {
                        canDelete = true,
                        canListObjects = true,
                        canCreateFiles = true,
                        canCreateFolders = true,
                        canChangePermissions = true,
                        fk_FolderId = f.pk_FolderId,
                        SecurityObjectId = createdBy.SecurityObjectId
                    };
                    context.SaveChanges();


                    if (inheritSecurity)
                    {
                        foreach (FolderSecurity fs in parentFolder.FolderSecurities)
                        {
                            FolderSecurity folderSecurity = new FolderSecurity()
                            {
                                SecurityObjectId = fs.SecurityObjectId,
                                fk_FolderId = f.pk_FolderId,
                                canCreateFolders = fs.canCreateFolders,
                                canDelete = fs.canDelete,
                                canChangePermissions = fs.canChangePermissions,
                                canCreateFiles = fs.canCreateFiles,
                                canListObjects = fs.canListObjects
                            };
                            context.FolderSecurities.Add(folderSecurity);
                        }

                        context.SaveChanges();

                        FolderSecurity us = context.FolderSecurities.FirstOrDefault(d => d.fk_FolderId == f.pk_FolderId && d.SecurityObjectId == createdBy.SecurityObjectId);
                        if (us == null)
                        {
                            us = new FolderSecurity()
                            {
                                canListObjects = true,
                                canChangePermissions = true,
                                canCreateFiles = true,
                                canCreateFolders = true,
                                canDelete = true,
                                fk_FolderId = f.pk_FolderId,
                                SecurityObjectId = createdBy.SecurityObjectId
                            };
                            context.FolderSecurities.Add(us);
                        }
                        else
                        {
                            us.canListObjects = true;
                            us.canChangePermissions = true;
                            us.canCreateFolders = true;
                            us.canCreateFiles = true;
                            us.canDelete = true;
                        }
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create new folder.", ex);
                }
                return f;
            }



        }
Exemple #11
0
        /// <summary>
        /// Creates a new Folder object.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parentFolderGuid"></param>
        /// <param name="createdBy"></param>
        /// <param name="inheritSecurity"></param>
        /// <param name="isSystemCreate"></param>
        /// <returns></returns>
        public static Folder Create(string name, Guid?parentFolderGuid, SecurityObject createdBy, bool inheritSecurity = true, bool isSystemCreate = false)
        {
            using (var context = new OnlineFilesEntities())
            {
                //Get Folder object for parent folder
                Folder parentFolder = context.Folders
                                      .Include(x => x.CatalogCollection)
                                      .Include(x => x.FolderSecurities)
                                      .FirstOrDefault(d => d.pk_FolderId == parentFolderGuid);

                if (!isSystemCreate)
                {
                    if (!(parentFolder.FolderSecurities.Any(x => createdBy.mySecurityGroups.Contains(x.SecurityObjectId) && x.canCreateFolders)))
                    {
                        throw new SecurityException("Not Authorized.");
                    }
                }


                //Check Name
                name = parentFolder.CheckFolderName(name);

                //If Parent Folder is null, throw exception
                if (parentFolder == null)
                {
                    throw new Exception("Folder is null");
                }


                //Create Folder
                Folder f = new Folder
                {
                    fk_ParentFolderId = parentFolderGuid,
                    Name     = name,
                    CreateDt = DateTime.Now,
                    fk_CatalogCollectionId = parentFolder.fk_CatalogCollectionId,
                    Win32FileAttribute     = (int)FileAttributes.Directory,
                    IsDeleted   = false,
                    DeletedDt   = null,
                    DeletedBy   = null,
                    OwnerId     = createdBy.SecurityObjectId,
                    CreatedById = createdBy.SecurityObjectId
                };
                try
                {
                    context.Folders.Add(f);
                    context.SaveChanges();
                    var pfs = new FolderSecurity()
                    {
                        canDelete            = true,
                        canListObjects       = true,
                        canCreateFiles       = true,
                        canCreateFolders     = true,
                        canChangePermissions = true,
                        fk_FolderId          = f.pk_FolderId,
                        SecurityObjectId     = createdBy.SecurityObjectId
                    };
                    context.SaveChanges();


                    if (inheritSecurity)
                    {
                        foreach (FolderSecurity fs in parentFolder.FolderSecurities)
                        {
                            FolderSecurity folderSecurity = new FolderSecurity()
                            {
                                SecurityObjectId     = fs.SecurityObjectId,
                                fk_FolderId          = f.pk_FolderId,
                                canCreateFolders     = fs.canCreateFolders,
                                canDelete            = fs.canDelete,
                                canChangePermissions = fs.canChangePermissions,
                                canCreateFiles       = fs.canCreateFiles,
                                canListObjects       = fs.canListObjects
                            };
                            context.FolderSecurities.Add(folderSecurity);
                        }

                        context.SaveChanges();

                        FolderSecurity us = context.FolderSecurities.FirstOrDefault(d => d.fk_FolderId == f.pk_FolderId && d.SecurityObjectId == createdBy.SecurityObjectId);
                        if (us == null)
                        {
                            us = new FolderSecurity()
                            {
                                canListObjects       = true,
                                canChangePermissions = true,
                                canCreateFiles       = true,
                                canCreateFolders     = true,
                                canDelete            = true,
                                fk_FolderId          = f.pk_FolderId,
                                SecurityObjectId     = createdBy.SecurityObjectId
                            };
                            context.FolderSecurities.Add(us);
                        }
                        else
                        {
                            us.canListObjects       = true;
                            us.canChangePermissions = true;
                            us.canCreateFolders     = true;
                            us.canCreateFiles       = true;
                            us.canDelete            = true;
                        }
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create new folder.", ex);
                }
                return(f);
            }
        }