Пример #1
0
        public static Geography FromName(string geographyName)
        {
            // TODO: Possible dupes here, need resolution once we see the extent of the problem

            return(FromBasic(GeographyCache.GetGeographyByName(geographyName)));
            //return FromBasic(SwarmDb.GetDatabaseForReading().GetGeographyByName(geographyName));
        }
Пример #2
0
    public RadTreeNode EnsureGeographyLoaded(int geoToLoad, int expandTree)
    {
        try
        {
            RadTreeNode nod = Tree.FindNodeByValue(geoToLoad.ToString());
            if (nod != null)
            {
                //Already loaded, just return it.
                if (expandTree == 1)
                {
                    nod.ExpandParentNodes();
                }
                return(nod);
            }

            //get the line to make sure all nodes down to the selected are loaded;
            BasicGeography[] line = GeographyCache.GetGeographyLine(geoToLoad);

            if (Tree.Nodes.Count == 0)
            {
                // Tree is empty, insert the root.
                Tree.Nodes.Add(new RadTreeNode(this.Root.Name, this.Root.Identity.ToString()));
            }
            BasicGeography        parentbg         = null;
            RadTreeNodeCollection parentCollection = null;
            nod = Tree.Nodes[0];
            foreach (BasicGeography bg in line)
            {
                nod = Tree.FindNodeByValue(bg.Identity.ToString());
                if (parentbg == null)
                {
                    if (nod != null)
                    {
                        parentbg         = bg;
                        parentCollection = nod.Nodes;
                    }
                }
                else
                {
                    // if node found that parent is already loaded
                    if (nod == null)
                    {
                        AddChildren(parentCollection, parentbg.Identity);
                        nod = Tree.FindNodeByValue(bg.Identity.ToString());
                        nod.ParentNode.ExpandMode = TreeNodeExpandMode.ClientSide;
                    }
                    nod.ParentNode.Expanded = (expandTree == 0) ? nod.ParentNode.Expanded : (expandTree < 0) ? false : true;
                    parentbg         = bg;
                    parentCollection = nod.Nodes;
                }
            }
            Tree.Nodes[0].Expanded = (expandTree == 0) ? Tree.Nodes[0].Expanded : (expandTree < 0) ? false : true;;
            return(nod);
        }
        catch
        {
            return(null);
        }
    }
Пример #3
0
        public static Organizations GetAllOrganizationsAvailableAtGeography(int geographyId)
        {
            List <BasicGeography> nodeList = new List <BasicGeography>();

            nodeList.AddRange(GeographyCache.GetGeographyLine(geographyId));
            nodeList.AddRange(GeographyCache.GetGeographyTree(geographyId));

            return(FromIdentities(OrganizationCache.GetOrganizationsIdsInGeographies(nodeList.ToArray())));
        }
Пример #4
0
 private void AddChildren(RadTreeNodeCollection coll, int parentIdentity)
 {
     BasicGeography[] geos = GeographyCache.GetGeographyChildren(parentIdentity);
     foreach (BasicGeography geo in geos)
     {
         RadTreeNode node = new RadTreeNode(geo.Name, geo.Identity.ToString());
         node.ExpandMode = TreeNodeExpandMode.ClientSide;
         coll.Add(node);
         if ((GeographyCache.CountGeographyChildren(geo.Identity)) > 0)
         {
             node.ExpandMode = TreeNodeExpandMode.WebService;
         }
         node.Expanded = node.ParentNode.Expanded;
     }
 }
Пример #5
0
        public static BasicGeography[] GetNodesInAuthorityForOrganization(BasicAuthority authority, int organizationId,
                                                                          RoleType[] roleTypes)
        {
            Organizations organizationLine = Organization.FromIdentity(organizationId).GetLine();

            // Build lookup tables

            Dictionary <int, BasicOrganization> orgLookup = new Dictionary <int, BasicOrganization>();

            foreach (BasicOrganization organization in organizationLine)
            {
                orgLookup[organization.OrganizationId] = organization;
            }

            Dictionary <RoleType, bool> roleLookup = new Dictionary <RoleType, bool>();

            foreach (RoleType roleType in roleTypes)
            {
                roleLookup[roleType] = true;
            }

            // Create list

            List <BasicGeography> result = new List <BasicGeography>();

            if (authority.AllPersonRoles.Length > 0)
            {
                Dictionary <int, BasicGeography> geoDict = GeographyCache.GetGeographyHashtable(Geography.RootIdentity);

                foreach (BasicPersonRole role in authority.AllPersonRoles)
                {
                    if (orgLookup.ContainsKey(role.OrganizationId))
                    {
                        if (roleLookup.ContainsKey(role.Type))
                        {
                            result.Add(geoDict[role.GeographyId]);
                        }
                    }
                }
            }

            return(result.ToArray());
        }
