Permission Providers

  • 2 months ago
  • 34 views
  • 0 comments

  • About 1 minute to read

Permission providers within Plato allow modules to expose additional permissions to Plato. Permission providers within Plato implement the IPermissionProvider<TPermission> interface which exposes 2 methods GetPermissions and GetDefaultPermissions.

The GetPermissions method returns a list of all available permissions whilst the GetDefaultPermissions method is used during feature installation to ensure the correct default permissions are associated with the correct roles within Plato.

You can see an example of the permission provider from Plato.Theming below. Notice how we are giving the administrator role all permissions to edit themes by default when the feature is enabled via the GetDefaultPermissions method.

using System.Collections.Generic;
using Plato.Internal.Security.Abstractions;

namespace Plato.Theming
{
    public class Permissions : IPermissionsProvider<Permission>
    {

        public static readonly Permission ManageThemes =
            new Permission("ManageThemes", "Manage themes");

        public static readonly Permission CreateThemes =
            new Permission("CreateThemes", "Create themes");

        public static readonly Permission EditThemes =
            new Permission("EditThemes", "Edit themes");

        public static readonly Permission DeleteThemes =
            new Permission("DeleteThemes", "Delete themes");

        public IEnumerable<Permission> GetPermissions()
        {
            return new[]
            {
                ManageThemes,
                CreateThemes,
                EditThemes,
                DeleteThemes
            };
        }

        public IEnumerable<DefaultPermissions<Permission>> GetDefaultPermissions()
        {
            return new[]
            {
                new DefaultPermissions<Permission>
                {
                    RoleName = DefaultRoles.Administrator,
                    Permissions = new[]
                    {
                        ManageThemes,
                        CreateThemes,
                        EditThemes,
                        DeleteThemes
                    }
                }
            };

        }

    }

}

For further information on how permissions work please see Permissions.

Can we improve this doc? Login or register to tell us how
Your Feedback
Cancel
In this doc