예제 #1
0
 private MultipleValueDictionary <string, string> GetOrderedActivityNameByWorkflowName()
 => Cacher.FindOrCreateValue(
     nameof(GetOrderedActivityNameByWorkflowName),
     () =>
 {
     var m = new MultipleValueDictionary <string, string>(null, () => new List <string>());
     foreach (var wd in DB.WorkflowDefinitions.Where(wfd => wfd.IsActive == true))
     {
         foreach (var activityName in wd.Description.WebActionWorkflowActivities.OrderBy(a => a.SequenceNumber).Select(a => a.ActivityName))
         {
             m.Add(wd.WorkflowDefinitionName, activityName);
         }
     }
     return(m);
 },
     PortalHelpers.MediumCacheTimeout
     );
예제 #2
0
        public ActionResult View(int?documentId, string docType, bool allowDocumentEdit = false)
        {
            if (docType == null && documentId.HasValue)
            {
                docType =
                    (
                        from z in DB.Documents
                        where z.DocumentId == documentId.Value
                        select z.Workflow.TargetUlo.DocType
                    ).FirstOrDefault();
            }
            Requires.NonNull(docType, nameof(docType));
            Document document;

            if (documentId.GetValueOrDefault() == 0)
            {
                document = new Document();
            }
            else
            {
                document = DB.Documents.
                           Include(z => z.DocumentAttachments).
                           Include(z => z.Workflow.OwnerUser).
                           Include(z => z.DocumentDocumentDocumentTypes).
                           FirstOrDefault(dt => dt.DocumentId == documentId);
                if (document == null)
                {
                    return(NotFound());
                }
            }
            document.DocumentAttachments = document.DocumentAttachments ?? new List <Attachment>();
            var documentTypes = Cacher.FindOrCreateValue(
                Cache.CreateKey(typeof(DocumentsController), "documentTypes", docType),
                () => DB.DocumentTypes.Where(dt => dt.DocType == null || dt.DocType == docType).OrderBy(dt => dt.Name).ToList().AsReadOnly(),
                PortalHelpers.MediumCacheTimeout);

            var workflowAssignedTo = document.DocumentId == 0 ? true : CheckOwner(document);

            return(PartialView("~/Views/Ulo/Details/Documents/_View.cshtml", new DocumentModalViewModel(document, documentTypes, workflowAssignedTo)));
        }
