Example #1
0
 public Access(Organization organization, Geography geography, AccessAspect aspect, AccessType type)
 {
     this.Organization = organization;
     this.Geography = geography;
     this.Aspect = aspect;
     this.Type = type;
 }
Example #2
0
 public static ExternalActivity Create (Organization organization, Geography geograpy, ExternalActivityType type, DateTime date, string description, Person createdByPerson)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreateExternalActivity(organization.Identity, geograpy.Identity,
                                                                    date, type, description,
                                                                    createdByPerson.Identity));
 }
Example #3
0
 public static MeetingElection Create (Person creator, Organization org, Geography geo, string name, InternalPollResultsType resultsType, int maxVoteLength, DateTime runningOpens, DateTime runningCloses, DateTime votingOpens, DateTime votingCloses)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreateInternalPoll(org.Identity, geo.Identity, name, maxVoteLength,
                                                                resultsType, creator.Identity, runningOpens,
                                                                runningCloses, votingOpens, votingCloses));
 }
Example #4
0
        public static OfficerChain FromOrganizationAndGeography (Organization org, Geography geo)
        {
            int[] concernedPeopleId = Roles.GetAllUpwardRoles(org.Identity, geo.Identity);
            People concernedPeople = People.FromIdentities(concernedPeopleId);

            return new OfficerChain(concernedPeople, org.Identity);
        }
 static public MeetingElectionVote Create (MeetingElection poll, Geography voteGeography)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreateInternalPollVote(poll.Identity, voteGeography.Identity,
                                                                    Authentication.
                                                                        CreateRandomPassword(12)));
 }
Example #6
0
 public static AutoMail Create (AutoMailType type, Organization org, Geography geo,
                                Person author, string title, string body)
 {
     SwarmDb.GetDatabaseForWriting().SetAutoMail (type, org.Identity, geo.Identity,
                                         author == null ? 0 : author.Identity, title, body);
     return FromTypeOrganizationAndGeography (type, org, geo);
 }
Example #7
0
 public static OutboundMail Create (Person author, string title,
                                    string body, int mailPriority, int mailType,
                                    Organization organization, Geography geography)
 {
     return Create(author, title, body, mailPriority, mailType, organization,
                    geography, DateTime.Now);
 }
Example #8
0
 public static OutboundMail Create (Person author, string title,
                                    string body, int mailPriority, int mailType,
                                    Organization organization, Geography geography, DateTime releaseDateTime)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreateOutboundMail(MailAuthorType.Person, author.Identity, title,
                                                                  body, mailPriority, mailType,
                                                                  geography.Identity, organization.Identity,
                                                                  releaseDateTime));
 }
Example #9
0
        public static Parley Create (Organization organization, Person person, FinancialAccount budgetInitial, string name, Geography geography, string description, string informationUrl, DateTime startDate, DateTime endDate, Int64 budgetCents, Int64 guaranteeCents, Int64 attendanceFeeCents)
        {
            Parley newParley = 
                FromIdentity(SwarmDb.GetDatabaseForWriting().CreateParley(organization.Identity, person.Identity,
                                                                 -(budgetInitial.Identity), name, geography.Identity,
                                                                 description, informationUrl, startDate, endDate,
                                                                 budgetCents, guaranteeCents, attendanceFeeCents));

            PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ParleyCreated, person.Identity, organization.Identity, 0, 0, newParley.Identity, string.Empty); 

            return newParley;
        }
Example #10
0
 public static void CreateActivistWithLogging (Geography geo, Person newActivist, string logMessage, EventSource evtSrc, bool isPublic, bool isConfirmed, int orgId)
 {
     PWEvents.CreateEvent(evtSrc,
         EventType.NewActivist,
         newActivist.Identity,
         orgId,
         geo.Identity,
         newActivist.Identity,
         0,
         string.Empty);
     newActivist.CreateActivist(isPublic, isConfirmed);
     PWLog.Write(newActivist, PWLogItem.Person, newActivist.Identity, PWLogAction.ActivistJoin, "New activist joined.", logMessage);
 }
