public async Task HandleAsync(AuthorizationHandlerContext context) { string projectId = null; switch (context.Resource) { case Project project: projectId = project.Id; break; case Engine engine: projectId = engine.Projects.First(); break; } if (projectId != null) { Attempt <SFProject> attempt = await _realtimeService.TryGetSnapshotAsync <SFProject>(projectId); if (attempt.TryResult(out SFProject project)) { string userId = context.User.FindFirst(XFClaimTypes.UserId)?.Value; if (project.UserRoles.TryGetValue(userId, out string role) && (role == SFProjectRole.Administrator || role == SFProjectRole.Translator)) { List <IAuthorizationRequirement> pendingRequirements = context.PendingRequirements.ToList(); foreach (IAuthorizationRequirement requirement in pendingRequirements) { context.Succeed(requirement); } } } } }
public static async Task <T> GetSnapshotAsync <T>(this IRealtimeService realtimeService, string id) where T : IIdentifiable { Attempt <T> attempt = await realtimeService.TryGetSnapshotAsync <T>(id); if (attempt.Success) { return(attempt.Result); } return(default(T)); }