Exemple #1
0
        public async Task <IEnumerable <PendingAccessRequest> > GetAccessRequests(int profileId)
        {
            var user = await this.userManager.GetUserAsync(HttpContext.User);

            var userPermissionLevel = await this.dataRepo.GetProfilePermissionForUserAsync(profileId, user.Id);

            if (!userPermissionLevel.HasValue ||
                !PermissionsOrder.GreaterThanOrEqual(userPermissionLevel.Value, GuildProfilePermissionLevel.Officer))
            {
                throw new UserReportableError($"User does not have permissions to approve access requests for profile '{profileId}'.",
                                              (int)HttpStatusCode.Unauthorized);
            }

            var efRequests = await this.dataRepo.GetAccessRequestsAsync(profileId);

            return(efRequests.Select(x => new PendingAccessRequest()
            {
                Id = x.Id,
                CreatedOn = x.CreatedOn,
                ProfileId = x.ProfileId,
                User = new UserStub()
                {
                    Id = x.Requester.Id,
                    Email = x.Requester.Email,
                    Username = x.Requester.UserName
                }
            }));
        }
Exemple #2
0
        public async Task <FullGuildProfile> GetFullGuildProfile(int profileId)
        {
            var user = await this.userManager.GetUserAsync(HttpContext.User);

            var permissionLevel = await this.GetCurrentPermissionLevel(profileId, user);

            bool isOfficer = permissionLevel.HasValue
                ? PermissionsOrder.GreaterThanOrEqual(permissionLevel.Value,
                                                      GuildProfilePermissionLevel.Officer)
                : false;

            var repoProfile = await this.dataRepo.GetFullGuildProfileAsync(profileId);

            var efProfile = repoProfile;

            var returnProfile = new FullGuildProfile()
            {
                Id          = efProfile.Id,
                ProfileName = efProfile.ProfileName,
                Creator     = new UserStub()
                {
                    Id       = efProfile.Creator?.Id,
                    Email    = efProfile.Creator?.Email,
                    Username = efProfile.Creator?.UserName
                },
                GuildName = efProfile.CreatorGuild?.Name,
                Mains     = efProfile.PlayerMains.Select(x => this.MapPlayerMain(x, isOfficer)),
                Realm     = new StoredRealm()
                {
                    Id       = efProfile.Realm.Id,
                    Name     = efProfile.Realm.Name,
                    RegionId = efProfile.Realm.Region.Id
                },
                Region             = efProfile.Realm.Region.RegionName,
                IsPublic           = efProfile.IsPublic,
                FriendGuilds       = efProfile.FriendGuilds.Select(x => this.mapper.Map <FriendGuild>(x)),
                AccessRequestCount = isOfficer ? efProfile.AccessRequests.Count() : 0
            };

            returnProfile.Players =
                (await this.GetOrInsertAllProfileGuilds(efProfile))
                .Select(x => this.mapper.Map <StoredPlayer>(x));

            returnProfile.CurrentPermissionLevel = (int?)permissionLevel;

            return(returnProfile);
        }
Exemple #3
0
        public async Task <PlayerMain> PromoteAltToMain([FromBody] PromoteAltToMain input)
        {
            var user = await this.userManager.GetUserAsync(HttpContext.User);

            if (!await this.UserCanPromoteAltsAsync(user, input.ProfileId))
            {
                throw new UserReportableError("This user doesn't have permissions to perform this operation.", 401);
            }

            var permissionLevel = await this.GetCurrentPermissionLevel(input.ProfileId, user);

            bool isOfficer = permissionLevel.HasValue
                ? PermissionsOrder.GreaterThanOrEqual(permissionLevel.Value,
                                                      GuildProfilePermissionLevel.Officer)
                : false;

            var newMain = await this.dataRepo.PromoteAltToMainAsync(input.AltId, input.ProfileId);

            return(this.MapPlayerMain(newMain, isOfficer));
        }