From 08275325fbe5871644a03bf00967b18837a9b20f Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sun, 14 Sep 2014 18:01:02 +0200 Subject: [PATCH] Update /base for wiki --- OurUmbraco.Site/config/restExtensions.config | 6 - OurUmbraco.Site/scripts/powers/uPowers.js | 4 +- OurUmbraco.Site/scripts/projects/projects.js | 2 +- OurUmbraco.Site/scripts/wiki/uWiki.js | 14 +- uWiki/Api/WikiController.cs | 172 +++++++++++++++++++ uWiki/Library/rest.cs | 170 ------------------ uWiki/Library/xslt.cs | 4 +- uWiki/uWiki.csproj | 2 +- 8 files changed, 185 insertions(+), 189 deletions(-) create mode 100644 uWiki/Api/WikiController.cs delete mode 100644 uWiki/Library/rest.cs diff --git a/OurUmbraco.Site/config/restExtensions.config b/OurUmbraco.Site/config/restExtensions.config index bce6fcb7..114e3672 100644 --- a/OurUmbraco.Site/config/restExtensions.config +++ b/OurUmbraco.Site/config/restExtensions.config @@ -12,10 +12,4 @@ - - - - - - \ No newline at end of file diff --git a/OurUmbraco.Site/scripts/powers/uPowers.js b/OurUmbraco.Site/scripts/powers/uPowers.js index 11c9c4e1..9cbc50aa 100644 --- a/OurUmbraco.Site/scripts/powers/uPowers.js +++ b/OurUmbraco.Site/scripts/powers/uPowers.js @@ -53,11 +53,11 @@ var uPowers = function () { }, WikiDelete: function (s_Id) { - $.get("/base/uWiki/Delete/" + s_Id); + $.get("/umbraco/api/wiki/Delete/?wikiId=" + s_Id); }, WikiMove: function (s_Id, s_target) { - $.get("/base/uWiki/Move/" + s_Id + "/" + s_target, + $.get("/umbraco/api/wiki/Move/?wikiId=" + s_Id + "&target=" + s_target, function (data) { top.location = jQuery("value", data).text(); }); diff --git a/OurUmbraco.Site/scripts/projects/projects.js b/OurUmbraco.Site/scripts/projects/projects.js index a6c0a96f..5d4685d9 100644 --- a/OurUmbraco.Site/scripts/projects/projects.js +++ b/OurUmbraco.Site/scripts/projects/projects.js @@ -8,7 +8,7 @@ function RemoveTagFromProject(projectid,tag){ function VerifyFile(fileId) { - $.post("/base/uWiki/VerifyFile/" + fileId + ".aspx"); + $.post("/umbraco/api/Wiki/VerifyFile/?fileId=" + fileId); } jQuery(document).ready(function () { diff --git a/OurUmbraco.Site/scripts/wiki/uWiki.js b/OurUmbraco.Site/scripts/wiki/uWiki.js index aa747546..98874185 100644 --- a/OurUmbraco.Site/scripts/wiki/uWiki.js +++ b/OurUmbraco.Site/scripts/wiki/uWiki.js @@ -1,9 +1,9 @@ var uWiki = function() { return { Edit: function(s_baseId, s_baseVersion,readOnlyTitle) { - + //fetch content from the server in case someone has changed it - $.post("/base/uWiki/GetContentVersion/" + s_baseId + "/" + s_baseVersion + ".aspx", + $.post("/umbraco/api/Wiki/GetContentVersion/?id=" + s_baseId + "&guid=" + s_baseVersion, function(data){ if(_currentContent == ''){ @@ -82,7 +82,7 @@ var uWiki = function() { }, Save: function(s_pageId, s_title, s_body, s_keywords) { - $.post("/base/uWiki/Update/" + s_pageId + ".aspx", {body: s_body, title: s_title, keywords: s_keywords}, + $.post("/umbraco/api/Wiki/Update/", { pageId: s_pageId, body: s_body, title: s_title, keywords: s_keywords }, function(data){ window.location = jQuery("value", data).text(); }); @@ -90,7 +90,7 @@ var uWiki = function() { uWiki.Cancel(false); }, Create: function(s_parentId, s_title, s_body,s_keywords){ - $.post("/base/uWiki/Create/" + s_parentId + ".aspx", {body: s_body, title: s_title, keywords: s_keywords}, + $.post("/umbraco/api/Wiki/Create/", {parentId: s_parentId, body: s_body, title: s_title, keywords: s_keywords}, function(data){ window.location = jQuery("value", data).text(); }); @@ -120,7 +120,7 @@ var uWiki = function() { } }, PreviewOldVersion: function(s_pageId, s_versionGuid, s_currentVersionGuid){ - $.post("/base/uWiki/GetContentVersion/" + s_pageId + "/" + s_versionGuid + ".aspx", + $.post("/umbraco/api/Wiki/GetContentVersion/?id=" + s_pageId + "&guid=" + s_versionGuid, function(data){ //jQuery("#wikiContent").html( diffString(_c, jQuery("node/data [alias = 'bodyText']", data).text()) ); jQuery("#wikiContent").html( jQuery("node/data [alias = 'bodyText']", data).text() ).effect('highlight'); @@ -128,14 +128,14 @@ var uWiki = function() { ); }, Rollback: function(s_pageId, s_versionGuid){ - $.post("/base/uWiki/Rollback/" + s_pageId + "/" + s_versionGuid + ".aspx", + $.post("/umbraco/api/Wiki/Rollback/?pageId=" + s_pageId + "&guid=" + s_versionGuid, function(data){ window.location = jQuery("value", data).text(); }); }, ClearHelpRequests: function(s_section, s_applicationPage){ - $.get("/base/uWiki/ClearHelpRequests/" + s_section + "/" + s_applicationPage + ".aspx"); + $.get("/umbraco/api/Wiki/ClearHelpRequests/?section=" + s_section + "&applicationPage=" + s_applicationPage); } }; }(); diff --git a/uWiki/Api/WikiController.cs b/uWiki/Api/WikiController.cs new file mode 100644 index 00000000..cbc01ff0 --- /dev/null +++ b/uWiki/Api/WikiController.cs @@ -0,0 +1,172 @@ +using System; +using System.Linq; +using System.Web; +using System.Web.Http; +using System.Web.Security; +using umbraco.cms.businesslogic.web; +using Umbraco.Web.WebApi; +using uWiki.Businesslogic; +using uWiki.Library; + +namespace uWiki.Api +{ + public class WikiController : UmbracoApiController + { + + public string FileUpload(string pageVersion, string memberGuid) + { + return ""; + } + + [HttpPost] + public string Create(int parentId, string body, string title, string keywords) + { + var currentMemberId = Members.GetCurrentMember().Id; + if (parentId > 0 && currentMemberId > 0) + { + var isAdmin = (Xslt.IsInGroup("admin") || Xslt.IsInGroup("wiki editor")); + var doc = new Document(parentId); + var isLocked = (doc.getProperty("umbracoNoEdit").Value.ToString() == "1"); + + if ((isAdmin || isLocked == false) && doc.ContentType.Alias == "WikiPage") + { + var wikiPage = WikiPage.Create(parentId, currentMemberId, body, title, keywords); + return umbraco.library.NiceUrl(wikiPage.NodeId); + } + } + + return ""; + } + + [HttpPost] + public string Update(int pageId, string body, string title, string keywords) + { + var currentMemberId = Members.GetCurrentMember().Id; + var isAdmin = (Xslt.IsInGroup("admin") || Xslt.IsInGroup("wiki editor")); + + if (pageId > 0 && currentMemberId > 0 && body.Trim() != "" && title.Trim() != "") + { + + var wikiPage = new WikiPage(pageId); + + if (wikiPage.Exists && (isAdmin || wikiPage.Locked == false)) + { + + wikiPage.Title = title; + wikiPage.Author = currentMemberId; + wikiPage.Body = body; + wikiPage.Keywords = keywords; + wikiPage.Save(); + + return umbraco.library.NiceUrl(wikiPage.NodeId); + } + + return "not allowed " + isAdmin + " " + wikiPage.Locked + " " + wikiPage.Exists; + } + + return ""; + } + + [HttpPost] + public string GetContentVersion(int id, string guid = null) + { + if (guid == null) + guid = string.Empty; + + return Xslt.GetXmlNodeFromVersion(id, guid, false); + } + + [HttpGet] + public string Move(int wikiId, int target) + { + var currentMemberId = Members.GetCurrentMember().Id; + if (Xslt.IsMemberInGroup("admin", currentMemberId) || Xslt.IsMemberInGroup("wiki editor", currentMemberId)) + { + Document document = new Document(wikiId); + Document documentTarget = new Document(target); + + if (documentTarget.ContentType.Alias == "WikiPage") + { + + Document o = new Document(document.Parent.Id); + + document.Move(documentTarget.Id); + document.Save(); + + document.Publish(new umbraco.BusinessLogic.User(0)); + documentTarget.Publish(new umbraco.BusinessLogic.User(0)); + o.Publish(new umbraco.BusinessLogic.User(0)); + + umbraco.library.UpdateDocumentCache(document.Id); + umbraco.library.UpdateDocumentCache(documentTarget.Id); + umbraco.library.UpdateDocumentCache(o.Id); + + umbraco.library.RefreshContent(); + + return umbraco.library.NiceUrl(document.Id); + } + + } + + return ""; + } + + [HttpGet] + public string Delete(int wikiId) + { + var currentMemberId = Members.GetCurrentMember().Id; + + if (Xslt.IsMemberInGroup("admin", currentMemberId) || Xslt.IsMemberInGroup("wiki editor", currentMemberId)) + { + var document = new Document(wikiId); + + umbraco.library.UnPublishSingleNode(document.Id); + document.delete(); + } + + return ""; + } + + [HttpGet] + public string VerifyFile(int fileId) + { + if (Xslt.IsMemberInGroup("admin", Members.GetCurrentMember().Id)) + { + var wikiFile = new WikiFile(fileId) { Verified = true }; + wikiFile.Save(); + } + + return ""; + } + + [HttpPost] + public string Rollback(int pageId, string guid) + { + var currentMemberId = Members.GetCurrentMember().Id; + var olddoc = new Document(pageId, new Guid(guid)); + var wikiPage = new WikiPage(pageId); + + if (olddoc != null && wikiPage.Exists && !wikiPage.Locked && currentMemberId > 0 && wikiPage.Version.ToString() != guid) + { + + wikiPage.Body = olddoc.getProperty("bodyText").Value.ToString(); + wikiPage.Title = olddoc.Text; + wikiPage.Author = currentMemberId; + wikiPage.Save(); + + return umbraco.library.NiceUrl(wikiPage.NodeId); + } + + return ""; + } + + [HttpGet] + public void ClearHelpRequests(string section, string applicationPage) + { + Data.SqlHelper.ExecuteNonQuery( + "Delete from wikiHelpRequest where section = @section and applicationPage = @applicationPage", + Data.SqlHelper.CreateParameter("@section", section), + Data.SqlHelper.CreateParameter("@applicationPage", applicationPage)); + } + } +} diff --git a/uWiki/Library/rest.cs b/uWiki/Library/rest.cs deleted file mode 100644 index 5cb42086..00000000 --- a/uWiki/Library/rest.cs +++ /dev/null @@ -1,170 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Web; -using umbraco.cms.businesslogic.web; -using System.Xml.XPath; -using System.Xml; -using uWiki.Businesslogic; -using System.Web.Security; - -namespace uWiki.Library { - public class Rest { - //public static int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - public static string FileUpload(string pageVersion, string memberGuid) { - return ""; - } - - public static string Create(int parentID) { - string _body = HttpContext.Current.Request["body"]; - string _title = HttpContext.Current.Request["title"]; - string _keywords = HttpContext.Current.Request["keywords"]; - - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (parentID > 0 && _currentMember > 0) { - - bool isAdmin = (Library.Xslt.IsInGroup("admin") || Library.Xslt.IsInGroup("wiki editor")); - umbraco.cms.businesslogic.web.Document doc = new umbraco.cms.businesslogic.web.Document(parentID); - bool isLocked = (doc.getProperty("umbracoNoEdit").Value.ToString() == "1"); - - if ((isAdmin || !isLocked) && doc.ContentType.Alias == "WikiPage") { - Businesslogic.WikiPage wp = Businesslogic.WikiPage.Create(parentID, _currentMember, _body, _title, _keywords); - return umbraco.library.NiceUrl(wp.NodeId); - } - } - - return ""; - } - - public static string Update(int ID) { - int _currentMember = umbraco.cms.businesslogic.member.Member.CurrentMemberId(); - string _body = HttpContext.Current.Request["body"]; - string _title = HttpContext.Current.Request["title"]; - string _keywords = HttpContext.Current.Request["keywords"]; - - bool isAdmin = (Library.Xslt.IsInGroup("admin") || Library.Xslt.IsInGroup("wiki editor")); - - if (ID > 0 && _currentMember > 0 && _body.Trim() != "" && _title.Trim() != "") { - - Businesslogic.WikiPage wp = new uWiki.Businesslogic.WikiPage(ID); - - if (wp.Exists && (isAdmin || !wp.Locked)) { - - wp.Title = _title; - wp.Author = _currentMember; - wp.Body = _body; - wp.Keywords = _keywords; - wp.Save(); - - return umbraco.library.NiceUrl(wp.NodeId); - } - - return "not allowed " + isAdmin.ToString() + " " + wp.Locked + " " + wp.Exists; - } - - return ""; - } - - public static XPathNodeIterator GetContentVersion(int id, string guid) { - return Xslt.GetXmlNodeFromVersion(id, guid, false); - } - - public static string Move(int ID, int target) - { - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (Xslt.IsMemberInGroup("admin", _currentMember) || Xslt.IsMemberInGroup("wiki editor", _currentMember)) - { - Document d = new Document(ID); - Document t = new Document(target); - - if(t.ContentType.Alias == "WikiPage"){ - - Document o = new Document(d.Parent.Id); - - d.Move(t.Id); - d.Save(); - - d.Publish(new umbraco.BusinessLogic.User(0)); - t.Publish(new umbraco.BusinessLogic.User(0)); - o.Publish(new umbraco.BusinessLogic.User(0)); - - umbraco.library.UpdateDocumentCache(d.Id); - umbraco.library.UpdateDocumentCache(t.Id); - umbraco.library.UpdateDocumentCache(o.Id); - - umbraco.library.RefreshContent(); - - return umbraco.library.NiceUrl(d.Id); - } - - } - - return ""; - } - - public static string Delete(int ID) - { - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (Xslt.IsMemberInGroup("admin", _currentMember) || Xslt.IsMemberInGroup("wiki editor", _currentMember)) - { - Document d = new Document(ID); - - if (d != null) - { - umbraco.library.UnPublishSingleNode(d.Id); - d.delete(); - } - } - - return ""; - } - - - public static string VerifyFile(int ID) - { - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - if (Xslt.IsMemberInGroup("admin", _currentMember)) - { - WikiFile wf = new WikiFile(ID); - wf.Verified = true; - wf.Save(); - } - - return ""; - } - - public static string Rollback(int ID, string guid) { - - int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0; - - umbraco.cms.businesslogic.web.Document olddoc = new umbraco.cms.businesslogic.web.Document(ID, new Guid(guid)); - Businesslogic.WikiPage wp = new uWiki.Businesslogic.WikiPage(ID); - - if (olddoc != null && wp.Exists && !wp.Locked && _currentMember > 0 && wp.Version.ToString() != guid) { - - wp.Body = olddoc.getProperty("bodyText").Value.ToString(); - wp.Title = olddoc.Text; - wp.Author = _currentMember; - wp.Save(); - - return umbraco.library.NiceUrl(wp.NodeId); - } - - return ""; - } - - public static void ClearHelpRequests(string section, string applicationPage) - { - - Data.SqlHelper.ExecuteNonQuery( - "Delete from wikiHelpRequest where section = @section and applicationPage = @applicationPage", - Data.SqlHelper.CreateParameter("@section", section), - Data.SqlHelper.CreateParameter("@applicationPage", applicationPage)); - } - - } -} diff --git a/uWiki/Library/xslt.cs b/uWiki/Library/xslt.cs index daa440e4..bb753f0f 100644 --- a/uWiki/Library/xslt.cs +++ b/uWiki/Library/xslt.cs @@ -53,7 +53,7 @@ namespace uWiki.Library { ); } - public static XPathNodeIterator GetXmlNodeFromVersion(int id, string guid, bool deep) { + public static string GetXmlNodeFromVersion(int id, string guid, bool deep) { Document d; @@ -67,7 +67,7 @@ namespace uWiki.Library { XmlNode x = umbraco.xmlHelper.addTextNode(xd, "node", ""); d.XmlPopulate(xd, ref x, deep); - return x.CreateNavigator().Select("."); + return x.OuterXml; } diff --git a/uWiki/uWiki.csproj b/uWiki/uWiki.csproj index 36c4ba52..9cee9e46 100644 --- a/uWiki/uWiki.csproj +++ b/uWiki/uWiki.csproj @@ -225,6 +225,7 @@ + @@ -232,7 +233,6 @@ -