Example #1
0
#pragma warning restore CA3147 // No need to Validate Antiforgery Token for abstract function

        protected List <DeleteAccountListPackageItemViewModel> GetOwnedPackagesViewModels(User account)
        {
            return(PackageService
                   .FindPackagesByAnyMatchingOwner(account, includeUnlisted: true)
                   .Select(p => CreateDeleteAccountListPackageItemViewModel(p, account, GetCurrentUser()))
                   .ToList());
        }
        public virtual ActionResult Packages()
        {
            var currentUser = GetCurrentUser();

            var owners = new List <ListPackageOwnerViewModel> {
                new ListPackageOwnerViewModel
                {
                    Username = "******"
                },
                new ListPackageOwnerViewModel(currentUser)
            }.Concat(currentUser.Organizations.Select(o => new ListPackageOwnerViewModel(o.Organization)));

            var wasMultiFactorAuthenticated = User.WasMultiFactorAuthenticated();

            var packages       = PackageService.FindPackagesByAnyMatchingOwner(currentUser, includeUnlisted: true);
            var listedPackages = packages
                                 .Where(p => p.Listed)
                                 .Select(p => new ListPackageItemRequiredSignerViewModel(p, currentUser, SecurityPolicyService, wasMultiFactorAuthenticated))
                                 .OrderBy(p => p.Id)
                                 .ToList();
            var unlistedPackages = packages
                                   .Where(p => !p.Listed)
                                   .Select(p => new ListPackageItemRequiredSignerViewModel(p, currentUser, SecurityPolicyService, wasMultiFactorAuthenticated))
                                   .OrderBy(p => p.Id)
                                   .ToList();

            // find all received ownership requests
            var userReceived = _packageOwnerRequestService.GetPackageOwnershipRequests(newOwner: currentUser);
            var orgReceived  = currentUser.Organizations
                               .Where(m => ActionsRequiringPermissions.HandlePackageOwnershipRequest.CheckPermissions(currentUser, m.Organization) == PermissionsCheckResult.Allowed)
                               .SelectMany(m => _packageOwnerRequestService.GetPackageOwnershipRequests(newOwner: m.Organization));
            var received = userReceived.Union(orgReceived);

            // find all sent ownership requests
            var userSent = _packageOwnerRequestService.GetPackageOwnershipRequests(requestingOwner: currentUser);
            var orgSent  = currentUser.Organizations
                           .Where(m => ActionsRequiringPermissions.HandlePackageOwnershipRequest.CheckPermissions(currentUser, m.Organization) == PermissionsCheckResult.Allowed)
                           .SelectMany(m => _packageOwnerRequestService.GetPackageOwnershipRequests(requestingOwner: m.Organization));
            var sent = userSent.Union(orgSent);

            var ownerRequests = new OwnerRequestsViewModel(received, sent, currentUser, PackageService);

            var userReservedNamespaces          = currentUser.ReservedNamespaces;
            var organizationsReservedNamespaces = currentUser.Organizations.SelectMany(m => m.Organization.ReservedNamespaces);

            var reservedPrefixes = new ReservedNamespaceListViewModel(userReservedNamespaces.Union(organizationsReservedNamespaces).ToArray());

            var model = new ManagePackagesViewModel
            {
                User                        = currentUser,
                Owners                      = owners,
                ListedPackages              = listedPackages,
                UnlistedPackages            = unlistedPackages,
                OwnerRequests               = ownerRequests,
                ReservedNamespaces          = reservedPrefixes,
                WasMultiFactorAuthenticated = User.WasMultiFactorAuthenticated()
            };

            return(View(model));
        }
Example #3
0
        public virtual ActionResult Packages()
        {
            var currentUser = GetCurrentUser();

            var owners = new List <ListPackageOwnerViewModel> {
                new ListPackageOwnerViewModel
                {
                    Username = "******"
                },
                new ListPackageOwnerViewModel(currentUser)
            }.Concat(currentUser.Organizations.Select(o => new ListPackageOwnerViewModel(o.Organization)));

            var wasAADLoginOrMultiFactorAuthenticated = User.WasMultiFactorAuthenticated() || User.WasAzureActiveDirectoryAccountUsedForSignin();

            var packages       = PackageService.FindPackagesByAnyMatchingOwner(currentUser, includeUnlisted: true);
            var listedPackages = packages
                                 .Where(p => p.Listed && p.PackageStatusKey == PackageStatus.Available)
                                 .Select(p => _listPackageItemRequiredSignerViewModelFactory.Create(p, currentUser, wasAADLoginOrMultiFactorAuthenticated))
                                 .OrderBy(p => p.Id)
                                 .ToList();
            var unlistedPackages = packages
                                   .Where(p => !p.Listed || p.PackageStatusKey != PackageStatus.Available)
                                   .Select(p => _listPackageItemRequiredSignerViewModelFactory.Create(p, currentUser, wasAADLoginOrMultiFactorAuthenticated))
                                   .OrderBy(p => p.Id)
                                   .ToList();

            // find all received ownership requests
            var userReceived = _packageOwnerRequestService.GetPackageOwnershipRequests(newOwner: currentUser);
            var orgReceived  = currentUser.Organizations
                               .Where(m => ActionsRequiringPermissions.HandlePackageOwnershipRequest.CheckPermissions(currentUser, m.Organization) == PermissionsCheckResult.Allowed)
                               .SelectMany(m => _packageOwnerRequestService.GetPackageOwnershipRequests(newOwner: m.Organization));
            var received = userReceived.Union(orgReceived);

            // find all sent ownership requests
            var userSent = _packageOwnerRequestService.GetPackageOwnershipRequests(requestingOwner: currentUser);
            var orgSent  = currentUser.Organizations
                           .Where(m => ActionsRequiringPermissions.HandlePackageOwnershipRequest.CheckPermissions(currentUser, m.Organization) == PermissionsCheckResult.Allowed)
                           .SelectMany(m => _packageOwnerRequestService.GetPackageOwnershipRequests(requestingOwner: m.Organization));
            var sent = userSent.Union(orgSent);

            var ownerRequests = CreateOwnerRequestsViewModel(received, sent, currentUser);

            var userReservedNamespaces          = currentUser.ReservedNamespaces;
            var organizationsReservedNamespaces = currentUser.Organizations.SelectMany(m => m.Organization.ReservedNamespaces);

            var reservedPrefixes = new ReservedNamespaceListViewModel(userReservedNamespaces.Union(organizationsReservedNamespaces).ToArray());

            var model = new ManagePackagesViewModel
            {
                User                        = currentUser,
                Owners                      = owners,
                ListedPackages              = listedPackages,
                UnlistedPackages            = unlistedPackages,
                OwnerRequests               = ownerRequests,
                ReservedNamespaces          = reservedPrefixes,
                WasMultiFactorAuthenticated = User.WasMultiFactorAuthenticated(),
                IsCertificatesUIEnabled     = ContentObjectService.CertificatesConfiguration?.IsUIEnabledForUser(currentUser) ?? false
            };

            return(View(model));
        }