Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
        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();
        }
Exemplo n.º 11
0
        internal static void AddFormEntry(string formname, Guid uid, string fields, ServiceOutput output)
        {
            if (!string.IsNullOrEmpty(formname) &&
                !string.IsNullOrEmpty(fields))
            {
                //get the form.
                Form form = null;
                if (FormsPlugin.Instance.TryRead(formname, out form))
                {
                    //form was found.
                    logger.Log(LogLevel.Info, "Attempting to save entry for form - {0}.", form.Name);

                    //check if there is already an entry with uid
                    FormEntry entry = null;

                    if (uid != Guid.Empty)
                    {
                        // get the entry
                        entry = PluginStore.Instance.Read<FormEntry>(FormEntryPlugin.Instance, uid);
                    }

                    if (entry == null)
                    {
                        //create a new entry
                        entry = new FormEntry();
                        entry.Form = formname;
                        entry.Id = Utility.GetUniqueString();
                    }

                    // split the fields
                    string[] tokens = fields.Split(',');
                    foreach (string field in tokens)
                    {
                        if (string.IsNullOrEmpty(field))
                        {
                            continue;
                        }

                        //generate the response data
                        Data data = new Data();
                        data.Name = field;
                        data.Value = HttpContext.Current.Request[field];

                        entry.Add(data);
                    }

                    try
                    {
                        // app execution before saving the entry
                        AppEngine.ExecuteApps(AppEvent.FormEntrySaving, entry);

                        // submit the response
                        FormEntryPlugin.Instance.Add(entry);

                        AppEngine.ExecuteApps(AppEvent.FormEntrySaved, entry);

                        //notify
                        Notifier.Notify(ResourceManager.GetLiteral("FormResponses.NewResponseSubject") /* subject */,
                                        string.Format(ResourceManager.GetLiteral("FormResponses.NewResponseBody"), form.DisplayName) /* body */);

                        output.Success = true;
                        output.AddOutput("uid", entry.UId);
                    }
                    catch (MessageException me)
                    {
                        string errorMessage = me.Message;
                        if (me.ErrorNumber == FormsErrorCodes.NotAllRequiredFieldsSupplied)
                        {
                            errorMessage = ResourceManager.GetLiteral("FormResponses.NotAllRequiredFieldsSupplied");
                        }
                        else if (me.ErrorNumber == FormsErrorCodes.FieldValueDoesnotMatchWithFieldType)
                        {
                            errorMessage = ResourceManager.GetLiteral("FormResponses.FieldValueDoesnotMatchWithFieldType");
                        }

                        output.AddOutput(Constants.Json.Error, errorMessage);
                    }

                }
                else
                {
                    //form not found error
                    output.AddOutput(
                            Constants.Json.Error,
                            string.Format(ResourceManager.GetLiteral("Admin.Forms.NotFound"), formname)
                        );
                }
            }
            else
            {
                //either the form name was null, or the fields were null.
                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("FormResponses.Invalid"));
            }
        }
Exemplo n.º 12
0
        public string Save(string uid, string formname, string displayname)
        {
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            // without the formname and displayname, it cannot be saved.
            if (string.IsNullOrEmpty(formname)
                || string.IsNullOrEmpty(displayname))
            {
                // do nothing.
                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.NameOrDisplayNameNotSpecified"));
            }
            else
            {

                try
                {
                    // convert the uid to GUID. if failed to convert, assume that this is a new form.
                    Guid uuid;
                    if (Guid.TryParse(uid, out uuid))
                    {
                        Form form;
                        if (FormsPlugin.Instance.TryRead(formname, out form))
                        {
                            // match the uid
                            if (uuid == form.UId)
                            {
                                logger.Log(LogLevel.Info, "Updating form - {0}, uid - {1}", formname, uuid);
                                form.DisplayName = displayname;

                                FormsPlugin.Instance.Add(form);
                                output.AddOutput("uid", form.UId);
                                output.Success = true;
                            }
                            else
                            {
                                logger.Log(LogLevel.Warn, "Unble to save form with name - [{0}] and uid - {1}. Uid and name mismatch", formname, uuid);

                                // mismatch of name and uid
                                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.NameAndUIdMismatch"));
                            }
                        }
                        else
                        {
                            // unable to locate form with the given name
                            logger.Log(LogLevel.Warn, "Unble to locate form with name - [{0}] and uid - {1}", formname, uuid);
                            output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.NoFormFoundWithName"));
                        }
                    }
                    else
                    {
                        logger.Log(LogLevel.Info, "Creating new form - {0}, display name - [{1}]", formname, displayname);

                        Form form = new Form();
                        try
                        {
                            form.Name = formname;
                        }
                        catch (ArgumentException)
                        {
                            throw new MessageException(ResourceManager.GetLiteral("Admin.Forms.Save.Error.FormNameInvalid"));
                        }

                        form.DisplayName = displayname;

                        FormsPlugin.Instance.Add(form);

                        output.AddOutput("uid", form.UId);
                        output.Success = true;
                    }
                }
                catch (MessageException me)
                {
                    logger.Log(LogLevel.Warn, "Unble to save form - {0} ", me);

                    if (me.ErrorNumber == PluginErrorCodes.IdAlreadyInUse)
                    {
                        output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.FormNameInUse"));
                    }
                    else
                    {
                        output.AddOutput(Constants.Json.Error, me.Message);
                    }

                    output.Success = false;
                }
            }

            return output.GetJson();
        }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
