/* Fix for Ticket #64 - showing role and geography of assignable leaders */ private string GetRoles(int personId) { string roles = String.Empty; Authority authority = Authorization.GetPersonAuthority(personId); Dictionary <RoleType, List <string> > rolesDict = new Dictionary <RoleType, List <string> >(); rolesDict.Add(RoleType.LocalLead, new List <string>()); rolesDict.Add(RoleType.LocalDeputy, new List <string>()); rolesDict.Add(RoleType.LocalAdmin, new List <string>()); foreach (Activizr.Basic.Types.BasicPersonRole basicRole in authority.LocalPersonRoles) { PersonRole personRole = PersonRole.FromBasic(basicRole); if (personRole.Type == RoleType.LocalLead || personRole.Type == RoleType.LocalDeputy || personRole.Type == RoleType.LocalAdmin) { rolesDict[personRole.Type].Add(personRole.Geography.Name); } } foreach (RoleType r in rolesDict.Keys) { if (rolesDict[r].Count > 0) { string innerroles = r.ToString().Replace("Local", "") + ":"; foreach (string town in rolesDict[r]) { innerroles += town.Replace("Distriktet", "distr.").Replace("valkrets", "valkr.").Replace("kommun", "k.") + ", "; } roles += innerroles.Substring(0, innerroles.Length - 2) + " "; } } if (!string.IsNullOrEmpty(roles)) { roles = " (" + roles + ")"; } return(roles); }
// This should run daily, suggested right after midnight. public static void ChurnExpiredMembers() { Organizations organizations = Organizations.GetAll(); foreach (Organization organization in organizations) { Memberships memberships = Memberships.GetExpired(organization); // Mail each expiring member foreach (Membership membership in memberships) { //only remove expired memberships if (membership.Expires > DateTime.Now.Date) { continue; } Person person = membership.Person; // Remove all roles and responsibilities for this person in the org Authority authority = person.GetAuthority(); foreach (BasicPersonRole basicRole in authority.LocalPersonRoles) { PersonRole personRole = PersonRole.FromBasic(basicRole); if (personRole.OrganizationId == membership.OrganizationId) { PWEvents.CreateEvent(EventSource.PirateBot, EventType.DeletedRole, person.Identity, personRole.OrganizationId, personRole.GeographyId, person.Identity, (int)personRole.Type, string.Empty); personRole.Delete(); } } // Mail Memberships personMemberships = person.GetMemberships(); Memberships membershipsToDelete = new Memberships(); foreach (Membership personMembership in personMemberships) { if (personMembership.Expires <= DateTime.Now.Date) { membershipsToDelete.Add(personMembership); } } ExpiredMail expiredmail = new ExpiredMail(); string membershipsIds = ""; if (membershipsToDelete.Count > 1) { foreach (Membership personMembership in membershipsToDelete) { membershipsIds += "," + personMembership.MembershipId; } membershipsIds = membershipsIds.Substring(1); string expiredMemberships = ""; foreach (Membership personMembership in membershipsToDelete) { if (personMembership.OrganizationId != organization.Identity) { expiredMemberships += ", " + personMembership.Organization.Name; } } expiredMemberships += ". "; expiredmail.pMemberships = expiredMemberships.Substring(2).Trim(); } //TODO: URL for renewal, recieving end of this is NOT yet implemented... // intended to recreate the memberships in MID string tokenBase = person.PasswordHash + "-" + membership.Expires.Year; string stdLink = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" + person.Identity + "&SecHash=" + SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8) + "&MID=" + membershipsIds; expiredmail.pStdRenewLink = stdLink; expiredmail.pOrgName = organization.MailPrefixInherited; person.SendNotice(expiredmail, organization.Identity); person.DeleteSubscriptionData(); string orgIdString = string.Empty; foreach (Membership personMembership in membershipsToDelete) { if (personMembership.Active) { orgIdString += " " + personMembership.OrganizationId; personMembership.Terminate(EventSource.PirateBot, null, "Member churned in housekeeping."); } } } } }