public bool HasRoleAtOrganization (Organization organization, RoleType[] roleTypes, Authorization.Flag flags) { if (organization == null) { if ((flags & Authorization.Flag.AnyOrganization) != 0) return true; else return false; } if (organization != null && organization.Identity == Organization.SandboxIdentity) { return true; // UGLY UGLY HACK } foreach (BasicPersonRole role in OrganizationPersonRoles) { foreach (RoleType type in roleTypes) { if (type == role.Type) { if ((flags & Authorization.Flag.AnyOrganization) != 0) return true; if (organization.Identity == role.OrganizationId) { return true; } if ((flags & Authorization.Flag.ExactOrganization) == 0) { if (organization.Inherits(role.OrganizationId)) { return true; } } } } } return false; }
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; }