Esempio n. 1
0
        public virtual ActionResult ArticleDetails(long articleId)
        {
            ActionResult returnValue = null;

            if (!ProviderArticle.Exists(articleId))
            {
                returnValue = RedirectToAction(MVC.Error.Index(404));
            }
            else
            {
                ProviderArticle anArticle = new ProviderArticle(articleId);

                if (anArticle.IsPublished || ProviderCurrentMember.Instance.CanEdit(anArticle))
                {
                    // increment view count and don't update edit date when saving article
                    anArticle.ViewCount += 1;
                    anArticle.Save();

                    // Send a shadow vote
                    ProviderArticleVote shadowVote = new ProviderArticleVote();
                    shadowVote.IsShadowVote = true;
                    shadowVote.ArticleId = anArticle.Id.Value;
                    shadowVote.Save();

                    returnValue = View(new DetailsVM(anArticle, ProviderCurrentMember.Instance));
                }
                else
                {
                    returnValue = RedirectToAction(MVC.Error.Index(404));
                }
            }

            return returnValue;
        }
Esempio n. 2
0
 public bool Save(ProviderCurrentMember currentMember)
 {
     if (!currentMember.IsNew)
     {
         ProviderArticle anArticle;
         List<long> tempList = new List<long>(ArticleIdList);
         foreach (long id in tempList)
         {
             anArticle = new ProviderArticle(id);
             // if the article already has a value then don't override or add a new one.
             if (!anArticle.MemberId.HasValue)
             {
                 anArticle.MemberId = currentMember.Id;
                 anArticle.Save();
             }
             ArticleIdList.Remove(id);
         }
     }
     return true;
 }
        protected void DelegateRefreshArticle(object sender, DoWorkEventArgs e)
        {
            InsideWordWebLog.Instance.Log.Debug("AsyncRefreshArticleManager.DelegateRefreshArticle(sender, e)");
            while(_articleIdQueue.Count > 0)
            {
                List<string> tempErrorList = new List<string>();
                ProviderArticle anArticle = new ProviderArticle(_articleIdQueue.Dequeue());
                try
                {
                    // Refresh it once to force re-parsing of the text
                    anArticle.ForceRefresh();

                    // Associate the photos, but don't bother returning any errors.
                    ArticleBL.AssociatePhotos(anArticle.ParsedText, anArticle, ref tempErrorList);
                    if (tempErrorList.Count > 0)
                    {
                        InsideWordWebLog.Instance.Log.Debug(string.Join(", ", tempErrorList));
                    }

                    // save it one more time to save the relationships
                    anArticle.Save();
                }
                catch (Exception caughtException)
                {
                    tempErrorList.Add("article " + anArticle.Id.Value + " exception: " + caughtException);
                }
                ErrorList.AddRange(tempErrorList);
                _currentRefreshWorker.ReportProgress(_articleIdQueue.Count());
            }
            Provider.DbCtx.DisposeCtx();
        }
