Example #1
0
 private void Rebind()
 {
     cboEnvironment.DataSource = null;
     cboEnvironment.Refresh();
     cboEnvironment.DataSource = _itemList;
     if (SelectedItem == null && ItemList.Any())
     {
         SelectedItem = ItemList.First();
     }
 }
        public void ValidRelation()
        {
            var tl = new List <DesignLink>();

            LinkList.ToList().ForEach(v =>
            {
                if (!ItemList.Any(item => item.TargetObjectID == v.SourceID) ||
                    !ItemList.Any(item => item.TargetObjectID == v.TargetID))
                {
                    tl.Add(v);
                }
            });
            tl.ForEach(v => LinkList.Remove(v));
        }
Example #3
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.Text != string.Empty && txtDescription.Text != string.Empty && txtPrice.Text != string.Empty &&
                    IsNumeric(txtPrice.Text) && txtPurchaseLocation.Text != string.Empty && txtQuantity.Text != string.Empty &&
                    IsNumeric(txtQuantity.Text) && txtJustification.Text != string.Empty)
                {
                    Item tmpItem = ItemFactory.Create();
                    tmpItem.Name             = txtName.Text;
                    tmpItem.Description      = txtDescription.Text;
                    tmpItem.Price            = Convert.ToDouble(txtPrice.Text);
                    tmpItem.PurchaseLocation = txtPurchaseLocation.Text;
                    tmpItem.Quantity         = Convert.ToInt16(txtQuantity.Text);
                    tmpItem.Justification    = txtJustification.Text;
                    tmpItem.Status           = "Pending";
                    tmpItem.Subtotal         = tmpItem.Price * tmpItem.Quantity;

                    if (VAL.Validate.cleanItem(tmpItem))
                    {
                        if (ItemList.Count > 0)
                        {
                            if (ItemList.Any(Item => Item.Name == tmpItem.Name) && ItemList.Any(Item => Item.Description == tmpItem.Description) &&
                                ItemList.Any(Item => Item.Price == tmpItem.Price) && ItemList.Any(Item => Item.PurchaseLocation == tmpItem.PurchaseLocation) &&
                                ItemList.Any(Item => Item.Justification == tmpItem.Justification))
                            {
                                foreach (Item item in ItemList)
                                {
                                    if (tmpItem.Name.Equals(item.Name) && tmpItem.Description.Equals(item.Description) &&
                                        tmpItem.Price == item.Price && tmpItem.PurchaseLocation.Equals(item.PurchaseLocation) &&
                                        tmpItem.Justification.Equals(item.Justification))
                                    {
                                        item.Quantity   += tmpItem.Quantity;
                                        item.Subtotal    = item.Price * item.Quantity;
                                        grdItems.Visible = true;
                                        grdItems.DataBind();
                                        totals.Visible = true;
                                        ClearInputs();
                                        txtName.Focus();

                                        CalculateTotals();
                                    }
                                }
                            }
                            else
                            {
                                grdItems.Visible = true;
                                totals.Visible   = true;
                                ItemList.Add(tmpItem);
                                grdItems.DataBind();
                                ClearInputs();
                                txtName.Focus();

                                CalculateTotals();
                            }
                        }
                        else
                        {
                            grdItems.Visible = true;
                            totals.Visible   = true;
                            ItemList.Add(tmpItem);
                            grdItems.DataBind();
                            ClearInputs();
                            txtName.Focus();

                            CalculateTotals();
                        }
                    }
                    confirmation.Attributes.Add("style", "display:none");
                    lblMessage.Text = "";
                }
                else
                {
                    confirmation.Attributes.Add("style", "display:block");
                    lblMessage.Text = "Item addition was unsuccessful. Please make sure all fields are filled in properly and resubmit";
                }
            }
            catch (Exception ex)
            {
                confirmation.Attributes.Add("style", "display:block");
                lblMessage.Text = "An error has occurred. " + ex.Message;
            }
        }
