public static List<Issue> CreateRandomIssues(string preTitle, string preDescription, int numIssues)
        {
            List<Issue> outputIssues = new List<Issue>();
            List<Project> ps = ProjectManager.GetAllProjects();
            if (ps.Count > 0)
            {

                Project p = ps[0];

                int StartIssueCount = IssueManager.GetByProjectId(p.Id).Count;

                RandomProjectData prand = new RandomProjectData(p);

                for (int i = 0; i < numIssues; i++)
                {
                    // Get Random yet valid data for the current project
                    Category c = prand.GetCategory();
                    Milestone ms = prand.GetMilestone();
                    Status st = prand.GetStatus();
                    Priority pr = prand.GetPriority();
                    IssueType isst = prand.GetIssueType();
                    Resolution res = prand.GetResolution();

                    string assigned = prand.GetUsername();
                    // creator is also the owner
                    string createdby = prand.GetUsername();

                    var issue = new Issue
                    {
                        ProjectId = p.Id,
                        Id = Globals.NEW_ID,
                        Title = preTitle + RandomStrings.RandomString(30),
                        CreatorUserName = createdby,
                        DateCreated = DateTime.Now,
                        Description = preDescription + RandomStrings.RandomString(250),
                        DueDate = DateTime.MinValue,
                        IssueTypeId = isst.Id,
                        AffectedMilestoneId = ms.Id,
                        AssignedUserName = assigned,
                        CategoryId = c.Id,
                        MilestoneId = ms.Id,
                        OwnerUserName = createdby,
                        PriorityId = pr.Id,
                        ResolutionId = res.Id,
                        StatusId = st.Id,
                        Estimation = 0,
                        Visibility = 1
                    };

                    IssueManager.SaveOrUpdate(issue);

                    // To return to the unit tests
                    outputIssues.Add(issue);
                }

            }
            return outputIssues;

        }
示例#2
0
 /// <summary>
 /// Toes the issue contract.
 /// </summary>
 /// <param name="issue">The issue.</param>
 /// <returns></returns>
 public static IssueContract ToIssueContract(Issue issue)
 {
     return new IssueContract { Id = issue.Id, Title = issue.Title, Description = issue.Description, StatusId = issue.StatusId, ResolutionId = issue.ResolutionId,
     IssueTypeId = issue.IssueTypeId, MilestoneId = issue.MilestoneId, AffectedMilestoneId = issue.AffectedMilestoneId, MilestoneDueDate = issue.MilestoneDueDate,
     Votes = issue.Votes, Visibility = issue.Visibility, CategoryId = issue.CategoryId, Estimation = issue.Estimation, Disabled = issue.Disabled, Progress = issue.Progress,
     AssignedUserId = issue.AssignedUserId, CreatorUserId = issue.CreatorUserId, DateCreated = issue.DateCreated, DueDate = issue.DueDate, ProjectId = issue.ProjectId,
      LastUpdate = issue.LastUpdate, OwnerUserId = issue.OwnerUserId, PriorityId =issue.PriorityId};
 }
示例#3
0
        public void TestCreateNewIssueClean()
        {
            Issue issue = new Issue()
            {
                Id = 0,
                ProjectId = 95,
                Title = "This is an issue added from the unit test",
                Description = "This is a new description",
                CategoryId = 409,
                CategoryName = "Category 4",
                PriorityId = 12,
                PriorityName = "High",
                StatusId = 27,
                StatusName = "New Status",
                IssueTypeId = 18,
                IssueTypeName = "Task",
                AssignedDisplayName = "Davin Dubeau",
                AssignedUserId = Guid.Empty,
                AssignedUserName = "******",
                MilestoneId = 35,
                MilestoneName = "Release 1",
                AffectedMilestoneId = 35,
                AffectedMilestoneName = "Release 1",
                Visibility = 0,
                TimeLogged = 0,
                Estimation = 34,
                Progress = 55,
                Disabled = false,
                Votes = 1,
                CreatorDisplayName ="Davin Dubeau",
                CreatorUserId = Guid.Empty,
                CreatorUserName = "******",
                DateCreated = DateTime.Now,
                OwnerDisplayName ="Davin Dubeau",
                OwnerUserId = Guid.Empty,
                OwnerUserName = "******",
                LastUpdate = DateTime.Now,
                LastUpdateDisplayName ="Davin Dubeau",
                LastUpdateUserName = "******",
                DueDate = DateTime.MinValue
            };

            //Issue newIssue = new Issue(0, ProjectId, string.Empty, string.Empty, "This is an issue added from the unit test", "This is a new description",
            //    409, "Category 4", 12, "High",
            //    string.Empty, 27, "New Status", string.Empty, 18,
            //    "Task", string.Empty,7, "Fixed", string.Empty,
            //    "admin","Davin Dubeau", Guid.Empty, "Davin Dubeau",
            //    "admin", Guid.Empty,  "Davin Dubeau", "admin", Guid.Empty, DateTime.Now,
            //    35, "Release 1", string.Empty, null, 35, "Release 1",
            //    string.Empty, 0,
            //    0, 0, DateTime.MinValue, DateTime.MinValue, "admin", "Davin Dubeau",
            //    25, false, 0);

            IssueManager.SaveOrUpdate(issue);
            Assert.IsTrue(issue.Id != 0);
            Issue FetchedIssue = IssueManager.GetById(issue.Id);
            Assert.IsNotNull(FetchedIssue);
        }
示例#4
0
 public RoadMapIssue(Issue issue, int milestoneSortOrder)
 {
     Mapper.CreateMap<Issue, RoadMapIssue>();
     Mapper.Map(issue, this);
     MilestoneSortOrder = milestoneSortOrder;
 }
示例#5
0
        /// <summary>
        /// Saves the issue
        /// </summary>
        /// <param name="entity">The issue to save.</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(Issue entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            if (entity.ProjectId <= Globals.NEW_ID) throw (new ArgumentException("The issue project id is invalid"));
            if (string.IsNullOrEmpty(entity.Title)) throw (new ArgumentException("The issue title cannot be empty or null"));

            if (entity.Id <= Globals.NEW_ID)
            {
                var tempId = DataProviderManager.Provider.CreateNewIssue(entity);

                if (tempId > 0)
                {
                    entity.Id = tempId;

                    //add vote
                    var vote = new IssueVote { IssueId = entity.Id, VoteUsername = entity.CreatorUserName };
                    IssueVoteManager.SaveOrUpdate(vote);

                    //TOOD: handle adding an attachment for new issue.

                    //send notifications for add issue
                    IssueNotificationManager.SendIssueAddNotifications(entity.Id);

                    return true;
                }

                return false;
            }

            var issueChanges = GetIssueChanges(GetById(entity.Id), entity);

            if (issueChanges.Count > 0)
            {
                var result = DataProviderManager.Provider.UpdateIssue(entity);
                if (result)
                {
                    UpdateHistory(issueChanges);

                    IssueNotificationManager.SendIssueNotifications(entity.Id, issueChanges);
                    if (entity.SendNewAssigneeNotification)
                    {
                        //add this user to notifications and send them a notification
                        var notification = new IssueNotification() { IssueId = entity.Id, NotificationUsername = entity.AssignedUserName };

                        IssueNotificationManager.SaveOrUpdate(notification);
                        IssueNotificationManager.SendNewAssigneeNotification(notification);
                    }
                }
                return result;
            }

            return true;
        }