Esempio n. 4
0
        public static bool EditArticle(ref ProviderArticle anArticle, ProviderMember aMember, MessageInfo info)
        {
            _log.Info("Populating article from e-mail");
            bool returnValue = false;
            MailAddress senderAddress = new MailAddress(info.Envelope.Sender[0].Address);

            // Now parse the data from the e-mail
            EmailArticle anEmailArticle = new EmailArticle(info, _emailClient);

            if(anEmailArticle.IsHelp && !anEmailArticle.IsSubjectHelp)
            {
                // If we got the help command in the body but not in the subject then send the e-mail.
                // it's important that we check the subject help because otherwise we will send the help e-mail twice.
                _log.Info("Found the [help] command in the e-mail so respond with the help e-mail.");
                EmailManager.Instance.SendHelpEmail(senderAddress, aMember);
            }

            if (anEmailArticle.IsSubjectHelp)
            {
                // If we got help in the subject then ONLY send the help e-mail. Since the subject can't be an article title or id.
                _log.Info("This was a subject help request so send the help e-mail but do nothing else.");
                EmailManager.Instance.SendHelpEmail(senderAddress, aMember);
            }
            else
            {
                if(anEmailArticle.IsBlankEmail)
                {
                    _log.Info("E-mail was completely blank");
                }
                else if (anEmailArticle.Delete)
                {
                    if (anArticle.IsNew)
                    {
                        _log.Info("Attempted to delete a new article, which makes no sense so ignore this e-mail.");
                        MailMessage aMailMessage = new MailMessage("donotreply@insideword",
                                                                    senderAddress.Address,
                                                                    "insideword - article " + info.Envelope.Subject + " rejected",
                                                                    "DO NOT REPLY TO THIS E-MAIL<br />"
                                                                    + "The delete command you sent us in an e-mail was ignored since you tried to delete an article that doesn't exist. Be sure that you used the correct article id number in the subject.");
                        aMailMessage.IsBodyHtml = true;
                        EmailManager.Instance.DefaultSmtp.Send(aMailMessage);
                    }
                    else
                    {
                        _log.Info("Deleting article.");
                        string title = anArticle.Title;
                        long id = anArticle.Id.Value;
                        string result;
                        if (anArticle.Delete())
                        {
                            result = "Successfully deleted article " + title + " with id " + id;
                        }
                        else
                        {
                            result = "Failed to delete article " + title + " with id " + id;
                        }
                        _log.Info(result);
                        MailMessage aMailMessage = new MailMessage("donotreply@insideword",
                                                                    senderAddress.Address,
                                                                    "insideword - article " + info.Envelope.Subject + " rejected",
                                                                    "DO NOT REPLY TO THIS E-MAIL<br />"
                                                                    + result + "<br />");
                        aMailMessage.IsBodyHtml = true;
                        EmailManager.Instance.DefaultSmtp.Send(aMailMessage);
                        returnValue = false;
                    }
                }
                else
                {
                    if (anArticle.IsNew)
                    {
                        anArticle.CreateDate = DateTime.UtcNow;

                        // only update the member id when we first create the article otherwise an admin could end up taking control when editing it.
                        anArticle.MemberId = aMember.Id.Value;
                    }
                    anArticle.EditDate = DateTime.UtcNow;

                    if (anArticle.IsNew || !string.IsNullOrWhiteSpace(anEmailArticle.Title))
                    {
                        anArticle.Title = anEmailArticle.Title;
                    }

                    if (anEmailArticle.CategoryId.HasValue)
                    {
                        anArticle.AddCategory(anEmailArticle.CategoryId.Value);
                    }

                    if (anEmailArticle.Blurb != null)
                    {
                        if (string.IsNullOrWhiteSpace(anEmailArticle.Blurb))
                        {
                            anArticle.Blurb = null;
                        }
                        else
                        {
                            anArticle.Blurb = anEmailArticle.Blurb;
                        }
                    }

                    // don't overwrite unless we have some content.
                    if (!string.IsNullOrWhiteSpace(anEmailArticle.Text))
                    {
                        if (anArticle.IsNew || !anEmailArticle.Append)
                        {
                            anArticle.RawText = anEmailArticle.Text;
                        }
                        else
                        {
                            anArticle.RawText += anEmailArticle.Text;
                        }
                    }

                    if (anEmailArticle.IsPublished.HasValue)
                    {
                        // if the e-mail specifically set the publish status then set it in the article
                        anArticle.IsPublished = anEmailArticle.IsPublished.Value && anEmailArticle.CategoryId.HasValue;
                    }
                    else if (anArticle.IsNew)
                    {
                        // if the article is new but no status was set in the e-mail then set the status based on the following
                        anArticle.IsPublished = anEmailArticle.CategoryId.HasValue;
                    }
                    else
                    {
                        // don't change the status of the article
                    }
                    anArticle.Save();
                    returnValue = true;
                }

                if (anEmailArticle.IsReadArticle)
                {
                    if (anEmailArticle.ReadArticle.HasValue)
                    {
                        _log.Info("Request to send back article " + anEmailArticle.ReadArticle.Value);
                        try
                        {
                            ProviderArticle aDifferentArticle = new ProviderArticle(anEmailArticle.ReadArticle.Value);
                            if (aDifferentArticle.IsPublished || aMember.CanEdit(aDifferentArticle))
                            {
                                EmailManager.Instance.SendArticleEmail(senderAddress, anArticle, aMember);
                            }
                            else
                            {
                                throw new Exception("Member doesn't have the rights to request article " + anEmailArticle.ReadArticle.Value);
                            }
                        }
                        catch (Exception caughtException)
                        {
                            _log.Info("Failed to send back article " + anEmailArticle.ReadArticle.Value, caughtException);
                            MailMessage aMailMessage = new MailMessage("donotreply@insideword",
                                                                        senderAddress.Address,
                                                                        "insideword - article request " + anEmailArticle.ReadArticle.Value + " failed",
                                                                        "DO NOT REPLY TO THIS E-MAIL<br />"
                                                                        + "Failed to return the article with id " + anEmailArticle.ReadArticle.Value + "<br />"
                                                                        + "Check to make sure the article id is a valid id.<br />");
                            aMailMessage.IsBodyHtml = true;
                            EmailManager.Instance.DefaultSmtp.Send(aMailMessage);
                        }
                    }
                    else
                    {
                        _log.Info("Sending back current article");
                        EmailManager.Instance.SendArticleEmail(senderAddress, anArticle, aMember);
                    }
                }
            }

            return returnValue;
        }