Example #4
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;
        }
        public override void Migrate()
        {
            if (!ShouldImport)
            {
                return;
            }

            var drivePath = Directory.Exists(Path.Combine(rootFolder, "data", user.Key, "files")) ?
                            Path.Combine(rootFolder, "data", user.Key) : null;

            if (drivePath == null)
            {
                return;
            }
            matchingFileId = new Dictionary <object, int>();
            var foldersDict = new Dictionary <string, Folder>();

            if (folders != null)
            {
                foreach (var folder in folders)
                {
                    var split = folder.Path.Split('/');
                    for (var i = 0; i < split.Length; i++)
                    {
                        var path = string.Join(Path.DirectorySeparatorChar.ToString(), split.Take(i + 1));
                        if (foldersDict.ContainsKey(path))
                        {
                            continue;
                        }
                        var parentId = i == 0 ? Global.FolderMy : foldersDict[string.Join(Path.DirectorySeparatorChar.ToString(), split.Take(i))].ID;
                        try
                        {
                            var newFolder = Global.FileStorageService.CreateNewFolder(parentId.ToString(), split[i]);
                            foldersDict.Add(path, newFolder);
                            matchingFileId.Add(newFolder.ID, folder.FileId);
                        }
                        catch (Exception ex)
                        {
                            Log($"Couldn't create folder {path}", ex);
                        }
                    }
                }
            }

            if (files != null)
            {
                foreach (var file in files)
                {
                    string[] maskPaths = file.Path.Split('/');
                    if (maskPaths[0] == "OwnCloud’s Files " + DateTime.Now.ToString("dd.MM.yyyy"))
                    {
                        maskPaths[0] = "files";
                    }
                    var maskPath   = string.Join(Path.DirectorySeparatorChar.ToString(), maskPaths);
                    var parentPath = Path.GetDirectoryName(file.Path);
                    try
                    {
                        var realPath = Path.Combine(drivePath, maskPath);
                        using (var fs = new FileStream(realPath, FileMode.Open))
                            using (var fileDao = Global.DaoFactory.GetFileDao())
                                using (var folderDao = Global.DaoFactory.GetFolderDao())
                                {
                                    var parentFolder = string.IsNullOrWhiteSpace(parentPath) ? folderDao.GetFolder(Global.FolderMy) : foldersDict[parentPath];

                                    var newFile = new ASCFile
                                    {
                                        FolderID      = parentFolder.ID,
                                        Comment       = FilesCommonResource.CommentCreate,
                                        Title         = Path.GetFileName(file.Path),
                                        ContentLength = fs.Length
                                    };
                                    newFile = fileDao.SaveFile(newFile, fs);
                                    matchingFileId.Add(newFile.ID, file.FileId);
                                }
                    }
                    catch (Exception ex)
                    {
                        Log($"Couldn't create file {parentPath}/{Path.GetFileName(file.Path)}", ex);
                    }
                }
            }

            foreach (var item in matchingFileId)
            {
                var list        = new ItemList <AceWrapper>();
                var entryIsFile = files.Exists(el => el.FileId == item.Value) ? true : false;
                var entry       = entryIsFile ? files.Find(el => el.FileId == item.Value) : folders.Find(el => el.FileId == item.Value);
                if (entry.Share.Count == 0)
                {
                    continue;
                }
                foreach (var shareInfo in entry.Share)
                {
                    if (shareInfo.ShareWith == null)
                    {
                        continue;
                    }
                    var shareType = GetPortalShare(shareInfo.Premissions, entryIsFile);
                    users.TryGetValue(shareInfo.ShareWith, out var userToShare);
                    groups.TryGetValue(shareInfo.ShareWith, out var groupToShare);

                    if (userToShare != null || groupToShare != null)
                    {
                        var entryGuid = userToShare == null ? groupToShare.Guid : userToShare.Guid;
                        list.Add(new AceWrapper
                        {
                            Share        = shareType.Value,
                            SubjectId    = entryGuid,
                            SubjectGroup = false
                        });
                    }
                }
                if (!list.Any())
                {
                    continue;
                }
                var aceCollection = new AceCollection
                {
                    Entries = new ItemList <string> {
                        (entryIsFile ? "file_" : "folder_") + (int)item.Key
                    },
                    Aces    = list,
                    Message = null
                };

                try
                {
                    Global.FileStorageService.SetAceObject(aceCollection, false);
                }
                catch (Exception ex)
                {
                    Log($"Couldn't change file permissions for {aceCollection.Entries.First()}", ex);
                }
            }
        }