示例#6
0
        /// <summary>
        /// Page Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var s = GetLocalResourceObject("DeleteIssueQuestion").ToString().Trim().JsEncode();
                lnkDelete.Attributes.Add("onclick", string.Format("return confirm('{0}');", s));

                IssueId = Request.QueryString.Get("id", 0);

                // If don't know issue id then redirect to something missing page
                if (IssueId == 0)
                    ErrorRedirector.TransferToSomethingMissingPage(Page);
                
                //set up global properties
                _currentIssue = IssueManager.GetById(IssueId);

                if (_currentIssue == null || _currentIssue.Disabled)
                {
                    ErrorRedirector.TransferToNotFoundPage(Page);
                    return;
                }

                //private issue check
                var issueVisible = IssueManager.CanViewIssue(_currentIssue, Security.GetUserName());

                //private issue check
                if (!issueVisible)
                {
                    ErrorRedirector.TransferToLoginPage(Page);
                }

                _currentProject = ProjectManager.GetById(_currentIssue.ProjectId);

                if (_currentProject == null)
                {
                    ErrorRedirector.TransferToNotFoundPage(Page);
                    return;
                }

                ProjectId = _currentProject.Id;

                if (_currentProject.AccessType == ProjectAccessType.Private && !User.Identity.IsAuthenticated)
                {
                    ErrorRedirector.TransferToLoginPage(Page);
                }
                else if (User.Identity.IsAuthenticated && _currentProject.AccessType == ProjectAccessType.Private 
                    && !ProjectManager.IsUserProjectMember(User.Identity.Name, ProjectId))
                {
                    ErrorRedirector.TransferToLoginPage(Page);
                }

                BindValues(_currentIssue);

                // Page.Title = string.Concat(_currentIssue.FullId, ": ", Server.HtmlDecode(_currentIssue.Title));
                lblIssueNumber.Text = string.Format("{0}-{1}", _currentProject.Code, IssueId);
                ctlIssueTabs.Visible = true;

                SetFieldSecurity();

                if (!_currentProject.AllowIssueVoting)
                { 
                    VoteBox.Visible = false;
                }
          
                //set the referrer url
                if (Request.UrlReferrer != null)
                {
                    if (Request.UrlReferrer.ToString() != Request.Url.ToString())
                        Session["ReferrerUrl"] = Request.UrlReferrer.ToString();
                }
                else
                {
                    Session["ReferrerUrl"] = string.Format("~/Issues/IssueList.aspx?pid={0}", ProjectId);
                }

            }

            Page.Title = string.Concat(lblIssueNumber.Text, ": ", Server.HtmlDecode(TitleTextBox.Text));

            //need to rebind these on every postback because of dynamic controls
            ctlCustomFields.DataSource = CustomFieldManager.GetByIssueId(IssueId);
            ctlCustomFields.DataBind();

            // The ExpandIssuePaths method is called to handle
            // the SiteMapResolve event.
            SiteMap.SiteMapResolve += ExpandIssuePaths;

            ctlIssueTabs.IssueId = IssueId;
            ctlIssueTabs.ProjectId = ProjectId;
        }
示例#7
0
        /// <summary>
        /// Saves the issue.
        /// </summary>
        /// <returns></returns>
        private bool SaveIssue()
        {
            decimal estimation;
            decimal.TryParse(txtEstimation.Text.Trim(), out estimation);
            var dueDate = DueDatePicker.SelectedValue == null ? DateTime.MinValue : (DateTime)DueDatePicker.SelectedValue;

            // WARNING: DO NOT ENCODE THE HTMLEDITOR TEXT. 
            // It expects raw input. So pass through a raw string. 
            // This is a potential XSS vector as the Issue Class should
            // handle sanitizing the input and checking that its input is HtmlEncoded
            // (ie no < or > characters), not the IssueDetail.aspx.cs

            var issue = new Issue
                            {
                                AffectedMilestoneId = DropAffectedMilestone.SelectedValue,
                                AffectedMilestoneImageUrl = string.Empty,
                                AffectedMilestoneName = DropAffectedMilestone.SelectedText,
                                AssignedDisplayName = DropAssignedTo.SelectedText,
                                AssignedUserId = Guid.Empty,
                                AssignedUserName = DropAssignedTo.SelectedValue,
                                CategoryId = DropCategory.SelectedValue,
                                CategoryName = DropCategory.SelectedText,
                                CreatorDisplayName = Security.GetDisplayName(),
                                CreatorUserId = Guid.Empty,
                                CreatorUserName = Security.GetUserName(),
                                DateCreated = DateTime.Now,
                                Description = DescriptionHtmlEditor.Text.Trim(),
                                Disabled = false,
                                DueDate = dueDate,
                                Estimation = estimation,
                                Id = IssueId,
                                IsClosed = false,
                                IssueTypeId = DropIssueType.SelectedValue,
                                IssueTypeName = DropIssueType.SelectedText,
                                IssueTypeImageUrl = string.Empty,
                                LastUpdate = DateTime.Now,
                                LastUpdateDisplayName = Security.GetDisplayName(),
                                LastUpdateUserName = Security.GetUserName(),
                                MilestoneDueDate = null,
                                MilestoneId = DropMilestone.SelectedValue,
                                MilestoneImageUrl = string.Empty,
                                MilestoneName = DropMilestone.SelectedText,
                                OwnerDisplayName = DropOwned.SelectedText,
                                OwnerUserId = Guid.Empty,
                                OwnerUserName = DropOwned.SelectedValue,
                                PriorityId = DropPriority.SelectedValue,
                                PriorityImageUrl = string.Empty,
                                PriorityName = DropPriority.SelectedText,
                                Progress = Convert.ToInt32(ProgressSlider.Text),
                                ProjectCode = string.Empty,
                                ProjectId = ProjectId,
                                ProjectName = string.Empty,
                                ResolutionId = DropResolution.SelectedValue,
                                ResolutionImageUrl = string.Empty,
                                ResolutionName = DropResolution.SelectedText,
                                StatusId = DropStatus.SelectedValue,
                                StatusImageUrl = string.Empty,
                                StatusName = DropStatus.SelectedText,
                                Title = Server.HtmlEncode(TitleTextBox.Text),
                                TimeLogged = 0,
                                Visibility = chkPrivate.Checked ? 1 : 0,
                                Votes = 0
                            };

            if (!IssueManager.SaveOrUpdate(issue))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueError);
                return false;
            }

            IssueId = issue.Id;

            if (!CustomFieldManager.SaveCustomFieldValues(IssueId, ctlCustomFields.Values))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveCustomFieldValuesError);
                return false;
            }

            return true;
        }