예제 #3
0
        public ActionResult Search(int?uloId, string pegasysDocumentNumber, string organization, int[] region, int[] zone, string fund, string[] baCode, string pegasysTitleNumber, string pegasysVendorName, string[] docType, string contractingOfficersName, string currentlyAssignedTo, string hasBeenAssignedTo, string awardNumber, string[] reasons, bool[] validity, string[] status, int[] reviews, bool?reassignableByMe,
                                   string sortCol = null, string sortDir = null, int?page = null, int?pageSize = null)
        {
            SetNoDataMessage(ConfigOptions.Value.NoSearchResults);
            var wfPredicate = PortalHelpers.GenerateWorkflowPredicate(this.User, uloId, pegasysDocumentNumber, organization, region, zone, fund,
                                                                      baCode, pegasysTitleNumber, pegasysVendorName, docType, contractingOfficersName, currentlyAssignedTo, hasBeenAssignedTo, awardNumber, reasons, validity, status, reviews, reassignableByMe);
            bool hasFilters = wfPredicate != null || !string.IsNullOrEmpty(Request.Query["f"]);

            if (!hasFilters)
            {
                wfPredicate = PredicateBuilder.Create <Workflow>(wf => false);
            }
            else if (wfPredicate == null)
            {
                wfPredicate = PredicateBuilder.Create <Workflow>(wf => true);
            }

            var workflows = ApplyBrowse(
                Workflows.Where(wfPredicate).AsNoTracking(),
                sortCol ?? nameof(Workflow.DueAtUtc), sortDir, page, pageSize).ToList();

            var baCodes = Cacher.FindOrCreateValue(
                Cache.CreateKey(nameof(Search), "baCodes"),
                () => DB.UnliquidatedObligations.Select(u => u.Prog).Distinct().OrderBy(p => p).ToList().AsReadOnly(),
                PortalHelpers.MediumCacheTimeout
                );

            var ReasonIncludedInReviewList = Cacher.FindOrCreateValue(
                Cache.CreateKey(nameof(Search), "ReasonIncludedInReviewList"),
                () => DB.UnliquidatedObligations.Select(u => u.ReasonIncludedInReview).Distinct().OrderBy(p => p).ToList().AsReadOnly(),
                PortalHelpers.MediumCacheTimeout
                );

            var activityNames = GetOrderedActivityNameByWorkflowName().AtomEnumerable.ConvertAll(z => z.Value).Distinct().OrderBy().ToList();


            var reviewListItems = Cacher.FindOrCreateValue(Cache.CreateKey(nameof(Search), "reviewListItems"),
                                                           () =>
                                                           DB.Reviews.OrderByDescending(r => r.ReviewId).ConvertAll(
                                                               r => new SelectListItem
            {
                Text  = $"{r.ReviewName} (#{r.ReviewId}) - {AspHelpers.GetDisplayName(r.ReviewScopeId)} - {AspHelpers.GetDisplayName(r.ReviewTypeId)}",
                Value = r.ReviewId.ToString()
            }).
                                                           ToList().
                                                           AsReadOnly(),
                                                           PortalHelpers.ShortCacheTimeout
                                                           );

            var statuses = Cacher.FindOrCreateValue(
                "AllWorkflowStatusNames",
                () =>
            {
                var names = new List <string>();
                foreach (var wd in DB.WorkflowDefinitions.Where(wfd => wfd.IsActive == true))
                {
                    names.AddRange(wd.Description.WebActionWorkflowActivities.Select(z => z.ActivityName));
                }
                return(names.Distinct().OrderBy());
            },
                PortalHelpers.MediumCacheTimeout);

            PopulateViewInfoIntoViewBag(workflows);

            return(View(
                       "~/Views/Ulo/Search/Index.cshtml",
                       new FilterViewModel(
                           workflows,
                           PortalHelpers.CreateDocumentTypeSelectListItems().SelectItems(docType),
                           PortalHelpers.CreateZoneSelectListItems().SelectItems(zone),
                           PortalHelpers.CreateRegionSelectListItems().SelectItems(region),
                           baCodes,
                           activityNames,
                           statuses,
                           ReasonIncludedInReviewList,
                           reviewListItems,
                           hasFilters,
                           new[] { new SelectListItem("Yes", "true"), new SelectListItem("No", "false") }.SelectItems(validity)
                           )));
        }
