private void SetTrafficLight(Article article)
    {
        if (SecurityHelper.CanUserView(Page.User.Identity.Name, article.Category.Id))
        {
            imgAck.ImageUrl = Utility.GetTrafficLight(article);

            //if (!article.RequiresAck || article.Acknowledged)
            //    btnAcknowledge.Enabled = false;

            if (article.RequiresAck)
            {
                if (article.Acknowledged)
                {
                    divAckButton.Attributes["class"] = "divAckChecked";
                    btnAcknowledge.Enabled           = false;
                }
                else
                {
                    divAckButton.Attributes["class"] = "divAckButton";
                }
            }
            else
            {
                ackText.Visible = false;
            }
        }
        else
        {
            divAckButton.Visible = false;
            trStatus.Visible     = false;
        }
    }
示例#2
0
        /// <summary>
        /// Returns the count of articles in the category.
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="pageIdentity"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public static int CountItems(string categoryId, string pageIdentity, string username)
        {
            int      itemCount = 0;
            Category cat       = DocoManager.GetCategory(categoryId);

            if (SecurityHelper.CanUserEdit(pageIdentity, categoryId))
            {
                itemCount = DocoManager.GetArticles(cat, ArticleStatus.All, false).Count;
            }
            else if (SecurityHelper.CanUserContribute(pageIdentity, categoryId))
            {
                IList <Article> allAritcles = DocoManager.GetArticles(cat, ArticleStatus.All, false);
                foreach (Article article in allAritcles)
                {
                    if (article.Owner.Equals(pageIdentity))
                    {
                        itemCount++;
                    }
                }
            }

            else if (SecurityHelper.CanUserView(pageIdentity, categoryId))
            {
                //change this in future to see only the published ones!.
                itemCount = itemCount + DocoManager.GetArticles(cat, ArticleStatus.Approved, false).Count;
            }
            return(itemCount);
        }
示例#3
0
        private static bool UserCanView(Item item, string username)
        {
            bool canView = false;

            if (SecurityHelper.CanUserEdit(username, item.Category.Id))
            {
                canView = true;
            }
            else
            {
                if (SecurityHelper.CanUserContribute(username, item.Category.Id))
                {
                    if (item.Owner.Equals(username))
                    {
                        canView = true;
                    }
                    else if (SecurityHelper.CanUserView(username, item.Category.Id))
                    {
                        if (item.ApprovalStatus.Name.Equals("Published"))
                        {
                            canView = true;
                        }
                    }
                }
                else if (SecurityHelper.CanUserView(username, item.Category.Id))
                {
                    if (item.ApprovalStatus.Name.Equals("Published"))
                    {
                        canView = true;
                    }
                }
            }

            return(canView);
        }
示例#4
0
    /// <summary>
    /// Set up the view.
    /// </summary>
    void SetupView()
    {
        // If the folder is bogus...
        if (!Directory.Exists(_root))
        {
            Label label = new Label();
            label.Text =
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resource.FolderNotFound,
                    _root);
            phDisplay.Controls.Add(label);
            return;
        }

        Folder folder = AccessManager.GetFolderKey(_root);

        ProfileCommon profile = HttpContext.Current.Profile as ProfileCommon;

        if (folder != null)
        {
            if (!SecurityHelper.CanUserView(HttpContext.Current.User.Identity.Name, folder.Id))
            {
                Label label = new Label();
                label.Text =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Access Denied",
                        _root);
                phDisplay.Controls.Add(label);
                btnNewFile.Visible = btnNewFolder.Visible = btnUpload.Visible = false;
                return;
            }
        }

        // Get a new table of files and folders.
        Table table = new TableEx(this, _root).Create();

        // Display the table.
        if (table != null)
        {
            phDisplay.Controls.Add(table);
        }
        else
        {
            // Table wasn't created.
            Label label = new Label();
            label.Text = Resource.CantCreateTable;
            phDisplay.Controls.Add(label);
        }

        // Finally, if a file link was clicked, open it.
        OpenFile();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["RefUrl"] = Request.UrlReferrer.ToString();
        }
        //check previous page's URL for the id if Id hasn't been brought forward.
        //if (Request.UrlReferrer.Query.Contains("id"))
        //    CategoryId = Request.UrlReferrer.Query.Substring(Request.UrlReferrer.Query.IndexOf("id") + 3);
        //else
        CategoryId = Request["id"];     //check for id in URL

        if (!string.IsNullOrEmpty(CategoryId))
        {
            Category category = null;
            if (!string.IsNullOrEmpty(CategoryId))
            {
                category = NewsManager.GetCategory(CategoryId);
            }

            if (!SecurityHelper.CanUserView(User.Identity.Name, category.Id))
            {
                // If the user cannot view the category, then return silently.
                object refUrl = ViewState["RefUrl"];
                if (refUrl != null)
                {
                    Response.Redirect((string)refUrl);
                }
            }

            lblDisplayName.InnerText = category.Name;

            var link = new HtmlLink();
            link.Href = Navigation.Doco_CategoryRss(CategoryId).GetServerUrl(true);
            link.Attributes.Add("rel", "alternate");
            link.Attributes.Add("type", "application/rss+xml");
            link.Attributes.Add("title", "Category " + category.Name + " Announcements");
            Header.Controls.Add(link);

            string url    = Navigation.Communication_NewsNewItem(category).GetAbsoluteClientUrl(true);
            bool   access = SecurityHelper.CanUserEdit(Page.User.Identity.Name, category.Id);
            newLink = new Navigation.NavigateNewItem(url, access);

            if (category.ParentCategory != null)
            {
                lblParentCategoryName.Text = category.ParentCategory.Name;
            }

            LoadPermissionsView();

            LoadList(category);
        }
    }