示例#8
0
        /// <summary>
        /// Gets the issue changes.
        /// </summary>
        /// <param name="originalIssue">The original issue.</param>
        /// <param name="issueToCompare">The issue to compare.</param>
        /// <returns></returns>
        public static List<IssueHistory> GetIssueChanges(Issue originalIssue, Issue issueToCompare)
        {
            var issueChanges = new List<IssueHistory>();

            if (originalIssue != null && issueToCompare != null)
            {
                var history = new IssueHistory { CreatedUserName = issueToCompare.CreatorUserName, IssueId = originalIssue.Id, DateChanged = DateTime.Now };

                if (originalIssue.Title.ToLower() != issueToCompare.Title.ToLower())
                    issueChanges.Add(GetNewIssueHistory(history, "Title", originalIssue.Title, issueToCompare.Title));

                if (originalIssue.Description.ToLower() != issueToCompare.Description.ToLower())
                    issueChanges.Add(GetNewIssueHistory(history, "Description", originalIssue.Description, issueToCompare.Description));

                if (originalIssue.CategoryId != issueToCompare.CategoryId)
                    issueChanges.Add(GetNewIssueHistory(history, "Category", originalIssue.CategoryName, issueToCompare.CategoryName));

                if (originalIssue.PriorityId != issueToCompare.PriorityId)
                    issueChanges.Add(GetNewIssueHistory(history, "Priority", originalIssue.PriorityName, issueToCompare.PriorityName));

                if (originalIssue.StatusId != issueToCompare.StatusId)
                    issueChanges.Add(GetNewIssueHistory(history, "Status", originalIssue.StatusName, issueToCompare.StatusName));

                if (originalIssue.MilestoneId != issueToCompare.MilestoneId)
                    issueChanges.Add(GetNewIssueHistory(history, "Milestone", originalIssue.MilestoneName, issueToCompare.MilestoneName));

                if (originalIssue.AffectedMilestoneId != issueToCompare.AffectedMilestoneId)
                    issueChanges.Add(GetNewIssueHistory(history, "Affected Milestone", originalIssue.AffectedMilestoneName, issueToCompare.AffectedMilestoneName));

                if (originalIssue.IssueTypeId != issueToCompare.IssueTypeId)
                    issueChanges.Add(GetNewIssueHistory(history, "Issue Type", originalIssue.IssueTypeName, issueToCompare.IssueTypeName));

                if (originalIssue.ResolutionId != issueToCompare.ResolutionId)
                    issueChanges.Add(GetNewIssueHistory(history, "Resolution", originalIssue.ResolutionName, issueToCompare.ResolutionName));

                var unassignedLiteral = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Unassigned", "Unassigned");

                var newAssignedUserName = String.IsNullOrEmpty(issueToCompare.AssignedUserName) ? unassignedLiteral : issueToCompare.AssignedUserName;

                if (originalIssue.AssignedUserName != newAssignedUserName)
                {
                    // if the new assigned user is the unassigned user then don't trigger the new assignee notification
                    issueToCompare.SendNewAssigneeNotification = (newAssignedUserName != unassignedLiteral);
                    issueToCompare.NewAssignee = true;
                    var newAssignedDisplayName = (newAssignedUserName == unassignedLiteral) ? newAssignedUserName : UserManager.GetUserDisplayName(newAssignedUserName);
                    issueChanges.Add(GetNewIssueHistory(history, "Assigned to", originalIssue.AssignedDisplayName, newAssignedDisplayName));
                }

                var newOwnerUserName = String.IsNullOrEmpty(issueToCompare.OwnerUserName) ? unassignedLiteral : issueToCompare.OwnerUserName;

                if (originalIssue.OwnerUserName != newOwnerUserName)
                {
                    var newOwnerDisplayName = (newOwnerUserName == unassignedLiteral) ? newOwnerUserName : UserManager.GetUserDisplayName(issueToCompare.OwnerUserName);
                    issueChanges.Add(GetNewIssueHistory(history, "Owner", originalIssue.OwnerDisplayName, newOwnerDisplayName));
                }


                if (originalIssue.Estimation != issueToCompare.Estimation)
                    issueChanges.Add(GetNewIssueHistory(history, "Estimation", Utilities.EstimationToString(originalIssue.Estimation), Utilities.EstimationToString(issueToCompare.Estimation)));

                if (originalIssue.Visibility != issueToCompare.Visibility)
                    issueChanges.Add(GetNewIssueHistory(history, "Visibility", Utilities.GetBooleanAsString(originalIssue.Visibility.ToBool()), Utilities.GetBooleanAsString(issueToCompare.Visibility.ToBool())));

                if (originalIssue.DueDate != issueToCompare.DueDate)
                {
                    var originalDate = originalIssue.DueDate == DateTime.MinValue ? string.Empty : originalIssue.DueDate.ToShortDateString();
                    var newDate = issueToCompare.DueDate == DateTime.MinValue ? string.Empty : issueToCompare.DueDate.ToShortDateString();

                    issueChanges.Add(GetNewIssueHistory(history, "Due Date", originalDate, newDate));
                }

                if (originalIssue.Progress != issueToCompare.Progress)
                {
                    var nfi = new NumberFormatInfo { PercentDecimalDigits = 0 };

                    var oldProgress = originalIssue.Progress.Equals(0) ? 0 : (originalIssue.Progress.To<double>() / 100);
                    var newProgress = issueToCompare.Progress.Equals(0) ? 0 : (issueToCompare.Progress.To<double>() / 100);

                    issueChanges.Add(GetNewIssueHistory(history, "Progress", oldProgress.ToString("P", nfi), newProgress.ToString("P", nfi)));
                }
            }
            else
            {
                throw new Exception("Unable to retrieve original issue data");
            }

            return issueChanges;
        }