예제 #4
0
        public IActionResult MyTasks(string t, string sortCol, string sortDir, int?page, int?pageSize)
        {
            LogInformation("{method}({t}, {sortCol}, {sortDir}, {page}, {pageSize})", nameof(MyTasks), t, sortCol, sortDir, page, pageSize);

            SetNoDataMessage(ConfigOptions.Value.NoTasks);

            var workflows = Workflows.Where(wf => wf.OwnerUserId == CurrentUserId);

            var countByKey = new Dictionary <string, int>(workflows.GroupBy(w => w.CurrentWorkflowActivityKey).Select(g => new { CurrentWorkflowActivityKey = g.Key, Count = g.Count() }).ToDictionaryOnConflictKeepLast(z => z.CurrentWorkflowActivityKey, z => z.Count), Comparers.CaseInsensitiveStringComparer);

            var keyByName = Cacher.FindOrCreateValue(
                "workflowKeyByActivityNameForAllActiveWorkflows",
                () =>
            {
                var d = new Dictionary <string, string>(Comparers.CaseInsensitiveStringComparer);
                foreach (var wfd in DB.WorkflowDefinitions.Where(z => z.IsActive))
                {
                    if (wfd.Description == null || wfd.Description.Activities == null)
                    {
                        continue;
                    }
                    foreach (var a in wfd.Description.Activities)
                    {
                        d[a.ActivityName] = a.WorkflowActivityKey;
                    }
                }
                return(d);
            }, PortalHelpers.MediumCacheTimeout);

            var tabs = new List <WorkflowListTab>();

            foreach (var name in ConfigOptions.Value.MyTasksTabs)
            {
                var tab = new WorkflowListTab {
                    TabName = StringHelpers.TrimOrNull(name)
                };
                if (tab.TabName == null)
                {
                    continue;
                }
                tab.TabKey = keyByName.GetValue(tab.TabName);
                if (tab.TabKey == null)
                {
                    continue;
                }
                tab.ItemCount = countByKey.GetValue(tab.TabKey);
                if (t == null && tab.ItemCount > 0)
                {
                    t = tab.TabKey;
                    LogInformation("Tabkey was null.  Setting it to the first tab that has data = {tabTabKey}", t);
                }
                tab.IsCurrent = tab.TabKey == t;
                LogInformation(
                    "TABITERATION: {controller} {name} {tabIsCurrent} {tabTabKey} {t}",
                    this.GetType().Name, name, tab.IsCurrent, tab.TabKey, t);
                tabs.Add(tab);
            }

            var items = DB.ListableWorkflows.Execute(CurrentUserId, CurrentUserId);

            if (t != null)
            {
                items = items.Where(z => z.CurrentWorkflowActivityKey == t);
            }

            sortCol = sortCol ?? nameof(ListableWorkflows_Result0.Status);
            if (sortCol == nameof(ListableWorkflows_Result0.Status))
            {
                items = ApplyBrowse(items, sortCol, sortDir, page, pageSize, orderedValues: ConfigOptions.Value.ReviewStatusOrdering);
            }
            else
            {
                items = ApplyBrowse(items, sortCol, sortDir, page, pageSize);
            }

            PopulateTabsIntoViewBag(tabs);
            return(View(items));
        }
예제 #5
0
        public IViewComponentResult Invoke(int?id, int workflowId, int uloRegionId, string wfDefintionOwnerName = "", bool isAdmin = false, RequestForReassignmentsController.DetailsBulkToken bulkToken = null)
        {
            bulkToken = (bulkToken != null && bulkToken.IsValid) ? bulkToken : new RequestForReassignmentsController.DetailsBulkToken(CurrentUser, DB, workflowId);
            var db = bulkToken.DB;
            RequestForReassignment requestForReassignment = null;

            if (id.HasValue)
            {
                requestForReassignment = db.RequestForReassignment.Include(z => z.UnliqudatedWorkflowQuestions).FirstOrDefault(r => r.RequestForReassignmentID == id.Value);
            }

            var workflow = db.Workflows.Find(workflowId);
            var wfDesc   = Manager.GetWorkflowDescriptionAsync(workflow).Result;

            string groupOwnerId;

            if (wfDefintionOwnerName == "")
            {
                var currentActivity = wfDesc.WebActionWorkflowActivities
                                      .FirstOrDefault(a => a.WorkflowActivityKey == workflow.CurrentWorkflowActivityKey);
                groupOwnerId = PortalHelpers.GetUserId(currentActivity.OwnerUserName);
            }
            else
            {
                groupOwnerId = PortalHelpers.GetUserId(wfDefintionOwnerName);
            }


            IList <SelectListItem> userSelectItems;

            if (PortalHelpers.UseOldGetEligibleReviewersAlgorithm)
            {
                var prohibitedUserIds = bulkToken.ProhibitedOwnerIdsByWorkflowId[workflowId];

                userSelectItems = Cacher.FindOrCreateValue(
                    Cache.CreateKey(groupOwnerId, uloRegionId, "fdsfdsaf"),
                    () => db.UserUsers
                    .Where(uu => uu.ParentUserId == groupOwnerId && uu.RegionId == uloRegionId && uu.ChildUser.UserType == AspNetUser.UserTypes.Person)
                    .Select(uu => new { UserName = uu.ChildUser.UserName, UserId = uu.ChildUserId }).ToList(),
                    PortalHelpers.MediumCacheTimeout
                    ).ConvertAll(z => UserHelpers.CreateUserSelectListItem(z.UserId, z.UserName, prohibitedUserIds.Contains(z.UserId))).ToList();

                if (Cacher.FindOrCreateValue(
                        Cache.CreateKey(uloRegionId, User.Identity.Name),
                        () =>
                {
                    var userReassignRegions = UserHelpers.GetReassignmentGroupRegions(User);
                    return(true);   //User.HasClaim("Application", ApplicationPermissionNames.CanReassign.ToString()) && userReassignRegions.Contains(uloRegionId); //sreen : need change back to this statement after Claims fix
                },
                        PortalHelpers.MediumCacheTimeout
                        ))
                {
                    userSelectItems.Add(UserHelpers.ToSelectListItem(bulkToken.CurrentUser));
                }
            }
            else
            {
                userSelectItems = new List <SelectListItem>();
                foreach (var p in bulkToken.PotentialReviewersByWorkflowId[workflowId])
                {
                    string text = MungeReviewerName(p.UserName, p.IsQualified);
                    userSelectItems.Add(UserHelpers.CreateUserSelectListItem(p.UserId, text));
                }
            }

            if (workflow.OwnerUserId == CurrentUserId)
            {
                userSelectItems.Remove(userSelectItems.Where(z => z.Value == CurrentUserId).ToList());
            }

            userSelectItems = userSelectItems.OrderBy(z => z.Text).ToList();

            userSelectItems.Insert(0, UserHelpers.CreateUserSelectListItem(UserHelpers.ReassignGroupUserId, UserHelpers.ReassignGroupUserName));

            var requestForReassignmentId = requestForReassignment?.RequestForReassignmentID;
            var suggestedReviewerId      = requestForReassignment != null ? requestForReassignment.SuggestedReviewerId : "";
            var justificationKey         = requestForReassignment?.UnliqudatedWorkflowQuestions.JustificationKey;

            var comments = requestForReassignment != null
                ? requestForReassignment.UnliqudatedWorkflowQuestions.Comments : "";

            var detailsView = isAdmin ? "_DetailsMasterList.cshtml" : "_Details.cshtml";

            return(View("~/Views/Ulo/Details/Workflow/RequestForReassignments/" + detailsView, new RequestForReassignmentViewModel(suggestedReviewerId, justificationKey, requestForReassignmentId, comments, workflowId, uloRegionId, userSelectItems, wfDesc.GetResassignmentJustifications())));
        }
