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));
        }
예제 #2
0
        public virtual ActionResult Packages()
        {
            var user = GetCurrentUser();

            var owners = new List <ListPackageOwnerViewModel> {
                new ListPackageOwnerViewModel
                {
                    Username = "******"
                },
                new ListPackageOwnerViewModel(user)
                {
                    CanManagePackageOwners = PermissionsService.IsActionAllowed(
                        account: user,
                        currentUser: user,
                        action: PackageActions.ManagePackageOwners)
                }
            }.Concat(user.Organizations.Select(o => new ListPackageOwnerViewModel(o.Organization)
            {
                CanManagePackageOwners = PermissionsService.IsActionAllowed(
                    account: o.Organization,
                    currentUser: user,
                    action: PackageActions.ManagePackageOwners)
            }));

            var packages       = _packageService.FindPackagesByAnyMatchingOwner(user, includeUnlisted: true);
            var listedPackages = packages
                                 .Where(p => p.Listed)
                                 .Select(p => new ListPackageItemViewModel(p)).OrderBy(p => p.Id)
                                 .ToList();
            var unlistedPackages = packages
                                   .Where(p => !p.Listed)
                                   .Select(p => new ListPackageItemViewModel(p)).OrderBy(p => p.Id)
                                   .ToList();

            var incoming = _packageOwnerRequestService.GetPackageOwnershipRequests(newOwner: user);
            var outgoing = _packageOwnerRequestService.GetPackageOwnershipRequests(requestingOwner: user);

            var ownerRequests    = new OwnerRequestsViewModel(incoming, outgoing, user, _packageService);
            var reservedPrefixes = new ReservedNamespaceListViewModel(user.ReservedNamespaces);

            var model = new ManagePackagesViewModel
            {
                Owners             = owners,
                ListedPackages     = listedPackages,
                UnlistedPackages   = unlistedPackages,
                OwnerRequests      = ownerRequests,
                ReservedNamespaces = reservedPrefixes
            };

            return(View(model));
        }
예제 #3
0
        private OwnerRequestsViewModel CreateOwnerRequestsViewModel(IEnumerable <PackageOwnerRequest> received, IEnumerable <PackageOwnerRequest> sent, User currentUser)
        {
            var viewModel = new OwnerRequestsViewModel
            {
                Received = new OwnerRequestsListViewModel
                {
                    Requests = received.Select(r => CreateOwnerRequestsListItemViewModel(r, currentUser)).ToList()
                },
                Sent = new OwnerRequestsListViewModel
                {
                    Requests = sent.Select(r => CreateOwnerRequestsListItemViewModel(r, currentUser)).ToList()
                },
            };

            return(viewModel);
        }
예제 #4
0
        public virtual ActionResult Packages()
        {
            var user     = GetCurrentUser();
            var packages = _packageService.FindPackagesByOwner(user, includeUnlisted: true)
                           .Select(p => new ListPackageItemViewModel(p)).OrderBy(p => p.Id).ToList();

            var incoming = _packageOwnerRequestService.GetPackageOwnershipRequests(newOwner: user);
            var outgoing = _packageOwnerRequestService.GetPackageOwnershipRequests(requestingOwner: user);

            var ownerRequests = new OwnerRequestsViewModel(incoming, outgoing, user, _packageService);

            var model = new ManagePackagesViewModel
            {
                Packages      = packages,
                OwnerRequests = ownerRequests
            };

            return(View(model));
        }
예제 #5
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 packages       = _packageService.FindPackagesByAnyMatchingOwner(currentUser, includeUnlisted: true);
            var listedPackages = packages
                                 .Where(p => p.Listed)
                                 .Select(p => new ListPackageItemViewModel(p, currentUser)).OrderBy(p => p.Id)
                                 .ToList();
            var unlistedPackages = packages
                                   .Where(p => !p.Listed)
                                   .Select(p => new ListPackageItemViewModel(p, currentUser)).OrderBy(p => p.Id)
                                   .ToList();

            var received = _packageOwnerRequestService.GetPackageOwnershipRequests(newOwner: currentUser);
            var sent     = _packageOwnerRequestService.GetPackageOwnershipRequests(requestingOwner: currentUser);

            var ownerRequests    = new OwnerRequestsViewModel(received, sent, currentUser, _packageService);
            var reservedPrefixes = new ReservedNamespaceListViewModel(currentUser.ReservedNamespaces);

            var model = new ManagePackagesViewModel
            {
                Owners             = owners,
                ListedPackages     = listedPackages,
                UnlistedPackages   = unlistedPackages,
                OwnerRequests      = ownerRequests,
                ReservedNamespaces = reservedPrefixes
            };

            return(View(model));
        }