示例#9
0
        public void CreateRandomIssues()
        {                        

            List<Project> ps = ProjectManager.GetAllProjects();
            if (ps.Count > 0) {

                Project p = ps[1];

                int StartIssueCount = IssueManager.GetByProjectId(p.Id).Count;

                RandomProjectData prand = new RandomProjectData(p);

                for (int i = 0; i < CNST_NumIssues; i++)
                {
                    // Get Random yet valid data for the current project
                    Category c = prand.GetCategory();
                    Milestone ms = prand.GetMilestone();
                    Status st = prand.GetStatus();
                    Priority pr = prand.GetPriority();
                    IssueType isst = prand.GetIssueType();
                    Resolution res = prand.GetResolution();

                    string assigned = prand.GetUsername();
                    // creator is also the owner
                    string createdby = prand.GetUsername();

                    DateTime date = GetRandomDate();

                    Issue iss = new Issue(){ 
                        Id =  0, 
                        ProjectId = p.Id,
                        Title = RandomStrings.RandomString(30),
                        Description = RandomStrings.RandomString(250),
                        CategoryId = c.Id, 
                        PriorityId = pr.Id, 
                        StatusId = st.Id, 
                        IssueTypeId = isst.Id,
                        MilestoneId = ms.Id, 
                        AffectedMilestoneId = ms.Id, 
                        ResolutionId = res.Id,
                        CreatorUserName = createdby,
                        LastUpdateUserName = createdby,
                        OwnerUserName = assigned,
                        AssignedUserName = assigned,
                        DateCreated = date,
                        LastUpdate = date,
                        DueDate = GetRandomDate(),
                        Disabled = false,
                        TimeLogged = RandomNumber(1, 24),
                        Votes = 0
                         
                    };
                    try
                    {

                        IssueManager.SaveOrUpdate(iss);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                int EndIssueCount = IssueManager.GetByProjectId(p.Id).Count;

                // Did we create only CNST_SmallIssues issues?
                Assert.IsTrue(EndIssueCount == StartIssueCount + CNST_NumIssues);
            }
        }
示例#10
0
        /// <summary>
        /// Returns true or false if the requesting user can view the issue or not
        /// </summary>
        /// <param name="issue">The issue to be viewed</param>
        /// <param name="requestingUserName">The requesting user name (Use Security.GetUserName()) for this</param>
        /// <returns></returns>
        public static bool CanViewIssue(Issue issue, string requestingUserName)
        {
            // if the current user is a super user don't bother checking at all
            if (UserManager.IsSuperUser()) return true;

            // if the issue is private and current user does not have project admin rights
            if (issue.Visibility == IssueVisibility.Private.To<int>() && !UserManager.IsInRole(issue.ProjectId, Globals.ProjectAdminRole))
            {
                // if the current user is either the assigned / creator / owner then they can see the private issue
                return (
                    issue.AssignedUserName.Trim().Equals(requestingUserName.Trim()) ||
                    issue.CreatorUserName.Trim().Equals(requestingUserName.Trim()) ||
                    issue.OwnerUserName.Trim().Equals(requestingUserName.Trim())
                );
            }

            return true;
        }
示例#11
0
        /// <summary>
        /// Saves the issue
        /// </summary>
        /// <param name="entity">The issue to save.</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(Issue entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            if (entity.ProjectId <= Globals.NEW_ID) throw (new ArgumentException("The issue project id is invalid"));
            if (string.IsNullOrEmpty(entity.Title)) throw (new ArgumentException("The issue title cannot be empty or null"));

            try
            {
                if (entity.Id <= Globals.NEW_ID)
                {
                    var tempId = DataProviderManager.Provider.CreateNewIssue(entity);

                    if (tempId > 0)
                    {
                        entity.Id = tempId;
                        return true;
                    }

                    return false;
                }
                else
                {
                    //existing issue
                    var issueChanges = GetIssueChanges(GetById(entity.Id), entity);

                    DataProviderManager.Provider.UpdateIssue(entity);

                    UpdateHistory(issueChanges);

                    IssueNotificationManager.SendIssueNotifications(entity.Id, issueChanges);

                    if (entity.SendNewAssigneeNotification)
                    {
                        //add this user to notifications and send them a notification
                        var notification = new IssueNotification() { IssueId = entity.Id, NotificationUsername = entity.AssignedUserName };

                        IssueNotificationManager.SaveOrUpdate(notification);
                        IssueNotificationManager.SendNewAssigneeNotification(notification);
                    }
                    return true;
                }
            }
            catch(Exception ex)
            {
                Log.Error(LoggingManager.GetErrorMessageResource("SaveIssueError"), ex);
                return false;
            }

            return false;
        }
示例#12
0
 private static void LocalizeUnassigned(Issue issue)
 {
     if (NeedLocalize)
         LocalizeUnassigned(issue, ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Unassigned", "Unassigned"));
 }
示例#13
0
 private static void LocalizeUnassigned(Issue issue, string unassignedLiteral)
 {
     if (issue.AffectedMilestoneId == 0) issue.AffectedMilestoneName = unassignedLiteral;
     if (issue.AssignedUserId == Guid.Empty) issue.AssignedDisplayName = issue.AssignedUserName = unassignedLiteral;
     if (issue.CategoryId == 0) issue.CategoryName = unassignedLiteral;
     if (issue.CreatorUserId == Guid.Empty) issue.CreatorDisplayName = issue.CreatorUserName = unassignedLiteral;
     if (issue.IssueTypeId == 0) issue.IssueTypeName = unassignedLiteral;
     if (issue.MilestoneId == 0) issue.MilestoneName = unassignedLiteral;
     if (issue.OwnerUserId == Guid.Empty) issue.OwnerDisplayName = issue.OwnerUserName = unassignedLiteral;
     if (issue.PriorityId == 0) issue.PriorityName = unassignedLiteral;
     if (issue.ResolutionId == 0) issue.ResolutionName = unassignedLiteral;
     if (issue.StatusId == 0) issue.StatusName = unassignedLiteral;
 }
示例#14
0
        /// <summary>
        /// Applies project default values to the issue
        /// </summary>
        /// <param name="issue">Issue that will be initialized with default values</param>
        private static void SetDefaultValues(Issue issue)
        {

            List<DefaultValue> defValues = IssueManager.GetDefaultIssueTypeByProjectId(issue.ProjectId);
            DefaultValue selectedValue = defValues.FirstOrDefault();

            if (selectedValue != null)
            {
                issue.IssueTypeId = selectedValue.IssueTypeId;
                issue.PriorityId = selectedValue.PriorityId;
                issue.ResolutionId = selectedValue.ResolutionId;
                issue.CategoryId = selectedValue.CategoryId;
                issue.MilestoneId = selectedValue.MilestoneId;
                issue.AffectedMilestoneId = selectedValue.AffectedMilestoneId;

                if (selectedValue.AssignedUserName != "none")
                    issue.AssignedUserName = selectedValue.AssignedUserName;

                if (selectedValue.OwnerUserName != "none")
                    issue.OwnerUserName = selectedValue.OwnerUserName;

                issue.StatusId = selectedValue.StatusId;

                issue.Visibility = selectedValue.IssueVisibility;

                if (selectedValue.DueDate.HasValue)
                {
                    DateTime date = DateTime.Today;
                    date = date.AddDays(selectedValue.DueDate.Value);
                    issue.DueDate = date;
                }

                issue.Progress = selectedValue.Progress;
                issue.Estimation = selectedValue.Estimation;
            }
        }
示例#15
0
        /// <summary>
        /// Returns an Issue object, pre-populated with defaults settings.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="issueTypeId"></param>
        /// <param name="assignedName"></param>
        /// <param name="ownerName"></param>
        /// <returns></returns>
        public static Issue GetDefaultIssueByProjectId(int projectId, string title, string description, int issueTypeId, string assignedName, string ownerName)
        {
            if (projectId <= Globals.NEW_ID)
                throw new ArgumentException(string.Format(LoggingManager.GetErrorMessageResource("InvalidProjectId"), projectId));

            var curProject = ProjectManager.GetById(projectId);

            if (curProject == null)
                throw new ArgumentException(string.Format(LoggingManager.GetErrorMessageResource("ProjectNotFoundError"), projectId));

            var issue = new Issue()
            {
                ProjectId = projectId
            };

            SetDefaultValues(issue);

            issue.Id = Globals.NEW_ID;
            issue.Title = title;
            issue.CreatorUserName = ownerName;
            issue.DateCreated = DateTime.Now;
            issue.Description = description;
            issue.IssueTypeId = issueTypeId;
            issue.AssignedUserName = assignedName;
            issue.OwnerUserName = ownerName;

            return issue;
        }
示例#16
0
        /// <summary>
        /// Saves the issue
        /// </summary>
        /// <param name="entity">The issue to save.</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(Issue entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            if (entity.ProjectId <= Globals.NEW_ID) throw (new ArgumentException("The issue project id is invalid"));
            if (string.IsNullOrEmpty(entity.Title)) throw (new ArgumentException("The issue title cannot be empty or null"));

            try
            {
                if (entity.Id <= Globals.NEW_ID)
                {
                    var tempId = DataProviderManager.Provider.CreateNewIssue(entity);

                    if (tempId > 0)
                    {
                        entity.Id = tempId;
                        return true;
                    }

                    return false;
                }

                // this is here due to issue with updating the issue from the Mailbox reader
                // to fix the inline images.  we don't have an http context so we are limited to what we can
                // do from here.  in any case the mailbox reader is creating and updating concurrently so
                // we are not missing anything.
                if (HttpContext.Current != null)
                {
                    //existing issue
                    entity.LastUpdate = DateTime.Now;
                    entity.LastUpdateUserName = Security.GetUserName();

                    var issueChanges = GetIssueChanges(GetById(entity.Id), entity);

                    DataProviderManager.Provider.UpdateIssue(entity);

                    UpdateHistory(issueChanges);

                    IssueNotificationManager.SendIssueNotifications(entity.Id, issueChanges);

                    if (entity.SendNewAssigneeNotification)
                    {
                        //add this user to notifications and send them a notification
                        var notification = new IssueNotification
                            {
                                IssueId = entity.Id,
                                NotificationUsername = entity.AssignedUserName,
                                NotificationCulture = string.Empty
                            };

                        var profile = new WebProfile().GetProfile(entity.AssignedUserName);
                        if (profile != null && !string.IsNullOrWhiteSpace(profile.PreferredLocale))
                        {
                            notification.NotificationCulture = profile.PreferredLocale;
                        }

                        IssueNotificationManager.SaveOrUpdate(notification);
                        IssueNotificationManager.SendNewAssigneeNotification(notification);
                    }
                }
                else
                {
                    DataProviderManager.Provider.UpdateIssue(entity);
                }

                return true;
            }
            catch (Exception ex)
            {
                Log.Error(LoggingManager.GetErrorMessageResource("SaveIssueError"), ex);
                return false;
            }
        }
示例#17
0
        /// <summary>
        /// Returns an Issue object, pre-populated with defaults settings.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="assignedName"></param>
        /// <param name="ownerName"></param>
        /// <returns></returns>
        public static Issue GetDefaultIssueByProjectId(int projectId, string title, string description, string assignedName, string ownerName)
        {
            if (projectId <= Globals.NEW_ID)
                throw new ArgumentException(string.Format(LoggingManager.GetErrorMessageResource("InvalidProjectId"), projectId));

            var curProject = ProjectManager.GetById(projectId);

            if (curProject == null)
                throw new ArgumentException(string.Format(LoggingManager.GetErrorMessageResource("ProjectNotFoundError"), projectId));

            var cats = CategoryManager.GetByProjectId(projectId);
            var statuses = StatusManager.GetByProjectId(projectId);
            var priorities = PriorityManager.GetByProjectId(projectId);
            var issueTypes = IssueTypeManager.GetByProjectId(projectId);
            var resolutions = ResolutionManager.GetByProjectId(projectId);
            var affectedMilestones = MilestoneManager.GetByProjectId(projectId);
            var milestones = MilestoneManager.GetByProjectId(projectId);

            // Select the first one in the list, not really the default intended.
            var defCat = cats[0];
            var defStatus = statuses[0];
            var defPriority = priorities[0];
            var defIssueType = issueTypes[0];
            var defResolution = resolutions[0];
            var defAffectedMilestone = affectedMilestones[0];
            var defMilestone = milestones[0];

            // Now create an issue
            var issue = new Issue
                            {
                                ProjectId = projectId,
                                Id = Globals.NEW_ID,
                                Title = title,
                                CreatorUserName = ownerName,
                                DateCreated = DateTime.Now,
                                Description = description,
                                DueDate = DateTime.MinValue,
                                IssueTypeId = defIssueType.Id,
                                AffectedMilestoneId = defAffectedMilestone.Id,
                                AssignedUserName = assignedName,
                                CategoryId = defCat.Id,
                                MilestoneId = defMilestone.Id,
                                OwnerUserName = ownerName,
                                PriorityId = defPriority.Id,
                                ResolutionId = defResolution.Id,
                                StatusId = defStatus.Id,
                                Estimation = 0,
                                Visibility = 1
                            };

            return issue;
        }
示例#18
0
 public abstract int CreateNewIssue(Issue issueToCreate);
示例#19
0
        /// <summary>
        /// Gets the issue changes.
        /// </summary>
        /// <param name="originalIssue">The original issue.</param>
        /// <param name="issueToCompare">The issue to compare.</param>
        /// <returns></returns>
        public static List<IssueHistory> GetIssueChanges(Issue originalIssue, Issue issueToCompare)
        {
            var issueChanges = new List<IssueHistory>();

            if (originalIssue != null && issueToCompare != null)
            {
                var history = new IssueHistory { CreatedUserName = issueToCompare.CreatorUserName, IssueId = originalIssue.Id, DateChanged = DateTime.Now };

                if (originalIssue.Title.ToLower() != issueToCompare.Title.ToLower())
                    issueChanges.Add(GetNewIssueHistory(history, "Title", originalIssue.Title, issueToCompare.Title));

                if (originalIssue.Description.ToLower() != issueToCompare.Description.ToLower())
                    issueChanges.Add(GetNewIssueHistory(history, "Description", originalIssue.Description, issueToCompare.Description));

                if (originalIssue.CategoryId != issueToCompare.CategoryId)
                    issueChanges.Add(GetNewIssueHistory(history, "Category", originalIssue.CategoryName, issueToCompare.CategoryName));

                if (originalIssue.PriorityId != issueToCompare.PriorityId)
                    issueChanges.Add(GetNewIssueHistory(history, "Priority", originalIssue.PriorityName, issueToCompare.PriorityName));

                if (originalIssue.StatusId != issueToCompare.StatusId)
                    issueChanges.Add(GetNewIssueHistory(history, "Status", originalIssue.StatusName, issueToCompare.StatusName));

                if (originalIssue.MilestoneId != issueToCompare.MilestoneId)
                    issueChanges.Add(GetNewIssueHistory(history, "Milestone", originalIssue.MilestoneName, issueToCompare.MilestoneName));

                if (originalIssue.AffectedMilestoneId != issueToCompare.AffectedMilestoneId)
                    issueChanges.Add(GetNewIssueHistory(history, "Affected Milestone", originalIssue.AffectedMilestoneName, issueToCompare.AffectedMilestoneName));

                if (originalIssue.IssueTypeId != issueToCompare.IssueTypeId)
                    issueChanges.Add(GetNewIssueHistory(history, "Issue Type", originalIssue.IssueTypeName, issueToCompare.IssueTypeName));

                if (originalIssue.ResolutionId != issueToCompare.ResolutionId)
                    issueChanges.Add(GetNewIssueHistory(history, "Resolution", originalIssue.ResolutionName, issueToCompare.ResolutionName));

                var newAssignedUserName = String.IsNullOrEmpty(issueToCompare.AssignedUserName) ? Globals.UNASSIGNED_DISPLAY_TEXT : issueToCompare.AssignedUserName;

                if ((originalIssue.AssignedUserName != newAssignedUserName))
                {
                    // if the new assigned user is the unassigned user then don't trigger the new assignee notification
                    originalIssue.SendNewAssigneeNotification = (newAssignedUserName != Globals.UNASSIGNED_DISPLAY_TEXT);
                    originalIssue.NewAssignee = true;

                    var newAssignedDisplayName = (newAssignedUserName == Globals.UNASSIGNED_DISPLAY_TEXT) ? newAssignedUserName : UserManager.GetUserDisplayName(newAssignedUserName);
                    issueChanges.Add(GetNewIssueHistory(history, "Assigned to", originalIssue.AssignedDisplayName, newAssignedDisplayName));
                }

                var newOwnerUserName = String.IsNullOrEmpty(issueToCompare.OwnerUserName) ? Globals.UNASSIGNED_DISPLAY_TEXT : issueToCompare.OwnerUserName;

                if (originalIssue.OwnerUserName != newOwnerUserName)
                {
                    var newOwnerDisplayName = (newOwnerUserName == Globals.UNASSIGNED_DISPLAY_TEXT) ? newOwnerUserName : UserManager.GetUserDisplayName(issueToCompare.OwnerUserName);
                    issueChanges.Add(GetNewIssueHistory(history, "Owner", originalIssue.OwnerDisplayName, newOwnerDisplayName));
                }

                if (originalIssue.Estimation != issueToCompare.Estimation)
                    issueChanges.Add(GetNewIssueHistory(history, "Estimation", Utilities.EstimationToString(originalIssue.Estimation), Utilities.EstimationToString(issueToCompare.Estimation)));

                if (originalIssue.Visibility != issueToCompare.Visibility)
                    issueChanges.Add(GetNewIssueHistory(history, "Visibility", Utilities.GetBooleanAsString(originalIssue.Visibility.ToBool()), Utilities.GetBooleanAsString(issueToCompare.Visibility.ToBool())));

                if (originalIssue.DueDate != issueToCompare.DueDate)
                {
                    var originalDate = originalIssue.DueDate == DateTime.MinValue ? string.Empty : originalIssue.DueDate.ToShortDateString();
                    var newDate = issueToCompare.DueDate == DateTime.MinValue ? string.Empty : issueToCompare.DueDate.ToShortDateString();

                    issueChanges.Add(GetNewIssueHistory(history, "Due Date", originalDate, newDate));
                }

                if (originalIssue.Progress != issueToCompare.Progress)
                    issueChanges.Add(GetNewIssueHistory(history, "Progress", originalIssue.Progress.ToString("p"), issueToCompare.Progress.ToString("p")));
            }
            else
            {
                throw new Exception("Unable to retrieve original issue data");
            }

            return issueChanges;
        }
示例#20
0
        /// <summary>
        /// Page Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lnkDelete.Attributes.Add("onclick", string.Format("return confirm('{0}');", GetLocalResourceObject("DeleteIssue")));
                imgDelete.Attributes.Add("onclick", string.Format("return confirm('{0}');", GetLocalResourceObject("DeleteIssue")));

                IssueId = Request.QueryString.Get("id", 0);
                ProjectId = Request.QueryString.Get("pid", 0);

                // If don't know project or issue then redirect to something missing page
                if (ProjectId == 0 && IssueId == 0)
                    ErrorRedirector.TransferToSomethingMissingPage(Page);

                // Initialize for Adding or Editing
                if (IssueId == 0) // new issue
                {
                    CurrentProject = ProjectManager.GetById(ProjectId);

                    if (CurrentProject == null)
                    {
                        ErrorRedirector.TransferToNotFoundPage(Page);
                    }

                    ProjectId = CurrentProject.Id;

                    //security check: add issue
                    if (!UserManager.HasPermission(ProjectId, Globals.Permission.AddIssue.ToString()))
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }

                    BindOptions();

                    TitleTextBox.Visible = true;
                    DescriptionHtmlEditor.Visible = true;
                    Description.Visible = false;
                    TitleLabel.Visible = false;
                    DisplayTitleLabel.Visible = false;
                    Page.Title = GetLocalResourceObject("PageTitleNewIssue").ToString();
                    lblIssueNumber.Text = GetGlobalResourceObject("SharedResources", "NotAvailableAbbr").ToString();
                    VoteButton.Visible = false;

                    //check users role permission for adding an attachment
                    if (!Page.User.Identity.IsAuthenticated || !UserManager.HasPermission(ProjectId, Globals.Permission.AddAttachment.ToString()))
                    {
                        pnlAddAttachment.Visible = false;
                    }
                    else
                    {
                        pnlAddAttachment.Visible = true;
                    }

                }
                else //existing issue
                {
                    //set up global properties
                    CurrentIssue = IssueManager.GetById(IssueId);

                    if (CurrentIssue == null || CurrentIssue.Disabled)
                    {
                        ErrorRedirector.TransferToNotFoundPage(Page);
                    }

                    //private issue check
                    if (CurrentIssue.Visibility == (int)Globals.IssueVisibility.Private && CurrentIssue.AssignedDisplayName != Security.GetUserName()
                        && CurrentIssue.CreatorDisplayName != Security.GetUserName()
                        && !UserManager.IsInRole(Globals.SUPER_USER_ROLE)
                        && !UserManager.IsInRole(Globals.ProjectAdminRole))
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }

                    CurrentProject = ProjectManager.GetById(CurrentIssue.ProjectId);

                    if (CurrentProject == null)
                    {
                        ErrorRedirector.TransferToNotFoundPage(Page);
                    }
                    else
                    {
                        ProjectId = CurrentProject.Id;
                    }

                    if (CurrentProject.AccessType == Globals.ProjectAccessType.Private && !User.Identity.IsAuthenticated)
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }
                    else if (User.Identity.IsAuthenticated && CurrentProject.AccessType == Globals.ProjectAccessType.Private
                        && !ProjectManager.IsUserProjectMember(User.Identity.Name, ProjectId))
                    {
                        ErrorRedirector.TransferToLoginPage(Page);
                    }

                    IsClosed = CurrentIssue.IsClosed;
                    BindValues(CurrentIssue);

                    Page.Title = string.Concat(CurrentIssue.FullId, ": ", Server.HtmlDecode(CurrentIssue.Title));
                    lblIssueNumber.Text = string.Format("{0}-{1}", CurrentProject.Code, IssueId);
                    ctlIssueTabs.Visible = true;
                    TimeLogged.Visible = true;
                    TimeLoggedLabel.Visible = true;
                    chkNotifyAssignedTo.Visible = false;
                    chkNotifyOwner.Visible = false;

                    SetFieldSecurity();
                }

                if (!CurrentProject.AllowIssueVoting)
                {
                    VoteBox.Visible = false;
                }

                //set the referrer url
                if (Request.UrlReferrer != null)
                {
                    if (Request.UrlReferrer.ToString() != Request.Url.ToString())
                        Session["ReferrerUrl"] = Request.UrlReferrer.ToString();
                }
                else
                {
                    Session["ReferrerUrl"] = string.Format("~/Issues/IssueList.aspx?pid={0}", ProjectId);
                }

            }

            //need to rebind these on every postback because of dynamic controls
            ctlCustomFields.DataSource = IssueId == 0 ?
                CustomFieldManager.GetByProjectId(ProjectId) :
                CustomFieldManager.GetByIssueId(IssueId);

            ctlCustomFields.DataBind();

            // The ExpandIssuePaths method is called to handle
            // the SiteMapResolve event.
            SiteMap.SiteMapResolve += ExpandIssuePaths;

            ctlIssueTabs.IssueId = IssueId;
            ctlIssueTabs.ProjectId = ProjectId;
        }
