public OrganizationMemberViewModel(Membership membership)
        {
            var member = membership?.Member ?? throw new ArgumentNullException(nameof(membership));

            Username     = member.Username;
            EmailAddress = member.EmailAddress;
            IsAdmin      = membership.IsAdmin;
            GravatarUrl  = GravatarHelper.Url(EmailAddress, Constants.GravatarElementSize);
        }
예제 #2
0
 public PackageOwnersResultViewModel(User user, User currentUser, PackageRegistration packageRegistration, UrlHelper url, bool isPending, bool isNamespaceOwner)
 {
     Name                             = user.Username;
     EmailAddress                     = user.EmailAddress;
     ProfileUrl                       = url.User(user, relativeUrl: false);
     ImageUrl                         = GravatarHelper.Url(user.EmailAddress, size: GalleryConstants.GravatarImageSize);
     GrantsCurrentUserAccess          = ActionsRequiringPermissions.ManagePackageOwnership.CheckPermissions(currentUser, user, packageRegistration) == PermissionsCheckResult.Allowed;
     IsCurrentUserAdminOfOrganization = (user as Organization)?.GetMembershipOfUser(currentUser)?.IsAdmin ?? false;
     Pending                          = isPending;
     IsNamespaceOwner                 = isNamespaceOwner;
 }
        private OrganizationMemberViewModel(User member)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            Username     = member.Username;
            EmailAddress = member.EmailAddress;
            GravatarUrl  = GravatarHelper.Url(EmailAddress, Constants.GravatarElementSize);
        }
 public PackageOwnersResultViewModel(User user, User currentUser, UrlHelper url, bool isPending, bool isNamespaceOwner)
 {
     Name                              = user.Username;
     EmailAddress                      = user.EmailAddress;
     ProfileUrl                        = url.User(user, relativeUrl: false);
     ImageUrl                          = GravatarHelper.Url(user.EmailAddress, size: Constants.GravatarImageSize);
     GrantsCurrentUserAccess           = PermissionsService.IsActionAllowed(user, currentUser, AccountActions.ManagePackageOwnershipOnBehalfOf);
     IsCurrentUserMemberOfOrganization = PermissionsService.IsActionAllowed(user, currentUser, AccountActions.DisplayPrivateOrganization);
     Pending                           = isPending;
     IsNamespaceOwner                  = isNamespaceOwner;
 }
