public static bool articleIsPermittedUnderAccountGroup(BaseArticle article)
        {
            var account = SessionPersister.account;

            if (account != null)
            {
                if (account.isRoleSuperadmin())
                {
                    return(true);
                }

                if (account.Group != null)
                {
                    if (article.categoryID == null)
                    {
                        return(true);
                    }
                    var categoryID = string.Format("{0}", article.categoryID);
                    if (account.Group.getAccessibleCategoryList().Contains(categoryID))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 public static string tryCatchAccountGroupPermissionError(BaseArticle article)
 {
     if (!articleIsPermittedUnderAccountGroup(article))
     {
         return("Access Denied");
     }
     return(null);
 }
コード例 #3
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            currentNode = (Node)Context.Items["currentNode"];
            lang        = SFGlobal.CurrentCulture.Name;
            rank        = SFGlobal.IsNumeric(Page.CustomQueryString["page"]) ? int.Parse(Page.CustomQueryString["page"]) : 1;
            string sql     = "";
            string columns = "TOP 1 templateID, title, summary, keywords, body, dateModified ";

            if (SFGlobal.IsUserCMS())
            {
                sql = "SELECT " + columns + " FROM " + dbTable + " WHERE nodeID={0} AND lang='{1}' AND rank = {2} ORDER BY preview DESC, publish DESC, dateModified DESC, version DESC";
            }
            else
            {
                dbTable += SFGlobal.PublicSuffix;
                sql      = "SELECT " + columns + " FROM " + dbTable + " WHERE nodeID = {0}AND lang = '{1}' and rank = {2}";
            }
            sql = String.Format(sql, currentNode.Id, lang, rank);
            DataRow dr = SFGlobal.DAL.execDataRow(sql);

            if (dr != null)
            {
                article = loadArticle((int)dr["templateID"]);
                article.ArticleTitle = dr["title"].ToString();
                article.ArticleBody  = dr["body"].ToString();
                article.Keywords     = dr["keywords"].ToString();
                article.Summary      = dr["summary"].ToString();
                article.LastModified = (DateTime)dr["dateModified"];
            }
            else
            {
                article              = loadArticle(1);
                article.ArticleBody  = String.Format("<h2>Article not Found.</h2><p>There is no Article for this node yet. Publish a new article</p>");
                article.ArticleTitle = "Error!";
                article.Keywords     = "ERROR";
                article.Summary      = "ERROR";
                article.LastModified = DateTime.Now;
                //throw new DuryTools.ErrorHandler("Problem loading article. Possible causes: haven't published yet, no article for this language");
            }
            holder.Controls.Add(article);
        }
コード例 #4
0
 public static bool SendEmailToAccountOnNewActivity(Account account, BaseArticle article, String action)
 {
     return(false);
 }
コード例 #5
0
        public List <Account> findAccountsByAccountGroupsToEmailNotify(List <AccountGroup> accountGroups, BaseArticle baseArticle)
        {
            List <int> accountGroupIDs = new List <int>();

            foreach (var group in accountGroups)
            {
                accountGroupIDs.Add(group.AccountGroupID);
            }

            if (accountGroupIDs.Count <= 0)
            {
                accountGroupIDs.Add(1);
            }

            int ownerAccountID = -1;

            if (SessionPersister.account != null)
            {
                ownerAccountID = SessionPersister.account.AccountID;
            }
            using (var db = new BaseDbContext())
            {
                return(db.accountDb.AsNoTracking().Where(acc =>
                                                         (
                                                             (
                                                                 (
                                                                     acc.EmailNotifications == 0 && accountGroupIDs.Contains(acc.GroupID ?? 1)
                                                                 )
                                                                 ||
                                                                 (
                                                                     acc.EmailNotifications == 1 && acc.AccountID == (baseArticle.createdBy ?? -2)
                                                                 )
                                                                 ||
                                                                 (
                                                                     acc.EmailNotifications == 1 && acc.AccountID == (baseArticle.approvedBy ?? -2)
                                                                 )
                                                                 ||
                                                                 (
                                                                     acc.EmailNotifications == 1 && acc.AccountID == (baseArticle.publishedBy ?? -2)
                                                                 )
                                                             )
                                                             &&
                                                             (
                                                                 (
                                                                     acc.AccountID != ownerAccountID
                                                                 )
                                                                 ||
                                                                 (
                                                                     acc.AccountID == ownerAccountID && !acc.EmailNotificationsNotNotifyOwnChangesToMySelf
                                                                 )
                                                             )
                                                             &&
                                                             (
                                                                 acc.isRemoved != true
                                                             )
                                                         )).ToList());
            }
        }
コード例 #6
0
        public static bool NotifyAllOnActionOfBaseArticle(string categoryStr, BaseArticle baseArticle, EmailNotificationAction action, List <Object> parameters = null)
        {
            if (action == EmailNotificationAction.UNKNOWN)
            {
                return(false);
            }

            var      categoryID = baseArticle.categoryID;
            Category category   = null;

            if (baseArticle.categoryID == null || baseArticle.categoryID <= 0)
            {
                category = InfrastructureCategoryDbContext.getInstance().findCategoryByID(categoryID);
            }



            // get createdBy
            Account owner = AccountDbContext.getInstance().findAccountByID(SessionPersister.account.AccountID);



            // analyze category for interested accounts (by account group)
            List <AccountGroup> accountGroups         = AccountGroupDbContext.getInstance().findGroups();
            List <AccountGroup> filteredAccountGroups = new List <AccountGroup>();

            foreach (var group in accountGroups)
            {
                List <int> categoryIDs = group.getAccessibleCategoryListInt();
                if (category != null && categoryIDs.Contains(category.ItemID))
                {
                    filteredAccountGroups.Add(group);
                }
            }


            List <Account> accounts = AccountDbContext.getInstance().findAccountsByAccountGroupsToEmailNotify(filteredAccountGroups, baseArticle);

            // filter...
            List <Account> filteredAccounts = new List <Account>();

            if (action == EmailNotificationAction.CREATE ||
                action == EmailNotificationAction.EDIT ||
                action == EmailNotificationAction.EDITPROPERTIES ||
                action == EmailNotificationAction.CREATENEWVERSION)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }
            if (action == EmailNotificationAction.DELETE)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            if (action == EmailNotificationAction.SUBMITFORAPPROVAL)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            if (action == EmailNotificationAction.APPROVE ||
                action == EmailNotificationAction.UNAPPROVE)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover() || acc.isRolePublisher())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            if (action == EmailNotificationAction.PUBLISH ||
                action == EmailNotificationAction.UNPUBLISH)
            {
                foreach (var acc in accounts)
                {
                    if (acc.isRoleSuperadmin() || acc.isRoleEditor() || acc.isRoleApprover() || acc.isRolePublisher())
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }

            foreach (var acc in filteredAccounts)
            {
                // send to owner?
                if (owner != null && owner.AccountID == acc.AccountID &&
                    owner.ShouldEmailNotifyBaseArticleChangesByOwn())
                {
                    SendEmail(categoryStr, owner, acc, baseArticle, category, action);
                    continue;
                }

                // send to all?
                if (acc.ShouldEmailNotifyBaseArticleChanges())
                {
                    SendEmail(categoryStr, owner, acc, baseArticle, category, action);
                    continue;
                }
            }

            return(true);
        }
コード例 #7
0
        public static void SendEmail(string categoryStr, Account owner, Account account, BaseArticle baseArticle, Category category, EmailNotificationAction action)
        {
            var dict    = MakeNotificationInfo(categoryStr, owner, account, baseArticle, category, action);
            var body    = dict["body"];
            var subject = dict["subject"];

            Thread email = new Thread(delegate()
            {
                EmailHelper.SendEmail(
                    new List <string> {
                    account.Email
                },
                    body,
                    subject
                    );
            });

            email.IsBackground = true;
            email.Start();
        }
コード例 #8
0
        public static System.Collections.Generic.Dictionary <string, string> MakeNotificationInfo(string categoryStr, Account owner, Account account, BaseArticle baseArticle, Category category, EmailNotificationAction action)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            var item_cat      = "Item";
            var item_url      = "";
            var articleID     = baseArticle.ArticleID;
            var baseArticleID = baseArticle.BaseArticleID;
            var name          = baseArticle.Name;

            if (categoryStr.Equals("Article"))
            {
                item_cat = "Article";
                if (account.isRolePublisher())
                {
                    item_url = "/ArticlePublisher/DetailsLocale?baseArticleID=" + baseArticle.BaseArticleID + "&version=" + baseArticle.Version + "&lang=" + baseArticle.Lang;
                }
                else if (account.isRoleApprover())
                {
                    item_url = "/ArticleApprover/DetailsLocale?baseArticleID=" + baseArticle.BaseArticleID + "&version=" + baseArticle.Version + "&lang=" + baseArticle.Lang;
                }
                else if (account.isRoleEditor())
                {
                    item_url = "/ArticleEditor/DetailsLocale?baseArticleID=" + baseArticle.BaseArticleID + "&version=" + baseArticle.Version + "&lang=" + baseArticle.Lang;
                }
            }
            else if (categoryStr.Equals("Content Page"))
            {
                item_cat = "Content Page";
                item_url = "/ContentPageEditor/DetailsLocale?baseArticleID=" + baseArticle.BaseArticleID + "&version=" + baseArticle.Version + "&lang=" + baseArticle.Lang;
            }

            item_url = ServerHelper.GetSiteRoot() + item_url;

            var item_action_tag         = "";
            var item_action_description = "";

            switch (action)
            {
            case EmailNotificationAction.CREATE:
                item_action_tag         = "Created";
                item_action_description = "{0} {1} has been created by {2}.";
                break;

            case EmailNotificationAction.EDIT:
                item_action_tag         = "Edited";
                item_action_description = "{0} {1}'s contents has been edited by {2}.";
                break;

            case EmailNotificationAction.EDITPROPERTIES:
                item_action_tag         = "Properties Edited";
                item_action_description = "{0} {1}'s properties has been edited by {2}.";
                break;

            case EmailNotificationAction.DELETE:
                item_action_tag         = "Deleted";
                item_action_description = "{0} {1} has been deleted by {2}.";
                break;

            case EmailNotificationAction.CREATENEWVERSION:
                item_action_tag         = "Created New Version";
                item_action_description = "A new version of {0} {1} has been created by {2}.";
                break;

            case EmailNotificationAction.SUBMITFORAPPROVAL:
                item_action_tag         = "Submitted for Approval";
                item_action_description = "{0} {1} has been submitted for approval by {2}.";
                break;

            case EmailNotificationAction.APPROVE:
                item_action_tag         = "Approved";
                item_action_description = "{0} {1} has been approved by {2}.";
                break;

            case EmailNotificationAction.UNAPPROVE:
                item_action_tag         = "Unapproved";
                item_action_description = "{0} {1} has been unapproved by {2}.";
                break;

            case EmailNotificationAction.PUBLISH:
                item_action_tag         = "Published";
                item_action_description = "{0} {1} has been published by {2}.";
                break;

            case EmailNotificationAction.UNPUBLISH:
                item_action_tag         = "Unpublished";
                item_action_description = "{0} {1} has been unpublished by {2}.";
                break;

            default:
                break;
            }

            var item_subject = String.Format("[GSL - {0} {1}] ({2}) {3}",
                                             item_cat,
                                             baseArticleID,
                                             item_action_tag,
                                             name
                                             );


            var item_action_description_impl = string.Format(
                item_action_description,
                item_cat,
                baseArticleID,
                owner.Username
                );


            var item_body = string.Format(
                "Dear {0} {1}, <br/><br/>" +
                "<p>{2}</p>" +
                "<p><a href='{3}'>{4}</a></p>" +
                "<hr />" +
                "<p>Geminis CMS Team</p>",
                account.Firstname,
                account.Lastname,
                item_action_description_impl,
                item_url,
                item_subject
                );

            dict.Add("subject", item_subject);
            dict.Add("body", item_body);

            return(dict);
        }