示例#21
0
 public abstract bool UpdateIssue(Issue issueToUpdate);
示例#22
0
        /// <summary>
        /// Saves the issue.
        /// </summary>
        /// <returns></returns>
        private bool SaveIssue()
        {
            decimal estimation;
            decimal.TryParse(txtEstimation.Text.Trim(), out estimation);
            var dueDate = DueDatePicker.SelectedValue == null ? DateTime.MinValue : (DateTime)DueDatePicker.SelectedValue;

            var isNewIssue = (IssueId <= 0);

            // WARNING: DO NOT ENCODE THE HTMLEDITOR TEXT.
            // It expects raw input. So pass through a raw string.
            // This is a potential XSS vector as the Issue Class should
            // handle sanitizing the input and checking that its input is HtmlEncoded
            // (ie no < or > characters), not the IssueDetail.aspx.cs

            var issue = new Issue
                            {
                                AffectedMilestoneId = DropAffectedMilestone.SelectedValue,
                                AffectedMilestoneImageUrl = string.Empty,
                                AffectedMilestoneName = DropAffectedMilestone.SelectedText,
                                AssignedDisplayName = DropAssignedTo.SelectedText,
                                AssignedUserId = Guid.Empty,
                                AssignedUserName = DropAssignedTo.SelectedValue,
                                CategoryId = DropCategory.SelectedValue,
                                CategoryName = DropCategory.SelectedText,
                                CreatorDisplayName = Security.GetDisplayName(),
                                CreatorUserId = Guid.Empty,
                                CreatorUserName = Security.GetUserName(),
                                DateCreated = DateTime.Now,
                                Description = DescriptionHtmlEditor.Text.Trim(),
                                Disabled = false,
                                DueDate = dueDate,
                                Estimation = estimation,
                                Id = IssueId,
                                IsClosed = false,
                                IssueTypeId = DropIssueType.SelectedValue,
                                IssueTypeName = DropIssueType.SelectedText,
                                IssueTypeImageUrl = string.Empty,
                                LastUpdate = DateTime.Now,
                                LastUpdateDisplayName = Security.GetDisplayName(),
                                LastUpdateUserName = Security.GetUserName(),
                                MilestoneDueDate = null,
                                MilestoneId = DropMilestone.SelectedValue,
                                MilestoneImageUrl = string.Empty,
                                MilestoneName = DropMilestone.SelectedText,
                                OwnerDisplayName = DropOwned.SelectedText,
                                OwnerUserId = Guid.Empty,
                                OwnerUserName = DropOwned.SelectedValue,
                                PriorityId = DropPriority.SelectedValue,
                                PriorityImageUrl = string.Empty,
                                PriorityName = DropPriority.SelectedText,
                                Progress = Convert.ToInt32(ProgressSlider.Text),
                                ProjectCode = string.Empty,
                                ProjectId = ProjectId,
                                ProjectName = string.Empty,
                                ResolutionId = DropResolution.SelectedValue,
                                ResolutionImageUrl = string.Empty,
                                ResolutionName = DropResolution.SelectedText,
                                StatusId = DropStatus.SelectedValue,
                                StatusImageUrl = string.Empty,
                                StatusName = DropStatus.SelectedText,
                                Title = Server.HtmlEncode(TitleTextBox.Text),
                                TimeLogged = 0,
                                Visibility = chkPrivate.Checked ? 1 : 0,
                                Votes = 0
                            };

            if (!IssueManager.SaveOrUpdate(issue))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueError);
                return false;
            }

            IssueId = issue.Id;

            if (!CustomFieldManager.SaveCustomFieldValues(IssueId, ctlCustomFields.Values))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveCustomFieldValuesError);
                return false;
            }

            //if new issue check if notify owner and assigned is checked.
            if (isNewIssue)
            {

                //add attachment if present.
                if (AspUploadFile.HasFile)
                {
                    // get the current file
                    var uploadFile = AspUploadFile.PostedFile;
                    string inValidReason;
                    var validFile = IssueAttachmentManager.IsValidFile(uploadFile.FileName, out inValidReason);

                    if (validFile)
                    {
                        if (uploadFile.ContentLength > 0)
                        {
                            byte[] fileBytes;
                            using (var input = uploadFile.InputStream)
                            {
                                fileBytes = new byte[uploadFile.ContentLength];
                                input.Read(fileBytes, 0, uploadFile.ContentLength);
                            }

                            var issueAttachment = new IssueAttachment
                            {
                                Id = Globals.NEW_ID,
                                Attachment = fileBytes,
                                Description = AttachmentDescription.Text.Trim(),
                                DateCreated = DateTime.Now,
                                ContentType = uploadFile.ContentType,
                                CreatorDisplayName = string.Empty,
                                CreatorUserName = Security.GetUserName(),
                                FileName = uploadFile.FileName,
                                IssueId = IssueId,
                                Size = fileBytes.Length
                            };

                            if (!IssueAttachmentManager.SaveOrUpdate(issueAttachment))
                            {
                                Message1.ShowErrorMessage(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName));
                            }
                        }

                    }
                    else
                    {
                        Message1.ShowErrorMessage(inValidReason);
                        return false;
                    }
                }

                //create a vote for the new issue
                var vote = new IssueVote { IssueId = IssueId, VoteUsername = Security.GetUserName() };

                if (!IssueVoteManager.SaveOrUpdate(vote))
                {
                    Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueVoteError);
                    return false;
                }

                if (chkNotifyOwner.Checked && !string.IsNullOrEmpty(issue.OwnerUserName))
                {
                    var oUser = UserManager.GetUser(issue.OwnerUserName);
                    if (oUser != null)
                    {
                        var notify = new IssueNotification { IssueId = IssueId, NotificationUsername = oUser.UserName };
                        IssueNotificationManager.SaveOrUpdate(notify);
                    }
                }
                if (chkNotifyAssignedTo.Checked && !string.IsNullOrEmpty(issue.AssignedUserName))
                {
                    var oUser = UserManager.GetUser(issue.AssignedUserName);
                    if (oUser != null)
                    {
                        var notify = new IssueNotification { IssueId = IssueId, NotificationUsername = oUser.UserName };
                        IssueNotificationManager.SaveOrUpdate(notify);
                    }
                }

                // add all users subscribed at the project level to the issue level
                IEnumerable<ProjectNotification> subscriptions = ProjectNotificationManager.GetByProjectId(ProjectId);
                foreach (ProjectNotification sub in subscriptions)
                {
                    IssueNotificationManager.SaveOrUpdate(new IssueNotification()
                    {
                        IssueId = IssueId,
                        NotificationUsername = sub.NotificationUsername
                    });
                }

                //send issue notifications
                IssueNotificationManager.SendIssueAddNotifications(IssueId);
            }

            return true;
        }