Esempio n. 5
0
        public virtual JsonResult ChangeArticleState(long articleId, InsideWordProvider.ProviderArticle.ArticleState state)
        {
            string from = "APILOGINFO - " + HttpContext.Request.UserHostAddress;
            InsideWordWebLog.Instance.Buffer(from, "ChangeArticleState(" + articleId + ", " + state.ToString() + ")");
            ApiMsgVM returnMessage = new ApiMsgVM( (int)ApiMsgVM.StatusEnum.failure );

            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
            ProviderArticle anArticle = new ProviderArticle();
            if (!currentMember.IsLoggedOn)
            {
                returnMessage.StatusCode = (int)ApiMsgVM.StatusEnum.failure;
                returnMessage.StatusMessage = "You must be logged in to use this command. Use the API function " + Url.Action(MVC.API.Login()) + " to login.";
            }
            else if (!anArticle.Load(articleId))
            {
                returnMessage.StatusCode = (int)ApiMsgVM.StatusEnum.failure;
                returnMessage.StatusMessage = "Could not change status. No article with id "+articleId;
                returnMessage.Content = String.Empty;
            }
            else if (!currentMember.CanEdit(anArticle))
            {
                returnMessage.StatusCode = (int)ApiMsgVM.StatusEnum.failure;
                returnMessage.StatusMessage = "Could not change status. Member does not have the rights to edit article " + articleId;
                returnMessage.Content = String.Empty;
            }
            else
            {
                bool returnMessageIsSet = false;
                anArticle.EditDate = DateTime.UtcNow;
                switch (state)
                {
                    case ProviderArticle.ArticleState.delete:
                        anArticle.IsHidden = true;
                        anArticle.IsPublished = false;
                        anArticle.Save();
                        break;
                    case ProviderArticle.ArticleState.flagged:
                        anArticle.IsHidden = true;
                        anArticle.IsPublished = false;
                        anArticle.Save();
                        break;
                    case ProviderArticle.ArticleState.hidden:
                        anArticle.IsHidden = true;
                        anArticle.IsPublished = false;
                        anArticle.Save();
                        break;
                    case ProviderArticle.ArticleState.draft:
                        anArticle.IsPublished = false;
                        anArticle.Save();
                        break;
                    case ProviderArticle.ArticleState.publish:
                        anArticle.IsPublished = true;
                        anArticle.Save();
                        break;
                    default:
                        returnMessageIsSet = true;
                        returnMessage.StatusCode = (int)ApiMsgVM.StatusEnum.failure;
                        returnMessage.StatusMessage = "Unknown status update "+state+" for article.";
                        returnMessage.Content = String.Empty;
                        break;
                }

                if (!returnMessageIsSet)
                {
                    returnMessage.StatusCode = (int)ApiMsgVM.StatusEnum.success;
                    returnMessage.StatusMessage = "Successfully updated article " + articleId + " status'.";
                    returnMessage.Content = String.Empty;
                }
            }
            InsideWordWebLog.Instance.Buffer(from, "Done ChangeArticleState - " + returnMessage);
            return Json(returnMessage);
        }