예제 #6
0
        public IActionResult MyTasks(string t, string sortCol, string sortDir, int?page, int?pageSize)
        {
            SetNoDataMessage(ConfigOptions.Value.NoTasks);

            var workflows = DB.Workflows.Where(wf => wf.OwnerUserId == CurrentUserId).WhereReviewExists();

            var countByKey = new Dictionary <string, int>(workflows.GroupBy(w => w.CurrentWorkflowActivityKey).Select(g => new { CurrentWorkflowActivityKey = g.Key, Count = g.Count() }).ToDictionaryOnConflictKeepLast(z => z.CurrentWorkflowActivityKey, z => z.Count), Comparers.CaseInsensitiveStringComparer);

            var keyByName = Cacher.FindOrCreateValue(
                "workflowKeyByActivityNameForAllActiveWorkflows",
                () =>
            {
                var d = new Dictionary <string, string>(Comparers.CaseInsensitiveStringComparer);
                foreach (var wfd in DB.WorkflowDefinitions.Where(z => z.IsActive))
                {
                    if (wfd.Description == null || wfd.Description.Activities == null)
                    {
                        continue;
                    }
                    foreach (var a in wfd.Description.Activities)
                    {
                        d[a.ActivityName] = a.WorkflowActivityKey;
                    }
                }
                return(d);
            }, PortalHelpers.MediumCacheTimeout);

            var tabs = new List <WorkflowListTab>();

            foreach (var name in ConfigOptions.Value.MyTasksTabs)
            {
                var tab = new WorkflowListTab {
                    TabName = StringHelpers.TrimOrNull(name)
                };
                if (tab.TabName == null)
                {
                    continue;
                }
                tab.TabKey = keyByName.GetValue(tab.TabName);
                if (tab.TabKey == null)
                {
                    continue;
                }
                tab.ItemCount = countByKey.GetValue(tab.TabKey);
                tab.IsCurrent = tab.TabKey == t;
                tabs.Add(tab);
            }

            var items = DB.ListableWorkflows.Execute(CurrentUserId, CurrentUserId);

            if (t != null)
            {
                items = items.Where(z => z.CurrentWorkflowActivityKey == t);
            }

            sortCol = sortCol ?? nameof(ListableWorkflows_Result0.Status);
            if (sortCol == nameof(ListableWorkflows_Result0.Status))
            {
                items = ApplyBrowse(
                    items,
                    sortCol,
                    ConfigOptions.Value.ReviewStatusOrdering,
                    sortDir, page, pageSize);
            }
            else
            {
                items = ApplyBrowse(
                    items,
                    sortCol, sortDir, page, pageSize);
            }

            PopulateTabsIntoViewBag(tabs);
            return(View(items));
        }