示例#23
0
        /// <summary>
        /// Saves the issue.
        /// </summary>
        /// <returns></returns>
        private bool SaveIssue()
        {
            decimal estimation;
            decimal.TryParse(txtEstimation.Text.Trim(), out estimation);
            var dueDate = DueDatePicker.SelectedValue ?? DateTime.MinValue;

            var issue = new Issue
                {
                    AffectedMilestoneId = DropAffectedMilestone.SelectedValue,
                    AffectedMilestoneImageUrl = string.Empty,
                    AffectedMilestoneName = DropAffectedMilestone.SelectedText,
                    AssignedDisplayName = DropAssignedTo.SelectedText,
                    AssignedUserId = Guid.Empty,
                    AssignedUserName = DropAssignedTo.SelectedValue,
                    CategoryId = DropCategory.SelectedValue,
                    CategoryName = DropCategory.SelectedText,
                    CreatorDisplayName = Security.GetDisplayName(),
                    CreatorUserId = Guid.Empty,
                    CreatorUserName = Security.GetUserName(),
                    DateCreated = DateTime.Now,
                    Description = DescriptionHtmlEditor.Text.Trim(),
                    Disabled = false,
                    DueDate = dueDate,
                    Estimation = estimation,
                    Id = 0,
                    IsClosed = false,
                    IssueTypeId = DropIssueType.SelectedValue,
                    IssueTypeName = DropIssueType.SelectedText,
                    IssueTypeImageUrl = string.Empty,
                    LastUpdate = DateTime.Now,
                    LastUpdateDisplayName = Security.GetDisplayName(),
                    LastUpdateUserName = Security.GetUserName(),
                    MilestoneDueDate = null,
                    MilestoneId = DropMilestone.SelectedValue,
                    MilestoneImageUrl = string.Empty,
                    MilestoneName = DropMilestone.SelectedText,
                    OwnerDisplayName = DropOwned.SelectedText,
                    OwnerUserId = Guid.Empty,
                    OwnerUserName = DropOwned.SelectedValue,
                    PriorityId = DropPriority.SelectedValue,
                    PriorityImageUrl = string.Empty,
                    PriorityName = DropPriority.SelectedText,
                    Progress = Convert.ToInt32(ProgressSlider.Text),
                    ProjectCode = string.Empty,
                    ProjectId = ProjectId,
                    ProjectName = string.Empty,
                    ResolutionId = DropResolution.SelectedValue,
                    ResolutionImageUrl = string.Empty,
                    ResolutionName = DropResolution.SelectedText,
                    StatusId = DropStatus.SelectedValue,
                    StatusImageUrl = string.Empty,
                    StatusName = DropStatus.SelectedText,
                    Title = Server.HtmlEncode(TitleTextBox.Text),
                    TimeLogged = 0,
                    Visibility = chkPrivate.Checked ? 1 : 0,
                    Votes = 0
                };

            if (!IssueManager.SaveOrUpdate(issue))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueError);
                return false;
            }

            if (!CustomFieldManager.SaveCustomFieldValues(issue.Id, ctlCustomFields.Values, true))
            {
                Message1.ShowErrorMessage(Resources.Exceptions.SaveCustomFieldValuesError);
                return false;
            }

            IssueId = issue.Id;

            //add attachment if present.
            if (AspUploadFile.HasFile)
            {
                // get the current file
                var uploadFile = AspUploadFile.PostedFile;
                string inValidReason;
                var validFile = IssueAttachmentManager.IsValidFile(uploadFile.FileName, out inValidReason);

                if (validFile)
                {
                    if (uploadFile.ContentLength > 0)
                    {
                        byte[] fileBytes;
                        using (var input = uploadFile.InputStream)
                        {
                            fileBytes = new byte[uploadFile.ContentLength];
                            input.Read(fileBytes, 0, uploadFile.ContentLength);
                        }

                        var issueAttachment = new IssueAttachment
                        {
                            Id = Globals.NEW_ID,
                            Attachment = fileBytes,
                            Description = AttachmentDescription.Text.Trim(),
                            DateCreated = DateTime.Now,
                            ContentType = uploadFile.ContentType,
                            CreatorDisplayName = string.Empty,
                            CreatorUserName = Security.GetUserName(),
                            FileName = uploadFile.FileName,
                            IssueId = issue.Id,
                            Size = fileBytes.Length
                        };

                        if (!IssueAttachmentManager.SaveOrUpdate(issueAttachment))
                        {
                            Message1.ShowErrorMessage(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName));
                        }
                    }

                }
                else
                {
                    Message1.ShowErrorMessage(inValidReason);
                    return false;
                }
            }

            //create a vote for the new issue
            var vote = new IssueVote { IssueId = issue.Id, VoteUsername = Security.GetUserName() };

            if (!IssueVoteManager.SaveOrUpdate(vote))
            { 
                Message1.ShowErrorMessage(Resources.Exceptions.SaveIssueVoteError);
                return false;
            }

            if (chkNotifyOwner.Checked && !string.IsNullOrEmpty(issue.OwnerUserName))
            {
                var oUser = UserManager.GetUser(issue.OwnerUserName);
                if (oUser != null)
                {
                    var notify = new IssueNotification { IssueId = issue.Id, NotificationUsername = oUser.UserName };
                    IssueNotificationManager.SaveOrUpdate(notify);
                }
            }
            if (chkNotifyAssignedTo.Checked && !string.IsNullOrEmpty(issue.AssignedUserName))
            {
                var oUser = UserManager.GetUser(issue.AssignedUserName);
                if (oUser != null)
                {
                    var notify = new IssueNotification { IssueId = issue.Id, NotificationUsername = oUser.UserName };
                    IssueNotificationManager.SaveOrUpdate(notify);
                }
            }

            //send issue notifications
            IssueNotificationManager.SendIssueAddNotifications(issue.Id);

            return true;
        }