Example #11
0
        public static AutoMail FromTypeOrganizationAndGeography (AutoMailType type, Organization org, Geography geo)
        {
            BasicAutoMail basic = SwarmDb.GetDatabaseForReading().GetAutoMail (type, org.Identity, geo.Identity);

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

            if (basic.Body.Trim().Length < 3)
            {
                return null; // If there is no body, there is no mail
            }

            return FromBasic (basic);
        }
Example #12
0
        private static int CheckSpecificValidRoles (Authority authority, RoleType[] roles,
                                                    Geography currentGeo, Organization currentOrg,
                                                    int thisFound, Flag flags)
        {
            if (authority.HasAnyRoleType(roles))
            {
                //Yes, we have one of the roles
                foreach (RoleType r in roles)
                {
                    if (authority.HasRoleType(r) && (Array.IndexOf(RoleTypes.AllLocalRoleTypes, r) > -1))
                    {
                        thisFound = authority.HasLocalRoleAtOrganizationGeography(currentOrg, currentGeo, r, flags) ? 1 : thisFound;
                    }
                    else if (authority.HasRoleType(r) && ((Array.IndexOf(RoleTypes.AllOrganizationalRoleTypes, r) > -1)))
                    {
                        thisFound = authority.HasRoleAtOrganization(currentOrg, r, flags) ? 1 : thisFound;
                    }
                    else if (authority.HasRoleType(r) && ((Array.IndexOf(RoleTypes.AllSystemRoleTypes, r) > -1)))
                    {   //System PersonRole
                        thisFound = 1;
                    }
                    // break if we found one that gives access
                    if (thisFound == 1)
                        return thisFound;
                }
                // if we found one valid it would already have returned; return -1
                thisFound = -1;
            }
            else
                thisFound = -1; //No, we don't have any of the roles


            return thisFound;
        }
Example #13
0
        /// <summary>
        ///          Assign the volunteer to a suitable owner will try to assign to ElectoralCircuit lead
        ///          If that is not possible it will go to district lead
        /// </summary>
        /// <param name="geo"></param>
        /// <param name="withinOrg"></param>
        /// <param name="defaultOwner"></param>
        /// <param name="stopGeography">The parent of top geographies that could/should recieve volunteer (country) </param>
        public void AutoAssign (Geography geo, int withinOrg, Person defaultOwner, int stopGeography)
        {

            //Note: stopGeography is only needed because Districts ar not properly defined. Districts are the ones below country.
            try
            {
                this.Owner = defaultOwner;
                Geography volonteerGeography = geo;


                //Move up to target geography level
                //GeographyLevel targetLevel = GeographyLevel.ElectoralCircuit;
                GeographyLevel targetLevel = GeographyLevel.District; //This will never hit bcse Districts ar not properly defined

                while (!(volonteerGeography.AtLevel(targetLevel))
                    && (volonteerGeography.ParentGeographyId != 0)
                        && (volonteerGeography.ParentGeographyId != stopGeography)
                        )
                {
                    volonteerGeography = volonteerGeography.Parent;
                }

                Person localLead = Swarm.Roles.GetLocalLead(withinOrg, volonteerGeography.Identity);

                if (localLead == null && volonteerGeography.Parent != null)
                {
                    // Move "geography" up to district, wich are next below country, if no lead was found at the target level
                    while ((volonteerGeography.ParentGeographyId != 0)
                        && (volonteerGeography.ParentGeographyId != stopGeography)
                        )
                    {
                        volonteerGeography = volonteerGeography.Parent;
                    }
                    localLead = Swarm.Roles.GetLocalLead(withinOrg, volonteerGeography.Parent.Parent.Identity);
                }

                //Found anyone? otherwise leave default Owner.
                if (localLead != null)
                {
                    this.Owner = localLead;
                }
            }
            catch (Exception)
            {
            }
        }
Example #14
0
 public OutboundMail CreateOutboundFake (Person author, Organization organization, Geography geography)
 {
     return OutboundMail.CreateFake(author, this.BaseName, this.SerializePlaceHolders(), 0,
                                  this.MailType, organization, geography);
 }