示例#6
0
    private void BindTrafficLight()
    {
        // The RadTabStrip1 is the edit/preview strip. This is visible when we are in edit mode.
        // Therefore don't show the acknowledge checkbox if we are in edit mode.

        if (this.RadTabStrip1.Visible)
        {
            ackText.Visible = false;
        }
        else
        {
            Article article = DocoManager.GetArticle(ArticleId);
            if (SecurityHelper.CanUserView(Page.User.Identity.Name, article.Category.Id))
            {
                if (!string.IsNullOrEmpty(Request.QueryString["mode"]) && Request.QueryString["mode"].Equals("approve"))
                {
                    divAckButton.Attributes["class"] = "divAckChecked";
                    btnAcknowledge.Enabled           = false;
                }
                else if (article.RequiresAck)
                {
                    if (article.Acknowledged)
                    {
                        divAckButton.Attributes["class"] = "divAckChecked";
                        btnAcknowledge.Enabled           = false;
                    }
                    else
                    {
                        divAckButton.Attributes["class"] = "divAckButton";
                    }
                }
                else
                {
                    //check the auti record for the article- audit if no records found.
                    IList <AuditRecord> records = AuditManager.GetAuditItems(Page.User.Identity.Name, ArticleId, AuditRecord.AuditAction.Viewed);
                    if (records.Count == 0)
                    {
                        AuditManager.Audit(Page.User.Identity.Name, ArticleId, AuditRecord.AuditAction.Viewed);
                    }
                    ackText.Visible = false;
                }
            }
            else
            {
                divAckButton.Visible = false;
                spanAcked.Visible    = false;
            }
        }
    }
    protected List <RepeaterItem> GetAccessibleList(List <NewsGridItem> gridItems)
    {
        List <RepeaterItem> repeaterItemList = new List <RepeaterItem>();

        foreach (NewsGridItem gridItem in gridItems)
        {
            if (gridItem.NewsItem != null)
            {
                if (SecurityHelper.CanUserEdit(Page.User.Identity.Name, gridItem.NewsItem.Category.Id))
                {
                    repeaterItemList.Add(new RepeaterItem {
                        NewsGridItem = gridItem, TrafficLightUrl = GetUserStatus(gridItem.NewsItem, gridItem.Draft.GroupId)
                    });
                }
                else
                {
                    if (SecurityHelper.CanUserContribute(Page.User.Identity.Name, gridItem.NewsItem.Category.Id))
                    {
                        //only add if the user is the owner
                        if (gridItem.NewsItem.Owner.Equals(Utilities.GetUserName(Page.User.Identity.Name)))
                        {
                            repeaterItemList.Add(new RepeaterItem {
                                NewsGridItem = gridItem, TrafficLightUrl = GetUserStatus(gridItem.NewsItem, gridItem.Draft.GroupId)
                            });
                        }
                        else if (SecurityHelper.CanUserView(Page.User.Identity.Name, gridItem.NewsItem.Category.Id))
                        {
                            if (gridItem.NewsItem.ApprovalStatus.Name.Equals("Published"))
                            {
                                repeaterItemList.Add(new RepeaterItem {
                                    NewsGridItem = gridItem, TrafficLightUrl = GetUserStatus(gridItem.NewsItem, gridItem.Draft.GroupId)
                                });
                            }
                        }
                    }
                    else if (SecurityHelper.CanUserView(Page.User.Identity.Name, gridItem.NewsItem.Category.Id))
                    {
                        if (gridItem.NewsItem.ApprovalStatus.Name.Equals("Published"))
                        {
                            repeaterItemList.Add(new RepeaterItem {
                                NewsGridItem = gridItem, TrafficLightUrl = GetUserStatus(gridItem.NewsItem, gridItem.Draft.GroupId)
                            });
                        }
                    }
                }
            }
        }
        return(repeaterItemList);
    }