示例#24
0
        /// <summary>
        /// Send notifications for the new issue
        /// </summary>
        /// <param name="issue">The issue generated from the email</param>
        void SendNotifications(Issue issue)
        {
            if (issue == null)
            {
                return;
            }

            List<DefaultValue> defValues = IssueManager.GetDefaultIssueTypeByProjectId(issue.ProjectId);
            DefaultValue selectedValue = defValues.FirstOrDefault();

            if (selectedValue != null)
            {
                if (selectedValue.OwnedByNotify)
                {
                    var oUser = UserManager.GetUser(issue.OwnerUserName);
                    if (oUser != null)
                    {
                        var notify = new IssueNotification { IssueId = issue.Id, NotificationUsername = oUser.UserName };
                        IssueNotificationManager.SaveOrUpdate(notify);
                    }
                }

                if (selectedValue.AssignedToNotify)
                {
                    var oUser = UserManager.GetUser(issue.AssignedUserName);
                    if (oUser != null)
                    {
                        var notify = new IssueNotification { IssueId = issue.Id, NotificationUsername = oUser.UserName };
                        IssueNotificationManager.SaveOrUpdate(notify);
                    }
                }
            }

            //send issue notifications
            IssueNotificationManager.SendIssueAddNotifications(issue.Id);
        }
