//====================================================================== GenericContent trash methods public static bool IsInTrash(GenericContent n) { //currently this is a simple path check, but //in the future, when local trash bins may exist, //it will be more complicated return(n != null && (n.Path + "/").StartsWith(TrashBinPath + "/")); }
public static IEnumerable<Node> GetNewItemNodes(GenericContent content) { if (content == null) throw new ArgumentNullException("content"); return GetNewItemNodes(content, content.GetAllowedChildTypes().ToArray()); }
public static void ForceDelete(GenericContent n) { Logger.WriteVerbose("Trashbin: Finally deleting from Repository", Logger.EmptyCategoryList, new Dictionary <string, object> { { "NodePath", n.Path } }); n.ForceDelete(); }
protected string GetProperty(GenericContent content, string propertyName) { if (content == null) return string.Empty; var value = content.GetProperty(propertyName); return value == null ? string.Empty : value.ToString(); }
public static TrashBag BagThis(GenericContent node) { var bin = TrashBin.Instance; if (bin == null) { return(null); } if (node == null) { throw new ArgumentNullException("node"); } //creating a bag has nothing to do with user permissions: Move will handle that TrashBag bag = null; var wsId = 0; var wsRelativePath = string.Empty; var ws = node.Workspace; if (ws != null) { wsId = ws.Id; wsRelativePath = node.Path.Substring(ws.Path.Length); } using (new SystemAccount()) { bag = new TrashBag(bin) { KeepUntil = DateTime.UtcNow.AddDays(bin.MinRetentionTime), OriginalPath = RepositoryPath.GetParentPath(node.Path), WorkspaceRelativePath = wsRelativePath, WorkspaceId = wsId, DisplayName = node.DisplayName, Link = node }; bag.Save(); CopyPermissions(node, bag); //add delete permission for the owner //bag.Security.SetPermission(User.Current, true, PermissionType.Delete, PermissionValue.Allow); } try { Node.Move(node.Path, bag.Path); } catch (Exception ex) { Logger.WriteException(ex); bag.Destroy(); throw new InvalidOperationException("Error moving item to the trash", ex); } return(bag); }
/// <summary> /// Checks if a content of the given ContentType is allowed under a given parent content /// </summary> /// <param name="parent"></param> /// <param name="child">child node whose NodeType will be checked</param> /// <returns></returns> public static bool CheckAllowedContentType(GenericContent parent, Node child) { if (child == null || parent == null) return true; var nodetypeName = child.NodeType.Name; return CheckAllowedContentType(parent, nodetypeName); }
protected string GetProperty(GenericContent content, string propertyName) { if (content == null) { return(string.Empty); } var value = content.GetProperty(propertyName); return(value == null ? string.Empty : value.ToString()); }
/// <summary> /// Checks if a content of the given ContentType is allowed under a given parent content /// </summary> /// <param name="parent"></param> /// <param name="contentTypeName"></param> /// <returns></returns> public static bool CheckAllowedContentType(GenericContent parent, string contentTypeName) { // check allowed content types // true: allowed list is empty, but current user is administrator (if allowed types list is empty: only administrator should upload any type.) // true: if this type is allowed var cTypes = parent.GetAllowedChildTypes().ToList(); if ((cTypes.Count == 0 && PortalContext.Current.ArbitraryContentTypeCreationAllowed) || (cTypes.Any(ct => ct.Name == contentTypeName))) return true; return false; }
public static bool HasUndoCheckOut(GenericContent node) { if (HasForceUndoCheckOutRight(node)) { return(false); } var s = SavingAction.Create(node); return(s.ValidateAction(StateAction.UndoCheckOut) == ActionValidationResult.Valid); }
public static string GetProperty(GenericContent content, string propertyName) { if (content == null) { return(string.Empty); } if (string.IsNullOrEmpty(propertyName)) { return(content.Id.ToString()); } var value = content.GetProperty(propertyName); return(value == null ? string.Empty : value.ToString()); }
public static bool DeleteNode(GenericContent n) { if (Instance != null && Instance.IsActive && n.IsTrashable) { if (Instance.BagCapacity > 0 && n.NodesInTree > Instance.BagCapacity) { throw new ApplicationException("Node tree size exceeds trash bag limit, use ForceDelete to purge physically."); } TrashBag.BagThis(n); } else { ForceDelete(n); } return(true); }
private static SavingAction CreateForGenericContent(GenericContent genericContent) { var mode = VersioningMode.None; switch (genericContent.VersioningMode) { case VersioningType.MajorOnly: mode = VersioningMode.Major; break; case VersioningType.MajorAndMinor: mode = VersioningMode.Full; break; } var savingAction = new SavingAction { Node = genericContent, VersioningMode = mode, HasApproving = genericContent.HasApproving }; return savingAction; }
//====================================================================== Helper methods private static void AssertRestoreContentType(GenericContent targetParent, Node node) { if (targetParent == null || node == null) { throw new ArgumentNullException(); } if (!(targetParent is IFolder)) { throw new RestoreException(RestoreResultType.ForbiddenContentType, targetParent.Path); } var ctNames = targetParent.GetAllowedChildTypeNames().ToArray(); if (ctNames.Length > 0 && !ctNames.Any(ctName => ctName == node.NodeType.Name)) { throw new RestoreException(RestoreResultType.ForbiddenContentType, targetParent.Path); } }
private Exception GetNotAllowedContentTypeExceptionOnMove(Node node, GenericContent target) { var ancestor = target; while (ancestor.NodeType.Name == "Folder" || ancestor.NodeType.Name == "Page") { var p = ancestor.Parent as GenericContent; if (p == null) { break; } ancestor = p; } var contentTypeName = node.NodeType.Name; return(new InvalidOperationException(String.Format("Cannot move the content '{0}' to '{1}' because target's ancestor does not allow the type '{2}'. Ancestor: {3} ({4}). Allowed types: {5}" , node.Path, target.Path, contentTypeName, ancestor.Path, ancestor.NodeType.Name, String.Join(", ", target.GetAllowedChildTypeNames())))); }
private static SavingAction CreateForGenericContent(GenericContent genericContent) { var mode = VersioningMode.None; switch (genericContent.VersioningMode) { case VersioningType.MajorOnly: mode = VersioningMode.Major; break; case VersioningType.MajorAndMinor: mode = VersioningMode.Full; break; } var savingAction = new SavingAction { Node = genericContent, VersioningMode = mode, HasApproving = genericContent.HasApproving }; return(savingAction); }
private Exception GetNotAllowedContentTypeExceptionOnCreate(Node node, GenericContent parent) { var ancestor = parent; while (ancestor.NodeType.Name == "Folder" || ancestor.NodeType.Name == "Page") { var p = ancestor.Parent as GenericContent; if (p == null) { break; } ancestor = p; } var contentTypeName = node.NodeType.Name; var nodePath = String.Concat(node.Parent.Path, "/", node.Name); return(new InvalidOperationException(String.Format("Cannot save the content '{0}' because its ancestor does not allow the type '{1}'. Ancestor: {2} ({3}). Allowed types: {4}" , nodePath, contentTypeName, ancestor.Path, ancestor.NodeType.Name, String.Join(", ", parent.GetAllowedChildTypeNames())))); }
// ================================================================================================ Methods protected override void OnInit(EventArgs e) { base.OnInit(e); if (this.ContextNode == null) return; if (ShowExecutionTime) Timer.Start(); UITools.AddScript(UITools.ClientScriptConfigurations.SNWallPath); UITools.AddPickerCss(); UITools.AddScript(UITools.ClientScriptConfigurations.SNPickerPath); // get items for content types drowpdown in dropbox var gc = new GenericContent(this.ContextNode, "Folder"); var newItems = GenericScenario.GetNewItemNodes(gc, ContentType.GetContentTypes()); string jsonData; using (var s = new MemoryStream()) { var workData = newItems.Select(n => new ContentTypeItem { value = n.Name, label = n.DisplayName }).OrderBy(n => n.label); var serializer = new DataContractJsonSerializer(typeof(ContentTypeItem[])); serializer.WriteObject(s, workData.ToArray()); s.Flush(); s.Position = 0; using (var sr = new StreamReader(s)) { jsonData = sr.ReadToEnd(); } } UITools.RegisterStartupScript("initdropboxautocomplete", string.Format("SN.Wall.initDropBox({0})", jsonData), this.Page); if (ShowExecutionTime) Timer.Stop(); }
public static bool HasUndoCheckOut(GenericContent node) { if (HasForceUndoCheckOutRight(node)) return false; var s = SavingAction.Create(node); return s.ValidateAction(StateAction.UndoCheckOut) == ActionValidationResult.Valid; }
public static bool HasReject(GenericContent node) { var s = SavingAction.Create(node); return(s.ValidateAction(StateAction.Reject) == ActionValidationResult.Valid); }
public static bool HasReject(GenericContent node) { var s = SavingAction.Create(node); return s.ValidateAction(StateAction.Reject) == ActionValidationResult.Valid; }
private Exception GetNotAllowedContentTypeExceptionOnCreate(Node node, GenericContent parent) { var ancestor = parent; while (ancestor.NodeType.Name == "Folder" || ancestor.NodeType.Name == "Page") { var p = ancestor.Parent as GenericContent; if (p == null) break; ancestor = p; } var contentTypeName = node.NodeType.Name; var nodePath = String.Concat(node.Parent.Path, "/", node.Name); return new InvalidOperationException(String.Format("Cannot save the content '{0}' because its ancestor does not allow the type '{1}'. Ancestor: {2} ({3}). Allowed types: {4}" , nodePath, contentTypeName, ancestor.Path, ancestor.NodeType.Name, String.Join(", ", parent.GetAllowedChildTypeNames()))); }
private bool CheckAllowedContentType(GenericContent parent, Node child, HttpContext context) { var result = UploadHelper.CheckAllowedContentType(parent, child); if (!result) RedirectToErrorPage(String.Format("Cannot upload this type of content to {0}.", parent.Path), context); return result; }
public static void ForceDelete(GenericContent n) { SnTrace.Repository.Write("Trashbin: Finally deleting from Repository. NodePath:{0}", n.Path); n.ForceDelete(); }
//====================================================================== GenericContent trash methods public static bool IsInTrash(GenericContent n) { //currently this is a simple path check, but //in the future, when local trash bins may exist, //it will be more complicated return n != null && (n.Path + "/").StartsWith(TrashBinPath + "/"); }
public static TrashBag BagThis(GenericContent node) { var bin = TrashBin.Instance; if (bin == null) return null; if (node == null) throw new ArgumentNullException("node"); //creating a bag has nothing to do with user permissions: Move will handle that TrashBag bag = null; using (new SystemAccount()) { bag = new TrashBag(bin) { KeepUntil = DateTime.Now.AddDays(bin.MinRetentionTime), OriginalPath = RepositoryPath.GetParentPath(node.Path), DisplayName = node.DisplayName, Link = node }; bag.Save(); CopyPermissions(node, bag); //add delete permission for the owner //bag.Security.SetPermission(User.Current, true, PermissionType.Delete, PermissionValue.Allow); } try { Node.Move(node.Path, bag.Path); } catch(Exception ex) { Logger.WriteException(ex); bag.Destroy(); throw new InvalidOperationException("Error moving item to the trash", ex); } return bag; }
public static bool DeleteNode(GenericContent n) { if (Instance != null && Instance.IsActive && n.IsTrashable) { if (Instance.BagCapacity > 0 && n.NodesInTree > Instance.BagCapacity) throw new ApplicationException("Node tree size exceeds trash bag limit, use ForceDelete to purge physically."); TrashBag.BagThis(n); } else { ForceDelete(n); } return true; }
public static void ForceDelete(GenericContent n) { Logger.WriteVerbose("Trashbin: Finally deleting from Repository", Logger.EmptyCategoryList, new Dictionary<string, object> { { "NodePath", n.Path } }); n.ForceDelete(); }
public static string GetProperty(GenericContent content, string propertyName) { if (content == null) return string.Empty; if (string.IsNullOrEmpty(propertyName)) return content.Id.ToString(); var value = content.GetProperty(propertyName); return value == null ? string.Empty : value.ToString(); }
public static IEnumerable<Node> GetNewItemNodes(GenericContent content, ContentType[] contentTypes) { if (content == null) throw new ArgumentNullException("content"); var templatesAndTypes = new List<Node>(); if (contentTypes != null && contentTypes.Length == 0) return templatesAndTypes; var notAllTypes = contentTypes != null && contentTypes.Length > 0 && contentTypes.Length < ContentType.GetContentTypes().Length; var site = Site.GetSiteByNode(content); var currentWorkspace = Workspace.GetWorkspaceForNode(content); var wsTemplatePath = currentWorkspace == null ? string.Empty : RepositoryPath.Combine(currentWorkspace.Path, Repository.ContentTemplatesFolderName); var siteTemplatePath = site == null ? string.Empty : RepositoryPath.Combine(site.Path, Repository.ContentTemplatesFolderName); var currentContentTemplatePath = RepositoryPath.Combine(content.Path, Repository.ContentTemplatesFolderName); //the query is built on the assumption that all content //templates are placed under a "TypeName" folder in a //container called "ContentTemplates", meaning their //depth equals the depth of the container +2. var sbQueryText = new StringBuilder("+("); //add filter for workspace and site templates if (!string.IsNullOrEmpty(wsTemplatePath) && wsTemplatePath.CompareTo(currentContentTemplatePath) != 0) sbQueryText.AppendFormat("(InTree:\"{0}\" AND Depth:{1}) OR", wsTemplatePath, RepositoryPath.GetDepth(wsTemplatePath) + 2); if (!string.IsNullOrEmpty(siteTemplatePath) && siteTemplatePath.CompareTo(currentContentTemplatePath) != 0) sbQueryText.AppendFormat(" (InTree:\"{0}\" AND Depth:{1}) OR", siteTemplatePath, RepositoryPath.GetDepth(siteTemplatePath) + 2); //add filter for local and global templates sbQueryText.AppendFormat(" (InTree:\"{0}\" AND Depth:{1}) OR", currentContentTemplatePath, RepositoryPath.GetDepth(currentContentTemplatePath) + 2); sbQueryText.AppendFormat(" (InTree:\"{0}\" AND Depth:{1}))", Repository.ContentTemplateFolderPath, RepositoryPath.GetDepth(Repository.ContentTemplateFolderPath) + 2); //content type filter if (notAllTypes) sbQueryText.AppendFormat(" +Type:({0})", string.Join(" ", contentTypes.Select(ct => ct.Name))); sbQueryText.Append(" .REVERSESORT:Depth"); var templateResult = ContentQuery.Query(sbQueryText.ToString(), new QuerySettings { EnableAutofilters = false, EnableLifespanFilter = false }).Nodes.ToList(); var templatesNonGlobal = templateResult.Where(ct => !ct.Path.StartsWith(Repository.ContentTemplateFolderPath)).ToList(); var templatesGlobal = templateResult.Where(ct => ct.Path.StartsWith(Repository.ContentTemplateFolderPath)).ToList(); var addedTemplates = new Dictionary<string, List<string>>(); //add all local and ws/site level templates foreach (var localTemplate in templatesNonGlobal) { //query correction: if the query returned a type that we do not want, skip it if (notAllTypes && !contentTypes.Any(ct => ct.Name.CompareTo(localTemplate.ParentName) == 0)) continue; AddTemplate(templatesAndTypes, localTemplate, addedTemplates); } //add global templates foreach (var globalTemplate in templatesGlobal) { //query correction: if the query returned a type that we do not want, skip it if (notAllTypes && !contentTypes.Any(ct => ct.Name.CompareTo(globalTemplate.ParentName) == 0)) continue; AddTemplate(templatesAndTypes, globalTemplate, addedTemplates); } //add content types without a template if (contentTypes != null) templatesAndTypes.AddRange(contentTypes.Where(contentType => !addedTemplates.ContainsKey(contentType.Name))); return templatesAndTypes; }
/// <summary> /// Returns a new <see cref="TrashBag"/> instance that packages the /// given <see cref="GenericContent"/> instance. /// </summary> /// <param name="node">The <see cref="GenericContent"/> instance that will be wrapped.</param> public static TrashBag BagThis(GenericContent node) { var bin = TrashBin.Instance; if (bin == null) { return(null); } if (node == null) { throw new ArgumentNullException("node"); } // creating a bag has nothing to do with user permissions: Move will handle that TrashBag bag = null; var currentUserId = User.Current.Id; var wsId = 0; var wsRelativePath = string.Empty; var ws = SystemAccount.Execute(() => node.Workspace); if (ws != null) { wsId = ws.Id; wsRelativePath = node.Path.Substring(ws.Path.Length); } using (new SystemAccount()) { bag = new TrashBag(bin) { KeepUntil = DateTime.UtcNow.AddDays(bin.MinRetentionTime), OriginalPath = RepositoryPath.GetParentPath(node.Path), WorkspaceRelativePath = wsRelativePath, WorkspaceId = wsId, DisplayName = node.DisplayName, Link = node, Owner = node.Owner }; bag.Save(); CopyPermissions(node, bag); // Add Delete permission for the owner to let them remove it later and also // AddNew permission to let the move operation below actually move // the content into the TrashBag. Providers.Instance.SecurityHandler.CreateAclEditor() .Allow(bag.Id, node.OwnerId, false, PermissionType.Delete, PermissionType.AddNew) .Allow(bag.Id, currentUserId, true, PermissionType.Delete, PermissionType.AddNew) .Apply(); } try { Node.Move(node.Path, bag.Path); } catch (SenseNetSecurityException ex) { SnLog.WriteException(ex); bag.Destroy(); if (ex.Data.Contains("PermissionType") && (string)ex.Data["PermissionType"] == "Delete") { throw new InvalidOperationException("You do not have enough permissions to delete this content to the Trash.", ex); } throw new InvalidOperationException("Error moving item to the trash", ex); } catch (Exception ex) { SnLog.WriteException(ex); bag.Destroy(); throw new InvalidOperationException("Error moving item to the trash", ex); } return(bag); }
private Exception GetNotAllowedContentTypeExceptionOnMove(Node node, GenericContent target) { var ancestor = target; while (ancestor.NodeType.Name == "Folder" || ancestor.NodeType.Name == "Page") { var p = ancestor.Parent as GenericContent; if (p == null) break; ancestor = p; } var contentTypeName = node.NodeType.Name; return new InvalidOperationException(String.Format("Cannot move the content '{0}' to '{1}' because target's ancestor does not allow the type '{2}'. Ancestor: {3} ({4}). Allowed types: {5}" , node.Path, target.Path, contentTypeName, ancestor.Path, ancestor.NodeType.Name, String.Join(", ", target.GetAllowedChildTypeNames()))); }
protected string GetProperty(GenericContent content, string propertyName) { //TODO: handle recursive property definitions - e.g. @@Node.Reference.FieldName@@ if (content == null) return string.Empty; if (string.IsNullOrEmpty(propertyName)) return content.Id.ToString(); var value = content.GetProperty(propertyName); return value == null ? string.Empty : value.ToString(); }
//====================================================================== Helper methods private static void AssertRestoreContentType(GenericContent targetParent, Node node) { if (targetParent == null || node == null) throw new ArgumentNullException(); if (!(targetParent is IFolder)) throw new RestoreException(RestoreResultType.ForbiddenContentType, targetParent.Path); var ctNames = targetParent.GetAllowedChildTypeNames().ToArray(); if (ctNames.Length > 0 && !ctNames.Any(ctName => ctName == node.NodeType.Name)) throw new RestoreException(RestoreResultType.ForbiddenContentType, targetParent.Path); }