/// <summary> /// Initializes a new instance of the <see cref="BrochureOperations"/> class. /// </summary> public BrochureOperations(NancyContextWrapper context) { this.Class.SupportsGet().Title("Get brochure"); if (context.HasPermission(Permissions.WriteSources)) { this.Class .SupportsPut() .Title("Update brochure") .TypedAs((IriRef)Schema.UpdateAction) .Expects((IriRef)Wbo.Brochure); } if (context.HasPermission(Permissions.AdminSources)) { this.Property(b => b.Location) .SupportsPut() .Title("Update location") .TypedAs((IriRef)Schema.UpdateAction); } this.Property(b => b.WishlistItem) .SupportsPut() .TypedAs((IriRef)Api.AddToWishlistAction) .Title("Add to wishlist") .Description("Brochure will be scanned to PDF with highest priority"); }
public void Resolves_ClientId() { var context = new NancyContext { CurrentUser = new TestPrincipal(new Claim(JwtClaimTypes.ClientId, "fabric-authorization")) }; var contextWrapper = new NancyContextWrapper(context); var eventContextResolver = new EventContextResolverService(contextWrapper); Assert.Equal("fabric-authorization", eventContextResolver.ClientId); }
public void Resolves_Subject() { var context = new NancyContext { CurrentUser = new TestPrincipal(new Claim(JwtClaimTypes.Subject, "12345")) }; var contextWrapper = new NancyContextWrapper(context); var eventContextResolver = new EventContextResolverService(contextWrapper); Assert.Equal("12345", eventContextResolver.Subject); }
public void Resolves_Username() { var context = new NancyContext { CurrentUser = new TestPrincipal(new Claim(JwtClaimTypes.Name, "bob")) }; var contextWrapper = new NancyContextWrapper(context); var eventContextResolver = new EventContextResolverService(contextWrapper); Assert.Equal("bob", eventContextResolver.Username); }
public void Resolves_IpAddress() { var request = new Request("POST", "http://test/test", null, null, "192.168.0.1"); var context = new NancyContext { Request = request }; var contextWrapper = new NancyContextWrapper(context); var eventContextResolver = new EventContextResolverService(contextWrapper); Assert.Equal("192.168.0.1", eventContextResolver.RemoteIpAddress); }
public IssueSupportedOperations(NancyContextWrapper current) { Class.SupportsGet(); if (current.Context.CurrentUser?.IsInRole("Admin") == true) { Class.SupportsDelete(); } Property(issue => issue.ProjectId).SupportsGet(); }
public BrochureCollectionOperations(NancyContextWrapper context) { if (context.Current?.CurrentUser.HasPermission(Permissions.WriteSources) == true) { this.Class.SupportsPost() .Title("Create brochure") .Expects((IriRef)Wbo.Brochure) .Returns((IriRef)Wbo.Brochure) .TypedAs((IriRef)Schema.CreateAction); } }
public void ResolvesAllToNull_IfNotSpecified() { var context = new NancyContext { CurrentUser = new TestPrincipal() }; var contextWrapper = new NancyContextWrapper(context); var eventContextResolver = new EventContextResolverService(contextWrapper); Assert.Null(eventContextResolver.Username); Assert.Null(eventContextResolver.Subject); Assert.Null(eventContextResolver.ClientId); Assert.Null(eventContextResolver.RemoteIpAddress); }
/// <summary> /// Initializes a new instance of the <see cref="EntrypointOperations"/> class. /// </summary> public EntrypointOperations(NancyContextWrapper context) { this.Class.SupportsGet() .Title("Gets the API entrypoint") .Description("The entrypoint is the the API starts"); this.Property(e => e.Books).SupportsGet().Title("Gets the collection of books (paged)"); this.Property(e => e.Brochures) .SupportsGet().Title("Gets the collection of brochures (paged)"); if (context.Current?.CurrentUser?.HasClaim(claim => claim.Value == "write:sources") == true) { this.Property(e => e.Brochures) .SupportsPost() .Title("Add a new brochure") .Expects((IriRef)Wbo.Brochure) .Returns((IriRef)Wbo.Brochure) .TypedAs((IriRef)Schema.CreateAction); } this.Property(e => e.Magazines).SupportsGet().Title("Gets the collection of magazines"); }
/// <summary> /// Initializes a new instance of the <see cref="SourceOperations"/> class. /// </summary> public SourceOperations(NancyContextWrapper context) { if (context.HasPermission(Permissions.WriteSources)) { this.Property(s => s.Images) .SupportsPost() .Title("Upload image") .TypedAs((IriRef)Schema.TransferAction) .Expects((IriRef)Api.ImageUpload); this.Property(s => s.Image) .SupportsDelete() .TypedAs((IriRef)Schema.DeleteAction) .Title("Remove image"); this.Property(s => s.Image) .SupportsPost() .TypedAs((IriRef)Schema.MoveAction) .Expects((IriRef)Api.ImageOrder) .Title("Move image"); this.Property(s => s.Content) .SupportsPost() .Title("Upload PDF") .Expects((IriRef)Api.PdfUpload) .TypedAs((IriRef)Schema.TransferAction); } if (context.HasPermission(Permissions.AdminSources)) { this.Property(s => s.Content) .SupportsDelete() .Title("Remove PDF") .TypedAs((IriRef)Schema.DeleteAction); } }
public static bool IsAuthenticated(this NancyContextWrapper context) { return(context?.Current?.CurrentUser?.IsAuthenticated() == true); }
public static bool HasPermission(this NancyContextWrapper context, string permission) { return(context?.Current?.CurrentUser?.HasPermission(permission) == true); }
public EventContextResolverService(NancyContextWrapper contextWrapper) { _context = contextWrapper.Context; }