コード例 #1
0
ファイル: Processor.cs プロジェクト: alanapz/snorlax
        private Task <List <User> > GetUsersForProjectAsync(string projectKey, List <User> users)
        {
            return(Task.Run(() =>
            {
                // Slightly complex - permissions can be granted via groups or directly on users
                // With no web service to retrieve aggregated data, we need to lookup group + user details
                List <GroupPermission> groupPermissions = ExecutePageableRequest <GroupPermissionsList, GroupPermission>($"permissions/groups?projectKey={projectKey}");

                HashSet <string> groupKeys = groupPermissions
                                             .Where(groupPermission => groupPermission.Permissions.Count > 0)              // Ignore empty entries
                                             .Where(groupPermission => groupPermission.GroupKey != "sonar-administrators") // Ignore admins (otherwise admin would be spammed with details for every project)
                                             .Where(groupPermission => !AdminGroups.Contains(groupPermission.GroupKey))    // See SNLX-1: supplemental admin groups
                                             .Select(groupPermission => groupPermission.GroupKey)
                                             .ToHashSet();

                List <UserPermission> userPermissions = ExecutePageableRequest <UserPermissionsList, UserPermission>($"permissions/users?projectKey={projectKey}");

                HashSet <string> userKeys = userPermissions
                                            .Where(userPermission => userPermission.Permissions.Count > 0) // Ignore empty entries
                                            .Select(userPermission => userPermission.UserKey)
                                            .ToHashSet();

                return users.Where(user => userKeys.Contains(user.Key) || groupKeys.Intersect(user.Groups).Any()).ToList();
            }));
        }