public bool CanTransformUserToOrganization(User accountToTransform, User adminUser, out string errorReason) { if (!CanTransformUserToOrganization(accountToTransform, out errorReason)) { return(false); } if (adminUser.MatchesUser(accountToTransform)) { errorReason = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_AdminMustBeDifferentAccount, adminUser.Username); } else if (!adminUser.Confirmed) { errorReason = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_AdminAccountNotConfirmed, adminUser.Username); } else if (adminUser is Organization) { errorReason = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_AdminAccountIsOrganization, adminUser.Username); } return(errorReason == null); }
public bool CanTransformUserToOrganization(User accountToTransform, User adminUser, out string errorReason) { if (!CanTransformUserToOrganization(accountToTransform, out errorReason)) { return(false); } if (adminUser.MatchesUser(accountToTransform)) { errorReason = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_AdminMustBeDifferentAccount, adminUser.Username); } else if (!adminUser.Confirmed) { errorReason = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_AdminAccountNotConfirmed, adminUser.Username); } else if (adminUser is Organization) { errorReason = String.Format(CultureInfo.CurrentCulture, Strings.TransformAccount_AdminAccountIsOrganization, adminUser.Username); } else { var tenantId = GetAzureActiveDirectoryCredentialTenant(adminUser); if (string.IsNullOrWhiteSpace(tenantId)) { errorReason = String.Format(CultureInfo.CurrentCulture, Strings.Organizations_AdminAccountDoesNotHaveTenant, adminUser.Username); } } return(errorReason == null); }
public bool ShouldMarkNewPackageIdVerified(User account, string id, out IReadOnlyCollection <ReservedNamespace> ownedMatchingReservedNamespaces) { ownedMatchingReservedNamespaces = GetReservedNamespacesForId(id) .Where(rn => rn.Owners.AnySafe(o => account.MatchesUser(o))) .ToList() .AsReadOnly(); return(ownedMatchingReservedNamespaces.Any()); }
internal static PermissionLevel GetPermissionLevel(IEnumerable <User> owners, User currentUser) { if (currentUser == null) { return(PermissionLevel.Anonymous); } return(GetPermissionLevel( owners, currentUser.IsAdministrator(), u => currentUser.MatchesUser(u))); }
private static bool HasPermission(IEnumerable <User> owners, User currentUser, PermissionLevel actionPermissionLevel) { if (currentUser == null) { return(PermissionLevelsIntersect(PermissionLevel.Anonymous, actionPermissionLevel)); } return(HasPermission( owners, currentUser.IsAdministrator(), u => currentUser.MatchesUser(u), actionPermissionLevel)); }
/// <summary> /// Is <paramref name="currentPrincipal"/> allowed to perform an action with a requirement of <paramref name="permissionsRequirement"/> on the entity owned by <paramref name="entityOwners"/>? /// </summary> public static bool IsRequirementSatisfied(PermissionsRequirement permissionsRequirement, User currentUser, ICollection <User> entityOwners) { if (currentUser == null) { /// If the current user is logged out, only <see cref="PermissionsRequirement.None"/> is satisfied. return(WouldSatisfy(PermissionsRequirement.None, permissionsRequirement)); } return(IsRequirementSatisfied( permissionsRequirement, currentUser.IsAdministrator, u => currentUser.MatchesUser(u), entityOwners)); }