Base solution for your next web application

Activities of "bbakermmc"

Can you guys provide a GIST/small project that implements this. I need to be able to login as a tenant and run an app service.

I tried copying your test project and swapping out the ServiceCollectionRegistrar but it throws an error.

This gets me half way there:

public static void Register(IIocManager iocManager)
        {
            RegisterIdentity(iocManager);

            var builder = new DbContextOptionsBuilder<PlatformDbContext>();
            builder.UseSqlServer("Server=mmcsqldev02; Database=MMCPlatformControl_BradV2; Trusted_Connection=True;", o => o.UseRowNumberForPaging());

                     iocManager.IocContainer.Register(
                Component
                    .For<DbContextOptions<PlatformDbContext>>()
                    .Instance(builder.Options)
                    .LifestyleSingleton()
            );
        }

How do I make this change the connection to the clients db now, I'm missing something to change the ctx?

protected void LoginAsTenant(string tenancyName, string userName)
        {
            AbpSession.TenantId = null;

            var tenant = UsingDbContext(context => context.Tenants.FirstOrDefault(t => t.TenancyName == tenancyName));
            if (tenant == null)
            {
                throw new Exception("There is no tenant: " + tenancyName);
            }

            AbpSession.TenantId = tenant.Id;
            if (string.IsNullOrEmpty(tenant.ConnectionString))
            {
                var user = UsingDbContext(
                    context => context.Users.FirstOrDefault(
                        u => u.TenantId == AbpSession.TenantId && u.UserName == userName));
                if (user == null)
                {
                    throw new Exception("There is no user: " + userName + " for tenant: " + tenancyName);
                }

                AbpSession.UserId = user.Id;
            }
            else
            {
                var connString = SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString);

                var builder = new DbContextOptionsBuilder<PlatformDbContext>();
                builder.UseSqlServer(connString, o => o.UseRowNumberForPaging());
                
                var ctx = new PlatformDbContext(builder.Options);
                
                var user = UsingDbContext(
                    context => context.Users.FirstOrDefault(
                        u => u.TenantId == AbpSession.TenantId && u.UserName == userName));
                if (user == null)
                {
                    throw new Exception("There is no user: " + userName + " for tenant: " + tenancyName);
                }

                AbpSession.UserId = user.Id;

            }
            
        }

Shouldn't there be an easier way to test our app services using real data? No one in their right mind is going to mock up data for every table they have.

Ideally I just want to say use this app service using this db context/connection string.

I'm not looking to run the test cases for all the stuff you guys wrote, its more for my own stuff.

ASP.NET Core

Question

Is there a way to setup a unit test/appservice/change out the context to use a read DB instead of in memory?

Whats the preferred way to add existing tables that aren't managed via EF Migrations.
I need to add about 100 tables to use. The DBMs also set them up as TableNameId and not Id.

Can I just create another Context that uses the same connection string from the base Dbcontext?

Incase anyone is looking to filter the Swagger UI to prevent showing End Points for users who don't have permissions.

Note: In this case its checking for explicit permissions (Our use case). If you want it to show end points w/no permissions you will need to adjust it.

startup.cs

services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info { Title = "Platform API", Version = "v1" });
                options.DocInclusionPredicate((docName, description) => true);
                options.DocumentFilter<SwaggerAbpAuthorizeAttributeAuthorizationFilter>();
            });
new class file
public class SwaggerAbpAuthorizeAttributeAuthorizationFilter : IDocumentFilter
        {          
            private readonly IPermissionChecker _permissionChecker;

            public SwaggerAbpAuthorizeAttributeAuthorizationFilter( IPermissionChecker permissionChecker)
            {
                _permissionChecker = permissionChecker;
            }

            public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
            {
                var descriptions = context.ApiDescriptionsGroups.Items.SelectMany(group => group.Items);

                foreach (var description in descriptions)
                {
                  var authAttributes = description.ControllerAttributes()
                        .OfType<AbpAuthorizeAttribute>()
                        .Union(description.ActionAttributes()
                            .OfType<AbpAuthorizeAttribute>());

                    // check if this action should be visible
                    var forbiddenDuePermissions = IsForbiddenDuePermissions(authAttributes);

                    if (!forbiddenDuePermissions)
                        continue; // user passed all permissions checks

                    var route = "/" + description.RelativePath.TrimEnd('/');
                    var path = swaggerDoc.Paths[route];

                    // remove method or entire path (if there are no more methods in this path)
                    switch (description.HttpMethod)
                    {
                        case "DELETE":
                            path.Delete = null;
                            break;
                        case "GET":
                            path.Get = null;
                            break;
                        case "HEAD":
                            path.Head = null;
                            break;
                        case "OPTIONS":
                            path.Options = null;
                            break;
                        case "PATCH":
                            path.Patch = null;
                            break;
                        case "POST":
                            path.Post = null;
                            break;
                        case "PUT":
                            path.Put = null;
                            break;
                        default: throw new ArgumentOutOfRangeException("Method name not mapped to operation");
                    }

                    if (path.Delete == null && path.Get == null &&
                        path.Head == null && path.Options == null &&
                        path.Patch == null && path.Post == null && path.Put == null)
                        swaggerDoc.Paths.Remove(route);
                }
            }

            private bool IsForbiddenDuePermissions(IEnumerable<AbpAuthorizeAttribute> attributes)
            {
                var authorizeAttributes = attributes
                    .Where(p => p.Permissions != null).ToList();

                var permissions = new List<string>();
                if (authorizeAttributes.Count != 0)
                {
                    foreach (var authorizeAttribute in authorizeAttributes)
                    {
                        permissions.AddRange(authorizeAttribute.Permissions.ToList());
                    }
                }
                else
                {
                    return true;
                }

                foreach (var permission in permissions)
                {
                    var allow = _permissionChecker.IsGranted(permission);
                    if (allow)
                    {
                        return false;
                    }
                }

                return true;
            }
        }

You and bunch of other people are still waiting for a reply on this :)

We have a DLL that contains all of our DB logic for connecting to each of our clients DBs. Is there a way to register it so it can make the methods usable in JS like the APP/AppServices does?

I found this but I cant find a DynamicApiControllerBuilder in any of the code.

DynamicApiControllerBuilder
    .ForAll<IApplicationService>(Assembly.GetAssembly(typeof (SimpleTaskSystemApplicationModule)), "tasksystem")
    .Build();

Can you please provide updated documentation. The referenced method in the "User Manager" doesn't exist in the Core 4.1.4 solution.

It looks like in signinmager StoreToFactorInfo creates some claims but I'm not sure if that's called by a non two auth sign in?

Question

I extended the Tenant entity and deployed the change to my DB/updated the created/edit forms.

How do I pull this extra info I need into my controller/Extend the ABPSession to put it there. The field is an API key that we need to use all the time for each client to hit our internal APIs.

Showing 131 to 140 of 164 entries