示例#8
0
        public static int CountItems(IList <Item> items, string username)
        {
            if (items != null && items.Count > 0)
            {
                IList <VersionItem> vItems = new List <VersionItem>();
                foreach (Item item1 in items)
                {
                    VersionItem v = VersionManager.GetVersionByItemId(item1.Id);
                    if (v != null)
                    {
                        VersionItem         latest   = new VersionItem();
                        IList <VersionItem> versions = VersionManager.GetAllVersions(v.GroupId);

                        foreach (VersionItem version in versions)
                        {
                            if (VersionManager.IsLatestVersion(version.Id))
                            {
                                latest = version;
                            }
                        }
                        if (latest == null)
                        {
                            if (SecurityHelper.CanUserEdit(username, item1.Category.Id) || SecurityHelper.CanUserContribute(username, item1.Category.Id))
                            {
                                vItems.Add(v);
                            }
                        }
                        else
                        {
                            Item item2 = NewsManager.GetItem(latest.ItemId);
                            if ((SecurityHelper.CanUserView(username, item2.Category.Id) && item2.ApprovalStatus.Name == "Published") ||
                                (SecurityHelper.CanUserContribute(username, item2.Category.Id) && item2.Owner.ToLower() == username.ToLower()) ||
                                (SecurityHelper.CanUserEdit(username, item2.Category.Id)))
                            {
                                if (item1.Category.Id == item2.Category.Id)
                                {
                                    vItems.Add(v);
                                }
                            }
                        }
                    }
                }
                IEnumerable <VersionItem> disItems = vItems.Distinct(new KeyEqualityComparer <VersionItem>(x => x.GroupId));

                return(disItems.Count());
            }
            return(0);
        }
示例#9
0
 private void BindTrafficLight()
 {
     //check for reader access. If not in reader's access than do not apply traffic lights and no auditing required.
     if (SecurityHelper.CanUserView(Page.User.Identity.Name, Item.Category.Id))
     {
         if (!string.IsNullOrEmpty(Request.QueryString["mode"]) && Request.QueryString["mode"].Equals("approve"))
         {
             lblAck.CssClass = "ack";
             divAckButton.Attributes["class"] = "divAckChecked";
             btnAcknowledge.Enabled           = false;
         }
         else if (Item.RequiresAck)
         {
             if (Item.Acknowledged)
             {
                 lblAck.CssClass = "ack";
                 divAckButton.Attributes["class"] = "divAckChecked";
                 btnAcknowledge.Enabled           = false;
             }
             else
             {
                 lblAck.CssClass = "notAck";
                 divAckButton.Attributes["class"] = "divAckButton";
             }
             IList <AuditRecord> records = AuditManager.GetAuditItems(Page.User.Identity.Name, Item.Id, AuditRecord.AuditAction.Acknowledged);
             if (records.Count > 0)
             {
                 lblAck.Text = records[0].TimeStamp.ToString();
             }
         }
         else
         {
             IList <AuditRecord> records = AuditManager.GetAuditItems(Page.User.Identity.Name, Item.Id, AuditRecord.AuditAction.Viewed);
             if (records.Count == 0)
             {
                 AuditManager.Audit(Page.User.Identity.Name, Item.Id, AuditRecord.AuditAction.Viewed);
             }
             ackText.Visible = false;
             lblAck.CssClass = "view";
         }
     }
     else
     {
         HideTrafficLight();
     }
 }
示例#10
0
    private IList <Article> GetAllArticles()
    {
        IList <Category> categories = DocoManager.GetAllCategories();
        IList <Article>  articles   = new List <Article>();

        foreach (Category category in categories)
        {
            if (SecurityHelper.CanUserView(Page.User.Identity.Name, category.Id))
            {
                IList <Article> arts = DocoManager.GetArticles(category, ArticleStatus.All, false);
                foreach (Article article in arts)
                {
                    articles.Add(article);
                }
            }
        }
        return(articles);
    }
