예제 #1
0
        private async Task <bool> IsAdmin(EfModels.UserWithData user)
        {
            if (user == null)
            {
                return(false);
            }

            var roles = await this.GetRolesForUser(user);

            return(roles.Any(r => r == GuildToolsRoles.AdminRole.Name));
        }
예제 #2
0
        private async Task <bool> UserHasStandardOfficerPermissions(int profileId, EfModels.UserWithData user)
        {
            if (await this.IsAdmin(user))
            {
                return(true);
            }

            if (await this.dataRepo.ProfileIsPublicAsync(profileId))
            {
                return(true);
            }

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

            if (!permissionsForProfile.HasValue)
            {
                return(false);
            }

            return(PermissionsOrder.GetPermissionOrder(permissionsForProfile.Value)
                   >= PermissionsOrder.GetPermissionOrder(GuildProfilePermissionLevel.Officer));
        }
예제 #3
0
 private async Task <IEnumerable <string> > GetRolesForUser(EfModels.UserWithData user)
 {
     return(await this.userManager.GetRolesAsync(user));
 }
예제 #4
0
        private async Task <GuildProfilePermissionLevel?> GetCurrentPermissionLevel(int profileId, EfModels.UserWithData user)
        {
            var isAdminTask           = this.IsAdmin(user);
            var profilePermissionTask = this.dataRepo.GetProfilePermissionForUserAsync(profileId, user?.Id);

            await Task.WhenAll(isAdminTask, profilePermissionTask);

            if (isAdminTask.Result)
            {
                return(GuildProfilePermissionLevel.Admin);
            }

            if (!profilePermissionTask.Result.HasValue)
            {
                return(null);
            }

            return(profilePermissionTask.Result.Value);
        }
예제 #5
0
 private async Task <bool> UserCanAddRemoveFriendGuilds(int profileId, EfModels.UserWithData user)
 {
     return(await this.UserHasStandardOfficerPermissions(profileId, user));
 }
예제 #6
0
 private async Task <bool> UserCanEditNotes(int profileId, EfModels.UserWithData user)
 {
     return(await this.UserHasStandardOfficerPermissions(profileId, user));
 }
예제 #7
0
 private async Task <bool> CanUpdatePermissions(EfModels.UserWithData user, int profileId)
 {
     return(await this.UserHasStandardOfficerPermissions(profileId, user));
 }
예제 #8
0
 private async Task <bool> UserCanApproveAccessRequest(EfModels.UserWithData user, int profileId)
 {
     return(await this.UserHasStandardOfficerPermissions(profileId, user));
 }
예제 #9
0
 private async Task <bool> UserCanPromoteAltsAsync(EfModels.UserWithData user, int profileId)
 {
     return(await this.UserHasStandardOfficerPermissions(profileId, user));
 }