Example #15
0
 public void DeleteUptakeGeography(Geography geo)
 {
     DeleteUptakeGeography(geo.Identity);
 }
Example #16
0
 public static Activists FromGeography (Geography geography)
 {
     Geographies geographies = geography.GetTree();
     return new Activists(SwarmDb.GetDatabaseForReading().GetActivistPersonIds(geographies.Identities));
 }
Example #17
0
        public static GeographyStatistics GeneratePresent(int[] memberCountForOrganizations)
        {
            Dictionary <int, int> voterCounts = SwarmDb.GetDatabaseForReading().GetGeographyVoterCounts();
            var result = new GeographyStatistics();

            // Step 1 - tally the leaf nodes

            foreach (int geographyId in voterCounts.Keys)
            {
                var dataPoint = new GeographyDataPoint
                {
                    GeographyName = Geography.FromIdentity(geographyId).Name,
                    GeographyId   = geographyId,
                    VoterCount    = voterCounts[geographyId]
                };

                result[geographyId] = dataPoint;
            }


            // Step 2 - add the member counts to the individual requested geo nodes

            foreach (int orgId in memberCountForOrganizations)
            {
                People members =
                    People.FromMemberships(
                        Memberships.ForOrganizations(Organization.FromIdentity(orgId).GetTree()));

                foreach (Person person in members)
                {
                    Geography geography = person.Geography;

                    // If we don't have this key, it's because it's too far down. Move up the tree until we're at least
                    // at municipal level.

                    while (geography.Identity != 1 && !result.ContainsKey(geography.Identity))
                    {
                        geography = geography.Parent;
                    }

                    // Add the data, unless we hit the roof in the last op.

                    if (geography.Identity != 1)
                    {
                        int birthYearBracket = (person.Birthdate.Year - 1900) / 5;

                        if (birthYearBracket >= 0 && birthYearBracket < 30)
                        {
                            result[geography.Identity].OrganizationData[orgId - 1].BirthYearBracketMemberCounts[
                                birthYearBracket]++;
                        }

                        if (person.IsFemale)
                        {
                            result[geography.Identity].OrganizationData[orgId - 1].FemaleMemberCount++;
                        }
                        else if (person.IsMale)
                        {
                            result[geography.Identity].OrganizationData[orgId - 1].MaleMemberCount++;
                        }
                    }
                }
            }

            // TODO: Activist count as a new step


            // Step 3 - add up the totals for every intermediate node (expensive!)

            Geographies allGeographies = Geography.Root.GetTree();

            foreach (Geography geography in allGeographies)
            {
                Geographies localTree   = geography.GetTree();
                int         voterCount  = 0;
                var         tempOrgData = new GeographyOrganizationDataPoint[2]; // HACK
                tempOrgData[0] = new GeographyOrganizationDataPoint();
                tempOrgData[1] = new GeographyOrganizationDataPoint();

                foreach (Geography localNode in localTree)
                {
                    // Increment our temp values for every geo node below the one we're currently processing.

                    if (!result.ContainsKey(localNode.Identity))
                    {
                        continue;
                    }

                    voterCount += result[localNode.Identity].VoterCount;

                    for (int orgIndex = 0; orgIndex < 2; orgIndex++)
                    {
                        for (int ageBracketIndex = 0; ageBracketIndex < 30; ageBracketIndex++)
                        {
                            tempOrgData[orgIndex].BirthYearBracketMemberCounts[ageBracketIndex] +=
                                result[localNode.Identity].OrganizationData[orgIndex].BirthYearBracketMemberCounts[
                                    ageBracketIndex];
                        }

                        tempOrgData[orgIndex].ActivistCount +=
                            result[localNode.Identity].OrganizationData[orgIndex].ActivistCount;
                        tempOrgData[orgIndex].FemaleMemberCount +=
                            result[localNode.Identity].OrganizationData[orgIndex].FemaleMemberCount;
                        tempOrgData[orgIndex].MaleMemberCount +=
                            result[localNode.Identity].OrganizationData[orgIndex].MaleMemberCount;
                    }
                }

                if (!result.ContainsKey(geography.Identity))
                {
                    result[geography.Identity] = new GeographyDataPoint
                    {
                        GeographyId   = geography.Identity,
                        GeographyName = geography.Name
                    };
                }

                // Save our temp values to the processed node.

                result[geography.Identity].VoterCount = voterCount;

                for (int orgIndex = 0; orgIndex < 2; orgIndex++)
                {
                    for (int ageBracketIndex = 0; ageBracketIndex < 30; ageBracketIndex++)
                    {
                        result[geography.Identity].OrganizationData[orgIndex].BirthYearBracketMemberCounts[
                            ageBracketIndex] =
                            tempOrgData[orgIndex].BirthYearBracketMemberCounts[ageBracketIndex];
                    }

                    result[geography.Identity].OrganizationData[orgIndex].ActivistCount =
                        tempOrgData[orgIndex].ActivistCount;
                    result[geography.Identity].OrganizationData[orgIndex].FemaleMemberCount =
                        tempOrgData[orgIndex].FemaleMemberCount;
                    result[geography.Identity].OrganizationData[orgIndex].MaleMemberCount =
                        tempOrgData[orgIndex].MaleMemberCount;
                }
            }


            // Step 4 - collect

            return(result);
        }
