Ejemplo n.º 1
0
        public DiscussionTopicContract(DiscussionTopic topic, IUserIconFactory userIconFactory, DiscussionTopicOptionalFields fields)
        {
            ParamIs.NotNull(() => topic);

            Author   = new UserWithIconContract(topic.Author, userIconFactory);
            Created  = topic.Created;
            FolderId = topic.Folder.Id;
            Id       = topic.Id;
            Name     = topic.Name;

            if (fields.HasFlag(DiscussionTopicOptionalFields.Comments))
            {
                Comments = topic.Comments.Select(c => new CommentForApiContract(c, userIconFactory)).ToArray();
            }

            if (fields.HasFlag(DiscussionTopicOptionalFields.CommentCount))
            {
                CommentCount = topic.Comments.Count;
            }

            if (fields.HasFlag(DiscussionTopicOptionalFields.Content))
            {
                Content = topic.Content;
            }

            if (fields.HasFlag(DiscussionTopicOptionalFields.LastComment) && topic.Comments.Any())
            {
                LastComment = new CommentForApiContract(topic.Comments.MaxItem(c => c.Created),
                                                        userIconFactory, includeMessage: false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the DiscussionTopic defined by the discussion Id and topic name arguments
        /// to the database.
        /// Returns true iff successful.
        /// Returns false if the Discussion with the specified discussionId or the Topic with
        /// the specified topicName referenced do not already exist in their respective
        /// database tables.
        /// </summary>
        /// <param name="discussionId"></param>
        /// <param name="topicName"></param>
        /// <returns></returns>
        public async Task <bool> AddDiscussionTopic(int discussionId, string topicName)
        {
            var discussionExists = DiscussionExists(discussionId);

            if (!discussionExists)
            {
                Console.WriteLine("RepoLogic.AddDiscussionTopic() was called for a discussion id that doesn't exist.");
                return(false);
            }
            var topicExists = TopicExists(topicName);

            if (!topicExists)
            {
                Console.WriteLine("RepoLogic.AddDiscussionTopic() was called for a topic that doesn't exist.");
                return(false);
            }
            var discussionTopic = new DiscussionTopic();

            discussionTopic.DiscussionId = discussionId;
            discussionTopic.TopicName    = topicName;

            await _dbContext.DiscussionTopics.AddAsync(discussionTopic);

            await _dbContext.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 3
0
        private void MoveTopic(IDatabaseContext ctx, DiscussionTopic topic, int targetFolderId)
        {
            PermissionContext.VerifyPermission(PermissionToken.DeleteComments);

            var folder = ctx.Load <DiscussionFolder>(targetFolderId);

            ctx.AuditLogger.AuditLog(string.Format("Moving {0} to {1}", topic, folder));

            topic.MoveToFolder(folder);
        }
Ejemplo n.º 4
0
        public static bool CanEdit(IUserPermissionContext permissionContext, DiscussionTopic topic)
        {
            if (!permissionContext.HasPermission(PermissionToken.CreateComments))
            {
                return(false);
            }

            // TODO: admins should be able to edit all topics, even locked

            return(topic.Author != null && topic.Author.IsTheSameUser(permissionContext.LoggedUser));
        }
Ejemplo n.º 5
0
        public static bool CanEdit(IUserPermissionContext permissionContext, DiscussionTopic topic)
        {
            if (!permissionContext.HasPermission(PermissionToken.CreateComments))
            {
                return(false);
            }

            if (permissionContext.HasPermission(PermissionToken.DeleteComments))
            {
                return(true);
            }

            return(topic.Author != null && topic.Author.IsTheSameUser(permissionContext.LoggedUser));
        }
Ejemplo n.º 6
0
        public DiscussionTopicContract CreateTopic(int folderId, DiscussionTopicContract contract)
        {
            PermissionContext.VerifyPermission(PermissionToken.CreateComments);

            if (contract.Author == null || contract.Author.Id != PermissionContext.LoggedUserId)
            {
                throw new NotAllowedException("Can only post as self");
            }

            return(repository.HandleTransaction(ctx => {
                var folder = ctx.Load(folderId);
                var agent = ctx.OfType <User>().CreateAgentLoginData(PermissionContext, ctx.OfType <User>().Load(contract.Author.Id));

                var topic = new DiscussionTopic(folder, contract.Name, contract.Content, agent);
                folder.AllTopics.Add(topic);

                ctx.Save(topic);

                ctx.AuditLogger.AuditLog("created " + topic, agent);

                return new DiscussionTopicContract(topic, userIconFactory, DiscussionTopicOptionalFields.None);
            }));
        }
Ejemplo n.º 7
0
 // Only used for recent comments atm.
 public EntryForApiContract(DiscussionTopic topic, ContentLanguagePreference languagePreference)
     : this((IEntryWithNames)topic, languagePreference, EntryOptionalFields.None)
 {
     CreateDate = topic.Created;
 }
Ejemplo n.º 8
0
    private void Display_Add()
    {
        bool bModerate = false;
        //If security_data.CanAdd = False Then
        //    Throw New Exception("User does not have permission")
        //End If
        if (this.m_iTopicID == 0)
        {
            this.m_iTopicID = m_iID;
            m_iID = 0;
        }

        if (this.m_iTopicID != 0 && this.m_iTopicID != -1)
        {
            _Board = m_refContent.GetTopicbyIDForEdit(this.m_iTopicID.ToString());
            security_data = m_refContentApi.LoadPermissions(this.m_iTopicID, "folder", 0);
            if (!(_Board == null) && _Board.Forums.Length > 0 && !(_Board.Forums[0].Topics == null) && (_Board.Forums[0].Topics.Length > 0))
            {
                bModerate = System.Convert.ToBoolean(_Board.Forums[0].ModerateComments);
                _Topic = _Board.Forums[0].Topics[0];
                ltr_topic_data.Text = "(" + this.m_iTopicID.ToString() + ") " + _Topic.Title;
            }
            else
            {
                throw (new Exception(base.GetMessage("error: content does not exist") + " \"" + this.m_iTopicID + "\"."));
            }
        }
        base.SetTitleBarToMessage("atl btn add reply");

        if (closeOnFinish != true)
        {
            base.AddBackButton((string)("../content.aspx?action=ViewContentByCategory&id=" + m_iForumID.ToString() + "&LangType=" + m_refContentApi.RequestInformationRef.ContentLanguage + "&ContType=" + Convert.ToInt64(Ektron.Cms.Common.EkEnumeration.TaskType.TopicReply) + "&contentid=" + m_iTopicID));
        }

        base.AddButtonwithMessages(AppImgPath + "../UI/Icons/save.png", "#", "alt save button text (content)", "btn save", "OnClick=\"javascript:SubmitForm();return false;\"", StyleHelper.SaveButtonCssClass, true);

        base.AddHelpButton("AddReply");

        tr_createdBy.Visible = false;
        tr_createdDate.Visible = false;

        SetLabels();
        if (bModerate == true && (security_data.IsAdmin == false && security_data.CanAddToImageLib == false))
        {
            drp_state.SelectedIndex = 0; // pending
            this.drp_state.Enabled = false;
            pnl_message_editor.Controls.Add(new LiteralControl("<input type=\"hidden\" name=\"replystate\" value=\"5\" />"));
        }
        else if (bModerate == false && (security_data.IsAdmin == false && security_data.CanAddToImageLib == false))
        {
            drp_state.SelectedIndex = 1; // approved
            this.drp_state.Enabled = false;
            pnl_message_editor.Controls.Add(new LiteralControl("<input type=\"hidden\" name=\"replystate\" value=\"7\" />"));
        }
        else
        {
            drp_state.SelectedIndex = 1; // approved
        }

        _Board = m_refContent.GetTopicbyIDForEdit(m_iTopicID.ToString());

        ctlEditor.FolderId = m_iForumID;
        ctlEditor.SetPermissions(security_data);
        ctlEditor.AllowFonts = true;
        if (_Board != null && _Board.StyleSheet.Length > 0)
        {
            ctlEditor.Stylesheet = m_refContentApi.SitePath + _Board.StyleSheet;
        }
        ctlEditor.Visible = true;
        RenderJS();
        SuppressTitle();
    }
Ejemplo n.º 9
0
    private void Populate_ViewForumPostsByCategoryGrid(DiscussionTopic[] topics, ArrayList commenttally)
    {
        System.Web.UI.WebControls.BoundColumn colBound = new System.Web.UI.WebControls.BoundColumn();
        UserAPI objUserAPI = new UserAPI();
        UserData objUserData = new UserData();

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "APPROVAL";
        colBound.HeaderStyle.CssClass = "title-header";
        colBound.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(12);
        FolderDataGrid.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "TOPIC";
        colBound.HeaderStyle.CssClass = "title-header";
        colBound.ItemStyle.CssClass = "left";
        colBound.HeaderText = _MessageHelper.GetMessage("lbl Topic");
        FolderDataGrid.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "STARTER";
        colBound.HeaderStyle.CssClass = "title-header";
        colBound.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(80);
        colBound.HeaderText = _MessageHelper.GetMessage("topicstarter text");
        FolderDataGrid.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "REPLIES";
        colBound.HeaderStyle.CssClass = "title-header";
        colBound.HeaderText = _MessageHelper.GetMessage("lbl replies");
        colBound.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
        FolderDataGrid.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "VIEWS";
        colBound.HeaderStyle.CssClass = "title-header";
        colBound.HeaderText = _MessageHelper.GetMessage("views lbl");
        FolderDataGrid.Columns.Add(colBound);

        colBound = new System.Web.UI.WebControls.BoundColumn();
        colBound.DataField = "LASTPOST";
        colBound.HeaderStyle.CssClass = "title-header";
        colBound.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(200);
        colBound.HeaderText = _MessageHelper.GetMessage("lbl Last Reply");
        FolderDataGrid.Columns.Add(colBound);

        FolderDataGrid.ShowHeader = true;

        DataTable dt = new DataTable();
        DataRow dr;

        dt.Columns.Add(new DataColumn("APPROVAL", typeof(string)));
        dt.Columns.Add(new DataColumn("TOPIC", typeof(string)));
        dt.Columns.Add(new DataColumn("STARTER", typeof(string)));
        dt.Columns.Add(new DataColumn("REPLIES", typeof(string)));
        dt.Columns.Add(new DataColumn("VIEWS", typeof(string)));
        dt.Columns.Add(new DataColumn("LASTPOST", typeof(string)));

        string ViewUrl = "";
        string EditUrl = "";
        int i;
        bool bNewComment = false;
        int iReplyTally = 0;
        DateTime dtLastPosted = DateTime.Now;

        for (i = 0; i <= (topics.Length - 1); i++)
        {
            if (topics[i].LanguageId == _ContentLanguage | _ContentLanguage == Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES)
            {
                dr = dt.NewRow();
                //reset these values
                iReplyTally = 0;
                bNewComment = false;

                foreach (ArrayList ctally in commenttally)
                {
                    if (Convert.ToInt64(ctally[0]) == topics[i].Id)
                    {
                        iReplyTally = System.Convert.ToInt32(ctally[1]);
                        bNewComment = System.Convert.ToBoolean(System.Convert.ToInt32(ctally[2]) < (iReplyTally * 7));
                        if (iReplyTally > 0)
                        {
                            dtLastPosted = Convert.ToDateTime(ctally[3]);
                        }
                        commenttally.Remove(ctally); // remove so we don't need to go through this again
                        break;
                    }
                }

                iReplyTally = topics[i].Replies;
                if (iReplyTally > 0)
                {
                    dtLastPosted = topics[i].LastPostedDate;
                }
                if ((bNewComment || topics[i].Status.ToUpper() == "I") && (_PermissionData.IsAdmin || _PermissionData.CanAddToImageLib))
                {
                    dr[0] = "<img src=\"images/UI/Icons/approvalApproveItem.png\" alt=\"" + this._MessageHelper.GetMessage("lbl approval needed") + "\" title=\"" + this._MessageHelper.GetMessage("lbl approval needed") + "\" />";
                }
                else
                {
                    dr[0] = "";
                }
                switch (topics[i].Priority)
                {
                    case Ektron.Cms.Common.EkEnumeration.DiscussionObjPriority.Announcement:
                        dr[1] = "<img title=\"Announcement\" src=\"" + _ContentApi.AppPath + "images/ui/icons/asteriskRed.png\" style=\"margin-right:.25em; vertical-align: middle\" />";
                        break;
                    case Ektron.Cms.Common.EkEnumeration.DiscussionObjPriority.Sticky:
                        dr[1] = "<img title=\"Sticky Topic\" src=\"" + _ContentApi.AppPath + "images/ui/icons/asteriskYellow.png\" style=\"margin-right:.25em; vertical-align: middle\" />";
                        break;
                    default: // DiscussionObjPriority.Normal
                        dr[1] = "<img title=\"Topic\" src=\"" + _ContentApi.AppPath + "images/ui/icons/asteriskOrange.png\" style=\"margin-right:.25em; vertical-align: middle\" />";
                        break;
                }

                ViewUrl = (string)("content.aspx?id=" + _Id + "&action=ViewContentByCategory&LangType=" + topics[i].LanguageId + "&ContType=" + Ektron.Cms.Common.EkConstants.CMSContentType_BlogComments + "&contentid=" + topics[i].Id.ToString()); //view posts
                EditUrl = (string)("content.aspx?action=View&folder_id=" + _Id + "&id=" + topics[i].Id + "&LangType=" + topics[i].LanguageId + "&callerpage=content.aspx&origurl=" + EkFunctions.UrlEncode(Request.ServerVariables["QUERY_STRING"])); //more traditional content view
                dr[1] += "<a href=\"" + ViewUrl + "\" title=\'" + _MessageHelper.GetMessage("generic View") + " \"" + Strings.Replace((string)(topics[i].Title + "\""), "\'", "`", 1, -1, 0) + "\'" + ">" + topics[i].Title + " </a>";

                objUserData = objUserAPI.GetActiveUserById(topics[i].UserId, false);
                if ((objUserData != null) && (objUserData.Username != ""))
                {
                    dr[2] = objUserData.Username;
                }
                else
                {
                    dr[2] = topics[i].UserId;
                }

                //replies col
                dr[3] = "<a href=\"" + ViewUrl + "\">" + iReplyTally + "</a>";
                //status col
                dr[4] = topics[i].Views;
                //last post col
                if (iReplyTally > 0)
                {
                    if (dtLastPosted.Date.Equals(DateTime.Now.Date))
                    {
                        dr[5] = _MessageHelper.GetMessage("lbl today at") + " " + dtLastPosted.ToShortTimeString();
                    }
                    else if (dtLastPosted.Date.AddDays(1).Equals(DateTime.Now.Date))
                    {
                        dr[5] = _MessageHelper.GetMessage("lbl yesterday at") + " " + dtLastPosted.ToShortTimeString();
                    }
                    else
                    {
                        dr[5] = dtLastPosted.ToLongDateString() + " " + dtLastPosted.ToShortTimeString();
                    }
                }
                else
                {
                    dr[5] = "-";
                }
                dt.Rows.Add(dr);
            }
        }
        DataView dv = new DataView(dt);
        FolderDataGrid.DataSource = dv;
        FolderDataGrid.DataBind();
    }
Ejemplo n.º 10
0
 public LocationToDiscuss(bool initWithValues)
 {
     LocationId    = 0;
     LocationName  = "Нема локација!";
     LocationTopic = new DiscussionTopic(true);
 }