Starts in:
1 DAY
23 HRS
36 MIN
26 SEC
Starts in:
1 D
23 H
36 M
26 S

Activities of "Sturla"

Thank you for your answer Maliming, I haven't tried this with huge files yet (will today) but I was wondering what approach you would recommend taking to upload to blob from the service. Stop in a temp file or directly from stream?

public async Task<string> UploadBigFileAsync(IRemoteStreamContent streamContent)
{
    var filePath = Path.GetTempFileName();

    // use local temp file
    using (var fs = new FileStream(filePath, FileMode.Create))
    {
        await streamContent.GetStream().CopyToAsync(fs);
        await fs.FlushAsync();
    }

    var blobName = $"Uploaded-{streamContent.FileName}";

    // then read it to blob
    var bytes = await File.ReadAllBytesAsync(filePath);
    await blobContainer.SaveAsync(blobName, bytes, overrideExisting: true);

    return blobName;
    
    //delete file finaly()
}

Or just stream it directly

public async Task<string> UploadBigFileAsync(IRemoteStreamContent streamContent)
{
    var blobName = $"Uploaded-{streamContent.FileName}";
    
    await blobContainer.SaveAsync(blobName, streamContent.GetStream(), overrideExisting: true);

    return blobName;
}

I updated the code in my github question to have both a none-working abp version and a working classic Blazor/api that works.

Hopefully this is just some configuration problem but I haven't found it.

I´m trying to upload a big file using multipart request but using this framework I´m getting the following error

"Unexpected end of Stream, the content may have already been read by another component."

There is like something in Abp is "messing with" the communication and I can´t find out what.

I asked this question in details at GitHub but like to get some priority on it by posting it also here. Hope hearing from you soon.

  • ABP Framework version: v4.4 (also in a 4.4.4 project)
  • UI type: Blazor
  • DB provider: EF Core
  • Identity Server Separated: yes
Answer

Suite can't be used because it doesn't find xPermissions.cs or xPermissionDefinitionProvider.cs if they have been (like I had to do) moved to another project/place.

So at the moment I just can't use Suite at all to add properties/entities and I have to do it manually.

Bingo! That seems to have solved the problem! Thanks for your patiance with me ;-)

Here it is but the "create a tenant UI" is missing (not sure how the open source version works) so I couldn´t try that out.

I added some information to the Readme file but I hope this is all self explanatory what I´m trying to do.

Yes that is what I gathered

If I change the tenant to nul l I get the roles

[UnitOfWork]
public async virtual Task HandleEventAsync(EntityCreatedEto<UserEto> eventData)
{
    using (currentTenant.Change(null)) 
    {  
    var roleNotFound = await identityRoleRepository         
        .FindByNormalizedNameAsync(lookupNormalizer
        .NormalizeName(RoleConstants.TenantClientRole));
    }
}

BUT then I can´t add the role becuse the created user is not found

// this then throws
var userJustCreated = await identityUserManager.GetByIdAsync(eventData.Entity.Id/TenantId);
   
// this
'There is no such an entity. Entity type: Volo.Abp.Identity.IdentityUser, id: 7f7acfe7-4abe-2a43-f31f-39fe74a2a237'

What secret sauce/steps do I need?

One small help before I close this issue, because I really want to use role with permissions.

So why can't the role not be found when using the IDistributedEventHandler but is when seeding data?

[UnitOfWork]
public async virtual Task HandleEventAsync(EntityCreatedEto<UserEto> eventData)
{
    using (currentTenant.Change(eventData.Entity.TenantId)) 
    {   
        //This never returns the roles created when I seed. I have tried to skip the using etc.
        var role = await   identityRoleRepository
            .FindByNormalizedNameAsync(lookupNormalizer.NormalizeName(RoleConstants.TenantClientRole));
    
    if (role is null)
    {
        var newRole = new IdentityRole(guidGenerator.Create(),
            RoleConstants.TenantClientRole) { IsPublic = true, IsStatic = true };
        await identityRoleRepository.InsertAsync(newRole, true); 
    }
    
    //this will just return null
    var roleNotFound = await identityRoleRepository
        .FindByNormalizedNameAsync(lookupNormalizer.NormalizeName(RoleConstants.TenantClientRole));
    
    //and then I can't AddToRoleAsync because the role is not found!
    var userJustCreated = await identityUserManager.GetByIdAsync(eventData.Entity.Id);
    
    //this throws "Role TENANTCLIENTROLE not found"
    await identityUserManager.AddToRoleAsync(userJustCreated, RoleConstants.TenantClientRole); 
    }
}

And if I change to "null" tenant with using (currentTenant.Change(null)) I get the roles but var userJustCreated = await identityUserManager.GetByIdAsync(eventData.Entity.Id); throws "There is no such an entity".


For completeness sake I´m able to run and seed the role with the DbMigrator with basically the same code

public async Task SeedAsync(DataSeedContext context)
{
    var role = await identityRoleRepository
        .FindByNormalizedNameAsync(lookupNormalizer.NormalizeName(RoleConstants.TenantClientRole));
    
    if (role is not null)
    {
        return;
    }

    // Create the role and insert it
    var newRole = new IdentityRole(guidGenerator.Create(), 
        RoleConstants.TenantClientRole) { IsPublic = true, IsStatic = true };
    await identityRoleRepository.InsertAsync(newRole,true); 
    
    //returns the role
    var roleFound = await identityRoleRepository
        .FindByNormalizedNameAsync(lookupNormalizer.NormalizeName(RoleConstants.TenantClientRole));
}

Hopefully I can just close this off after this question. Thanks so much for your asstance!

Ok that was the last missing puzzle for me! Thank you!!

But I´m still not sure if I should use roles with permissions and add them to tenant or add/delete individual permissions.

I really think the roles/permissions documentation should be augmented by more scenarios and Q/A-ish code parts.

Ok I think I got it.

Should I do the following (and correct me if I´m wrong)

  1. On Tenant created: Delete all the given role permissions the user has, using permissionManager.DeleteAsync("R", entity.Name);
  2. Create a new role containing the permissions I want a tenant to have. (do this at db seeding)
  3. Add this user to the new role

Is that what we are talking about?

Something like this here?

[UnitOfWork]
public async virtual Task HandleEventAsync(EntityCreatedEto<UserEto> eventData)
{
    var isTenant = eventData.Entity.TenantId.HasValue;

    if (isTenant)
    {
        //Delete all the permissions 
        await permissionManager.DeleteAsync("R", eventData.Entity.Name);

        // Give it the correct permissions
        var permissions = new List<string>
        {
            "AbpIdentity.Roles",
            "AbpIdentity.Roles.ManagePermissions",
            "AbpIdentity.Users",
            "AbpIdentity.OrganizationUnits",
            "AbpAccount.SettingManagement",
            "IdentityServer.ApiResource"
        };

        foreach (var perm in permissions)
        {
            await permissionManager.SetForRoleAsync(RoleConstants.TenantClientRole, perm, true);
            
            //No sure about this one...
            await permissionManager.SetForUserAsync(eventData.Entity.Id, perm, true);
        }

    }
}

I can´t see any menu yeat but thats hopefully because I havent added all the permissions. I try that out to morrow if you say that I´m on the right track

Showing 171 to 180 of 210 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06