0
        public string AddComment(string key, string name, string email, string url, string body, string permalink, string threadrenderer)
        {
            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (string.IsNullOrEmpty(name) ||
                !Utility.IsValidEmail(email) ||
                string.IsNullOrEmpty(body))
            {
                // not a valid comment
                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Comments.Invalid"));
            }
            else
            {
                // image for the thread user.
                string imageUrl = null;

                RatnaUser user = base.ValidatedUser();

                if (user != null)
                {
                    imageUrl = user.Photo;
                }

                // save the comment
                Comment comment = new Comment();
                comment.Key = key;
                comment.Id = Utility.GetUniqueString();
                comment.Body = body;
                comment.Name = name;
                comment.Url = url;
                comment.Email = email;
                comment.Image = imageUrl;
                if (!string.IsNullOrEmpty(permalink))
                {
                    comment.PermaLink = permalink;
                }

                // invoke apps before saving comment
                AppEngine.ExecuteApps(AppEvent.CommentSaving, comment);

                // check for settings to put the comment in pending list
                SiteConfiguration config = SiteConfiguration.Read();
                if (config.IsCommentModerationOn)
                {
                    comment.Approved = false;
                }

                logger.Log(LogLevel.Info, "Saving comment from : {0}, key: {1}, id: {2}", comment.Email, comment.Key, comment.Id);
                CommentsPlugin.Instance.Add(comment);
                output.Success = true;

                //notify
                Notifier.Notify(string.Format(ResourceManager.GetLiteral("Comments.NewCommentSubject"), comment.Name) /* subject */,
                                string.Format(ResourceManager.GetLiteral("Comments.NewCommentBody"), comment.Name, comment.PermaLink) /* body */);

                // add the snippet code
                if (!string.IsNullOrEmpty(threadrenderer))
                {
                    string oneRowOutput = GetOneRowOutput(threadrenderer, imageUrl, name, DateTime.Now.ToString(), url, body);

                    if (oneRowOutput != null)
                    {
                        logger.Log(LogLevel.Debug, "Got thread control [{0}] output.", threadrenderer);
                        string jsonHtml = Jardalu.Ratna.Web.Utility.SanitizeJsonHtml(oneRowOutput);
                        output.AddOutput(Constants.Json.Html, jsonHtml);
                    }
                }

                // invoke apps after comments saved
                AppEngine.ExecuteApps(AppEvent.CommentSaved, comment);
            }

            return output.GetJson();
        }
Exemplo n.º 15
0
        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();
        }
Exemplo n.º 16
0
        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();
        }
Exemplo n.º 17
0
        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();
        }
Exemplo n.º 18
0
        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();
        }
Exemplo n.º 19
0
        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();
        }
Exemplo n.º 20
0
        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();
        }
Exemplo n.º 21
0
        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();
        }
Exemplo n.º 22
0
        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();
        }
Exemplo n.º 23
0
        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();
        }
Exemplo n.º 24
0
        public string AddField(string formname, string fieldname, string fieldtype, string required)
        {
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            bool validFieldName = true;

            if (string.IsNullOrEmpty(fieldname) ||
                !Regex.IsMatch(fieldname, "^[0-9a-zA-Z]+$"))
            {
                // field name with space and alpha numbers
                validFieldName = false;
            }

            if (validFieldName)
            {
                #region field name is valid

                FieldType ft = FieldType.Other;

                if (Enum.TryParse<FieldType>(fieldtype, true, out ft))
                {
                    bool isRequired = false;
                    bool success = false;

                    if (!Boolean.TryParse(required, out isRequired))
                    {
                        isRequired = false;
                    }

                    Form form = null;

                    if (!string.IsNullOrEmpty(formname))
                    {
                        FormsPlugin.Instance.TryRead(formname, out form);
                    }

                    if (form != null)
                    {
                        // if the field already exists, error out.
                        if (form.Fields.Contains(new Field() { Name = fieldname }))
                        {
                            output.AddOutput(Constants.Json.Error,
                                ResourceManager.GetLiteral("Admin.Forms.Field.Save.Error.FieldNameInUse"));
                        }
                        else
                        {
                            //add the field to the form
                            form.AddField(fieldname, ft, isRequired);
                            FormsPlugin.Instance.Save(form);
                            success = true;
                        }

                    }

                    if (success)
                    {
                        this.AddSnippet(output, System.Reflection.MethodBase.GetCurrentMethod());
                        output.Success = true;
                    }
                }

                #endregion
            }
            else
            {
                output.AddOutput(Constants.Json.Error,
                    ResourceManager.GetLiteral("Admin.Forms.Field.Save.Error.FieldNameInInvalid"));
            }

            return output.GetJson();
        }
Exemplo n.º 25
0
        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();
        }
Exemplo n.º 26
0
        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();
        }
Exemplo n.º 27
0
 protected string SendAccessDenied()
 {
     ServiceOutput output = new ServiceOutput();
     output.Success = false;
     output.AddOutput(Constants.Json.Message, ResourceManager.GetLiteral("Admin.Common.AccessDenied"));
     return output.GetJson();
 }
Exemplo n.º 28
0
        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());
                    }
                }
            }
        }
Exemplo n.º 29
0
        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();
                }
            }
        }
Exemplo n.º 30
0
        public string DeleteField(string formname, string fieldname)
        {
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(formname) && !string.IsNullOrEmpty(fieldname))
            {
                Form form = null;
                FormsPlugin.Instance.TryRead(formname, out form);

                if (form != null)
                {
                    form.RemoveField(fieldname);
                    FormsPlugin.Instance.Save(form);
                    output.Success = true;
                }
                else
                {
                    // no form or field found.
                    output.AddOutput(Constants.Json.Error,
                                string.Format(ResourceManager.GetLiteral("Admin.Forms.FormOrFieldNotFound"), formname, fieldname)
                            );
                }
            }

            return output.GetJson();
        }