示例#11
0
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        BusiBlocksTreeView categories = NewsManager.GetCategoriesItemsTree(Page.User.Identity.Name);

        object itemList = ViewState[ItemList];

        if (itemList != null)
        {
            IList <Item> items = new List <Item>();
            if (itemList.ToString().Equals("All"))
            {
                items = NewsManager.GetItems();
            }
            else
            {
                if (!string.IsNullOrEmpty(itemList.ToString()))
                {
                    string[] arr = itemList.ToString().Split(',');
                    foreach (string itemId in arr)
                    {
                        Item item = NewsManager.GetItem(itemId);
                        if (categories.Contains(item.Category.Id))
                        {
                            items.Add(NewsManager.GetItem(itemId));
                        }
                    }
                }
            }
            if (RadGrid1.MasterTableView.SortExpressions.Count == 0)
            {
                GridSortExpression expression = new GridSortExpression();
                expression.FieldName = "Item.UpdateDate";
                expression.SortOrder = GridSortOrder.Descending;
                RadGrid1.MasterTableView.SortExpressions.AddSortExpression(expression);
            }
            var allowedList =
                (from item in items where SecurityHelper.CanUserView(Page.User.Identity.Name, item.Category.Id) select new RepeaterItem {
                Item = item, TrafficLightUrl = GetUserStatus(item)
            }).ToList();
            RadGrid1.DataSource = allowedList;
        }
    }
示例#12
0
    private bool UserHasPermission(string categoryId)
    {
        Category cat               = NewsManager.GetCategory(categoryId);
        bool     UserCanView       = (cat.Name.Equals("All Announcements")) ? true : SecurityHelper.CanUserView(Username, categoryId);
        bool     UserCanEdit       = (cat.Name.Equals("All Announcements")) ? true : SecurityHelper.CanUserEdit(Username, categoryId);
        bool     UserCanContribute = (cat.Name.Equals("All Announcements")) ? true : SecurityHelper.CanUserContribute(Username, categoryId);

        bool permission = false;

        if (PermissionMode == TreePermissionMode.View)
        {
            permission = (UserCanView || UserCanEdit || UserCanContribute);
        }
        else if (PermissionMode == TreePermissionMode.Edit)
        {
            permission = (UserCanEdit || UserCanContribute);
        }

        return(permission);
    }
示例#13
0
    protected List <Article> GetAccessibleList(List <Article> articles)
    {
        List <Article> accesibleArticlesList = new List <Article>();

        foreach (Article article in articles)
        {
            if (article != null)
            {
                if (SecurityHelper.CanUserEdit(Page.User.Identity.Name, article.Category.Id))
                {
                    accesibleArticlesList.Add(article);
                }
                else
                {
                    if (SecurityHelper.CanUserContribute(Page.User.Identity.Name, article.Category.Id))
                    {
                        //only add if the user is the owner
                        if (article.Owner.Equals(Utilities.GetUserName(Page.User.Identity.Name)))
                        {
                            accesibleArticlesList.Add(article);
                        }
                        else if (SecurityHelper.CanUserView(Page.User.Identity.Name, article.Category.Id))
                        {
                            //if (article.ApprovalStatus.Name.Equals("Published")) --NEEDS TO BE UN COMMENTED WHEN APPROVAL STATUS IS DONE FOR DOCO BLOCK
                            accesibleArticlesList.Add(article);
                        }
                    }
                    else if (SecurityHelper.CanUserView(Page.User.Identity.Name, article.Category.Id))
                    {
                        //if (article.ApprovalStatus.Name.Equals("Published"))
                        accesibleArticlesList.Add(article);
                    }
                }
            }
        }
        return(accesibleArticlesList);
    }
示例#14
0
    public void Bind(IList <Category> categories)
    {
        List <Item>         items         = new List <Item>();
        List <NewsGridItem> gridItems     = new List <NewsGridItem>();
        string        approvalPublishedId = ItemApprovalStatusManager.GetStatusByName("Published").Id;
        List <string> uniqueGroupIds      = new List <string>();

        foreach (Category category in categories)
        {
            IList <Item> itms = (IList <Item>)NewsManager.GetItems(category, false);
            foreach (Item item in itms)
            {
                if (item.ApprovalStatus.Id.Equals(approvalPublishedId))
                {
                    VersionItem version = VersionManager.GetVersionByItemId(item.Id);
                    if (!uniqueGroupIds.Contains(version.GroupId))
                    {
                        gridItems.Add(new NewsGridItem()
                        {
                            Draft = version, NewsItem = item, TrafficLightUrl = GetUserStatus(item, version.GroupId)
                        });
                        uniqueGroupIds.Add(version.GroupId);
                    }
                }
            }
        }

        //do a 1-1 news & draft comparison to check whether all news have corresponding draft or not if not then add it to the grid. Pressing edit will create its first version.
        foreach (Category category in categories)
        {
            IList <Item> childItems = NewsManager.GetItems(category, false);

            foreach (Item newsItem in childItems)
            {
                VersionItem versionItem = VersionManager.GetVersionByItemId(newsItem.Id);
                if (versionItem == null && newsItem.ApprovalStatus == null)
                {
                    versionItem         = new VersionItem();
                    versionItem.ItemId  = newsItem.Id;
                    versionItem.GroupId = newsItem.Id;
                    gridItems.Add(new NewsGridItem()
                    {
                        Draft = versionItem, NewsItem = newsItem
                    });
                }
            }
        }

        List <NewsGridItem> gridItemsPermission = new List <NewsGridItem>();

        foreach (var gi in gridItems)
        {
            if (gi.NewsItem != null)
            {
                if (SecurityHelper.CanUserView(Page.User.Identity.Name, gi.NewsItem.Category.Id))
                {
                    gridItemsPermission.Add(gi);
                }
            }
        }

        RadGridRead.DataSource = gridItemsPermission;
    }