Example #18
0
 public bool Inherits (Geography prospectiveParent)
 {
     return Inherits(prospectiveParent.Identity);
 }
Example #19
0
 /// <summary>
 /// Creates an unusable OutboundMail. Used for rendering previews - ONLY.
 /// </summary>
 public static OutboundMail CreateFake (Person author, string title,
                                        string body, int mailType,
                                        Organization organization, Geography geography)
 {
     return FromBasic(new BasicOutboundMail(0, MailAuthorType.Person, author.PersonId, title,
                                              body, 99, mailType, organization.Identity,
                                              geography.Identity, DateTime.Now,
                                              DateTime.Now, false, false, false, DateTime.MinValue,
                                              DateTime.MinValue, DateTime.MinValue, 0, 0, 0));
 }
Example #20
0
        public static Memberships FilterMembershipsToMatchAuthority (Memberships memberships, Geography personGeography,
                                                                     Authority authority)
        {
            // First: If sysadmin, return the whole list uncensored.

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

            var 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

            var result = new Memberships();

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

            return result;
        }
Example #21
0
 public bool HasLocalRoleAtOrganizationGeography (Organization organization, Geography geography, Authorization.Flag flags)
 {
     return HasLocalRoleAtOrganizationGeography(organization, geography, RoleTypes.AllLocalRoleTypes, flags);
 }
Example #22
0
 public bool HasLocalRoleAtOrganizationGeography (Organization organization, Geography geography,
                                                  RoleType roleType, Authorization.Flag flags)
 {
     return HasLocalRoleAtOrganizationGeography(organization, geography,
                                                  new RoleType[] { roleType }, flags);
 }
Example #23
0
 public static RoleLookup FromGeographyAndOrganization (Geography geography, Organization organization)
 {
     return FromGeographyAndOrganization(geography.Identity, organization.Identity);
 }