Пример #6
0
 public static Geography FromIdentity(int geographyId)
 {
     return(FromBasic(GeographyCache.GetGeography(geographyId)));
     //return FromBasic(SwarmDb.GetDatabaseForReading().GetGeography(geographyId));
 }
Пример #7
0
 public Geographies GetLine()
 {
     return(Geographies.FromArray(GeographyCache.GetGeographyLine(Identity)));
     //return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyLine(Identity));
 }
Пример #8
0
 public static Organizations GetOrganizationsAvailableAtGeography(int geographyId)
 {
     BasicGeography[] nodeLine = GeographyCache.GetGeographyLine(geographyId);
     return(FromIdentities(OrganizationCache.GetOrganizationsIdsInGeographies(nodeLine)));
 }
Пример #9
0
        public static People FilterPeopleToMatchAuthority(People people, Authority authority, int gracePeriod)
        {
            // First: If sysadmin, return the whole list uncensored.

            if (IsSystemAdministrator(authority))
            {
                return(people);
            }

            SwarmDb databaseRead = SwarmDb.GetDatabaseForReading();

            if (gracePeriod == -1)
            {
                gracePeriod = Membership.GracePeriod;
            }

            Dictionary <int, List <BasicMembership> > membershipTable =
                databaseRead.GetMembershipsForPeople(people.Identities, gracePeriod);
            Dictionary <int, int> geographyTable = databaseRead.GetPeopleGeographies(people.Identities);

            Dictionary <int, Person> clearedPeople = new Dictionary <int, Person>();

            // TODO: Add org admin role, able to see previous members that aren't anonymized yet

            // Clear by organization roles

            foreach (BasicPersonRole role in authority.OrganizationPersonRoles)
            {
                Dictionary <int, BasicOrganization> clearedOrganizations =
                    OrganizationCache.GetOrganizationHashtable(role.OrganizationId);

                foreach (Person person in people)
                {
                    // Is the organization cleared in this officer's role for this to-be-viewed member?

                    if (membershipTable.ContainsKey(person.Identity))
                    {
                        foreach (BasicMembership membership in membershipTable[person.Identity])
                        {
                            if (clearedOrganizations.ContainsKey(membership.OrganizationId)
                                &&
                                authority.HasPermission(Permission.CanSeePeople, membership.OrganizationId,
                                                        person.GeographyId, Flag.Default))
                            {
                                if (membership.Active ||
                                    (membership.Expires > DateTime.Now.AddDays(-gracePeriod) &&
                                     membership.Expires.AddDays(1) > membership.DateTerminated
                                     &&
                                     authority.HasPermission(Permission.CanSeeExpiredDuringGracePeriod,
                                                             membership.OrganizationId, person.GeographyId, Flag.Default)))
                                {
                                    clearedPeople[person.Identity] = person;
                                    break;
                                }
                            }
                        }
                    }

                    /* -- commented out. This means "does the current authority have Org Admin privileges over Person"?
                     * else if (CanSeeNonMembers)
                     * { //person isn't member anywhere
                     *  clearedPeople[person.Identity] = person;
                     * }*/
                }
            }


            // Clear by node roles:
            //
            // For each node role, check if each member is in a cleared geography AND a cleared organization.
            // If so, permit view of this member. (A person in a branch of a geographical area for organizations X and Z
            // should see only people of those organizations only on those nodes.)


            foreach (BasicPersonRole role in authority.LocalPersonRoles)
            {
                Dictionary <int, BasicGeography> clearedGeographies =
                    GeographyCache.GetGeographyHashtable(role.GeographyId);
                Dictionary <int, BasicOrganization> clearedOrganizations =
                    OrganizationCache.GetOrganizationHashtable(role.OrganizationId);

                foreach (Person person in people)
                {
                    // Is the node AND the organization cleared in this officer's role for this to-be-viewed member?

                    if (membershipTable.ContainsKey(person.Identity))
                    {
                        foreach (BasicMembership membership in membershipTable[person.Identity])
                        {
                            int organizationClear = 0;
                            int geographyClear    = 0;
                            if (clearedOrganizations.ContainsKey(membership.OrganizationId))
                            {
                                organizationClear = membership.OrganizationId;

                                if (clearedGeographies.ContainsKey(geographyTable[person.Identity]))
                                {
                                    geographyClear = geographyTable[person.Identity];
                                }

                                if (organizationClear > 0 &&
                                    geographyClear > 0
                                    &&
                                    authority.HasPermission(Permission.CanSeePeople, organizationClear, geographyClear,
                                                            Flag.Default))
                                {
                                    if (membership.Active ||
                                        (membership.Expires > DateTime.Now.AddDays(-gracePeriod) &&
                                         membership.Expires.AddDays(1) > membership.DateTerminated
                                         &&
                                         authority.HasPermission(Permission.CanSeeExpiredDuringGracePeriod,
                                                                 membership.OrganizationId, person.GeographyId, Flag.Default)))
                                    {
                                        clearedPeople[person.Identity] = person;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }


            // End: Assemble an array of the resulting cleared people

            People result = new People();

            foreach (Person clearedPerson in clearedPeople.Values)
            {
                result.Add(clearedPerson);
            }

            return(result);
        }
Пример #10
0
        public static Memberships FilterMembershipsToMatchAuthority(Memberships memberships, Geography personGeography,
                                                                    Authority authority)
        {
            // First: If sysadmin, return the whole list uncensored.

            if (IsSystemAdministrator(authority))
            {
                return(memberships);
            }

            Dictionary <int, Membership> clearedMemberships = new Dictionary <int, Membership>();

            //
            foreach (BasicPersonRole role in authority.OrganizationPersonRoles)
            {
                Dictionary <int, BasicOrganization> clearedOrganizations =
                    OrganizationCache.GetOrganizationHashtable(role.OrganizationId);

                foreach (Membership membership in memberships)
                {
                    bool organizationClear = clearedOrganizations.ContainsKey(membership.OrganizationId);

                    if (organizationClear
                        &&
                        authority.HasPermission(Permission.CanViewMemberships, membership.OrganizationId,
                                                membership.Person.GeographyId, Flag.Default))
                    {
                        clearedMemberships[membership.Identity] = membership;
                    }
                }
            }


            foreach (BasicPersonRole role in authority.LocalPersonRoles)
            {
                Dictionary <int, BasicGeography> clearedGeographies =
                    GeographyCache.GetGeographyHashtable(role.GeographyId);
                Dictionary <int, BasicOrganization> clearedOrganizations =
                    OrganizationCache.GetOrganizationHashtable(role.OrganizationId);

                bool geographyClear = clearedGeographies.ContainsKey(personGeography.Identity);
                geographyClear = geographyClear &&
                                 authority.HasPermission(Permission.CanViewMemberships, role.OrganizationId,
                                                         personGeography.Identity, Flag.Default);

                if (geographyClear)
                {
                    foreach (Membership membership in memberships)
                    {
                        bool organizationClear = clearedOrganizations.ContainsKey(membership.OrganizationId);

                        if (organizationClear)
                        {
                            clearedMemberships[membership.Identity] = membership;
                        }
                    }
                }
            }


            // Assemble the array

            Memberships result = new Memberships();

            foreach (Membership membership in clearedMemberships.Values)
            {
                result.Add(membership);
            }

            return(result);
        }
Пример #11
0
 public static Geographies FromIdentities(int[] geoIds)
 {
     return(FromArray(GeographyCache.GetGeographies(geoIds)));
     //           return FromArray(SwarmDb.GetDatabaseForReading().GetGeographies(geoIds));
 }
Пример #12
0
 public Geographies ThisAndBelow()
 {
     return(Geographies.FromArray(GeographyCache.GetGeographyTree(Identity)));
     // return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyTree(Identity));
 }