<commit_before>﻿using Obsidian.Domain.Misc;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Claims;

namespace Obsidian.Domain.Services
{
    public class ClaimService
    {
        public IEnumerable<Claim> GetClaims(User user, IEnumerable<PermissionScope> scopes)
                => GetClaims(user, scopes.SelectMany(s => s.ClaimTypes).Distinct());

        public IEnumerable<Claim> GetClaims(User user, IEnumerable<string> claimTypes)
        {
            var userClaims = GetClaimsFromObjectByType(userClaimGetters, claimTypes, user);
            var profileClaims = GetClaimsFromObjectByType(userProfileClaimGetters, claimTypes, user.Profile);
            return userClaims.Union(profileClaims).Union(user.Claims);
        }

        private static IEnumerable<PropertyClaimGetter> userClaimGetters
                    = MetadataHelper.GetClaimPropertyGetters<User>();

        private static IEnumerable<PropertyClaimGetter> userProfileClaimGetters
                    = MetadataHelper.GetClaimPropertyGetters<UserProfile>();

        private static IEnumerable<Claim> GetClaimsFromObjectByType(IEnumerable<PropertyClaimGetter> getters, IEnumerable<string> claimTypes, object obj)
                => getters.Join(claimTypes, g => g.ClaimType, ct => ct, (g, ct) => g).Select(g => g.GetClaim(obj));
    }
}<commit_msg>fixed get claims<commit_after>﻿using Obsidian.Domain.Misc;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Claims;

namespace Obsidian.Domain.Services
{
    public class ClaimService
    {
        public IEnumerable<Claim> GetClaims(User user, IEnumerable<PermissionScope> scopes)
                => GetClaims(user, scopes.SelectMany(s => s.ClaimTypes).Distinct());

        public IEnumerable<Claim> GetClaims(User user, IEnumerable<string> claimTypes)
        {
            var userClaims = GetClaimsFromObjectByType(userClaimGetters, claimTypes, user);
            var profileClaims = GetClaimsFromObjectByType(userProfileClaimGetters, claimTypes, user.Profile);
            var extraClaims = user.Claims.Join(claimTypes, c => c.Type, ct => ct, (c, ct) => c);
            return userClaims.Union(profileClaims).Union(extraClaims);
        }

        private static IEnumerable<PropertyClaimGetter> userClaimGetters
                    = MetadataHelper.GetClaimPropertyGetters<User>();

        private static IEnumerable<PropertyClaimGetter> userProfileClaimGetters
                    = MetadataHelper.GetClaimPropertyGetters<UserProfile>();

        private static IEnumerable<Claim> GetClaimsFromObjectByType(IEnumerable<PropertyClaimGetter> getters, IEnumerable<string> claimTypes, object obj)
                => getters.Join(claimTypes, g => g.ClaimType, ct => ct, (g, ct) => g).Select(g => g.GetClaim(obj));
    }
}
{'fraction_non_alphanumeric': 0.09747545582047686, 'fraction_numerical': 0.0, 'mean_word_length': 3.669394435351882, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6878762', 'n_tokens_mistral': 800, 'n_tokens_neox': 771, 'n_words': 152}