コード例 #1
0
        public ActionResult FixupUnitMemberGroups(string id, string group, bool?commit)
        {
            if (!Permissions.IsUserOrLocal(Request))
            {
                Response.StatusCode = 403;
                return(CreateLoginRedirect());
            }
            string result = "";

            SarUnit unit = UnitsController.ResolveUnit(this.db.Units, id);

            if (string.IsNullOrEmpty(group))
            {
                group = UnitNameAsGroupName(unit.DisplayName) + ".members";
            }

            var unitMembers = (from m in this.db.UnitMemberships
                               where m.Unit.Id == unit.Id && m.EndTime == null && m.Status.GetsAccount
                               select m.Person).OrderBy(f => f.LastName).ThenBy(f => f.FirstName).Distinct().ToArray();

            var usersInGroup = Roles.GetUsersInRole(group).ToList();

            foreach (var member in unitMembers)
            {
                if (usersInGroup.Contains(member.Username))
                {
                    result += string.Format("{0} in group as {1}<br/>", member.FullName, member.Username);
                    usersInGroup.Remove(member.Username);
                }
                else
                {
                    result += string.Format("## {0} not in group. Should add {1}<br/>", member.FullName, member.Username);
                }
            }

            foreach (string username in usersInGroup)
            {
                result += string.Format("## suggest remove {0}<br/>", username);
            }

            //if (commit.HasValue && commit.Value)
            //{
            //        if (usersToAdd.Count > 0)
            //        {
            //            Roles.AddUsersToRole(usersToAdd.ToArray(), group);
            //        }

            //        if (usersToRemove.Count > 0)
            //        {
            //            Roles.RemoveUsersFromRole(usersToRemove.ToArray(), group);
            //        }
            //    }
            //}

            return(new ContentResult {
                ContentType = "text/html", Content = "Done.\n" + result
            });
        }
コード例 #2
0
        public ActionResult ReconcileActiveOnlyGroup(string group, string unit, string[] keep, bool?doit)
        {
            string msgs = string.Empty;

            doit = doit ?? false;

            //SarUnit withUnit = string.IsNullOrWhiteSpace(unit) ? null : UnitsController.ResolveUnit(ctx.Units, unit);

            var query = (from m in this.db.UnitMemberships where m.Status.IsActive && m.EndTime == null select m);

            if (!string.IsNullOrWhiteSpace(unit))
            {
                Guid unitId = UnitsController.ResolveUnit(this.db.Units, unit).Id;
                query = query.Where(f => f.Unit.Id == unitId);
            }
            List <string> desiredUsers  = query.Select(f => f.Person.Username ?? ("*" + f.Person.FirstName + " " + f.Person.LastName)).ToList();
            List <string> usersToRemove = new List <string>();
            List <string> forceKeep     = new List <string>();

            foreach (string user in Roles.GetUsersInRole(group))
            {
                if (desiredUsers.Contains(user))
                {
                    desiredUsers.Remove(user);
                }
                else if (keep != null && keep.Contains(user))
                {
                    forceKeep.Add(user);
                }
                else
                {
                    usersToRemove.Add(user);
                }
            }
            if (desiredUsers.Count > 1)
            {
                msgs += string.Join("\n", desiredUsers.Where(f => f[0] != '*').Select(f => "add " + f).ToArray());
                msgs += string.Join("\n", desiredUsers.Where(f => f[0] == '*').Select(f => "No username for active member " + f.Substring(1)).ToArray());
                if (doit.Value && desiredUsers.Count(f => f[0] != '*') > 0)
                {
                    Roles.AddUsersToRole(desiredUsers.Where(f => f[0] != '*').ToArray(), group);
                }
            }
            msgs += string.Join("\n", forceKeep.Select(f => "keeping " + f).ToArray());
            if (usersToRemove.Count > 1)
            {
                msgs += string.Join("\n", usersToRemove.Select(f => "remove " + f).ToArray());
                if (doit.Value)
                {
                    Roles.RemoveUsersFromRole(usersToRemove.ToArray(), group);
                }
            }
            return(new ContentResult {
                Content = msgs, ContentType = "text/plain"
            });
        }
コード例 #3
0
        public static MemberDetailView[] GetMemberEmails(IKcsarContext ctx, string id)
        {
            Guid unitId = UnitsController.ResolveUnit(ctx.Units, id).Id;

            Member[]           members = (from m in ctx.GetActiveMembers(unitId, DateTime.Now, "ContactNumbers", "Memberships.Unit", "Memberships.Status") select m).ToArray();
            MemberDetailView[] model   = members
                                         .Where(f => f.Memberships.Any(g => g.Unit.Id == unitId && g.Status.IsActive && g.Status.StatusName != "trainee") &&
                                                f.ContactNumbers.Count(g => g.Type == "email") > 0)
                                         .Select(m =>
                                                 new MemberDetailView
            {
                Id        = m.Id,
                FirstName = m.FirstName,
                LastName  = m.LastName,
                Contacts  = m.ContactNumbers.Where(f => f.Type == "email").Select(f => new MemberContactView {
                    Id = f.Id, Priority = f.Priority, Value = f.Value
                }).OrderBy(f => f.Priority).ToArray(),
                Units = m.Memberships.Where(f => f.Status.IsActive && (f.EndTime == null || f.EndTime > DateTime.Now)).Select(f => f.Unit.DisplayName).ToArray()
            })
                                         .ToArray();

            return(model);
        }