Ejemplo n.º 1
0
        public AceShortWrapper(AceWrapper aceWrapper)
        {
            var permission = string.Empty;

            switch (aceWrapper.Share)
            {
            case FileShare.Read:
                permission = FilesCommonResource.AceStatusEnum_Read;
                break;

            case FileShare.ReadWrite:
                permission = FilesCommonResource.AceStatusEnum_ReadWrite;
                break;

            case FileShare.Restrict:
                permission = FilesCommonResource.AceStatusEnum_Restrict;
                break;
            }

            User = aceWrapper.SubjectName;
            if (aceWrapper.SubjectId.Equals(FileConstant.ShareLinkId))
            {
                IsLink = true;
                User   = FilesCommonResource.AceShareLink;
            }
            Permissions = permission;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="aceWrapper"></param>
        public FileShareWrapper(AceWrapper aceWrapper)
        {
            IsOwner = aceWrapper.Owner;
            IsLocked = aceWrapper.LockedRights;
            if (aceWrapper.SubjectGroup)
            {
                //Shared to group
                SharedTo = new GroupWrapperSummary(Core.CoreContext.GroupManager.GetGroupInfo(aceWrapper.SubjectId));
            }
            else
            {
                SharedTo = EmployeeWraper.Get(aceWrapper.SubjectId);    
            }
            Access = aceWrapper.Share;

        }
Ejemplo n.º 3
0
        public AceShortWrapper(AceWrapper aceWrapper)
        {
            var permission = string.Empty;

            switch (aceWrapper.Share)
            {
                case FileShare.Read:
                    permission = FilesCommonResource.AceStatusEnum_Read;
                    break;
                case FileShare.ReadWrite:
                    permission = FilesCommonResource.AceStatusEnum_ReadWrite;
                    break;
                case FileShare.Restrict:
                    permission = FilesCommonResource.AceStatusEnum_Restrict;
                    break;
            }

            User = aceWrapper.SubjectName;
            Permissions = permission;
        }
Ejemplo n.º 4
0
        public AceShortWrapper(AceWrapper aceWrapper)
        {
            var permission = string.Empty;

            switch (aceWrapper.Share)
            {
            case FileShare.Read:
                permission = FilesCommonResource.AceStatusEnum_Read;
                break;

            case FileShare.ReadWrite:
                permission = FilesCommonResource.AceStatusEnum_ReadWrite;
                break;

            case FileShare.Restrict:
                permission = FilesCommonResource.AceStatusEnum_Restrict;
                break;
            }

            User        = aceWrapper.SubjectName;
            Permissions = permission;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name="aceWrapper"></param>
        public FileShareWrapper(AceWrapper aceWrapper)
        {
            IsOwner = aceWrapper.Owner;
            IsLocked = aceWrapper.LockedRights;
            if (aceWrapper.SubjectGroup)
            {
                if (aceWrapper.SubjectId == FileConstant.ShareLinkId)
                {

                    SharedTo = new FileShareLink { Id = aceWrapper.SubjectId, ShareLink = aceWrapper.SubjectName };
                }
                else
                {
                    //Shared to group
                    SharedTo = new GroupWrapperSummary(CoreContext.UserManager.GetGroupInfo(aceWrapper.SubjectId));
                }
            }
            else
            {
                SharedTo = new EmployeeWraperFull(CoreContext.UserManager.GetUsers(aceWrapper.SubjectId));
            }
            Access = aceWrapper.Share;
        }
Ejemplo n.º 6
0
        public ItemList<AceWrapper> GetSharedInfo(String objectId)
        {
            ErrorIf(!SecurityContext.IsAuthenticated, FilesCommonResource.ErrorMassage_SecurityException, true);
            ErrorIf(string.IsNullOrEmpty(objectId), FilesCommonResource.ErrorMassage_BadRequest, true);

            var entryType = objectId.StartsWith("file_") ? FileEntryType.File : FileEntryType.Folder;
            var entryId = objectId.Substring((entryType == FileEntryType.File ? "file_" : "folder_").Length);

            var shareLink = FileShare.Restrict;

            var result = new ItemList<AceWrapper>();

            using (var folderDao = GetFolderDao())
            using (var fileDao = GetFileDao())
            {
                var entry = entryType == FileEntryType.File
                                ? (FileEntry) fileDao.GetFile(entryId)
                                : (FileEntry) folderDao.GetFolder(entryId);

                ErrorIf(entry.RootFolderType == FolderType.COMMON && !Global.IsAdministrator, FilesCommonResource.ErrorMassage_SecurityException, true);
                ErrorIf(entry.RootFolderType == FolderType.USER && !Equals(entry.RootFolderId, Global.FolderMy), FilesCommonResource.ErrorMassage_SecurityException, true);

                var records = FileSecurity
                    .GetShares(entry)
                    .GroupBy(r => r.Subject)
                    .Select(g => g.OrderBy(r => r.Level).ThenByDescending(r => r.Share).FirstOrDefault());

                foreach (var r in records)
                {
                    if (r.Subject == FileConstant.ShareLinkId)
                    {
                        shareLink = r.Share;
                    }
                    else
                    {
                        var u = CoreContext.UserManager.GetUsers(r.Subject);
                        var isgroup = false;
                        var title = u.DisplayUserName(false);

                        if (u.ID == ASC.Core.Users.Constants.LostUser.ID)
                        {
                            var g = CoreContext.GroupManager.GetGroupInfo(r.Subject);
                            isgroup = true;
                            title = g.Name;

                            if (g.ID == ASC.Core.Users.Constants.GroupAdmin.ID)
                                title = FilesCommonResource.Admin;
                            if (g.ID == ASC.Core.Users.Constants.GroupEveryone.ID)
                                title = FilesCommonResource.Everyone;

                            if (g.ID == ASC.Core.Users.Constants.LostGroupInfo.ID)
                            {
                                FileSecurity.RemoveSubject(r.Subject);
                                continue;
                            }
                        }

                        var w = new AceWrapper
                                    {
                                        SubjectId = r.Subject,
                                        SubjectName = title,
                                        SubjectGroup = isgroup,
                                        Share = r.Share,
                                        Owner =
                                            entry.RootFolderType == FolderType.USER
                                                ? entry.RootFolderCreator == r.Subject
                                                : entry.CreateBy == r.Subject,
                                    };
                        result.Add(w);
                    }
                }

                if (entryType == FileEntryType.File && !result.Any(w => w.SubjectId == FileConstant.ShareLinkId))
                {
                    var w = new AceWrapper
                                {
                                    SubjectId = FileConstant.ShareLinkId,
                                    SubjectName = DocumentUtils.GetShareLinkParam(entryId),
                                    SubjectGroup = true,
                                    Share = shareLink,
                                    Owner = false
                                };
                    result.Add(w);
                }

                if (!result.Any(w => w.Owner))
                {
                    var ownerId = entry.RootFolderType == FolderType.USER ? entry.RootFolderCreator : entry.CreateBy;
                    var w = new AceWrapper
                                {
                                    SubjectId = ownerId,
                                    SubjectName = FileEntry.GetUserName(ownerId),
                                    SubjectGroup = false,
                                    Share = FileShare.ReadWrite,
                                    Owner = true,
                                };
                    result.Add(w);
                }
                if (entry.RootFolderType == FolderType.COMMON)
                {
                    if (result.All(w => w.SubjectId != ASC.Core.Users.Constants.GroupAdmin.ID))
                    {
                        var w = new AceWrapper
                                    {
                                        SubjectId = ASC.Core.Users.Constants.GroupAdmin.ID,
                                        SubjectName = FilesCommonResource.Admin,
                                        SubjectGroup = true,
                                        Share = FileShare.ReadWrite,
                                        Owner = false,
                                        LockedRights = true,
                                    };
                        result.Add(w);
                    }
                    if (result.All(w => w.SubjectId != ASC.Core.Users.Constants.GroupEveryone.ID))
                    {
                        var w = new AceWrapper
                                    {
                                        SubjectId = ASC.Core.Users.Constants.GroupEveryone.ID,
                                        SubjectName = FilesCommonResource.Everyone,
                                        SubjectGroup = true,
                                        Share = FileSecurity.DefaultCommonShare,
                                        Owner = false,
                                    };
                        result.Add(w);
                    }
                }
            }

            result.Sort((x, y) => string.Compare(x.SubjectName, y.SubjectName));

            return result;
        }
Ejemplo n.º 7
0
        public static List<AceWrapper> GetSharedInfo(FileEntry entry)
        {
            if (!CanSetAccess(entry)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException);

            var linkAccess = FileShare.Restrict;
            var result = new List<AceWrapper>();

            var fileSecurity = Global.GetFilesSecurity();

            var records = fileSecurity
                .GetShares(entry)
                .GroupBy(r => r.Subject)
                .Select(g => g.OrderBy(r => r.Level)
                              .ThenBy(r => r.Level)
                              .ThenByDescending(r => r.Share).FirstOrDefault());

            foreach (var r in records)
            {
                if (r.Subject == FileConstant.ShareLinkId)
                {
                    linkAccess = r.Share;
                    continue;
                }

                var u = CoreContext.UserManager.GetUsers(r.Subject);
                var isgroup = false;
                var title = u.DisplayUserName(false);

                if (u.ID == Constants.LostUser.ID)
                {
                    var g = CoreContext.GroupManager.GetGroupInfo(r.Subject);
                    isgroup = true;
                    title = g.Name;

                    if (g.ID == Constants.GroupAdmin.ID)
                        title = FilesCommonResource.Admin;
                    if (g.ID == Constants.GroupEveryone.ID)
                        title = FilesCommonResource.Everyone;

                    if (g.ID == Constants.LostGroupInfo.ID)
                    {
                        fileSecurity.RemoveSubject(r.Subject);
                        continue;
                    }
                }

                var w = new AceWrapper
                    {
                        SubjectId = r.Subject,
                        SubjectName = title,
                        SubjectGroup = isgroup,
                        Share = r.Share,
                        Owner =
                            entry.RootFolderType == FolderType.USER
                                ? entry.RootFolderCreator == r.Subject
                                : entry.CreateBy == r.Subject,
                        LockedRights = r.Subject == SecurityContext.CurrentAccount.ID
                    };
                result.Add(w);
            }

            if (entry is File && result.All(w => w.SubjectId != FileConstant.ShareLinkId))
            {
                var w = new AceWrapper
                    {
                        SubjectId = FileConstant.ShareLinkId,
                        SubjectName = FileShareLink.GetLink((File)entry),
                        SubjectGroup = true,
                        Share = linkAccess,
                        Owner = false
                    };
                result.Add(w);
            }

            if (!result.Any(w => w.Owner))
            {
                var ownerId = entry.RootFolderType == FolderType.USER ? entry.RootFolderCreator : entry.CreateBy;
                var w = new AceWrapper
                    {
                        SubjectId = ownerId,
                        SubjectName = Global.GetUserName(ownerId),
                        SubjectGroup = false,
                        Share = FileShare.ReadWrite,
                        Owner = true
                    };
                result.Add(w);
            }

            if (result.Any(w => w.SubjectId == SecurityContext.CurrentAccount.ID))
                result.Single(w => w.SubjectId == SecurityContext.CurrentAccount.ID).LockedRights =
                    true;

            if (entry.RootFolderType == FolderType.COMMON)
            {
                if (result.All(w => w.SubjectId != Constants.GroupAdmin.ID))
                {
                    var w = new AceWrapper
                        {
                            SubjectId = Constants.GroupAdmin.ID,
                            SubjectName = FilesCommonResource.Admin,
                            SubjectGroup = true,
                            Share = FileShare.ReadWrite,
                            Owner = false,
                            LockedRights = true,
                        };
                    result.Add(w);
                }
                if (result.All(w => w.SubjectId != Constants.GroupEveryone.ID))
                {
                    var w = new AceWrapper
                        {
                            SubjectId = Constants.GroupEveryone.ID,
                            SubjectName = FilesCommonResource.Everyone,
                            SubjectGroup = true,
                            Share = fileSecurity.DefaultCommonShare,
                            Owner = false,
                            DisableRemove = true
                        };
                    result.Add(w);
                }
            }

            return result;
        }