示例#15
0
    private IList <User> GetTotalUsers()
    {
        IList <User> totalUsers = new List <BusiBlocks.Membership.User>();//total number of users who have viewed the announcement
        List <User>  viewUsers  = new List <BusiBlocks.Membership.User>();

        IList <Access> accesses          = AccessManager.GetItemAccess(Item.Category.Id);
        const string   allGroupsLabel    = "All Groups";
        const string   allLocationsLabel = "All Sites";

        foreach (Access access in accesses)
        {
            PersonType personType = null;
            Site       site       = null;

            if (!string.IsNullOrEmpty(access.PersonTypeId))
            {
                personType = PersonManager.GetPersonTypeById(access.PersonTypeId);
            }
            if (!string.IsNullOrEmpty(access.SiteId))
            {
                site = SiteManager.GetSiteById(access.SiteId);
            }

            if (personType != null || site != null || access.AllSites || access.AllPersonTypes || access.AllUsers)
            {
                IList <Person> persons = PersonManager.GetAllPersons();
                foreach (Person person in persons)
                {
                    User user = MembershipManager.GetUserByPerson(person);
                    bool add  = false;
                    if (SecurityHelper.CanUserView(user.Name, Item.Category.Id))
                    {
                        if (access.AllUsers || access.AllPersonTypes || access.AllSites)
                        {
                            add = true;
                        }
                        else if (personType != null)
                        {
                            if (PersonManager.IsPersonInPersonType(person, personType))
                            {
                                add = true;
                            }
                        }
                        else if (site != null)
                        {
                            if (PersonManager.IsPersonInPersonSite(person, site))
                            {
                                add = true;
                            }
                        }
                        if (add && totalUsers.Contains(user) == false)
                        {
                            totalUsers.Add(user);
                        }
                    }
                }
            }
        }

        return(totalUsers);
    }
示例#16
0
        private static BusiBlocksTreeView PopulateTreeView(string username)
        {
            var catTreeView = new BusiBlocksTreeView();

            IList <Category> cats = GetAllCategories();

            IList <Category> toRemove = new List <Category>();

            foreach (Category cat in cats)
            {
                // Remove this category from the list if it is not viewable by this user.
                if (!SecurityHelper.CanUserView(username, cat.Id))
                {
                    toRemove.Add(cat);
                }
            }
            foreach (Category cat in toRemove)
            {
                cats.Remove(cat);
            }

            // Need to form the hierarchical structure by selecting the categories with no parent
            // and then adding sub collections of categories with the chosen parent.

            var noParent =
                from x in cats
                where x.ParentCategory == null
                select x;

            int maxLevel = 20;

            if (!noParent.Any())
            {
                // Try to pick the "all docs" category.
                noParent =
                    from x in cats
                    where x.DisplayName.Equals("All Documents")
                    select x;
            }
            foreach (Category cat in noParent)
            {
                var node = new BusiBlocksTreeNode {
                    Id = cat.Id, Name = cat.DisplayName, IsFolder = true
                };
                IList <Article> items = GetArticles(cat, ArticleStatus.All, false);
                foreach (Article item in items)
                {
                    node.ChildNodes.Add(new BusiBlocksTreeNode {
                        Id = item.Id, Name = item.Name, IsFolder = false
                    });
                }
                catTreeView.Nodes.Add(node);
                PopulateSub(cat, cats, node, maxLevel, 0);
            }
            // todo Remove this commented out block when we're sure it isn't doing anything.
            //// Set the selected category.
            //if (noParent.Any())
            //{
            //    Category cat = noParent.First();
            //}
            return(catTreeView);
        }