/// <summary>
        /// #2
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            var request = _departmentalAdminRequestRepository.GetNullableById(CurrentUser.Identity.Name);

            var ldap = _directorySearchService.FindUser(CurrentUser.Identity.Name);

            Check.Require(ldap != null, "Person requesting Departmental Access ID not found. ID = " + CurrentUser.Identity.Name);

            var model = DepartmentalAdminRequestViewModel.Create();

            model.DepartmentalAdminRequest             = request ?? new DepartmentalAdminRequest(ldap.LoginId.ToLower());
            model.DepartmentalAdminRequest.FirstName   = ldap.FirstName;
            model.DepartmentalAdminRequest.LastName    = ldap.LastName;
            model.DepartmentalAdminRequest.Email       = ldap.EmailAddress;
            model.DepartmentalAdminRequest.PhoneNumber = ldap.PhoneNumber;
            if (model.DepartmentalAdminRequest.Organizations != null && model.DepartmentalAdminRequest.Organizations.Any())
            {
                foreach (var orgId in model.DepartmentalAdminRequest.Organizations.Split(','))
                {
                    var org = _repositoryFactory.OrganizationRepository.GetNullableById(orgId);
                    if (org != null)
                    {
                        model.Organizations.Add(org);
                    }
                }
            }

            return(View(model));
        }
Exemplo n.º 2
0
        // ===================================================
        // User Functions
        // ===================================================
        public User GetUser(string kerb)
        {
            if (!string.IsNullOrWhiteSpace(kerb))
            {
                kerb = kerb.ToLower(); //So without this, if it finds the user, it has an upper case ID even if the found user id is lower case
            }
            var user = _repositoryFactory.UserRepository.GetNullableById(kerb);

            if (user == null)
            {
                var ldapUser = _directorySearchService.FindUser(kerb);

                if (ldapUser != null)
                {
                    user           = new User(kerb);
                    user.FirstName = ldapUser.FirstName;
                    user.LastName  = ldapUser.LastName;
                    user.Email     = ldapUser.EmailAddress;

                    _repositoryFactory.UserRepository.EnsurePersistent(user, false);
                }
            }

            return(user);
        }
Exemplo n.º 3
0
        public JsonNetResult FindUser(string searchTerm)
        {
            searchTerm = searchTerm.ToLower().Trim();

            var users = _userRepository.Queryable.Where(a => a.Email == searchTerm || a.Id == searchTerm).ToList();

            if (users.Count == 0)
            {
                var ldapuser = _searchService.FindUser(searchTerm);
                if (ldapuser != null)
                {
                    Check.Require(!string.IsNullOrWhiteSpace(ldapuser.LoginId));
                    Check.Require(!string.IsNullOrWhiteSpace(ldapuser.EmailAddress));

                    var user = new User(ldapuser.LoginId);
                    user.Email     = ldapuser.EmailAddress;
                    user.FirstName = ldapuser.FirstName;
                    user.LastName  = ldapuser.LastName;

                    users.Add(user);
                }
            }

            if (users.Count() == 0)
            {
                return(null);
            }
            return(new JsonNetResult(users.Select(a => new { id = a.Id, FirstName = a.FirstName, LastName = a.LastName, Email = a.Email, IsActive = a.IsActive })));
        }
Exemplo n.º 4
0
        [Authorize] //Must be kerb authorized
        public ActionResult UvSignIn(string @return)
        {
            string encodedToken;

            var user = _userRepository.Queryable.Where(x => x.LoginId == User.Identity.Name).SingleOrDefault();

            if (user == null)
            {
                //Can't find the user in catbert, use directory services to lookup info
                var directoryUser = _directorySearchService.FindUser(User.Identity.Name);

                if (directoryUser == null)
                {
                    //They aren't in ldap either?
                    throw new NotImplementedException("You are not found in Catbert or LDAP...");
                }
                else
                {
                    //TODO: What to do when email address is not found in ldap
                    encodedToken = UserVoiceTokenGenerator.Create(directoryUser.FullName ?? directoryUser.LoginId, directoryUser.EmailAddress,
                                                                  directoryUser.LoginId);
                }
            }
            else
            {
                //User is in catbert, generate sso token
                encodedToken = UserVoiceTokenGenerator.Create(user.FullName, user.Email, user.LoginId);
            }

            return(Redirect(string.Format("{0}{1}?sso={2}", UvRoot, @return, encodedToken)));
        }
        [HandleTransactionsManually] //We are just using directory services
        public ActionResult Find(string searchTerm)
        {
            if (string.IsNullOrWhiteSpace(searchTerm))
            {
                return(View());
            }

            var user = _directorySearchService.FindUser(searchTerm);

            if (user == null)
            {
                ViewData["searchTerm"] = searchTerm;
                Message = string.Format("No users found with email or kerberos Id = {0}", searchTerm);
                return(View());
            }

            Message = string.Format("User {0} found.  Please verify the information below and then click add",
                                    user.FullName);

            return(RedirectToAction("Add", new { id = user.LoginId }));
        }