コード例 #9
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            currentNode = (Node)Context.Items["currentNode"];             // get our current node from the context stack
            string sql = "";
            object id  = null;


            // lets give the CMS user special treatment
            if (SFGlobal.IsUserCMS())
            {
                publicSuffix = "";
                // see if there is a preview assigned to this node
                //sql = "SELECT b.versionNumber, b.pageNumber, b.title, b.summary, b.body, b.dateModified, b.templateID, b.keywords FROM  sf_ArticlePages b INNER JOIN sf_Articles a ON b.articleID = a.id WHERE (a.nodeID = " + currentNode.Id + ") AND (a.lang = '" + lang + "') AND (b.preview = 1)";
                id = SFGlobal.DAL.execScalar(String.Format("SELECT b.id FROM sf_ArticlePages b INNER JOIN sf_Articles a ON b.articleID = a.id WHERE (a.nodeID = {0}) AND (b.preview = 1) AND (a.lang = '{1}')", currentNode.Id, this.lang));
                Response.Write("1=" + id);


                // otherwise show the article set for publish
                if (id == null)
                {
                    id = SFGlobal.DAL.execScalar(String.Format("SELECT b.id FROM sf_ArticlePages b INNER JOIN sf_Articles a ON b.articleID = a.id WHERE (a.nodeID = {0}) AND (a.lang = '{1}') AND (b.publish = 1)", currentNode.Id, this.lang));
                    Response.Write("2=" + id);
                }


                // otherwise show the greatest version number
                if (id == null)
                {
                    id = SFGlobal.DAL.execScalar(String.Format("SELECT TOP 1 b.id FROM sf_ArticlePages b INNER JOIN sf_Articles a ON b.articleID = a.id WHERE (a.nodeID = {0}) AND (a.lang = '{1}') ORDER BY b.versionNumber DESC", currentNode.Id, this.lang));
                    Response.Write("3=" + id);
                }
            }
            else
            {
                //id = (int)SFGlobal.DAL.execScalar(String.Format("SELECT TOP 1 b.id FROM sf_ArticlePages" + this.publicSuffix + " b INNER JOIN sf_Articles" + this.publicSuffix + " a ON b.articleID = a.id WHERE (a.nodeID = {0}) AND (a.lang = '{1}')", currentNode.Id, this.lang));
            }

            if (id == null)
            {
                throw new DuryTools.ErrorHandler("can't find article for this node! help!");
            }
            else
            {
                DataSet ds = SFGlobal.DAL.execDataSet("SELECT * FROM sf_ArticlePages" + this.publicSuffix + " WHERE id = " + id.ToString());
                if (ds.Tables[0].Rows.Count >= 1)
                {
                    DataRow             dr = ds.Tables[0].Rows[0];
                    ArticleTemplateInfo at = SFGlobal.GetArticleTemplate((int)dr["templateID"]);
                    article = (BaseArticle)Page.LoadControl(SFGlobal.NodeTemplateLocation + "\\" + at.Src + ".ascx");
                    article.ArticleTitle = dr["title"].ToString();
                    article.ArticleBody  = dr["body"].ToString();
                    article.LastModified = (dr["dateModified"] != DBNull.Value) ? (DateTime)dr["dateModified"] : System.DateTime.Now;
                    article.Keywords     = dr["keywords"].ToString();
                    article.Summary      = dr["summary"].ToString();
                    //title = dr["title"].ToString();
                    holder.Controls.Add(article);

                    Response.Write(Page.CustomQueryString["page"]);
                }
                else
                {
                    throw new DuryTools.ErrorHandler("Can't load article id: " + id.ToString());
                }
            }

            //DataSet ds = SFGlobal.DAL.execDataSet(sql);
            //Response.Write(ds.Tables[0].Rows.Count);
        }