示例#25
0
        /// <summary>
        /// Binds the values.
        /// </summary>
        private void BindValues(Issue currentIssue)
        {
            BindOptions();

            lblIssueNumber.Text = string.Concat(currentIssue.FullId, ":");
            TitleLabel.Text = Server.HtmlDecode(currentIssue.Title);

            DropIssueType.SelectedValue = currentIssue.IssueTypeId;
            DropResolution.SelectedValue = currentIssue.ResolutionId;
            DropStatus.SelectedValue = currentIssue.StatusId;
            DropPriority.SelectedValue = currentIssue.PriorityId;
            DropOwned.SelectedValue = currentIssue.OwnerUserName;


            // SMOSS: XSS Bugfix
            Description.Text = (currentIssue.Description);

            // WARNING: Do Not html decode the text for the editor. 
            // The editor is expecting HtmlEncoded text as input.
            DescriptionHtmlEditor.Text = currentIssue.Description;
            lblLastUpdateUser.Text = currentIssue.LastUpdateDisplayName;
            lblReporter.Text = currentIssue.CreatorDisplayName;

            // XSS Bugfix
            // The text box is expecting raw html
            TitleTextBox.Text = Server.HtmlDecode(currentIssue.Title);
            DisplayTitleLabel.Text = currentIssue.Title;
            lblDateCreated.Text = currentIssue.DateCreated.ToString("g");
            lblLastModified.Text = currentIssue.LastUpdate.ToString("g");
            lblIssueNumber.Text = currentIssue.FullId;
            DropCategory.SelectedValue = currentIssue.CategoryId;
            DropMilestone.SelectedValue = currentIssue.MilestoneId;
            DropAffectedMilestone.SelectedValue = currentIssue.AffectedMilestoneId;
            DropAssignedTo.SelectedValue = currentIssue.AssignedUserName;
            lblLoggedTime.Text = currentIssue.TimeLogged.ToString();
            txtEstimation.Text = currentIssue.Estimation == 0 ? string.Empty : currentIssue.Estimation.ToString();
            DueDatePicker.SelectedValue = currentIssue.DueDate == DateTime.MinValue ? null : (DateTime?)currentIssue.DueDate;
            chkPrivate.Checked = currentIssue.Visibility != 0;
            ProgressSlider.Text = currentIssue.Progress.ToString();
            IssueVoteCount.Text = currentIssue.Votes.ToString();

            if (User.Identity.IsAuthenticated && IssueVoteManager.HasUserVoted(currentIssue.Id, Security.GetUserName()))
            {
                VoteButton.Visible = false;
                VotedLabel.Visible = true;
                VotedLabel.Text = GetLocalResourceObject("Voted").ToString();
            }
            else
            {
                VoteButton.Visible = true;
                VotedLabel.Visible = false;
            }

            if (currentIssue.StatusId != 0 && StatusManager.GetById(currentIssue.StatusId).IsClosedState)
            {
                VoteButton.Visible = false;
                VotedLabel.Visible = false;
            }

            List<DefaultValue> defValues = IssueManager.GetDefaultIssueTypeByProjectId(ProjectId);
            DefaultValue selectedValue = defValues.FirstOrDefault();

            if (selectedValue != null)
            {
                // Visibility Section
                IssueTypeField.Visible = selectedValue.TypeEditVisibility;
                StatusField.Visible = selectedValue.StatusEditVisibility;
                PriorityField.Visible = selectedValue.PriorityEditVisibility;
                PrivateField.Visible = selectedValue.PrivateEditVisibility;
                CategoryField.Visible = selectedValue.CategoryEditVisibility;
                DueDateField.Visible = selectedValue.DueDateEditVisibility;
                ProgressField.Visible = selectedValue.PercentCompleteEditVisibility;
                MilestoneField.Visible = selectedValue.MilestoneEditVisibility;
                EstimationField.Visible = selectedValue.EstimationEditVisibility;
                ResolutionField.Visible = selectedValue.ResolutionEditVisibility;
                AffectedMilestoneField.Visible = selectedValue.AffectedMilestoneEditVisibility;
                AssignedToField.Visible = selectedValue.AssignedToEditVisibility;
                OwnedByField.Visible = selectedValue.OwnedByEditVisibility;
                
            }
        }
        /// <summary>
        /// Creates the new issue.
        /// </summary>
        /// <param name="newIssue">The issue to create.</param>
        /// <returns></returns>
        public override int CreateNewIssue(Issue newIssue)
        {
            // Validate Parameters
            if (newIssue == null) throw (new ArgumentNullException("newIssue"));

            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, newIssue.ProjectId);
                AddParamToSqlCmd(sqlCmd, "@IssueTitle", SqlDbType.NVarChar, 255, ParameterDirection.Input, newIssue.Title);
                AddParamToSqlCmd(sqlCmd, "@IssueDescription", SqlDbType.NVarChar, 0, ParameterDirection.Input, newIssue.Description);
                AddParamToSqlCmd(sqlCmd, "@IssueCategoryId", SqlDbType.Int, 0, ParameterDirection.Input, (newIssue.CategoryId == 0) ? DBNull.Value : (object)newIssue.CategoryId);
                AddParamToSqlCmd(sqlCmd, "@IssueStatusId", SqlDbType.Int, 0, ParameterDirection.Input, (newIssue.StatusId == 0) ? DBNull.Value : (object)newIssue.StatusId);
                AddParamToSqlCmd(sqlCmd, "@IssuePriorityId", SqlDbType.Int, 0, ParameterDirection.Input, (newIssue.PriorityId == 0) ? DBNull.Value : (object)newIssue.PriorityId);
                AddParamToSqlCmd(sqlCmd, "@IssueTypeId", SqlDbType.Int, 0, ParameterDirection.Input, (newIssue.IssueTypeId == 0) ? DBNull.Value : (object)newIssue.IssueTypeId);
                AddParamToSqlCmd(sqlCmd, "@IssueResolutionId", SqlDbType.Int, 0, ParameterDirection.Input, (newIssue.ResolutionId == 0) ? DBNull.Value : (object)newIssue.ResolutionId);
                AddParamToSqlCmd(sqlCmd, "@IssueMilestoneId", SqlDbType.Int, 0, ParameterDirection.Input, (newIssue.MilestoneId == 0) ? DBNull.Value : (object)newIssue.MilestoneId);
                AddParamToSqlCmd(sqlCmd, "@IssueAffectedMilestoneId", SqlDbType.Int, 0, ParameterDirection.Input, (newIssue.AffectedMilestoneId == 0) ? DBNull.Value : (object)newIssue.AffectedMilestoneId);
                AddParamToSqlCmd(sqlCmd, "@IssueAssignedUserName", SqlDbType.NText, 255, ParameterDirection.Input, (newIssue.AssignedUserName == string.Empty) ? DBNull.Value : (object)newIssue.AssignedUserName);
                AddParamToSqlCmd(sqlCmd, "@IssueOwnerUserName", SqlDbType.NText, 255, ParameterDirection.Input, (newIssue.OwnerUserName == string.Empty) ? DBNull.Value : (object)newIssue.OwnerUserName);
                AddParamToSqlCmd(sqlCmd, "@IssueCreatorUserName", SqlDbType.NText, 255, ParameterDirection.Input, newIssue.CreatorUserName);
                AddParamToSqlCmd(sqlCmd, "@IssueDueDate", SqlDbType.DateTime, 0, ParameterDirection.Input, (newIssue.DueDate == DateTime.MinValue) ? DBNull.Value : (object)newIssue.DueDate);
                AddParamToSqlCmd(sqlCmd, "@IssueEstimation", SqlDbType.Decimal, 0, ParameterDirection.Input, newIssue.Estimation);
                AddParamToSqlCmd(sqlCmd, "@IssueVisibility", SqlDbType.Bit, 0, ParameterDirection.Input, newIssue.Visibility);
                AddParamToSqlCmd(sqlCmd, "@IssueProgress", SqlDbType.Int, 0, ParameterDirection.Input, newIssue.Progress);

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_ISSUE_CREATE);
                ExecuteScalarCmd(sqlCmd);
                return ((int)sqlCmd.Parameters["@ReturnValue"].Value);
            }
        }