+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Notify roles for content approval and publishing for blog posts

Notify roles for content approval and publishing for blog posts

17 posts, 1 answered
  1. vipul patel
    vipul patel avatar
    37 posts
    Registered:
    12 Mar 2010
    23 Jun 2010
    Link to this post

    Hi Ivan,

    I am using the below code to test notification emails for a blog post SendforApproval event:
    I am facing a lock problem as when a new blog post is created and sent for approval it is locked so it cannot be published by the publisher, my code is as below, please let me know where am i going wrong?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Workflow;
    using Telerik.Workflow.WebControls;
    using Telerik.Blogs.WebControls.Admin;
    using Telerik.Blogs;
    using Telerik.Blogs.Data;
    using Telerik.Cms.Engine;
    using System.Net.Mail;
    using Telerik.Cms.Web; 
      
    public partial class Sitefinity_Admin_ControlTemplates_Blogs_PostPreviewNew : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            workflowMenu.Command += new CommandEventHandler(workflowMenu_Command);   
        }
      
        void workflowMenu_Command(object sender, CommandEventArgs e)
        {
            WorkflowInstance workflow = ((WorkflowMenu)sender).GetWorkflow();
            if (workflow != null)
            {
                List<EventActivity> commands = new List<EventActivity>();
                this.LoadCommands(commands, workflow.Activity.Activities);
                int idx = int.Parse((string)e.CommandArgument);
      
                // The workflow events you could handle are: SendForApproval, Approve, Decline, Publish  
                if ((commands.Count > idx) && (commands[idx].CommandName.Equals("SendForApproval")))
                {
                    // Getting currently modified content and format the message  
                    PostPreviewView itemPreview = (PostPreviewView)this.Parent.Parent;
      
                    Guid contentID = new Guid(CmsHttpRequest.Current.QueryStirng[itemPreview.ParameterKey]);
      
                    IContent content = itemPreview.Manager.GetStagedContent(contentID);
                    string url = itemPreview.CreateHostViewCommand<PostPreviewView>(contentID.ToString());   
      
                    MailMessage mailMsg = new MailMessage();
      
                    // From   
                    MailAddress mailAddress = new MailAddress("vipul.patel@lg-legal.com");
                    mailMsg.From = mailAddress;
      
                    // Subject and Body   
                    mailMsg.Subject = "Blog posts item pending approval";
                    //mailMsg.Body = message;
                    //mailMsg.Body = "this is a test role workflow email notification";
                    mailMsg.Body = String.Format("'{0}' blog post item has been sent for approval\n\nhttp://{2}{3}", content.GetMetaData("Title"), content.ID, Request.Url.Host, url);  
      
      
                    // To  
                    string approversRole = "Blog Approver";
                    string[] usernames = Telerik.Security.UserManager.Default.GetUsersInRole(approversRole);
                    //if (usernames.Length == 0)
                    //    usernames = Telerik.Security.UserManager.Default.GetUsersInRole("administrators");   
                    foreach (string username in usernames)
                    {
                        System.Web.Security.MembershipUser user = Telerik.Security.UserManager.Default.GetUser(username);
                        mailMsg.To.Add(user.Email);
                    }
      
                    // Init SmtpClient and send   
                    SmtpClient smtpClient = new SmtpClient();
                    smtpClient.Send(mailMsg);
                }
            }   
              
        }
      
        private void LoadCommands(List<EventActivity> commands, IList<Activity> activities)
        {
            foreach (Activity act in activities)
            {
                if (act is EventActivity)
                    commands.Add((EventActivity)act);
                this.LoadCommands(commands, act.Activities);
            }
        }
      
        private string GetApproverGroup(string URL)
        {
            string strGroupName = "";
            string[] strArray = URL.Split('/');
            switch (strArray[1].ToString().ToLower())
            {
                case "case1":
                case "case1.aspx":
                    strGroupName = "case1-approvers";
                    break;
                case "case2":
                case "case2.aspx":
                    strGroupName = "case2-approvers";
                    break;
                default:
                    strGroupName = "case3-approvers";
                    break;
            }
      
            return strGroupName;
        }
        
      
    }

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Jun 2010
    Link to this post
    Hello vipul patel,

    As suggested in the other post you have opened, you should use GetCurrentState

    Quoted: Try using manager.GetCurrentState which should not change the content status and the content item should remain unchanged during the workflow stages.

    In your copied code you use

    IContent content = itemPreview.Manager.GetStagedContent(contentID); which LOCKS the items.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. vipul patel
    vipul patel avatar
    37 posts
    Registered:
    12 Mar 2010
    23 Jun 2010
    Link to this post
    Hi Ivan,

    Thanks, it works okay now,  sorry for the pain, but am working on too many things at the moment and i missed your suggestion.


    Vipul Patel
  4. Natalia
    Natalia avatar
    7 posts
    Registered:
    09 Jul 2010
    09 Jul 2010
    Link to this post
    Hello,
    I've been working on workflow email notifications project. I am new to Sitefinity. I've scrutinized, I think, everything related to this subject on Sitefinity website.
    My code is working except one thing: when content gets approved/declined I need to send email to a user who modified a content . To do it I need to get the user's identity. I saw in some examples that it is possible to do it something like this:

    Telerik.Cms.CmsManager manager = new Telerik.Cms.CmsManager();

    Telerik.Cms.ICmsPage page = manager.Provider.GetPageByWorkflow(workflow.ID);

    Then take user identity from Page history.

    Problem is : page values  is always NULL

    OR

    Telerik.Cms.Web.ICmsUrlContext urlContext = Telerik.Cms.Web.CmsUrlContext.Current;

    Telerik.Cms.ICmsPage page1 = (Telerik.Cms.ICmsPage)manager.GetPage(urlContext.PageID);

    urlContext is always NULL

    My all code is behind a corresponding (NewsItemPreviews, for example) external template user control.

    Appreciate your help
    P.S. To sum up: Could you explain to me why CmsUrlContext.Current and .ICmsPage  do not return any value?
    How can I get  a modifier user identity at the approval phase?


  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Jul 2010
    Link to this post
    Hi Natalia,

    If the user has approved an item this means that this user has been logged in. When the approval/publish button is clicked you could call GetCurrentUserName() method of UserManager class.

    string Modifier = Telerik.Security.UserManager.GetCurrentUserName();


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Natalia
    Natalia avatar
    7 posts
    Registered:
    09 Jul 2010
    09 Jul 2010
    Link to this post
    Hi Ivan,
    Thank you for the quick respond
    Sorry, I probably was not very clear: Users in the role "administrators" approve content, during approval one of the "administrators" would click on the 'approve' button, but
    I need to get info about a user who modified the page, that user is not current one during approval procedure.


    Thank you,
    Natalia
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Jul 2010
    Link to this post
    Hello Natalia,

    You have to get the staged version of the page and its modifier page.Staged.Modifier. You can get the current page ID from  Sitefinity\Admin\ControlTemplates\Pages\PageViewer.ascx as shown below.

    protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            var manager = new Telerik.Cms.CmsManager();
            Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;
         }


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Natalia
    Natalia avatar
    7 posts
    Registered:
    09 Jul 2010
    12 Jul 2010
    Link to this post
    Hello Ivan,

    This code did not work for me. It threw the cast exception: Unable to cast object of type 'System.Web.UI.Control' to type 'Telerik.Cms.Web.UI.PageEditor'.

    I've noticed that in some other posts you recommend to use this approach to get pageId from code in the location /Admin/ControlTemplates/Pages..

    My code is in /Admin/ControlTemplates/News/ and /Admin/ControlTemplates/Blogs/


    Regards,
    Natalia
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2010
    Link to this post
    Hi Natalia,

    In your previous post you said "I need to get info about a user who modified the page, that user is not current one during approval procedure."

    The code I sent you can be used  when you are working with pages. As far as I see, now you are talking about content items. The content items are not pages. In the backend you have modules and views.

    When you work with content items you can use content.Modifier property of IContent object. On Page_Load of your templates you have to subscribe for workflowMenu.Command event. There create a WorkflowInstance object and load the activities commands. Inside each command you can get the Modifier or just call Telerik.Security.UserManager.GetCurrentUserName(); and persists the returned value.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Natalia
    Natalia avatar
    7 posts
    Registered:
    09 Jul 2010
    13 Jul 2010
    Link to this post
    I appologize for the confusion. As I mentioned before I am new to Sitefinity. In ASP.NET world views, pages mean pretty much the same.
    Any way, referring to your reply: "get the Modifier or just call Telerik.Security.UserManager.GetCurrentUserName(); and persists the returned value." - what do you mean by "persists the returned value"? Could you elaborate, please?
    Do you mean I have to have my own structure(DB fo instance) to keep track of all modifications in Sitefinity DB?


    Best regards,
    Natalia
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2010
    Link to this post
    Hi Natalia,

    content.Modifer will return you the user that has edited and then saved the content.
    Telerik.Security.UserManager.GetCurrentUserName(); will return you the current user.

    The content does not get modified until someone edit it. Both options above should give you the ability to sent an email to appropriate groups/users.


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Natalia
    Natalia avatar
    7 posts
    Registered:
    09 Jul 2010
    13 Jul 2010
    Link to this post
    NewsManager newsManager = new NewsManager(providerName);
      
               // IContent content = newsManager.Content.GetStagedContent(this.contentPreview.ContentID);
                  
                IContent content = newsManager.Content.GetCurrentState(this.contentPreview.ContentID);
      
    //Here is what I have in the properties drop down:
                content.ID
                        ItemInfo
                        Language
                        Languages
                        MimeType
                        ParentId
    I do not see content.Modifier property.

    Thank you,
    Natalia
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2010
    Link to this post
    Hi Natalia,

    StagedContent.Modfier - Read-only property. Gets the modifier of the current staged content item.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Natalia
    Natalia avatar
    7 posts
    Registered:
    09 Jul 2010
    13 Jul 2010
    Link to this post

    We have here Sitefinity 3.6.
    Should this 'Modifier' property be available in this version?
    As I showed it in my code snippet, I do not have it.
    According Sitefinity documentation that property has to be b/w 'Mimetype' and 'Owner'.

    Public Property MimeType Gets or sets the MIME type of the current object.  
    Public Property Modifier Read-only property. Gets the modifier of the current staged content item.  
    Public Property Owner Gets or sets the owner of the current staged content item.  
    Public Property ParentID Gets or sets the identifier of the parent item.  
    Public Property ProviderName Gets or sets the name of the provider.

    Again, in my code for the StagedContent instance I do not have this property neither 'Read-only' nor any other:
    content.ID 
         ItemInfo

         Language
              Languages
         MimeType
         ParentId


     Regrads,
    Natalia

  15. Natalia
    Natalia avatar
    7 posts
    Registered:
    09 Jul 2010
    13 Jul 2010
    Link to this post
    Thank you,
    never mind, I got it,

    Best regards,
    Natalia
  16. Julio Molina-Muscara
    Julio Molina-Muscara avatar
    4 posts
    Registered:
    12 Aug 2005
    26 Jul 2010
    Link to this post
    Please verify and correct / remove the article at http://www.sitefinity.com/devnet/kb/sitefinity-3-x/how-to-notify-roles-that-content-has-been-sent-for-approval.aspx which has an incomplete C# code sample and it uses Manager.GetStagedContent instead of Manager.GetCurrentState, resulting in the item being locked during the workflow process. Thanks,
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Jul 2010
    Link to this post
    Hi Julio Molina-Muscara,

    The article will be updated. It contains some old references and some of the methods have been changed.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
17 posts, 1 answered