Example #24
0
        public bool HasLocalRoleAtOrganizationGeography (Organization organization, Geography geography,
                                                         RoleType[] roleTypes, Authorization.Flag flags)
        {

            if (organization != null && organization.Identity == Organization.SandboxIdentity)
            {
                return true; // UGLY UGLY HACK
            }

            if (organization == null && (flags & Authorization.Flag.AnyOrganization) == 0)
                return false;

            if (geography == null && (flags & Authorization.Flag.AnyGeography) == 0)
                return false;


            foreach (BasicPersonRole role in LocalPersonRoles)
            {
                foreach (RoleType type in roleTypes)
                {
                    if (type == role.Type)
                    {
                        // Expensive op. The org/geo lookups need a cache at the logic layer.

                        bool organizationClear = false;
                        bool geographyClear = false;

                        // First, check if the organization and geography match identically.

                        if ((flags & Authorization.Flag.AnyOrganization) != 0)
                        {
                            // then it is used to check if they have a local role for any org
                            organizationClear = true;
                        }
                        else if (organization != null && organization.Identity == role.OrganizationId)
                        {
                            organizationClear = true;
                        }

                        if ((flags & Authorization.Flag.AnyGeography) != 0)
                        {
                            // then it is used to check if they have a local role anywhere
                            geographyClear = true;
                        }
                        else if (geography != null && geography.Identity == role.GeographyId)
                        {
                            geographyClear = true;
                        }


                        // If not clear, then check if there is inherited authority.

                        if (!organizationClear
                            && (flags & Authorization.Flag.ExactOrganization) == 0)
                        {
                            if (organization != null && organization.Inherits(role.OrganizationId))
                            {
                                organizationClear = true;
                            }
                        }

                        if (!geographyClear && (flags & Authorization.Flag.ExactGeography) == 0)
                        {
                            if (geography != null && geography.Inherits(role.GeographyId))
                            {
                                geographyClear = true;
                            }
                        }

                        // If both are ok, return that there is authority at this org & geo.

                        if (organizationClear && geographyClear)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Example #25
0
 public bool Inherits(Geography prospectiveParent)
 {
     return(Inherits(prospectiveParent.Identity));
 }
Example #26
0
 public PersonRole AddRole (RoleType roleType, Organization organization, Geography geography)
 {
     return AddRole(roleType, organization.Identity, geography.Identity);
 }
Example #27
0
        public static int GetCountForGeography (Geography geography)
        {
            Geographies geographies = geography.GetTree();

            return SwarmDb.GetDatabaseForReading().GetActivistCountForGeographies(geographies.Identities);
        }
Example #28
0
 public void AddUptakeGeography (Geography geo)
 {
     AddUptakeGeography(geo.Identity);
 }
Example #29
0
 public void AddUptakeGeography(Geography geo)
 {
     AddUptakeGeography(geo.Identity);
 }
Example #30
0
 public void DeleteUptakeGeography (Geography geo)
 {
     DeleteUptakeGeography(geo.Identity);
 }
Example #31
0
		private static void ValidatePoll (int pollId, Geography geography, DateTime cutoffMembershipDate)
		{
			Dictionary<string, People> result = SwedishForumDatabase.GetDatabase().GetPollVotes (pollId);

			foreach (string pollAlternative in result.Keys)
			{
				People voters = result[pollAlternative];

				Console.WriteLine ("");
				Console.WriteLine ("Votes for " + pollAlternative + ":");

				foreach (Person voter in voters)
				{
					// Console.Write (voter.Name + "... ");
					Console.Write (voter.Geography.Name);

					if (voter.Geography.Inherits (geography))
					{
						Console.Write (" (ok)");
					}
					else
					{
						Console.Write (" (INVALID)");
					}

					Console.Write ("... member since " + voter.GetMemberships() [0].MemberSince.ToString("yyyy-MMM"));

					if (voter.GetMemberships() [0].MemberSince > cutoffMembershipDate)
					{
						Console.WriteLine (" (INVALID)");
					}
					else
					{
						Console.WriteLine (" (ok)");
					}
				}
			}
		}
Example #32
0
 public void AddRole (Organization organization, Geography geography, RoleType roleType)
 {
     AddRole(organization.Identity, geography.Identity, roleType);
 }
Example #33
0
        private void PopulateCache ()
        {
            if (this.person == null)
            {
                this.person = Person.FromIdentity(PersonId);
            }

            if (this.ownerPerson == null)
            {
                this.ownerPerson = Person.FromIdentity(OwnerPersonId);
            }

            if (this.geography == null)
            {
                if (this.person.GeographyId != 0)
                {
                    this.geography = this.person.Geography;
                }
                else
                {
                    this.geography = Geography.Root;
                }
            }
        }
Example #34
0
 public OutboundMail CreateFunctionalOutboundMail (MailAuthorType authorType, int mailPriority,
                                    Organization organization, Geography geography, DateTime releaseDateTime)
 {
     return OutboundMail.CreateFunctional(authorType, this.BaseName, this.SerializePlaceHolders(),
                                 mailPriority, this.MailType, organization.Identity, geography.Identity, releaseDateTime);
 }