Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var ex = Session["Silversite.Exception"] as Exception;
            if (ex == null && Request.QueryString["log"] != null) {
                var key = int.Parse(Request.QueryString["log"]);
                using (var db = new Silversite.Context()) {
                    var log = db.LogMessages.Find(key);
                    if (log != null) {
                        ex = log.Exception;
                        Session["Silversite.Exception"] = ex;

                        info.Property("Exception").Value = ex;
                        info.Property("LogMessage").Value = log;
                    }
                }
            }
            //if (Request.QueryString["raise"] != null) { // if query contains "raise" raise an exception found in the Session.

            /*} else {
                // If query does not contain raise, append raise an call the page again from the localhost, so the asp.net error page will show up for localhost (when customErrors is set to RemoteOnly in web.config).
                // Parse the result in a Html.Document and print the body.
                var url = Request.Url.ToString();
                if (url.Contains('?')) url += "&raise";
                else url += "?raise";
                var doc = Document.Open(new Uri(url));
                extext.Text = doc.Body.Text;
            } */
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the permissions for a user or a role.
 /// </summary>
 /// <param name="userOrRole">A user.</param>
 /// <returns>Returns the permissions for this user as a semicolon separated list string.</returns>
 public static string Get(string userOrRole)
 {
     using (var db = new Silversite.Context()) {
         var rights = db.EditRights.Find(userOrRole);
         if (rights != null) return rights.DocumentCategories;
         return null;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns all revisions of a document. 
 /// </summary>
 /// <param name="key">The document key.</param>
 /// <returns>A IQueryable of all revisions of that document.</returns>
 public static IQueryable<Document> Revisions(Nullable<int> key)
 {
     if (key == null) return new Document[0].AsQueryable();
     using (var db = new Silversite.Context()) {
         return db.Documents.Where(doc => doc.ContentKey == key);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Returns theDocument that corresponds to the supplied revision.
 /// </summary>
 /// <param name="key">The Document key.</param>
 /// <param name="revision">The document revision.</param>
 /// <returns>The revision of the document.</returns>
 public static Document Revision(Nullable<int> key, int revision)
 {
     if (key == null) return null;
     using (var db = new Silversite.Context()) {
         return db.Documents.FirstOrDefault(doc => doc.ContentKey == key && doc.Revision == revision);
     }
 }
Exemplo n.º 5
0
 /// <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();
     }
 }
Exemplo n.º 6
0
 /// <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();
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the document with the supplied key.
 /// </summary>
 /// <param name="key">The document key to look for.</param>
 /// <returns>The Document with the given key.</returns>
 public static Document Current(int contentKey)
 {
     using (var db = new Silversite.Context()) { return Current(db, contentKey); }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new document and returns the document key.
 /// </summary>
 /// <param name="path">The path of the .aspx page or control containing the document.</param>
 /// <returns></returns>
 public static IDocumentInfo Create(string path)
 {
     using (var db = new Silversite.Context()) {
         var doc = new Document { Author = null, Path = path, Domain = Domains.Current };
         db.Documents.Add(doc);
         db.SaveChanges();
         doc.ContentKey = doc.Key;
         doc.Revision = 1;
         return doc;
     }
 }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        /// <summary>
        /// sets the user's or role's persmission for a document or documentCategory
        /// </summary>
        /// <param name="userOrRole"></param>
        /// <param name="category"></param>
        /// <param name="a"></param>
        public static void Set(string userOrRole, string category, Permission a)
        {
            string categoryWithPermission;
            if (!(category.StartsWith("+") || category.StartsWith("-"))) categoryWithPermission = ((a == Permission.Allowed) ? "+" : "-") + category;
            else {
                categoryWithPermission = category;
                category = category.Substring(1);
            }

            using (var db = new Silversite.Context()) {
                var rights = db.EditRights.Find(userOrRole);
                if (rights != null) {
                    var categoriesWithPermission = rights.DocumentCategories.SplitList<string>(s => s, ',', ';').ToList();
                    var categories = categoriesWithPermission.Select(c => (c.StartsWith("+") || c.StartsWith("-")) ? c.Substring(1) : c).ToList();
                    if (categories.Contains(category)) {
                        categoriesWithPermission[categories.IndexOf(category)] = categoryWithPermission;
                    } else {
                        categoriesWithPermission.Add(categoryWithPermission);
                    }
                    rights.DocumentCategories = categoriesWithPermission.StringList("; ");
                } else {
                    rights = new EditRights { UserOrRole= userOrRole, DocumentCategories = categoryWithPermission, IsUser = IsNameUser(db, userOrRole) };
                    db.EditRights.Add(rights);
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Sets the person's or the role's rights so they can edit the document or the document category.
 /// </summary>
 /// <param name="userOrRole">A user or a role.</param>
 /// <param name="documentCategories">A comma or semicolon separated list of documents or document categories.</param>
 public static void Set(string userOrRole, string documentCategories)
 {
     using (var db = new Silversite.Context()) {
         var rights = db.EditRights.Find(userOrRole);
         if (rights != null) {
             rights.DocumentCategories = documentCategories;
         } else {
             rights = new EditRights { UserOrRole= userOrRole, DocumentCategories = documentCategories, IsUser = IsNameUser(db, userOrRole) };
             db.EditRights.Add(rights);
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Find the person that corresponds to the supplied username.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <returns>The person that correspond to the username.</returns>
 public static Person Find(string username)
 {
     if (Current != null && Current.UserName == username) return Current; using (var db = new Silversite.Context()) { return null; }
 }