Example #6
0
 public static bool HasAspect(this ItemList <NinjaItem> me, string s)
 {
     return(me.Any(z => z.Aspects.Where(x => x.IsActive()).Any(j => j.Name == s)));
 }
        public override void Migrate()
        {
            if (!ShouldImport)
            {
                return;
            }

            var tmpFolder = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(user.Key));

            try
            {
                ZipFile.ExtractToDirectory(user.Key, tmpFolder);
                var drivePath = Path.Combine(tmpFolder, "Takeout", "Drive");

                // Create all folders first
                var foldersDict = new Dictionary <string, Folder>();
                if (folders != null && folders.Count != 0)
                {
                    foreach (var folder in folders)
                    {
                        var split = folder.Split(Path.DirectorySeparatorChar); // recursivly create all the folders
                        for (var i = 0; i < split.Length; i++)
                        {
                            var path = string.Join(Path.DirectorySeparatorChar.ToString(), split.Take(i + 1));
                            if (foldersDict.ContainsKey(path))
                            {
                                continue;                                // skip folder if it was already created as a part of another path
                            }
                            var parentId = i == 0 ? Global.FolderMy : foldersDict[string.Join(Path.DirectorySeparatorChar.ToString(), split.Take(i))].ID;
                            try
                            {
                                var createdFolder = Global.FileStorageService.CreateNewFolder(parentId.ToString(), split[i]);
                                path = path.Contains(newParentFolder + Path.DirectorySeparatorChar.ToString()) ? path.Replace(newParentFolder + Path.DirectorySeparatorChar.ToString(), "") : path;
                                foldersDict.Add(path, createdFolder);
                            }
                            catch (Exception ex)
                            {
                                Log($"Couldn't create folder {path}", ex);
                            }
                        }
                    }
                }
                //create default folder
                if ((folders == null || folders.Count == 0) && (files != null && files.Count != 0))
                {
                    var parentId      = Global.FolderMy;
                    var createdFolder = Global.FileStorageService.CreateNewFolder(parentId.ToString(), newParentFolder);
                    foldersDict.Add(newParentFolder, createdFolder);
                }

                // Copy all files
                var filesDict = new Dictionary <string, ASCFile>();
                if (files != null && files.Count != 0)
                {
                    foreach (var file in files)
                    {
                        var maskFile       = file.Replace(ModuleName + " " + folderCreation + Path.DirectorySeparatorChar.ToString(), "");
                        var maskParentPath = Path.GetDirectoryName(maskFile);

                        // ToDo: maybe we should upload to root, if required folder wasn't created

                        try
                        {
                            var realPath = Path.Combine(drivePath, maskFile);
                            using (var fs = new FileStream(realPath, FileMode.Open))
                                using (var fileDao = Global.DaoFactory.GetFileDao())
                                    using (var folderDao = Global.DaoFactory.GetFolderDao())
                                    {
                                        var parentFolder = string.IsNullOrWhiteSpace(maskParentPath) ? foldersDict[newParentFolder] : foldersDict[maskParentPath];

                                        var newFile = new ASCFile
                                        {
                                            FolderID      = parentFolder.ID,
                                            Comment       = FilesCommonResource.CommentCreate,
                                            Title         = Path.GetFileName(file),
                                            ContentLength = fs.Length
                                        };
                                        newFile  = fileDao.SaveFile(newFile, fs);
                                        realPath = realPath.Contains(Path.DirectorySeparatorChar.ToString() + newParentFolder) ? realPath.Replace(Path.DirectorySeparatorChar.ToString() + newParentFolder, "") : realPath;
                                        filesDict.Add(realPath, newFile);
                                    }
                        }
                        catch (Exception ex)
                        {
                            Log($"Couldn't create file {maskParentPath}/{Path.GetFileName(file)}", ex);
                        }
                    }
                }

                var entries = filesDict
                              .ToDictionary(kv => kv.Key, kv => (FileEntry)kv.Value)
                              .Concat(foldersDict
                                      .ToDictionary(kv => Path.Combine(drivePath, kv.Key), kv => (FileEntry)kv.Value))
                              .OrderBy(kv => kv.Value is ASCFile)
                              .ThenBy(kv => kv.Key.Count(c => Path.DirectorySeparatorChar.Equals(c)));

                var favFolders = new ItemList <object>();
                var favFiles   = new ItemList <object>();

                var fileSec = new FileSecurity(Global.DaoFactory);

                foreach (var kv in entries)
                {
                    if (TryReadInfoFile(kv.Key, out var info))
                    {
                        if (info.Starred)
                        {
                            if (kv.Value is ASCFile)
                            {
                                favFiles.Add(kv.Value.ID);
                            }
                            else
                            {
                                favFolders.Add(kv.Value.ID);
                            }
                        }

                        var list = new ItemList <AceWrapper>();
                        foreach (var shareInfo in info.Permissions)
                        {
                            if (shareInfo.Type == "user" || shareInfo.Type == "group")
                            {
                                var shareType = GetPortalShare(shareInfo);
                                users.TryGetValue(shareInfo.EmailAddress, out var userToShare);
                                groups.TryGetValue(shareInfo.Name, out var groupToShare);
                                if (shareType == null || (userToShare == null && groupToShare == null))
                                {
                                    continue;
                                }

                                Func <FileEntry, Guid, bool> checkRights = null;
                                switch (shareType)
                                {
                                case ASCShare.ReadWrite:
                                    checkRights = fileSec.CanEdit;
                                    break;

                                case ASCShare.Comment:
                                    checkRights = fileSec.CanComment;
                                    break;

                                case ASCShare.Read:
                                    checkRights = fileSec.CanRead;
                                    break;

                                default:     // unused
                                    break;
                                }
                                var entryGuid = userToShare == null ? groupToShare.Guid : userToShare.Guid;

                                if (checkRights != null && checkRights(kv.Value, entryGuid))
                                {
                                    continue;                                                          // already have rights, skip
                                }
                                list.Add(new AceWrapper
                                {
                                    Share        = shareType.Value,
                                    SubjectId    = entryGuid,
                                    SubjectGroup = false
                                });
                            }
                        }

                        if (!list.Any())
                        {
                            continue;
                        }

                        var aceCollection = new AceCollection
                        {
                            Entries = new ItemList <string> {
                                (kv.Value is ASCFile ? "file_" : "folder_") + kv.Value.ID
                            },
                            Aces    = list,
                            Message = null
                        };
                        try
                        {
                            Global.FileStorageService.SetAceObject(aceCollection, false);
                        }
                        catch (Exception ex)
                        {
                            Log($"Couldn't change file permissions for {aceCollection.Entries.First()}", ex);
                        }
                    }
                }

                if (favFolders.Any() || favFiles.Any())
                {
                    Global.FileStorageService.AddToFavorites(favFolders, favFiles);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (Directory.Exists(tmpFolder))
                {
                    Directory.Delete(tmpFolder, true);
                }
            }
        }