예제 #1
0
        public async Task <Unit> Handle(CreateLibrary request, CancellationToken cancellationToken)
        {
            // Create library
            var library = await CreateLibrary(request.Title, request.Description, request.UserId);

            // Create role(s)
            var roleId = await _mediator.Send(new CreateRole("Instructor", library.Id), cancellationToken);

            // Add all privileges to new role
            await _mediator.Send(new AddPrivilegesToRole(roleId, Privilege.All()), cancellationToken);

            // Add a membership for the user creating the library
            await CreateMembership(library.Id, library.CreatedBy, roleId);

            return(Unit.Value);
        }
예제 #2
0
        public DtoProfile()
        {
            CreateMap<IEnumerable<RoleDto>, Role>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.First().Id))
                .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.First().Title))
                .ForMember(dest => dest.Privileges, opt => opt
                    .MapFrom(src => src.Select(r => Privilege.All().SingleOrDefault(p => p.Alias == r.PrivilegeAlias))
                    .ToHashSet()));

            CreateMap<IEnumerable<RoleDto>, IEnumerable<Role>>()
                .ConvertUsing((src, dst, ctx) => src.GroupBy(r => r.Id).Select(ctx.Mapper.Map<Role>));

            CreateMap<MemberDto, Member>()
                .ForMember(dest => dest.Role, opt => opt.Ignore());

            CreateMap<IEnumerable<MemberDto>, IEnumerable<Member>>()
                .ConvertUsing((src, dst, ctx) => src.Select(m => ctx.Mapper.Map<Member>(m)));
        }
        public async Task Test()
        {
            var library = await _utility.CreateLibraryAsync();

            // Create a new role
            var roleId = await _fixture.SendAsync(new CreateRole("Student", library.Id));

            var allPriviliges = Privilege.All().ToArray();
            var oldPriviliges = new[] { allPriviliges[0] };
            var newPriviliges = new[] { allPriviliges[1], allPriviliges[2] };

            // Add a privilege
            await _fixture.SendAsync(new AddPrivilegesToRole(roleId, oldPriviliges));

            // Replace privilege
            var request = new ReplacePrivilegesOfRole(roleId, newPriviliges);
            await _fixture.SendAsync(request);

            // Get the roles for the library
            var roles = await _fixture.SendAsync(new GetRolesForLibrary(library.Id));

            // Check that the set of returned privileges is equal to our privileges
            Assert.True(roles.Single(r => r.Id == roleId).Privileges.SetEquals(newPriviliges));
        }
예제 #4
0
 public PageProfile()
 {
     CreateMap <IEnumerable <string>, ISet <Privilege> >()
     .ConstructUsing(src => Privilege.All().Where(p => src.Contains(p.Alias)).ToHashSet());
 }