Exemplo n.º 1
0
        public ActionResult Index(IssueErrorsPostModel postModel)
        {
            //this is a bit of a hack but the paging URL is generated based on the page URL so if we get
            //an ajax call just assume it's error page
            if (Request.IsAjaxRequest())
            {
                return(Errors(new ErrorCriteriaPostModel
                {
                    Id = postModel.Id,
                }));
            }

            var viewModel = GetViewModel(postModel, GetSinglePagingRequest());

            if (viewModel == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound", new IssueNotFoundViewModel {
                    Id = postModel.Id.GetFriendlyId()
                }));
            }

            if ((postModel.AppId == null || Application.GetId(postModel.AppId) != viewModel.Details.ApplicationId) ||
                (postModel.OrgId == null || Organisation.GetId(postModel.OrgId) != viewModel.Details.OrganisationId)
                )
            {
                var routeValues = Request.RequestContext.RouteData.Values;

                routeValues["appid"] = IdHelper.GetFriendlyId(viewModel.Details.ApplicationId);
                routeValues["orgid"] = IdHelper.GetFriendlyId(viewModel.Details.OrganisationId);

                return(RedirectToRoute(routeValues));
            }

            return(View(viewModel));
        }
Exemplo n.º 2
0
        private IssueViewModel GetViewModel(IssueErrorsPostModel postModel, PageRequestWithSort paging, bool useSystemUser = false)
        {
            var issue = _getIssueQuery.Invoke(new GetIssueRequest
            {
                IssueId     = postModel.Id,
                CurrentUser = useSystemUser ? Errordite.Core.Domain.Organisation.User.System() : Core.AppContext.CurrentUser
            }).Issue;

            if (issue == null)
            {
                return(null);
            }

            var users        = Core.GetUsers();
            var applications = Core.GetApplications();
            var assignedUser = users.Items.FirstOrDefault(u => u.Id == issue.UserId);

            //if the assigned user has been deleted, update it to the current user
            if (assignedUser == null)
            {
                var updateIssue = Core.Session.Raven.Load <Issue>(issue.Id);
                updateIssue.UserId = Core.AppContext.CurrentUser.Id;
                assignedUser       = Core.AppContext.CurrentUser;
            }

            int ii = 0;

            var extraDataKeys = _getExtraDataKeysForIssueQuery.Invoke(new GetExtraDataKeysForIssueRequest
            {
                IssueId = issue.Id,
            }).Keys ?? new List <string>();

            var ruleViewModels = issue.Rules.OfType <PropertyMatchRule>().Select(r => new RuleViewModel
            {
                ErrorProperty  = r.ErrorProperty,
                StringOperator = r.StringOperator,
                Value          = r.Value,
                Index          = ii++,
                Properties     = _configuration.GetRuleProperties(r.ErrorProperty)
                                 .Union(extraDataKeys.Select(k => new SelectListItem
                {
                    Selected = r.ErrorProperty == k,
                    Text     = k,
                    Value    = k
                })),
            }).ToList();

            var updateViewModel = new UpdateIssueViewModel
            {
                ApplicationId           = issue.ApplicationId,
                Rules                   = ruleViewModels,
                Name                    = issue.Name,
                AdjustmentName          = GetAdjustmentRejectsName(issue.Name),
                IssueId                 = issue.Id,
                Users                   = users.Items.ToSelectList(u => u.Id, u => "{0} {1}".FormatWith(u.FirstName, u.LastName), sortListBy: SortSelectListBy.Text, selected: u => u.Id == issue.UserId),
                Statuses                = issue.Status.ToSelectedList(IssueResources.ResourceManager, false, issue.Status == IssueStatus.Unacknowledged ? IssueStatus.Acknowledged.ToString() : issue.Status.ToString()),
                UserId                  = issue.UserId,
                Status                  = issue.Status == IssueStatus.Unacknowledged ? IssueStatus.Acknowledged : issue.Status,
                NotifyFrequency         = issue.NotifyFrequency,
                Reference               = issue.Reference,
                NotificationFrequencies = FrequencyHours,
                Comment                 = null
            };

            var viewModel = new IssueViewModel
            {
                Details = new IssueDetailsViewModel
                {
                    ApplicationId    = issue.ApplicationId,
                    OrganisationId   = issue.OrganisationId,
                    ErrorCount       = issue.ErrorCount,
                    LastErrorUtc     = issue.LastErrorUtc,
                    FirstErrorUtc    = issue.CreatedOnUtc,
                    UserName         = assignedUser == null ? string.Empty : assignedUser.FullName,
                    ApplicationName  = applications.Items.First(a => a.Id == issue.ApplicationId).Name,
                    ErrorLimitStatus = IssueResources.ResourceManager.GetString("ErrorLimitStatus_{0}".FormatWith(issue.LimitStatus)),
                    TestIssue        = issue.TestIssue,
                    IssueId          = issue.Id,
                    Status           = issue.Status,
                    NotifyFrequency  = issue.NotifyFrequency,
                    Reference        = issue.Reference
                },
                Errors    = GetErrorsViewModel(postModel, paging, extraDataKeys),
                Update    = updateViewModel,
                Tab       = postModel.Tab,
                PublicUrl = "{0}/issue/public?token={1}".FormatWith(
                    _configuration.SiteBaseUrl,
                    _encryptor.Encrypt("{0}|{1}|{2}".FormatWith(
                                           Core.AppContext.CurrentUser.ActiveOrganisation.FriendlyId,
                                           issue.FriendlyId,
                                           Core.AppContext.CurrentUser.ActiveOrganisation.ApiKeySalt)).Base64Encode())
            };

            //dont let users set an issue to unacknowledged
            if (issue.Status != IssueStatus.Unacknowledged)
            {
                var statuses = viewModel.Update.Statuses.ToList();
                statuses.Remove(viewModel.Update.Statuses.First(s => s.Value == IssueStatus.Unacknowledged.ToString()));
                viewModel.Update.Statuses = statuses;
            }

            return(viewModel);
        }