Esempio n. 1
0
        public async Task <TreeView> GetRootTreeView(string userId)
        {
            if (!await HasAccessToLibrary())
            {
                return(null);
            }

            var locationResolver = new DocumentPhysicalLocationResolver("Site", _adminContext.ClientId, _adminContext.SiteId, ownerId);

            //ensure Site library is created if not done yet for whatever reason
            if ((await _folderManager.GetDocumentLibraryAsync(ownerId) == null))
            {
                await _folderManager.CreateDocumentLibrary(ownerId, "Site", locationResolver.Resolve());
            }

            var rootUserFolder = await _folderManager.GetRootFolderAsync(ownerId);

            var childFolders = await _folderManager.GetFoldersRecursivelyAsync(rootUserFolder, false);

            ((Folder)rootUserFolder).ChildFolders = childFolders;
            //IFolder firstLevelFolder = new Folder
            //{
            //    Title ="",
            //    Id = "FolderRoot",
            //    ChildFolders = folders
            //};

            return(FolderToTreeView(rootUserFolder));
        }
Esempio n. 2
0
        private async Task CreateLibraryAndRootFolder(Site site)
        {
            var locationResolver = new DocumentPhysicalLocationResolver("Site", site.ClientId, site.Id, "");

            //creates the document library
            var documentLibrary = await _folderManager.CreateDocumentLibrary(site.Id, "Site", locationResolver.Resolve());

            //create root folder / ensure there is a root folder
            await _folderManager.GetRootFolderAsync(site.Id);
        }
        private async void CreateLibraryAndRootFolder(Client client)
        {
            var locationResolver = new DocumentPhysicalLocationResolver("Client", client.Id, "", "");

            //creates the document library
            var documentLibrary = await _folderManager.CreateDocumentLibrary(client.Id, "Client", locationResolver.Resolve());

            //create root folder / ensure there is a root folder
            await _folderManager.GetRootFolderAsync(client.Id);
        }
Esempio n. 4
0
        public async Task <TreeView> GetRootTreeView(string userId)
        {
            var locationResolver = new DocumentPhysicalLocationResolver("User", _adminContext.ClientId, "", userId);

            //ensure users has a library
            if ((await _folderManager.GetDocumentLibraryAsync(userId) == null))
            {
                await _folderManager.CreateDocumentLibrary(userId, "User", locationResolver.Resolve());
            }

            var rootUserFolder = await _folderManager.GetRootFolderAsync(userId);

            var childFolders = await _folderManager.GetFoldersRecursivelyAsync(rootUserFolder, false);

            ((Folder)rootUserFolder).ChildFolders = childFolders;

            return(FolderToTreeView(rootUserFolder));
        }
        public async Task <IActionResult> CreateUser(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var valid = await _directoryManager.IsMapped(model.DirectoryId, Client.SecurityPoolId);

                if (!valid)
                {
                    return(BadRequest("Invalid or Unmapped Site Directory"));
                }

                var user   = model.ProjectTo <User>();
                var result = await _userManager.CreateAsync(user);

                if (!result.Succeeded)
                {
                    return(BadRequest(String.Join(". ", result.Errors.Select(x => x.Description).ToArray())));
                }

                //Ensure user has a library created
                var locationResolver = new DocumentPhysicalLocationResolver("User", Client.Id, "", user.Id);

                var userLibrary = await _folderManager.CreateDocumentLibrary(user.Id, "User", locationResolver.Resolve());

                //TODO. If success, then send email to user. Email user to set password.
                //MDJ: Use Try Catch so that this part doesn't blow up dev environment
                try
                {
                    await SendNewUserSetPasswordEmailAsync(user);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }


                return(Ok(user));
            }

            return(BadRequest(ModelState));
        }
Esempio n. 6
0
        public async Task <IActionResult> MediaFolders(string userId, string id = null)
        {
            IList <Folder> foldersToReturn = new List <Folder>();

            if (string.IsNullOrEmpty(id))
            {
                if (await _folderManager.GetDocumentLibraryAsync(userId) == null)
                {
                    var locationResolver = new DocumentPhysicalLocationResolver("User", _adminContext.ClientId, _adminContext.SiteId, userId);
                    await _folderManager.CreateDocumentLibrary(userId, "User", locationResolver.Resolve());
                }

                foldersToReturn.Add((Folder)await _folderManager.GetRootFolderAsync(userId, true));

                //check permissions for site library access and add it with the result treeview
                if (await _authorizationService.AuthorizeAsync(User, PolicyNames.SiteLibraryRead))
                {
                    var siteRoot = ((Folder)await _folderManager.GetRootFolderAsync(_adminContext.SiteId));
                    siteRoot.Title = "Site Library";
                    foldersToReturn.Add(siteRoot);
                }

                //check permissions for client library access and add it with the result treeview
                if (await _authorizationService.AuthorizeAsync(User, PolicyNames.ClientLibraryRead))
                {
                    var clientRoot = ((Folder)await _folderManager.GetRootFolderAsync(_adminContext.ClientId));
                    clientRoot.Title = "Client Library";
                    foldersToReturn.Add(clientRoot);
                }

                //get shared Document root folder
                //Get Product Definition flag for sharing Documents
                var isSiteDocumentSharingEnabled = _siteContext.ProductContext.Features.Get(FeatureId.DocumentSharing)?.GetSettingValue <bool>("enabled") ?? false;

                if (isSiteDocumentSharingEnabled && await _fileFolderBrowser.IsAnythingShared(userId))
                {
                    foldersToReturn.Add(new Folder()
                    {
                        Title = "Shared Documents",
                        Id    = SharedDocumentsFolderId,
                    });
                }
            }
            else
            {
                var folder = await _folderManager.GetFolderAsync(id);

                foldersToReturn.AddRange((IEnumerable <Folder>) await _folderManager.GetFoldersAsync(folder, true));
            }

            IList <TreeView> mediaTree = new List <TreeView>();

            var model = foldersToReturn.Select(x => new
            {
                Id          = x.Id,
                Title       = string.IsNullOrEmpty(x.Title) ? "My Library" : x.Title,
                Path        = "",
                HasChildren = x.ChildFolders.Any()
            });


            return(new JsonResult(model, new Newtonsoft.Json.JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }