<commit_before>﻿using Aritter.Application.DTO.SecurityModule.Authentication;
using Aritter.Domain.SecurityModule.Aggregates.PermissionAgg;
using Aritter.Domain.SecurityModule.Aggregates.UserAgg;
using Aritter.Infra.Crosscutting.Security;
using AutoMapper;
using System;
using System.Linq;

namespace Aritter.Application.DTO.Profiles.SecurityModule
{
    public class AuthenticationProfile : Profile
    {
        public AuthenticationProfile()
        {
            CreateMap<User, AuthenticationDto>()
                .ForMember(dest => dest.User, opt => opt.MapFrom(src => src))
                .ForMember(dest => dest.Permissions, opt => opt.MapFrom(src =>
                    src.UserAssignments
                    .SelectMany(p => p.Role.Authorizations)
                    .Select(ParsePermission)
                    .Distinct()))
                .ForMember(dest => dest.Roles, opt => opt.MapFrom(src =>
                    src.UserAssignments
                    .Select(p => p.Role.Name)
                    .Distinct()));

            CreateMap<User, UserDto>()
                .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.Username))
                .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.Person.FirstName))
                .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.Person.LastName))
                .ForMember(dest => dest.UID, opt => opt.MapFrom(src => src.UID));
        }

        private string ParsePermission(Authorization authorization)
        {
            var rule = Rule.None;
            Enum.TryParse(authorization.Permission.Operation.Name, out rule);

            return $"{authorization.Permission.Resource.Name}:{rule}";
        }
    }
}<commit_msg>refact profiles<commit_after>﻿using Aritter.Application.DTO.SecurityModule.Authentication;
using Aritter.Domain.SecurityModule.Aggregates.PermissionAgg;
using Aritter.Domain.SecurityModule.Aggregates.UserAgg;
using Aritter.Infra.Crosscutting.Security;
using AutoMapper;
using System;
using System.Linq;

namespace Aritter.Application.DTO.Profiles.SecurityModule
{
    public class AuthenticationProfile : Profile
    {
        public AuthenticationProfile()
        {
            CreateMap<User, AuthenticationDto>()
                .ForMember(dest => dest.User, opt => opt.MapFrom(src => src))
                .ForMember(dest => dest.Permissions, opt => opt.MapFrom(src =>
                    src.UserAssignments
                    .SelectMany(p => p.Role.Authorizations)
                    .Select(ParsePermission)
                    .Distinct()))
                .ForMember(dest => dest.Roles, opt => opt.MapFrom(src =>
                    src.UserAssignments
                    .Select(p => p.Role.Name)
                    .Distinct()));
        }

        private string ParsePermission(Authorization authorization)
        {
            var rule = Rule.None;
            Enum.TryParse(authorization.Permission.Operation.Name, out rule);

            return $"{authorization.Permission.Resource.Name}:{rule}";
        }
    }
}
{'fraction_non_alphanumeric': 0.11287706779111255, 'fraction_numerical': 0.0, 'mean_word_length': 2.143730886850153, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 40, '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': '3114756', 'n_tokens_mistral': 830, 'n_tokens_neox': 808, 'n_words': 139}