Mewriick / Blazor.FlexGrid

GridView component for Blazor
MIT License
199 stars 35 forks source link

I cant set on write permission #88

Closed Methraen closed 4 years ago

Methraen commented 4 years ago

Hello @Mewriick Im having some trouble using the permission feature My final goal is to forbid the editing of a column, in order to complete that goal, i followed the provided example :

  1. First i created a class which implements ICurrentUserPermission,
  2. Then i provided the configuration for permission restriction,
  3. Finally i registered ICurrentUserPermission into DI container as Singleton

The problem is that i can still edit the column i try to make not editable...

(1) - In TestCurrentUserPermission.cs file

namespace IndicateurRHFront.GridConfigurations
{
  public class TestCurrentUserPermission : ICurrentUserPermission
  {
    public bool HasClaim(string claimName)
    {
      if (claimName == "Admin")
      {
        return true;
      }

      return false;
    }

    public bool IsInRole(string roleName)
    {
      if (roleName == "AdminRole")
      {
        return true;
      }

      return false;
    }
  }
}

(2) - In TestGridConfiguration.cs file

builder.Property(e => e.SalariesNomPre)
          .HasWritePermissionRestriction(perm => perm.IsInRole("None"))
          .HasCaption("Nom Prénom")
          .IsFilterable();

(None is not defined in TestCurrentUserPermission so that it returns false)

(3) - In Startup.cs file

public void ConfigureServices(IServiceCollection services)
    {
      services.AddFlexGrid(
          cfg =>
          {
            cfg.ApplyConfiguration(new TestGridConfiguration());
          },
          options =>
          {
            options.IsServerSideBlazorApp = false;
            options.UseAuthorizationForHttpRequests = true;
          }
          );

      services.AddSingleton<ICurrentUserPermission, TestCurrentUserPermission>();
    }

I may have missed something...

Mewriick commented 4 years ago

Hello @Methraen

I have bug in code. I have to create new version and release it.

Methraen commented 4 years ago

Thank you for your response @Mewriick and good luck resolving it!

Mewriick commented 4 years ago

@Methraen

New version is released.