Inhalte aufrufen

Profilbild

Extend permissions in custom plugin

permissioncustom plugin

2 Antworten zu diesem Thema

#1 Bố Kün

Bố Kün

    Newbie

  • Members
  • 3 Beiträge

Geschrieben: 30 May 2017 - 17:15

Hi all,

 

I'm developing a custom plugin. In my plugin require custom permission named "AccessAbcPanel". So my issue is how to integrate my custom permission into Access Control List but not change SM Core?

 

Thanks,

Dien



#2 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1071 Beiträge

Geschrieben: 30 May 2017 - 18:07

Definition:

public partial class MyPermissionProvider : IPermissionProvider
{
    public static readonly PermissionRecord AccessAbcPanel = new PermissionRecord { Name = " Access Abc Panel.", SystemName = "AccessAbcPanel", Category = "Plugin" };

    public virtual IEnumerable<PermissionRecord> GetPermissions()
    {
        return new[] { AccessAbcPanel };
    }

    public virtual IEnumerable<DefaultPermissionRecord> GetDefaultPermissions()
    {
        return new[] 
        {
            new DefaultPermissionRecord 
            {
                CustomerRoleSystemName = SystemCustomerRoleNames.Administrators,
                PermissionRecords = new[] { AccessAbcPanel }
            },
        };
    }
}

Install/Uninstall:

 

In your plugin class, which implements IPlugin.

public override void Install()
{
    _permissionService.InstallPermissions(new MyPermissionProvider());
    // [...]
}

public override void Uninstall()
{
    _permissionService.UninstallPermissions(new MyPermissionProvider());
   // [...]
}

Usage:

 

e.g. in any controller action method

bool hasPermission = _permissionService.Authorize(MyPermissionProvider.AccessAbcPanel);

if (!hasPermission) 
{
    return new HttpUnauthorizedResult("Please fuck off :-)");
}

Murat Cakir
SmartStore AG


#3 Bố Kün

Bố Kün

    Newbie

  • Members
  • 3 Beiträge

Geschrieben: 31 May 2017 - 05:32

Excellent, thank to resolve my issue, give you a hug. ;)

 

Love SmartStore





Auf dieses Thema antworten