private string getRightsJson(ContentFolder dir, AccessLevel level) { var right = dir.QueryDistinctAccess(level); return(string.Format("{0}", right ? '1' : '0')); //return string.Format("{{\"read\",\"{0}\"}}, {{\"del\",\"{1}\"}}, {{\"move\",\"{2}\"}}", read, del, move); }
public void LoadRecursiveFromMedia(ContentFolder rootDir, FileTreeInfo theNode, IPrincipal epiUser, string rootreference) { if (theNode == null) { throw new ArgumentNullException("theNode"); } var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); var rootFolder = contentRepository.Get <ContentFolder>(ContentReference.Parse(rootreference)); //Get directories var dirs = FileManagement.GetFolders(contentRepository, rootDir); var contentFolders = dirs as ContentFolder[] ?? dirs.ToArray(); if (contentFolders.Any()) { foreach (var dir in contentFolders) { var path = rootFolder.Name == rootDir.Name ? rootFolder.Name + "/" : rootFolder.Name + "/" + rootDir.Name + "/"; var node = new FileTreeInfo { id = dir.ContentLink.ID.ToString(CultureInfo.InvariantCulture), link = path, name = dir.Name, size = 0, parentId = rootDir.ContentLink.ID.ToString(CultureInfo.InvariantCulture), type = "dir", children = new List <FileTreeInfo>() //key = dir.ContentLink.ID.ToString(CultureInfo.InvariantCulture), //folder = true, //title = dir.Name, //path = path, //folderPath = rootFolder.Name + "/", //edit = getRightsJson(dir, AccessLevel.Edit), //delete = getRightsJson(dir, AccessLevel.Delete), //contentreference = dir.ContentLink.ToString(), //typeofmedia = "folder", //children = new List<TreeNode>() }; if (dir.QueryDistinctAccess(AccessLevel.Read)) { theNode.children.Add(node); } LoadRecursiveFromMedia(dir, node, epiUser, rootreference); } } //Get files if epiUser has access //TODO: Hantera rättigheter om man får redigera, deleta. Anders Sjöberg 2015-05-12 10:38 if (rootDir.QueryDistinctAccess(AccessLevel.Read)) { var files = GetFiles(rootDir); if (files.Any()) { var path = rootFolder.Name == rootDir.Name ? rootFolder.Name + "/" : rootFolder.Name + "/" + rootDir.Name + "/"; theNode.children.AddRange(files.Select(media => new FileTreeInfo { id = media.ContentLink.ID.ToString(CultureInfo.InvariantCulture), type = GetFileType(media.MimeType), name = FileManagement.IsLinkNode(media) ? GetLinkName(media.Name) : media.Name, link = FileManagement.IsLinkNode(media) ? GetLink(media) : "", parentId = theNode.id, size = 1, path = GetFilePath(media.ContentLink, media.Name), children = new List <FileTreeInfo>() //key = media.ContentLink.ID.ToString(CultureInfo.InvariantCulture), //folder = false, //title = FileManagement.IsLinkNode(media) ? GetLinkName(media.Name) : media.Name, //path = GetFilePath(media.ContentLink, media.Name), //folderPath = path, //edit = getRightsJson(rootDir, AccessLevel.Edit), //delete = getRightsJson(rootDir, AccessLevel.Delete), //link = FileManagement.IsLinkNode(media) ? GetLink(media) : "", //GetFilePath(uFile.ContentLink, uFile.Name), //icon = FileManagement.IsLinkNode(media) ? "/images/link.png" : GetKnowIcon(media.MimeType), //typeofmedia = "file", //contentreference = media.ContentLink.ToString(), //children = new List<TreeNode>() }).ToList()); } } }
public ViewResult Index(SitePageData currentPage, string orderBy = "ASC") { IPageViewModel <SitePageData> model = CreateModel(currentPage); if (currentPage is IContentWithComments) { var commentsModel = new CommentsPageViewModel(currentPage); // get (or create if necessary) the start page's comments folder var start = repo.Get <StartPage>(ContentReference.StartPage); ContentReference siteCommentsFolderReference; if (!ContentReference.IsNullOrEmpty(start.CommentFolder)) { siteCommentsFolderReference = start.CommentFolder; } else { // create the site comments folder inside the "For This Site" block folder ContentFolder siteCommentsFolder = repo.GetDefault <ContentFolder>(ContentReference.SiteBlockFolder); siteCommentsFolder.Name = "Comments"; siteCommentsFolderReference = repo.Save(siteCommentsFolder, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess); // set reference to the site comments folder on the start page start = start.CreateWritableClone() as StartPage; start.CommentFolder = siteCommentsFolderReference; repo.Save(start, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess); } // check if the Start page has its CommentFolder set commentsModel.StartPageHasCommentsFolder = (!ContentReference.IsNullOrEmpty(start.CommentFolder)); bool publishToStartComments = false; if (commentsModel.StartPageHasCommentsFolder) { // check if the current user has Publish rights to the Start page's CommentFolder ContentFolder startCommentsFolder = repo.Get <ContentFolder>(start.CommentFolder); publishToStartComments = (startCommentsFolder.QueryDistinctAccess(EPiServer.Security.AccessLevel.Publish)); } bool publishToThisPagesComments = false; if (!ContentReference.IsNullOrEmpty(currentPage.CommentFolder)) { // if current page has CommentFolder, get the comments IEnumerable <CommentBlock> blocks = repo.GetChildren <CommentBlock>(currentPage.CommentFolder); // filter comments to only show those: // 1) with a partial view // 2) the current user can access // 3) are published var filter = new FilterContentForVisitor(TemplateTypeCategories.MvcPartialView, string.Empty); var listOfBlocks = blocks.OfType <IContent>().ToList(); filter.Filter(listOfBlocks); var listOfComments = listOfBlocks.OfType <CommentBlock>(); // sort the comments by publish date if (orderBy == "ASC") { commentsModel.Comments = listOfComments.OrderBy(c => c.When); } else { commentsModel.Comments = listOfComments.OrderByDescending(c => c.When); } commentsModel.ThisPageHasAtLeastOneComment = (commentsModel.Comments.Count() > 0); // check if the current user has Publish rights to the current page's CommentFolder ContentFolder commentsFolder = repo.Get <ContentFolder>(currentPage.CommentFolder); publishToThisPagesComments = (commentsFolder.QueryDistinctAccess(EPiServer.Security.AccessLevel.Publish)); } // set flag to indicate the current user can add comments because either: // 1) they have Publish rights to Start's CommentFolder // 2) they have Publish rights to current page's CommentFolder commentsModel.CurrentUserCanAddComments = (publishToStartComments || publishToThisPagesComments); model = commentsModel; } return(View(string.Format("~/Views/{0}/Index.cshtml", currentPage.GetOriginalType().Name), model)); }