/// <summary> /// Publishes a new document. /// </summary> /// <param name="doc">The IDocumentInfo for the document, including the document key.</param> /// <param name="text">The document's text.</param> public static void Publish(IDocumentInfo doc, string text) { using (var db = new Silversite.Context()) { var d = Current(db, doc.ContentKey); if (d == null) throw new ArgumentException("invalid key"); if (d.Text != string.Empty) db.Documents.Add(d.Old()); d.CopyFrom(doc); d.Text = text; db.SaveChanges(); } }
/// <summary> /// Sets the IDocumentInfo of the corresponding document in the database. /// </summary> /// <param name="doc">The IDocumentInfo of the document.</param> public static void Modify(IDocumentInfo doc) { using (var db = new Silversite.Context()) { var d = Current(db, doc.ContentKey); if (d == null) return; d.CopyFrom(doc); db.SaveChanges(); } }
/// <summary> /// Copies IDocumentInfos. /// </summary> /// <param name="doc">The IDocumentInfo to copy from.</param> public void CopyFrom(IDocumentInfo doc) { CopyInfo(doc, this); }
/// <summary> /// Copies DocumentInfo's. /// </summary> /// <param name="source">The source IDocumentInfo.</param> /// <param name="dest">The destination IDocumentInfo.</param> public static void CopyInfo(IDocumentInfo source, IDocumentInfo dest) { dest.Author = source.Author; dest.Categories = source.Categories; dest.Title = source.Title; dest.Notes = source.Notes; dest.Published = source.Published; dest.ContentKey = source.ContentKey; dest.Revision = source.Revision; dest.Tags = source.Tags; }
/// <summary> /// True if the the person is allowed to edit the document. /// </summary> /// <param name="doc">A document.</param> /// <param name="p">A person.</param> /// <returns>True if the the person is allowed to edit the document.</returns> public static bool IsEditable(IDocumentInfo doc, Person p) { if (doc == null) return true; var cats = (doc.Categories ?? string.Empty).SplitList(',', ';').ToList(); if (cats.Contains("*")) return true; if (p == null) return false; if (cats.Contains("?")) return true; if (p.EditorSettings.EditableDocuments == null) { // build the editable documents cache for this person. var edocs = p.EditorSettings.EditableDocuments = new List<EditRight>(); using (var db = new Silversite.Context()) { // first find the rights for this user var rights = db.EditRights.Find(p.UserName); if (rights != null) { edocs.AddRange(rights.DocumentCategories.SplitList(s => new EditRight(s), ',',';')); } // and then for the users roles foreach (var role in p.Roles) { rights = db.EditRights.Find(role); if (rights != null) { edocs.AddRange(rights.DocumentCategories.SplitList(s => new EditRight(s), ',',';')); } } } } foreach (var right in p.EditorSettings.EditableDocuments) { foreach (var cat in cats) { if (Paths.Match(right.DocumentCategory, cat)) { return right.Permission == Permission.Allowed; } } } return false; }
public ErrorSnapShot(IDocumentInfo docInfo, BrowserType browserType) { _docInfo = docInfo; _browserType = browserType; }