예제 #7
0
        public async Task <ActionResult> Save(
            [Bind(new[] {
            nameof(UserModel.UserId),
            nameof(UserModel.UserName),
            nameof(UserModel.Email),
            nameof(UserModel.UserType),
            nameof(UserModel.Claims),
            nameof(UserModel.Permissions),
            nameof(UserModel.GroupMembershipRegionIds),
            nameof(UserModel.Groups),
            nameof(UserModel.SubjectCategoryClaims),
            nameof(UserModel.SubjectCategoryClaims) + "." + nameof(SubjectCatagoryClaimValue.BACode),
            nameof(UserModel.SubjectCategoryClaims) + "." + nameof(SubjectCatagoryClaimValue.DocType),
            nameof(UserModel.SubjectCategoryClaims) + "." + nameof(SubjectCatagoryClaimValue.OrgCode),
            nameof(UserModel.SubjectCategoryClaims) + "." + nameof(SubjectCatagoryClaimValue.Regions)
        }
                  )]
            UserModel m)
        {
            AspNetUser u = null;

            m.UserId   = StringHelpers.TrimOrNull(m.UserId);
            m.UserName = StringHelpers.TrimOrNull(m.UserName);
            m.Email    = StringHelpers.TrimOrNull(m.Email);
            var users = await DB.AspNetUsers
                        .Include(u => u.UserAspNetUserClaims)
                        .Include(u => u.ChildUserUserUsers)
                        .Where(z => z.UserName == m.UserName || z.Email == m.Email || z.Id == m.UserId)
                        .ToListAsync();

            bool hasErrors     = false;
            bool userNameError = false;
            bool emailError    = false;

            foreach (var user in users)
            {
                if (user.Id == m.UserId)
                {
                    u = user;
                    continue;
                }
                if (0 == string.Compare(m.UserName, user.UserName, true) && !userNameError && m.UserName != null)
                {
                    ModelState.AddModelError(nameof(m.UserName), $"Username {m.UserName} already exists, cannot re-add");
                    hasErrors     = true;
                    userNameError = true;
                }
                if (0 == string.Compare(m.Email, user.Email, true) && !emailError && m.Email != null)
                {
                    ModelState.AddModelError(nameof(m.Email), $"Email {m.Email} already exists, cannot re-add");
                    hasErrors  = true;
                    emailError = true;
                }
            }
            if (ModelState.IsValid && !hasErrors)
            {
                if (u == null && m.UserId == null)
                {
                    var res = await UserManager.CreateAsync(new AspNetUser { UserName = m.UserName, Email = StringHelpers.TrimOrNull(m.Email) });

                    u = await DB.AspNetUsers.FirstOrDefaultAsync(z => z.UserName == m.UserName);

                    if (u != null)
                    {
                        LogInformation("Created new user UserId={UserId} => UserName={UserName}, Email={Email}", u.Id, u.UserName, u.Email);
                    }
                }
                else if (u == null)
                {
                    return(NotFound());
                }
                else
                {
                    LogInformation("Modified existing with UserId={UserId} => OldUserName={OldUserName}, OldEmail={OldEmail}, NewUserName={NewUserName}, NewEmail={NewEmail}", u.Id, u.UserName, u.Email, m.UserName, m.Email);
                    u.Email    = m.Email;
                    u.UserName = m.UserName;
                }

                var myGroups = await DB.AspNetUsers.Where(UserHelpers.GrouplikeUserPredicate).Where(g => m.Groups.Contains(g.UserName)).ToListAsync();

                foreach (var uu in u.ChildUserUserUsers.ToList())
                {
                    DB.UserUsers.Remove(uu);
                }
                m.GroupMembershipRegionIds.ForEach(rid => myGroups.ForEach(g => DB.UserUsers.Add(new UserUser {
                    ParentUser = g, ChildUser = u, RegionId = rid
                })));
                foreach (var c in u.UserAspNetUserClaims.Where(z => z.ClaimType == ApplicationPermissionClaimValue.ClaimType || z.ClaimType == SubjectCatagoryClaimValue.ClaimType).ToList())
                {
                    DB.AspNetUserClaims.Remove(c);
                }
                var allRegions = Cacher.FindOrCreateValue("allRegionsHashSet", () => DB.Regions.Select(z => z.RegionId).ToSet());
                foreach (var p in m.Permissions)
                {
                    DB.AspNetUserClaims.Add(new AspNetUserClaim
                    {
                        ClaimType = ApplicationPermissionClaimValue.ClaimType,
                        UserId    = u.Id,
                        //AspNetUser = u,
                        ClaimValue = new ApplicationPermissionClaimValue
                        {
                            ApplicationPermissionName = Parse.ParseEnum <ApplicationPermissionNames>(p),
                            Regions = allRegions
                        }.ToXml()
                    });
                }


                var sccDocTypes = HttpContext.Request.Form["scc.docType"];
                var sccBaCodes  = HttpContext.Request.Form["scc.bacode"];
                var sccOrgCodes = HttpContext.Request.Form["scc.orgcode"];
                var sccRegions  = HttpContext.Request.Form["scc.region"];
                m.Claims.Clear();
                m.SubjectCategoryClaims = new List <AspnetUserSubjectCategoryClaim>();
                int n = 0;
                for (int z = 0; z < sccDocTypes.Count; ++z)
                {
                    var docType = StringHelpers.TrimOrNull(sccDocTypes[z]);
                    if (docType == null)
                    {
                        continue;
                    }
                    if (docType == PortalHelpers.FormFieldsBreak)
                    {
                        ++n;
                        continue;
                    }
                    var sccv = new SubjectCatagoryClaimValue
                    {
                        DocType = docType,
                        BACode  = sccBaCodes[sccBaCodes.IndexOfOccurrence(PortalHelpers.FormFieldsBreak, n, -1).Value + 1],
                        OrgCode = sccOrgCodes[sccOrgCodes.IndexOfOccurrence(PortalHelpers.FormFieldsBreak, n, -1).Value + 1]
                    };
                    sccv.Regions = new HashSet <int>();
                    for (int rn = sccRegions.IndexOfOccurrence(PortalHelpers.FormFieldsBreak, n, -1).Value + 1; ; ++rn)
                    {
                        if (sccRegions[rn] == PortalHelpers.FormFieldsBreak)
                        {
                            break;
                        }
                        if (int.TryParse(sccRegions[rn], out int regionId))
                        {
                            sccv.Regions.Add(regionId);
                        }
                    }
                    if (sccv.Regions.Count == PortalHelpers.RegionCount)
                    {
                        sccv.Regions.Clear();
                    }
                    DB.AspNetUserClaims.Add(new AspNetUserClaim
                    {
                        ClaimType = SubjectCatagoryClaimValue.ClaimType,
                        UserId    = u.Id,
                        //AspNetUser = u,
                        ClaimValue = sccv.ToXml()
                    });
                    var scc = new AspnetUserSubjectCategoryClaim
                    {
                        BACode       = sccv.BACode,
                        DocumentType = sccv.DocType,
                        OrgCode      = sccv.OrgCode,
                    };
                    m.SubjectCategoryClaims.Add(scc);
                    m.Claims.Add(scc.ToString());
                }
                await DB.SaveChangesAsync();

                return(RedirectToIndex());
            }
            await PopulateDetailsViewBag();

            if (m.UserId == null)
            {
                return(View("Create", m));
            }
            else
            {
                return(View("Details", m));
            }
        }