Exemplo n.º 6
0
        /// <summary>
        /// #2
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <returns></returns>
        public JsonResult FindUser(string searchTerm)
        {
            ServiceUser serviceUser = null;

            var directoryUser = _directorySearchService.FindUser(searchTerm);

            if (directoryUser != null)
            {
                serviceUser = new ServiceUser(directoryUser);
            }

            return(Json(serviceUser, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        private User GetUser()
        {
            var user = Esra.Core.Domain.User.GetByLoginId(Repository, CurrentUser.Identity.Name);

            if (user != null && String.IsNullOrEmpty(user.EmployeeID))
            {
                // try getting employee ID from LDAP:
                var tempUser = _directorySearchService.FindUser(CurrentUser.Identity.Name);
                if (tempUser != null)
                {
                    user.EmployeeID = tempUser.EmployeeId;
                }
            }
            return(user);
        }
Exemplo n.º 8
0
        public static AccessRequestViewModel Create(IRepository repository, IDirectorySearchService directorySearchService, string loginId)
        {
            Check.Require(repository != null, "Repository must be supplied");

            // execute the search
            var directoryUser = directorySearchService.FindUser(loginId);

            var accessRequest = new AccessRequest()
                                    {
                                        LoginId = loginId,
                                        FirstName = directoryUser.FirstName, LastName = directoryUser.LastName,
                                        Email = directoryUser.EmailAddress
                                    };

            var viewModel = new AccessRequestViewModel
                                {
                                    AccessRequest = accessRequest,
                                    Departments = repository.OfType<Department>().GetAll()
                                };

            return viewModel;
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">Workgroup Id</param>
        /// <param name="role">Role being for people being added</param>
        /// <param name="workgroup">workgroup</param>
        /// <param name="successCount">how many have already been successfully added</param>
        /// <param name="lookupUser">user being added</param>
        /// <param name="failCount">count of number not added</param>
        /// <param name="notAddedKvp">list of users not added and reason why.</param>
        /// <returns></returns>
        public int TryToAddPeople(int id, Role role, Workgroup workgroup, int successCount, string lookupUser, ref int failCount, ref int duplicateCount, List <KeyValuePair <string, string> > notAddedKvp)
        {
            var saveParm = lookupUser;
            var user     = _userRepository.GetNullableById(lookupUser);

            if (user == null)
            {
                var ldapuser = _searchService.FindUser(lookupUser);
                if (ldapuser != null)
                {
                    lookupUser = ldapuser.LoginId;
                    user       = _userRepository.GetNullableById(ldapuser.LoginId);
                    if (user == null)
                    {
                        user           = new User(ldapuser.LoginId);
                        user.Email     = ldapuser.EmailAddress;
                        user.FirstName = ldapuser.FirstName;
                        user.LastName  = ldapuser.LastName;

                        _userRepository.EnsurePersistent(user);

                        var emailPrefs = new EmailPreferences(user.Id);
                        _emailPreferencesRepository.EnsurePersistent(emailPrefs);
                    }
                }
            }

            if (user == null)
            {
                //notAddedSb.AppendLine(string.Format("{0} : Not found", saveParm));
                notAddedKvp.Add(new KeyValuePair <string, string>(saveParm, "Not found"));
                failCount++;
                return(successCount);
            }

            if (!_workgroupPermissionRepository.Queryable.Any(a => a.Role == role && a.User == user && a.Workgroup == workgroup && a.IsAdmin == false))
            {
                var workgroupPermission = new WorkgroupPermission();
                workgroupPermission.Role      = role;
                workgroupPermission.User      = _userRepository.GetNullableById(lookupUser);
                workgroupPermission.Workgroup = _workgroupRepository.GetNullableById(id);

                _workgroupPermissionRepository.EnsurePersistent(workgroupPermission);

                if (workgroup.Administrative)
                {
                    var ids = GetChildWorkgroups(workgroup.Id);
                    foreach (var childid in ids)
                    {
                        var childWorkgroup = _workgroupRepository.Queryable.Single(a => a.Id == childid);
                        if (!_workgroupPermissionRepository.Queryable.Any(a => a.Workgroup == childWorkgroup && a.Role == role && a.User == user && a.IsAdmin && a.ParentWorkgroup == workgroup))
                        {
                            Check.Require(role.Id != Role.Codes.Requester);
                            var childPermission = new WorkgroupPermission();
                            childPermission.Role            = role;
                            childPermission.User            = workgroupPermission.User;
                            childPermission.Workgroup       = childWorkgroup;
                            childPermission.IsAdmin         = true;
                            childPermission.IsFullFeatured  = workgroup.IsFullFeatured;
                            childPermission.ParentWorkgroup = workgroup;
                            _workgroupPermissionRepository.EnsurePersistent(childPermission);
                        }
                    }
                }
                // invalid the cache for the user that was just given permissions
                _userIdentity.RemoveUserRoleFromCache(Resources.Role_CacheId, workgroupPermission.User.Id);

                successCount++;
            }
            else
            {
                //notAddedSb.AppendLine(string.Format("{0} : Is a duplicate", lookupUser));
                notAddedKvp.Add(new KeyValuePair <string, string>(lookupUser, "Is a duplicate"));
                failCount++;
                duplicateCount++;
            }

            return(successCount);
        }
Exemplo n.º 10
0
        public JsonNetResult FindPerson(string loginOrEmail)
        {
            var user = _directorySearchService.FindUser(loginOrEmail);

            return(new JsonNetResult(user));
        }
        public ActionResult Create(int?workgroupId, string orgId, ConditionalApprovalModifyModel modifyModel)
        {
            if (workgroupId.HasValue)
            {
                ViewBag.WorkgroupId      = workgroupId.Value;
                modifyModel.ApprovalType = WorkgroupType;
                modifyModel.Workgroup    = _workgroupRepository.GetNullableById(workgroupId.Value);
                var workgroup = _workgroupRepository.Queryable.Single(a => a.Id == workgroupId.Value);
                if (workgroup.Administrative)
                {
                    ErrorMessage = "Conditional Approval may not be added to an administrative workgroup.";
                    return(this.RedirectToAction <WizardController>(a => a.Details(workgroup.Id)));
                }
            }
            else if (!string.IsNullOrWhiteSpace(orgId))
            {
                modifyModel.ApprovalType = OrganizationType;
                modifyModel.Organization = _organizationRepository.GetNullableById(orgId);
                ViewBag.OrganizationId   = orgId;
            }

            var primaryApproverInDb   = GetUserBySearchTerm(modifyModel.PrimaryApprover);
            var secondaryApproverInDb = string.IsNullOrWhiteSpace(modifyModel.SecondaryApprover)
                                            ? null
                                            : GetUserBySearchTerm(modifyModel.SecondaryApprover);

            if (primaryApproverInDb == null)
            {
                DirectoryUser primaryApproverInLdap = _directorySearchService.FindUser(modifyModel.PrimaryApprover);

                if (primaryApproverInLdap == null)
                {
                    ModelState.AddModelError("primaryapprover",
                                             "No user could be found with the kerberos or email address entered");
                }
                else //found the primary approver in ldap
                {
                    primaryApproverInDb = new User(primaryApproverInLdap.LoginId)
                    {
                        FirstName = primaryApproverInLdap.FirstName,
                        LastName  = primaryApproverInLdap.LastName,
                        Email     = primaryApproverInLdap.EmailAddress,
                        IsActive  = true
                    };

                    _userRepository.EnsurePersistent(primaryApproverInDb, forceSave: true);
                }
            }

            if (!string.IsNullOrWhiteSpace(modifyModel.SecondaryApprover)) //only check if a value was provided
            {
                if (secondaryApproverInDb == null)
                {
                    DirectoryUser secondaryApproverInLdap = _directorySearchService.FindUser(modifyModel.SecondaryApprover);

                    if (secondaryApproverInLdap == null)
                    {
                        ModelState.AddModelError("secondaryapprover",
                                                 "No user could be found with the kerberos or email address entered");
                    }
                    else //found the secondary approver in ldap
                    {
                        secondaryApproverInDb = new User(secondaryApproverInLdap.LoginId)
                        {
                            FirstName = secondaryApproverInLdap.FirstName,
                            LastName  = secondaryApproverInLdap.LastName,
                            Email     = secondaryApproverInLdap.EmailAddress,
                            IsActive  = true
                        };

                        _userRepository.EnsurePersistent(secondaryApproverInDb, forceSave: true);
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(CreateModifyModel(modifyModel.ApprovalType, modifyModel)));
            }

            Check.Require(modifyModel.Workgroup != null || modifyModel.Organization != null, "Must have a Workgroup or an Organization");

            var newConditionalApproval = new ConditionalApproval
            {
                Question          = modifyModel.Question,
                Organization      = modifyModel.Organization,
                Workgroup         = modifyModel.Workgroup,
                PrimaryApprover   = primaryApproverInDb,
                SecondaryApprover = secondaryApproverInDb
            };

            _conditionalApprovalRepository.EnsurePersistent(newConditionalApproval);

            Message = "Conditional approval added successfully";

            if (workgroupId.HasValue)
            {
                return(this.RedirectToAction(a => a.ByWorkgroup(workgroupId.Value)));
            }

            if (!string.IsNullOrWhiteSpace(orgId))
            {
                return(this.RedirectToAction(a => a.ByOrg(orgId)));
            }

            //return this.RedirectToAction(a => a.Index());
            return(this.RedirectToAction <ErrorController>(a => a.Index()));
        }
Exemplo n.º 12
0
        public ActionResult AddPeople(int id, WizardWorkgroupPeoplePostModel workgroupPeoplePostModel, string roleFilter, string bulkEmail, string bulkKerb)
        {
            var notAddedKvp = new List <KeyValuePair <string, string> >();

            var workgroup = _workgroupRepository.GetNullableById(id);

            if (workgroup == null)
            {
                Message = "Workgroup not found.";
                this.RedirectToAction <WorkgroupController>(a => a.Index(false));
            }
            if (workgroupPeoplePostModel.Users == null)
            {
                workgroupPeoplePostModel.Users = new List <string>();
            }

            ModelState.Clear();

            workgroupPeoplePostModel.Role = _roleRepository.Queryable.FirstOrDefault(a => a.Id == roleFilter);
            //Ensure role picked is valid.
            if (workgroupPeoplePostModel.Role != null)
            {
                if (!_roleRepository.Queryable.Any(a => !a.IsAdmin && a.Id == workgroupPeoplePostModel.Role.Id))
                {
                    ModelState.AddModelError("Role", "Invalid Role Selected - don't mess with the query string!");
                }
            }

            if (!ModelState.IsValid)
            {
                var viewModel = WorgroupPeopleCreateModel.Create(_roleRepository, workgroup);

                if (workgroupPeoplePostModel.Role != null)
                {
                    viewModel.Role = workgroupPeoplePostModel.Role;
                }
                if (workgroupPeoplePostModel.Users != null && workgroupPeoplePostModel.Users.Count > 0)
                {
                    var users = new List <IdAndName>();
                    foreach (var user in workgroupPeoplePostModel.Users)
                    {
                        var temp = _userRepository.GetNullableById(user);
                        if (temp != null)
                        {
                            users.Add(new IdAndName(temp.Id, temp.FullName));
                        }
                        else
                        {
                            var ldapuser = _searchService.FindUser(user);
                            if (ldapuser != null)
                            {
                                users.Add(new IdAndName(ldapuser.LoginId, string.Format("{0} {1}", ldapuser.FirstName, ldapuser.LastName)));
                            }
                        }
                    }
                    viewModel.Users = users;
                }
                ViewBag.rolefilter = roleFilter;
                if (!string.IsNullOrWhiteSpace(roleFilter))
                {
                    viewModel.Role = _roleRepository.Queryable.SingleOrDefault(a => !a.IsAdmin && a.Id == roleFilter);
                }
                if (viewModel.Role.Level == 0)
                {
                    ViewBag.StepNumber = 3 + (5 - 1); // Ugliness because a reviewer is level zero
                }
                else
                {
                    ViewBag.StepNumber = 3 + (viewModel.Role.Level - 1);
                }
                return(View(viewModel));
            }

            int successCount   = 0;
            int failCount      = 0;
            int duplicateCount = 0;

            foreach (var u in workgroupPeoplePostModel.Users)
            {
                successCount = _workgroupService.TryToAddPeople(id, workgroupPeoplePostModel.Role, workgroup, successCount, u, ref failCount, ref duplicateCount, notAddedKvp);
            }



            #region Bulk Load Email
            successCount = _workgroupService.TryBulkLoadPeople(bulkEmail, true, id, workgroupPeoplePostModel.Role, workgroup, successCount, ref failCount, ref duplicateCount, notAddedKvp);

            //const string regexPattern = @"\b[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}\b";

            //// Find matches
            //System.Text.RegularExpressions.MatchCollection matches = System.Text.RegularExpressions.Regex.Matches(bulkEmail, regexPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //foreach(System.Text.RegularExpressions.Match match in matches)
            //{
            //    var temp = match.ToString().ToLower();
            //    successCount = _workgroupService.TryToAddPeople(id, workgroupPeoplePostModel.Role, workgroup, successCount, temp,  ref failCount, notAddedKvp);
            //}
            #endregion

            #region Bulk Load Kerb

            successCount = _workgroupService.TryBulkLoadPeople(bulkKerb, false, id, workgroupPeoplePostModel.Role, workgroup, successCount, ref failCount, ref duplicateCount, notAddedKvp);

            //const string regexPattern4Kerb = @"\b[A-Z0-9]{2,10}\b";

            //// Find matches
            //System.Text.RegularExpressions.MatchCollection matchesKerb = System.Text.RegularExpressions.Regex.Matches(bulkKerb, regexPattern4Kerb, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //foreach(System.Text.RegularExpressions.Match match in matchesKerb)
            //{
            //    var temp = match.ToString().ToLower();
            //    successCount = _workgroupService.TryToAddPeople(id, workgroupPeoplePostModel.Role, workgroup, successCount, temp, ref failCount, notAddedKvp);
            //}
            #endregion

            Message = string.Format("Successfully added {0} people to workgroup as {1}. {2} not added because of duplicated role or not found.", successCount,
                                    workgroupPeoplePostModel.Role.Name, failCount);

            if (failCount > 0 || successCount == 0)
            {
                if (failCount == 0)
                {
                    ModelState.AddModelError("Users", "Must add at least 1 user or Skip");
                }
                else if (failCount == duplicateCount)
                {
                    Message = string.Format("The {0} users you added already have the role {1}", duplicateCount,
                                            workgroupPeoplePostModel.Role.Name);
                    return(this.RedirectToAction(a => a.People(id, workgroupPeoplePostModel.Role.Id)));
                }


                var viewModel = WorgroupPeopleCreateModel.Create(_roleRepository, workgroup);
                viewModel.ErrorDetails = notAddedKvp;
                // ViewBag.DetailedMessage = notAddedSb.ToString();

                ViewBag.rolefilter = roleFilter;
                if (!string.IsNullOrWhiteSpace(roleFilter))
                {
                    viewModel.Role = _roleRepository.Queryable.SingleOrDefault(a => !a.IsAdmin && a.Id == roleFilter);
                }
                if (viewModel.Role.Level == 0)
                {
                    ViewBag.StepNumber = 3 + (5 - 1); // Ugliness because a reviewer is level zero
                }
                else
                {
                    ViewBag.StepNumber = 3 + (viewModel.Role.Level - 1);
                }
                return(View(viewModel));
            }

            Message = string.Format("Successfully added {0} people to workgroup as {1}.", successCount,
                                    workgroupPeoplePostModel.Role.Name);
            return(this.RedirectToAction(a => a.People(id, workgroupPeoplePostModel.Role.Id)));
        }