public string Delete(string uid) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; Guid guid = Guid.Empty; if (Guid.TryParse(uid, out guid)) { try { TemplatePlugin.Instance.Delete(guid /*uid*/); output.AddOutput("uid", uid); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } return output.GetJson(); }
public string Update(string locale, bool isCommentModerated) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; //get the configuration. SiteConfiguration configuration = SiteConfiguration.Read(); if (!string.IsNullOrEmpty(locale)) { configuration.Locale = locale; } configuration.IsCommentModerationOn = isCommentModerated; try { configuration.Update(); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } return output.GetJson(); }
public string AddReponse(string form, string fields) { ServiceOutput output = new ServiceOutput(); output.Success = false; formsmanage.AddFormEntry(form, Guid.Empty, fields, output); return output.GetJson(); }
protected void AddSnippet(ServiceOutput output, MethodBase methodBase) { if (output == null) { throw new ArgumentNullException("output"); } if (methodBase == null) { throw new ArgumentNullException("methodBase"); } // get the action associated with the call SnippetAction action = SnippetManager.Instance.Parse(HttpContext.Current.Request.Params); if (action.IsEnabled) { bool snippetMatch = false; //get the name of the snippet that needs to be loaded string snippetName = action.Name; // make sure the method can support this snippet. object[] attributes = methodBase.GetCustomAttributes(typeof(SupportedSnippetAttribute), false); foreach (object a in attributes) { SupportedSnippetAttribute attribute = a as SupportedSnippetAttribute; if (attribute != null && attribute.Name.Equals(attribute.Name, StringComparison.OrdinalIgnoreCase) ) { snippetMatch = true; break; } } logger.Log(LogLevel.Debug, "SnippetName - [{0}] , Match - {1}", snippetName, snippetMatch); // asked snippet can be supported by the service. if (snippetMatch && SnippetManager.Instance.IsRegistered(snippetName)) { // load the snippet control from the location Control control = FormlessPage.GetControl(SnippetManager.Instance.GetControlPath(snippetName)); SnippetControl snippet = control as SnippetControl; if (snippet != null) { logger.Log(LogLevel.Debug, "Got snippet [{0}], invoking to get output.", snippetName); //set the control values snippet.SetProperties(action.Properties); output.AddOutput(Constants.Json.Html, snippet.GetJsonHtml()); } } } }
public string AddImages(string urlKey, string[] images) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { try { // photos can't be added to published articles Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.Draft); if (article != null) { if (BlogArticleHandler.CanHandle(article)) { BlogArticle blogArticle = new BlogArticle(article); foreach (string image in images) { blogArticle.AddImage(image); } blogArticle.Update(); output.Success = true; } } } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } catch { output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Update.Error")); } } return output.GetJson(); }
public string Save(string path, string title, string pathType, int pagesize, string nav) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; CollectionPath collectionPath = CollectionPathPlugin.Instance.Read(path); if (collectionPath == null) { collectionPath = new CollectionPath(); collectionPath.Path = path; } collectionPath.Title = title; collectionPath.Navigation = nav ?? string.Empty; collectionPath.PageSize = pagesize > 0 ? pagesize : 4; CollectionType collectionType; if (!Enum.TryParse<CollectionType>(pathType, true, out collectionType)) { collectionType = CollectionType.BlogArticle; } // set the collection type collectionPath.CollectionType = collectionType; try { //save CollectionPathPlugin.Instance.Update(collectionPath); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } return output.GetJson(); }
public string Delete(string path) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; CollectionPathPlugin.Instance.Delete(CollectionPath.KeyName, path); output.AddOutput("path", path); output.Success = true; return output.GetJson(); }
public string DeleteUser(string alias) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(alias)) { output.Success = UserStore.Instance.DeleteUser(alias); } return output.GetJson(); }
public string Update(bool isLogEnabled, string logLevel) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; //get the configuration. Configuration configuration = Configuration.Instance; configuration.IsLoggingOn = isLogEnabled; //logging level LogLevel level = LogLevel.Info; if (!Enum.TryParse<LogLevel>(logLevel, out level)) { level = LogLevel.Info; } configuration.LoggingLevel = level; try { configuration.Update(); // apply the logging Jardalu.Ratna.Utilities.Logger.IsEnabled = Configuration.Instance.IsLoggingOn; Jardalu.Ratna.Utilities.Logger.EnabledLevel = Configuration.Instance.LoggingLevel; output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } return output.GetJson(); }
public string Delete(string url) { // make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(url)) { MediaStore.Instance.Delete(url); output.Success = true; } return output.GetJson(); }
public string SearchGroup(string query) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(query)) { //find user or group Principal principal = PrincipalStore.Instance.Find(query); if (principal != null) { bool isGroup = false; if (principal.GetType() == typeof(Group)) { isGroup = true; // add name, principalid, group properties output.AddOutput("name", principal.Name); output.AddOutput("principalId", principal.PrincipalId); output.AddOutput("isGroup", isGroup); this.AddSnippet(output, System.Reflection.MethodBase.GetCurrentMethod()); output.Success = true; } } } return output.GetJson(); }
public string Update(string displayName, string firstName, string lastName, string description) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; // set the user data user.DisplayName = displayName; user.FirstName = firstName; user.LastName = lastName; user.Description = description; try { UserStore.Instance.UpdateUser(user); output.Success = true; } catch(Exception ex) { // log the error MessageException me = ex as MessageException; if (me != null) { output.AddOutput(Constants.Json.Error, me.Message); } logger.Log(LogLevel.Debug, "Unable to update user : {0}", ex); } return output.GetJson(); }
public string AddPhotos(string url, string[] photos) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(url)) { // read the gallery Gallery gallery = GalleryPlugin.Instance.Read(url); if (gallery != null && photos != null && photos.Length > 0) { foreach (string photo in photos) { if (!string.IsNullOrEmpty(photo)) { // add image to the gallery gallery.Add(photo); } } } //save GalleryPlugin.Instance.Save(gallery); output.Success = true; } return output.GetJson(); }
public string Save(string uid, string url, string name, string description, string nav) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; Guid guid = Guid.Empty; if (Guid.TryParse(uid, out guid)) { try { // make sure name, and url are not empty if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(url) || !Uri.IsWellFormedUriString(url, UriKind.Relative) || !url.StartsWith("/")) { throw new MessageException(ResourceManager.GetLiteral("Admin.Media.Gallery.Error.NameUrlInvalid")); } Gallery gallery = ReadOrThrow(guid, name, url, description, nav); if (gallery != null) { GalleryPlugin.Instance.Save(gallery); output.AddOutput("uid", gallery.UId); output.Success = true; } } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } return output.GetJson(); }
public string Publish(string urlKey) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { try { logger.Log(LogLevel.Debug, "Publishing article at url - {0}", urlKey); ArticleStore.Instance.Publish(urlKey); logger.Log(LogLevel.Info, "Article published at url - {0}", urlKey); // get the title for the article Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.Published); logger.Log(LogLevel.Debug, "Version of the published article - {0}", article.Version); // add the location to the output as well. output.AddOutput("urlKey", urlKey); output.AddOutput("title", article.Title); // published article must move to the published column. snippet generation. this.AddSnippet(output, System.Reflection.MethodBase.GetCurrentMethod()); output.Success = true; } catch (MessageException me) { logger.Log(LogLevel.Error, "Unable to publish article. Exception - {0}", me); output.AddOutput(Constants.Json.Error, me.Message); } } return output.GetJson(); }
public string SaveTemplate(string uid, string name, string url, string path, string master, bool active) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; Guid guid = Guid.Empty; if (Guid.TryParse(uid, out guid)) { if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(master)) { try { // save the template Template template = new Template() { Name = name, TemplatePath = path, MasterFileName = master, UrlPath = url, UId = guid }; // add the template TemplatePlugin.Instance.Add(template); if (active) { TemplatePlugin.Instance.Activate(template); } else { TemplatePlugin.Instance.Deactivate(template); } output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } } return output.GetJson(); }
protected string SendAccessDenied() { ServiceOutput output = new ServiceOutput(); output.Success = false; output.AddOutput(Constants.Json.Message, ResourceManager.GetLiteral("Admin.Common.AccessDenied")); return output.GetJson(); }
public string SavePage(string urlKey, string title, string body) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { //make sure the url is relative and valid. if (!Uri.IsWellFormedUriString(urlKey, UriKind.Relative)) { // failed because URL is not valid. output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Url.Validate.Error")); } else { try { bool exists = ArticleStore.Instance.Exists(urlKey); StaticArticle article = new StaticArticle(); article.UrlKey = urlKey; // if the article already exists, read the article // to sync with latest version if (exists) { article.Read(PublishingStage.Draft); } article.Title = title; article.Body = body; if (!exists) { article.Owner = user; article.Create(); } else { article.Update(); } output.Success = true; } catch (MessageException me) { logger.Log(LogLevel.Error, "Unable to save page. MessageException - {0}", me); output.AddOutput(Constants.Json.Error, me.Message); } catch (Exception ex) { logger.Log(LogLevel.Error, "Unable to save page. Exception - {0}", ex); output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Create.Error")); } } } return output.GetJson(); }
public string Revert(string urlKey, int version) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { try { ArticleStore.Instance.Revert(urlKey, version); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } return output.GetJson(); }
public string Delete(string urlKey) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { try { ArticleStore.Instance.Delete(urlKey); // add the location to the output as well. output.AddOutput("urlKey", urlKey); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } return output.GetJson(); }
public string UpdateCustomResponses( string error404, string error500, string otherErrors) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; //get the custom response. CustomResponse customResponse = CustomResponse.Read(); customResponse.PageNotFound = error404; customResponse.InteralServerError = error500; customResponse.OtherErrors = otherErrors; try { customResponse.Update(); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } return output.GetJson(); }
public string UpdateSmtp( string smtpAddress, string smtpUserName, string smtpPassword, string smtpFrom) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; //get the configuration. NotificationConfiguration configuration = NotificationConfiguration.Read(); configuration.SmtpUserName = smtpUserName; if (!string.IsNullOrEmpty(smtpPassword)) { configuration.SmtpPassword = smtpPassword; } configuration.SmtpAddress = smtpAddress; // if the from is specified, it must be email address if (!string.IsNullOrEmpty(smtpFrom) && Utility.IsValidEmail(smtpFrom)) { configuration.FromAddress = smtpFrom; } try { configuration.Update(); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } return output.GetJson(); }
public string UpdateNotification( string notificationEmail, bool comment, bool formsResponse ) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; bool validEmail = Utility.IsValidEmail(notificationEmail); if (validEmail) { //get the configuration. NotificationConfiguration configuration = NotificationConfiguration.Read(); configuration.NotifyToEmail = notificationEmail; configuration.NotifyOnComment = comment; configuration.NotifyOnFormResponse = formsResponse; try { configuration.Update(); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } else { output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Errors.InvalidEmailAddress")); } return output.GetJson(); }
public string SavePageMetadata(string urlKey, string navigationtab, string tags, string description, string head) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { try { bool exists = ArticleStore.Instance.Exists(urlKey); if (exists) { StaticArticle article = new StaticArticle(); article.UrlKey = urlKey; article.Read(PublishingStage.Draft); article.RemoveTags(); ((INavigationTag)article).Name = navigationtab ?? string.Empty;; if (!string.IsNullOrEmpty(tags)) { article.AddTags(tags); } article.Head = head ?? string.Empty; article.Description = description ?? string.Empty; article.Update(); output.Success = true; } } catch (MessageException me) { logger.Log(LogLevel.Error, "Unable to save article metadata. MessageException - {0}", me); output.AddOutput(Constants.Json.Error, me.Message); } catch (Exception ex) { logger.Log(LogLevel.Error, "Unable to save article metadata. Exception - {0}", ex); output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Create.Error")); } } return output.GetJson(); }
public string Delete(string url) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(url)) { GalleryPlugin.Instance.Delete(Gallery.KeyName, url); // add the location to the output as well. output.AddOutput("url", url); output.Success = true; } return output.GetJson(); }
public string RemoveImage(string urlKey, string images) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { try { // photos can't be added to published articles Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.Draft); if (article != null) { //multiple images can be deleted at the same time. if (images != null) { //check if there are multiple images to be deleted. string[] tokens = images.Split(','); if (tokens.Length > 0 && BlogArticleHandler.CanHandle(article)) { BlogArticle blogArticle = new BlogArticle(article); foreach (string token in tokens) { if (!string.IsNullOrEmpty(token)) { blogArticle.RemoveImage(token); } } blogArticle.Update(); output.Success = true; } } } } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } catch { output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Update.Error")); } } return output.GetJson(); }
public string MarkForReview(string urlKey) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { try { ArticleStore.Instance.Publish(urlKey); // get the title for the article Article article = ArticleStore.Instance.GetArticle(urlKey, PublishingStage.InReview); // add the location to the output as well. output.AddOutput("urlKey", urlKey); output.AddOutput("title", article.Title); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } return output.GetJson(); }
public string PublishMultiple(string urlKeys) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (user == null) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKeys)) { try { string[] tokens = urlKeys.Split(','); List<string> urlList = new List<string>(); foreach (string token in tokens) { if (!string.IsNullOrEmpty(token)) { urlList.Add(token); logger.Log(LogLevel.Info, "Adding article at url '{0}' to get published", token); } } logger.Log(LogLevel.Info, "Calling publish on multiple articles"); ArticleStore.Instance.Publish(urlList); output.Success = true; } catch (MessageException me) { output.AddOutput(Constants.Json.Error, me.Message); } } return output.GetJson(); }
protected void ResponderModule_EndRequest(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; ServiceOutput output = null; string responseText = null; CustomResponse customReponse = CustomResponse.Read(); string redirectUrl = null; #region non 200 response if (context.Response.StatusCode != (int)HttpStatusCode.OK) { logger.Log(LogLevel.Debug, "Response status code [{0}.{1}] url : {2}", context.Response.StatusCode, context.Response.SubStatusCode, context.Request.RawUrl); switch (context.Response.StatusCode) { case (int)HttpStatusCode.NotFound : if (context.Response.SubStatusCode == 13) { // upload size exceeding - content size too large. output = new ServiceOutput(); output.Success = false; output.AddOutput( Constants.Json.Error, string.Format(ResourceManager.GetLiteral("Errors.UploadMaxSizeExceeded"), Configuration.GetMaxUploadSize()) ); } else { // check for custom response. if (!string.IsNullOrEmpty(customReponse.PageNotFound)) { if (context.Request.RawUrl != customReponse.PageNotFound) { redirectUrl = customReponse.PageNotFound; } } else { // the defined 404 was not found // read the default page for 404. responseText = GetStandard404Response(); } } break; case (int)HttpStatusCode.InternalServerError: if (context.Request.RawUrl.EndsWith(".asmx")) { //send internal server for asmx pages. output = new ServiceOutput(); output.Success = false; output.AddOutput( Constants.Json.Error, string.Format(ResourceManager.GetLiteral("Errors.InternalServerError"), WebContext.Current.StickyId) ); } else { // check for redirect if (!string.IsNullOrEmpty(customReponse.InteralServerError)) { redirectUrl = customReponse.InteralServerError; } else { // display the standard err responseText = GetStandardErrResponse(); } } if (HttpContext.Current.Error != null) { // log the output logger.Log(LogLevel.Error, "Exception serving {0} - {1}", HttpContext.Current.Request.RawUrl, HttpContext.Current.Error); } else { logger.Log(LogLevel.Error, "Internal Server Error serving url [{0}]", HttpContext.Current.Request.RawUrl); } break; default: // any other error condition ? if (context.Response.StatusCode >= 400 && !string.IsNullOrEmpty(customReponse.OtherErrors)) { redirectUrl = customReponse.OtherErrors; } break; } } #endregion if (!string.IsNullOrEmpty(redirectUrl)) { // one of the known path for redirecting the url. context.Response.Clear(); context.Response.Redirect(Jardalu.Ratna.Web.Utility.ResolveUrl(redirectUrl)); } if (output != null) { // json output context.Response.Clear(); context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentType = "application/json"; context.Response.Write(output.GetJson()); context.Response.Flush(); context.Response.End(); } else { if (responseText != null) { //standard error response context.Response.Clear(); context.Response.Write(responseText); context.Response.Flush(); context.Response.End(); } } }
public string ValidateUrlKey(string urlKey) { //make sure the user has access RatnaUser user = base.ValidatedUser(); if (!(IsAccessAllowed(user))) { return SendAccessDenied(); } ServiceOutput output = new ServiceOutput(); output.Success = false; if (!string.IsNullOrEmpty(urlKey)) { //make sure the url is relative and valid. if (Uri.IsWellFormedUriString(urlKey, UriKind.Relative)) { output.Success = !ArticleStore.Instance.Exists(urlKey); } } return output.GetJson(); }