protected override void OnLoad(EventArgs e) { int currentUserId = 0; int currentOrganizationId = 0; string identity = HttpContext.Current.User.Identity.Name; string[] identityTokens = identity.Split(','); string userIdentityString = identityTokens[0]; string organizationIdentityString = identityTokens[1]; currentUserId = Convert.ToInt32(userIdentityString); currentOrganizationId = Convert.ToInt32(organizationIdentityString); _currentUser = Person.FromIdentity(currentUserId); _currentOrganization = Organization.FromIdentity(currentOrganizationId); _authority = _currentUser.GetAuthority(); base.OnLoad(e); }
//public void Terminate () //{ // Terminate(EventSource.Unknown); //} public void Terminate(EventSource eventSource, Person actingPerson, string description) { if (base.Active) { //Added removal of Roles here to make SURE they always are removed with the membership. Authority authority = Person.GetAuthority(); int actingPersonId = actingPerson == null ? 0 : actingPerson.Identity; BasicPersonRole[] roles = authority.AllPersonRoles; List <PersonRole> theRoles = new List <PersonRole>(); foreach (BasicPersonRole basicRole in roles) { PersonRole personRole = PersonRole.FromBasic(basicRole); theRoles.Add(personRole); if (personRole.OrganizationId == OrganizationId) { PWEvents.CreateEvent(eventSource, EventType.DeletedRole, actingPersonId, personRole.OrganizationId, personRole.GeographyId, Person.Identity, (int)personRole.Type, string.Empty); PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted, "Role " + personRole.Type + " of " + personRole.Geography.Name + " was deleted with membership.", string.Empty); personRole.Delete(); } } //now check if this means that you no longer are a member of some uplevel org, then remove those roles as well foreach (PersonRole personRole in theRoles) { if (!Person.MemberOfWithInherited(personRole.Organization)) { PWEvents.CreateEvent(eventSource, EventType.DeletedRole, actingPersonId, personRole.OrganizationId, personRole.GeographyId, Person.Identity, (int)personRole.Type, string.Empty); PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted, "Role " + personRole.Type + " of " + personRole.Geography.Name + " was deleted with membership of all suborgs.", string.Empty); personRole.Delete(); } } EventSource src = EventSource.PirateWeb; try { if (HttpContext.Current == null) { src = EventSource.PirateBot; } } catch { src = EventSource.PirateBot; } PWLog.Write(actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.MemberLost, eventSource + ":" + description, string.Empty); PWEvents.CreateEvent(src, EventType.LostMember, actingPersonId, OrganizationId, Person.GeographyId, Person.Identity, 0, OrganizationId.ToString()); //Added LogChurn here to make SURE they always are logged with the membership. if (PersonId > 0 && OrganizationId > 0 && base.Expires != new DateTime(1900, 1, 1)) { ChurnData.LogChurn(PersonId, OrganizationId); } SwarmDb.GetDatabaseForWriting().TerminateMembership(Identity); base.Active = false; base.DateTerminated = DateTime.Now; // Remove all newsletter subscriptions once the membership is terminated (to make sure default is now off and only turn off explicitly turned-on subscriptions) // HACK HACK HACK: uses feed IDs in an extremely ugly way to loop 1-9. Should use NewsletterFeeds.ForOrganization() once support for newsletters in different orgs are established. for (int newsletterFeedId = 1; newsletterFeedId < 10; newsletterFeedId++) { try { if (this.person.IsSubscribing(newsletterFeedId)) { this.person.SetSubscription(newsletterFeedId, false); } } catch (Exception) { // ignore nonexisting newsletter feeds -- this is a hack anyway } } } }
public static PersonIconSpec ForPerson (Person person, Organizations organizations) { // HACK: For now, cheat and assume only PPSE roles matter. A future expansion of this is needed. // HACK: Rehacked to use another org in case there is one and PPSE is not among selected Organization org = null; if (organizations.Contains(Organization.PPSE) || organizations.Count == 0) { org = Organization.PPSE; } else { org = organizations[0]; } bool isMember = false; foreach (Organization org1 in organizations) { if (person.MemberOf(org1)) isMember = true; } if (!isMember) { // if he/she used to be a member, use exmember icons Memberships memberships = person.GetMemberships(true); foreach (Membership membership in memberships) { if (membership.Organization.Identity == org.Identity) { return new PersonIconSpec("pwcustom/exmember-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Expired member, " + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } } // If activist, use activist icon (as sex is unknown, use silhouette) if (person.IsActivist) { return new PersonIconSpec("pwcustom/activist-silhouette.png", "Activist"); } // TODO: Add case for was-activist // otherwise, use unknown icon return new PersonIconSpec("user-silhouette.png", "Unknown"); } Authority auth = person.GetAuthority(); if (auth.SystemPersonRoles.Length == 0 && auth.LocalPersonRoles.Length == 0 && auth.OrganizationPersonRoles.Length == 0) { // This is a fairly regular joe. if (person.IsActivist) { return new PersonIconSpec("pwcustom/activist-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Activist, " + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } else { return new PersonIconSpec("pwcustom/member-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Member, " + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } } // HACK: Cheat and return "org leader" for ID 1 if (person.Identity == 1) { return new PersonIconSpec("pwcustom/orglevel-3-male.png", "Org Lead"); } bool foundOddRole = false; foreach (Organization org1 in organizations) { string orgName = org1.NameShort + ", "; if (org1 == Organization.PPSE) orgName = ""; // Chairman / equivalent if (auth.HasRoleAtOrganization(org1, RoleType.OrganizationChairman, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/boardlevel-3-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Chairman, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // Board member if (auth.HasRoleAtOrganization(org1, RoleType.OrganizationBoardMember, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/boardlevel-2-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Board member, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // Board deputy if (auth.HasRoleAtOrganization(org1, RoleType.OrganizationBoardDeputy, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/boardlevel-1-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Board deputy, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // Auditor if (auth.HasRoleAtOrganization(org1, RoleType.OrganizationAuditor, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/boardlevel-1-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Autitor, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // Org-level leader or deputy if (auth.HasLocalRoleAtOrganizationGeography(org1, org1.PrimaryGeography, RoleType.LocalLead, Authorization.Flag.ExactGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/orglevel-3-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Org Lead, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } if (auth.HasLocalRoleAtOrganizationGeography(org1, org1.PrimaryGeography, RoleType.LocalDeputy, Authorization.Flag.ExactGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/orglevel-3-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Org Deputy, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // Org-level secretary if (auth.HasRoleAtOrganization(org1, RoleType.OrganizationSecretary, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/orglevel-2-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Org secretary, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // system roles if (auth.HasRoleType(RoleType.SystemAdmin)) { return new PersonIconSpec("user-worker.png", "Sys.adm., " + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // Org-level admin if (auth.HasRoleAtOrganization(org1, RoleType.OrganizationAdmin, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/orglevel-1-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Org admin, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } if (auth.HasLocalRoleAtOrganizationGeography(org1, org1.PrimaryGeography, RoleType.LocalAdmin, Authorization.Flag.ExactGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/orglevel-1-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Org admin, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } // TODO: ADD THE REST OF THE ROLES HERE SOMEWHERE // local roles if (auth.HasLocalRoleAtOrganizationGeography(org1, Geography.Root, RoleType.LocalLead, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/officer-lead-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Local lead, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } if (auth.HasLocalRoleAtOrganizationGeography(org1, Geography.Root, RoleType.LocalDeputy, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/officer-deputy-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Local deputy, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } if (auth.HasLocalRoleAtOrganizationGeography(org1, Geography.Root, RoleType.LocalAdmin, Authorization.Flag.AnyGeographyExactOrganization)) { return new PersonIconSpec("pwcustom/officer-admin-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Local admin, " + orgName + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } if (auth.HasRoleAtOrganization(org1, Authorization.Flag.AnyGeographyExactOrganization) || auth.HasLocalRoleAtOrganizationGeography(org1, Geography.Root, Authorization.Flag.AnyGeographyExactOrganization)) { foundOddRole = true; } } if (!foundOddRole) { if (person.IsActivist) { return new PersonIconSpec("pwcustom/activist-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Activist, " + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } else { return new PersonIconSpec("pwcustom/member-" + (person.IsFemale ? "female" : person.IsMale ? "male" : "") + ".png", "Member, " + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } } else { // unhandled role type return new PersonIconSpec("user-silhouette-question.png", "unknown role, " + (person.IsFemale ? "female" : person.IsMale ? "male" : "")); } }