Inheritance: Node, IIndexableDocument
コード例 #1
0
        //====================================================================== 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 + "/"));
        }
コード例 #2
0
ファイル: GenericScenario.cs プロジェクト: maxpavlov/FlexNet
        public static IEnumerable<Node> GetNewItemNodes(GenericContent content) 
        {
            if (content == null)
                throw new ArgumentNullException("content");

            return GetNewItemNodes(content, content.GetAllowedChildTypes().ToArray());
        }
コード例 #3
0
 public static void ForceDelete(GenericContent n)
 {
     Logger.WriteVerbose("Trashbin: Finally deleting from Repository", Logger.EmptyCategoryList, new Dictionary <string, object> {
         { "NodePath", n.Path }
     });
     n.ForceDelete();
 }
コード例 #4
0
 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();
 }
コード例 #5
0
ファイル: TrashBag.cs プロジェクト: vlslavik/SenseNet
        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);
        }
コード例 #6
0
ファイル: UploadHelper.cs プロジェクト: maxpavlov/FlexNet
 /// <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);
 }
コード例 #7
0
        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());
        }
コード例 #8
0
ファイル: UploadHelper.cs プロジェクト: maxpavlov/FlexNet
        /// <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;
        }
コード例 #9
0
        public static bool HasUndoCheckOut(GenericContent node)
        {
            if (HasForceUndoCheckOutRight(node))
            {
                return(false);
            }

            var s = SavingAction.Create(node);

            return(s.ValidateAction(StateAction.UndoCheckOut) == ActionValidationResult.Valid);
        }
コード例 #10
0
        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());
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: SavingAction.cs プロジェクト: jhuntsman/FlexNet
        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;
        }
コード例 #13
0
        //====================================================================== 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);
            }
        }
コード例 #14
0
        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()))));
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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()))));
        }
コード例 #17
0
ファイル: WallPortlet.cs プロジェクト: maxpavlov/FlexNet
        // ================================================================================================ 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();
        }
コード例 #18
0
ファイル: SavingAction.cs プロジェクト: jhuntsman/FlexNet
        public static bool HasUndoCheckOut(GenericContent node)
        {
            if (HasForceUndoCheckOutRight(node))
                return false;

            var s = SavingAction.Create(node);
            return s.ValidateAction(StateAction.UndoCheckOut) == ActionValidationResult.Valid;
        }
コード例 #19
0
        public static bool HasReject(GenericContent node)
        {
            var s = SavingAction.Create(node);

            return(s.ValidateAction(StateAction.Reject) == ActionValidationResult.Valid);
        }
コード例 #20
0
ファイル: SavingAction.cs プロジェクト: jhuntsman/FlexNet
 public static bool HasReject(GenericContent node)
 {
     var s = SavingAction.Create(node);
     return s.ValidateAction(StateAction.Reject) == ActionValidationResult.Valid;
 }
コード例 #21
0
ファイル: GenericContent.cs プロジェクト: jhuntsman/FlexNet
        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())));
        }
コード例 #22
0
ファイル: UploadHandler.cs プロジェクト: maxpavlov/FlexNet
        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;
        }
コード例 #23
0
 public static void ForceDelete(GenericContent n)
 {
     SnTrace.Repository.Write("Trashbin: Finally deleting from Repository. NodePath:{0}", n.Path);
     n.ForceDelete();
 }
コード例 #24
0
ファイル: TrashBin.cs プロジェクト: jhuntsman/FlexNet
        //====================================================================== 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 + "/");
        }
コード例 #25
0
ファイル: TrashBag.cs プロジェクト: jhuntsman/FlexNet
        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;
        }
コード例 #26
0
ファイル: TrashBin.cs プロジェクト: jhuntsman/FlexNet
        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;
        }
コード例 #27
0
ファイル: TrashBin.cs プロジェクト: jhuntsman/FlexNet
 public static void ForceDelete(GenericContent n)
 {
     Logger.WriteVerbose("Trashbin: Finally deleting from Repository", Logger.EmptyCategoryList, new Dictionary<string, object> { { "NodePath", n.Path } });
     n.ForceDelete();
 }
コード例 #28
0
ファイル: TemplateManager.cs プロジェクト: jhuntsman/FlexNet
        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();
        }
コード例 #29
0
ファイル: GenericScenario.cs プロジェクト: maxpavlov/FlexNet
        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;
        }
コード例 #30
0
        /// <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);
        }
コード例 #31
0
ファイル: GenericContent.cs プロジェクト: jhuntsman/FlexNet
        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())));
        }
コード例 #32
0
        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();
        }
コード例 #33
0
ファイル: TrashBin.cs プロジェクト: jhuntsman/FlexNet
        //====================================================================== 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);
        }