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)); }
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)); }
private async Task <IEnumerable <string> > GetRolesForUser(EfModels.UserWithData user) { return(await this.userManager.GetRolesAsync(user)); }
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); }
private async Task <bool> UserCanAddRemoveFriendGuilds(int profileId, EfModels.UserWithData user) { return(await this.UserHasStandardOfficerPermissions(profileId, user)); }
private async Task <bool> UserCanEditNotes(int profileId, EfModels.UserWithData user) { return(await this.UserHasStandardOfficerPermissions(profileId, user)); }
private async Task <bool> CanUpdatePermissions(EfModels.UserWithData user, int profileId) { return(await this.UserHasStandardOfficerPermissions(profileId, user)); }
private async Task <bool> UserCanApproveAccessRequest(EfModels.UserWithData user, int profileId) { return(await this.UserHasStandardOfficerPermissions(profileId, user)); }
private async Task <bool> UserCanPromoteAltsAsync(EfModels.UserWithData user, int profileId) { return(await this.UserHasStandardOfficerPermissions(profileId, user)); }