Esempio n. 6
0
        public static bool Save(ArticleEditorVM model, ProviderArticle anArticle, ProviderCurrentMember currentMember, ref List<string> errorList)
        {
            bool returnValue = false;

            ProviderMember owningMember = GetArticleOwner(model, anArticle, currentMember);

            // IsNowClaimedArticle indicates if an article's state changed from unclaimed to now claimed
            bool IsNowClaimedArticle = anArticle.MemberId == null && owningMember.Id.HasValue;
            anArticle.MemberId = owningMember.Id;

            if (AssociatePhotos(model.ArticleBody, anArticle, ref errorList))
            {
                if (owningMember.IsActive && !currentMember.IsLoggedOn)
                {
                    // The owner is an active member but the current member is not logged in?! We're not sure if the member was lazy
                    // and didn't bother to login or if this is a malicious person, so we will set IsPublished to false and treat
                    // the article as a draft just to be safe.
                    anArticle.IsPublished = false;
                }
                else if (model.SaveState == ArticleEditorVM.SaveStates.Published)
                {
                    anArticle.IsPublished = true;
                }
                else if (model.SaveState == ArticleEditorVM.SaveStates.DraftAndContinue ||
                         model.SaveState == ArticleEditorVM.SaveStates.DraftAndPreview)
                {
                    anArticle.IsPublished = false;
                }
                else
                {
                    // defensive programming
                    anArticle.IsPublished = false;
                }

                anArticle.Title = model.Title;
                anArticle.Blurb = model.Blurb;
                anArticle.RawText = model.ArticleBody;

                if (anArticle.IsNew)
                {
                    anArticle.CreateDate = DateTime.UtcNow;
                }
                anArticle.EditDate = DateTime.UtcNow;

                // remove previous categories before adding new ones
                anArticle.RemoveAllCategories();
                anArticle.AddCategory(model.ArticleCategoryId);

                // important that we fetch this info before we save because then the article is no longer new.
                bool isNew = anArticle.IsNew;

                anArticle.Save();

                // if the current member is not logged on then save it in their workspace
                if (!currentMember.IsLoggedOn)
                {
                    currentMember.CurrentWorkSpace.ArticleIdList.Add(anArticle.Id.Value);
                }

                // Send out an e-mail for the article only if it was claimed for the first time through e-mail
                // and the member is not active
                if (IsNowClaimedArticle && !string.IsNullOrEmpty(model.ArticleEmail) && !currentMember.IsActive)
                {
                    EmailManager.Instance.SendEditArticleEmail(new MailAddress(model.ArticleEmail), anArticle, owningMember);
                }
                returnValue = true;
            }

            return returnValue;
        }
Esempio n. 7
0
        public static JqGridResponse Edit(JqGridEditArticleVM model, ProviderCurrentMember currentMember)
        {
            JqGridResponse aResponse = new JqGridResponse();
            ProviderArticle anArticle = new ProviderArticle(model.Id);
            if (currentMember.CanEdit(anArticle))
            {
                anArticle.IgnoreFlags = model.IgnoreFlags;
                anArticle.IsHidden = model.IsHidden;
                anArticle.IsPublished = model.IsPublished;
                try
                {
                    anArticle.Save();
                    aResponse.Success = true;
                }
                catch (Exception caughtException)
                {
                    aResponse.Success = false;
                    aResponse.Message = ErrorStrings.OPERATION_FAILED;
                }
            }
            else
            {
                aResponse.Success = false;
                aResponse.Message = ErrorStrings.OPERATION_NO_RIGHTS;
            }

            return aResponse;
        }