protected override async Task HandleRequirementAsync( AuthorizationHandlerContext context, CanUploadBranchRequirement requirement, ProjectDto project) { if (context.User.Identity.AuthenticationType == "SecureToken") { if (context.User.Identity.Name == "System") { context.Succeed(requirement); } } else if (RequestHasProjectAccessToken(requirement)) { var authorization = requirement.Headers["Authorization"].ToString(); var authorizationParts = authorization.Split(' '); if (authorizationParts.Length == 2) { var projectToken = authorizationParts[1]; _projectsClient.CustomHeaders.Headers.Remove("Authorization"); _projectsClient.CustomHeaders.Headers.Add("Authorization", $"SecureToken {_applicationParameters.SecureToken}"); var existingProject = await _projectsClient.Get(project.Id); if (existingProject != null && !string.IsNullOrWhiteSpace(existingProject.AccessToken)) { if (string.Equals(projectToken, existingProject.AccessToken, StringComparison.OrdinalIgnoreCase)) { context.Succeed(requirement); } } } } else if (context.User.Identity.AuthenticationType == "Bearer" || context.User.Identity.AuthenticationType == "AuthenticationTypes.Federation" || context.User.Identity.AuthenticationType == "UserToken") { var userId = context.User.Identity.Name.ToLower(); var user = await _usersService.GetUserAsync(userId); if (user != null) { if (user.Role == RoleEnumDto.Administrator) { context.Succeed(requirement); } else if (user.Projects.Contains(project.Id)) { context.Succeed(requirement); } } } }
public async Task <FilteredResutsDto <ProjectDto> > GetProjectsAsync(ProjectsFilterDto filter, string userId) { IList <ProjectDto> projects = null; if (!_cacheService.TryGetProjects(out projects)) { var projectsTask = _projectsClient.Get(); var usersTask = _usersClient.Get(); projects = await projectsTask; CleanProjectsAccessTokens(projects); var users = await usersTask; AddOwnersToProjects(projects, users); _cacheService.AddProjectsToCache(projects); } IEnumerable <ProjectDto> query = projects; query = FilterByName(filter, query); query = FilterByDescription(filter, query); query = FilterByGroups(filter, query); query = FilterByTags(filter, query); query = FilterByLimitedAccess(filter, query, userId); var allResults = query.Count(); query = query.OrderBy(x => x.Name); if (filter.Limit > 0) { query = query.Skip(filter.Page * filter.Limit).Take(filter.Limit); } var filteredResults = new FilteredResutsDto <ProjectDto> { Results = query, AllResults = allResults }; return(filteredResults); }
public async Task <IList <string> > GetAvailableTagsAsync() { IList <string> tags = null; if (!_cacheService.TryGetTags(out tags)) { var projects = await _projectsClient.Get(); tags = new List <string>(); foreach (var project in projects) { project.Tags.ForEach(x => tags.Add(x)); } tags = tags.OrderBy(x => x).Distinct().ToList(); _cacheService.AddTags(tags); } return(tags); }
public IObservable <Project> Get(int id) { return(_client.Get(id).ToObservable()); }