예제 #5
0
        public virtual ActionResult GetPackageOwners(string id, string version)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(Json(new { message = Strings.AddOwner_PackageNotFound }));
            }

            if (!package.IsOwner(HttpContext.User))
            {
                return(new HttpUnauthorizedResult());
            }

            var owners = from u in package.PackageRegistration.Owners
                         select new
            {
                Name         = u.Username,
                EmailAddress = u.EmailAddress,
                Current      = u.Username == HttpContext.User.Identity.Name,
                Pending      = false
            };

            var pending =
                _packageOwnerRequestService.GetPackageOwnershipRequests(package: package.PackageRegistration)
                .Select(r => new
            {
                Name         = r.NewOwner.Username,
                EmailAddress = r.NewOwner.EmailAddress,
                Current      = false,
                Pending      = true
            });

            var result = owners.Union(pending).Select(o => new
            {
                name       = o.Name,
                profileUrl = Url.User(o.Name, relativeUrl: false),
                imageUrl   = GravatarHelper.Url(o.EmailAddress, size: Constants.GravatarImageSize),
                current    = o.Current,
                pending    = o.Pending,
            });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public async Task <JsonResult> AddPackageOwner(string id, string username, string message)
        {
            ManagePackageOwnerModel model;

            if (TryGetManagePackageOwnerModel(id, username, out model))
            {
                var encodedMessage = HttpUtility.HtmlEncode(message);

                var ownerRequest = await _packageOwnerRequestService.AddPackageOwnershipRequest(
                    model.Package, model.CurrentUser, model.User);

                var confirmationUrl = Url.ConfirmPendingOwnershipRequest(
                    model.Package.Id,
                    model.User.Username,
                    ownerRequest.ConfirmationCode,
                    relativeUrl: false);

                var rejectionUrl = Url.RejectPendingOwnershipRequest(
                    model.Package.Id,
                    model.User.Username,
                    ownerRequest.ConfirmationCode,
                    relativeUrl: false);

                var packageUrl    = Url.Package(model.Package.Id, version: null, relativeUrl: false);
                var policyMessage = GetNoticeOfPoliciesRequiredMessage(model.Package, model.User, model.CurrentUser);

                _messageService.SendPackageOwnerRequest(model.CurrentUser, model.User, model.Package, packageUrl,
                                                        confirmationUrl, rejectionUrl, encodedMessage, policyMessage);

                return(Json(new
                {
                    success = true,
                    name = model.User.Username,
                    profileUrl = Url.User(model.User.Username, relativeUrl: false),
                    imageUrl = GravatarHelper.Url(model.User.EmailAddress, size: Constants.GravatarImageSize),
                    pending = true
                }));
            }
            else
            {
                return(Json(new { success = false, message = model.Error }, JsonRequestBehavior.AllowGet));
            }
        }
        public OrganizationMemberViewModel(MembershipRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var member = request.NewMember;

            if (member == null)
            {
                throw new ArgumentNullException(nameof(request.NewMember));
            }

            Username    = member.Username;
            IsAdmin     = request.IsAdmin;
            Pending     = true;
            GravatarUrl = GravatarHelper.Url(member.EmailAddress, Constants.GravatarElementSize);
        }
예제 #8
0
        public virtual ActionResult GetPackageOwners(string id, string version)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(Json(new { message = Strings.AddOwner_PackageNotFound }));
            }

            if (!package.IsOwnerOrAdmin(HttpContext.User))
            {
                return(new HttpUnauthorizedResult());
            }

            var currentUserName            = HttpContext.User.Identity.Name;
            var packageRegistrationOwners  = package.PackageRegistration.Owners;
            var allMatchingNamespaceOwners = package
                                             .PackageRegistration
                                             .ReservedNamespaces
                                             .SelectMany(rn => rn.Owners)
                                             .Distinct();

            var packageAndReservedNamespaceOwners = packageRegistrationOwners.Intersect(allMatchingNamespaceOwners);
            var packageOwnersOnly = packageRegistrationOwners.Except(packageAndReservedNamespaceOwners);

            var owners =
                packageAndReservedNamespaceOwners
                .Select(u => new PackageOwnersResultViewModel(
                            u.Username,
                            u.EmailAddress,
                            isCurrentUser: u.Username == currentUserName,
                            isPending: false,
                            isNamespaceOwner: true));

            var packageOwnersOnlyResultViewModel =
                packageOwnersOnly
                .Select(u => new PackageOwnersResultViewModel(
                            u.Username,
                            u.EmailAddress,
                            isCurrentUser: u.Username == currentUserName,
                            isPending: false,
                            isNamespaceOwner: false));

            owners = owners.Union(packageOwnersOnlyResultViewModel);

            var pending =
                _packageOwnershipManagementService.GetPackageOwnershipRequests(package: package.PackageRegistration)
                .Select(r => new PackageOwnersResultViewModel(
                            r.NewOwner.Username,
                            r.NewOwner.EmailAddress,
                            isCurrentUser: false,
                            isPending: true,
                            isNamespaceOwner: false));

            var result = owners.Union(pending).Select(o => new
            {
                name             = o.Name,
                profileUrl       = Url.User(o.Name, relativeUrl: false),
                imageUrl         = GravatarHelper.Url(o.EmailAddress, size: Constants.GravatarImageSize),
                current          = o.Current,
                pending          = o.Pending,
                isNamespaceOwner = o.IsNamespaceOwner
            });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }