Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

StandardPermissionProvider.cs

using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Security;

namespace Nop.Services.Security;

/// 
/// Standard permission provider
/// 
public partial class StandardPermissionProvider : IPermissionProvider
{
    //admin area permissions
    public static readonly PermissionRecord AccessAdminPanel = new() { Name = "Access admin area", SystemName = "AccessAdminPanel", Category = "Standard" };
    public static readonly PermissionRecord AllowCustomerImpersonation = new() { Name = "Admin area. Allow Customer Impersonation", SystemName = "AllowCustomerImpersonation", Category = "Customers" };
    public static readonly PermissionRecord ManageProducts = new() { Name = "Admin area. Manage Products", SystemName = "ManageProducts", Category = "Catalog" };
    public static readonly PermissionRecord ManageCategories = new() { Name = "Admin area. Manage Categories", SystemName = "ManageCategories", Category = "Catalog" };
    public static readonly PermissionRecord ManageManufacturers = new() { Name = "Admin area. Manage Manufacturers", SystemName = "ManageManufacturers", Category = "Catalog" };
    public static readonly PermissionRecord ManageProductReviews = new() { Name = "Admin area. Manage Product Reviews", SystemName = "ManageProductReviews", Category = "Catalog" };
    public static readonly PermissionRecord ManageProductTags = new() { Name = "Admin area. Manage Product Tags", SystemName = "ManageProductTags", Category = "Catalog" };
    public static readonly PermissionRecord ManageAttributes = new() { Name = "Admin area. Manage Attributes", SystemName = "ManageAttributes", Category = "Catalog" };
    public static readonly PermissionRecord ManageCustomers = new() { Name = "Admin area. Manage Customers", SystemName = "ManageCustomers", Category = "Customers" };
    public static readonly PermissionRecord ManageVendors = new() { Name = "Admin area. Manage Vendors", SystemName = "ManageVendors", Category = "Customers" };
    public static readonly PermissionRecord ManageCurrentCarts = new() { Name = "Admin area. Manage Current Carts", SystemName = "ManageCurrentCarts", Category = "Orders" };
    public static readonly PermissionRecord ManageOrders = new() { Name = "Admin area. Manage Orders", SystemName = "ManageOrders", Category = "Orders" };
    public static readonly PermissionRecord SalesSummaryReport = new() { Name = "Admin area. Access sales summary report", SystemName = "SalesSummaryReport", Category = "Orders" };
    public static readonly PermissionRecord ManageRecurringPayments = new() { Name = "Admin area. Manage Recurring Payments", SystemName = "ManageRecurringPayments", Category = "Orders" };
    public static readonly PermissionRecord ManageGiftCards = new() { Name = "Admin area. Manage Gift Cards", SystemName = "ManageGiftCards", Category = "Orders" };
    public static readonly PermissionRecord ManageReturnRequests = new() { Name = "Admin area. Manage Return Requests", SystemName = "ManageReturnRequests", Category = "Orders" };
    public static readonly PermissionRecord OrderCountryReport = new() { Name = "Admin area. Access order country report", SystemName = "OrderCountryReport", Category = "Orders" };
    public static readonly PermissionRecord ManageAffiliates = new() { Name = "Admin area. Manage Affiliates", SystemName = "ManageAffiliates", Category = "Promo" };
    public static readonly PermissionRecord ManageCampaigns = new() { Name = "Admin area. Manage Campaigns", SystemName = "ManageCampaigns", Category = "Promo" };
    public static readonly PermissionRecord ManageDiscounts = new() { Name = "Admin area. Manage Discounts", SystemName = "ManageDiscounts", Category = "Promo" };
    public static readonly PermissionRecord ManageNewsletterSubscribers = new() { Name = "Admin area. Manage Newsletter Subscribers", SystemName = "ManageNewsletterSubscribers", Category = "Promo" };
    public static readonly PermissionRecord ManagePolls = new() { Name = "Admin area. Manage Polls", SystemName = "ManagePolls", Category = "Content Management" };
    public static readonly PermissionRecord ManageNews = new() { Name = "Admin area. Manage News", SystemName = "ManageNews", Category = "Content Management" };
    public static readonly PermissionRecord ManageBlog = new() { Name = "Admin area. Manage Blog", SystemName = "ManageBlog", Category = "Content Management" };
    public static readonly PermissionRecord ManageWidgets = new() { Name = "Admin area. Manage Widgets", SystemName = "ManageWidgets", Category = "Content Management" };
    public static readonly PermissionRecord ManageTopics = new() { Name = "Admin area. Manage Topics", SystemName = "ManageTopics", Category = "Content Management" };
    public static readonly PermissionRecord ManageForums = new() { Name = "Admin area. Manage Forums", SystemName = "ManageForums", Category = "Content Management" };
    public static readonly PermissionRecord ManageMessageTemplates = new() { Name = "Admin area. Manage Message Templates", SystemName = "ManageMessageTemplates", Category = "Content Management" };
    public static readonly PermissionRecord ManageCountries = new() { Name = "Admin area. Manage Countries", SystemName = "ManageCountries", Category = "Configuration" };
    public static readonly PermissionRecord ManageLanguages = new() { Name = "Admin area. Manage Languages", SystemName = "ManageLanguages", Category = "Configuration" };
    public static readonly PermissionRecord ManageSettings = new() { Name = "Admin area. Manage Settings", SystemName = "ManageSettings", Category = "Configuration" };
    public static readonly PermissionRecord ManagePaymentMethods = new() { Name = "Admin area. Manage Payment Methods", SystemName = "ManagePaymentMethods", Category = "Configuration" };
    public static readonly PermissionRecord ManageExternalAuthenticationMethods = new() { Name = "Admin area. Manage External Authentication Methods", SystemName = "ManageExternalAuthenticationMethods", Category = "Configuration" };
    public static readonly PermissionRecord ManageMultifactorAuthenticationMethods = new() { Name = "Admin area. Manage Multi-factor Authentication Methods", SystemName = "ManageMultifactorAuthenticationMethods", Category = "Configuration" };
    public static readonly PermissionRecord ManageTaxSettings = new() { Name = "Admin area. Manage Tax Settings", SystemName = "ManageTaxSettings", Category = "Configuration" };
    public static readonly PermissionRecord ManageShippingSettings = new() { Name = "Admin area. Manage Shipping Settings", SystemName = "ManageShippingSettings", Category = "Configuration" };
    public static readonly PermissionRecord ManageCurrencies = new() { Name = "Admin area. Manage Currencies", SystemName = "ManageCurrencies", Category = "Configuration" };
    public static readonly PermissionRecord ManageActivityLog = new() { Name = "Admin area. Manage Activity Log", SystemName = "ManageActivityLog", Category = "Configuration" };
    public static readonly PermissionRecord ManageAcl = new() { Name = "Admin area. Manage ACL", SystemName = "ManageACL", Category = "Configuration" };
    public static readonly PermissionRecord ManageEmailAccounts = new() { Name = "Admin area. Manage Email Accounts", SystemName = "ManageEmailAccounts", Category = "Configuration" };
    public static readonly PermissionRecord ManageStores = new() { Name = "Admin area. Manage Stores", SystemName = "ManageStores", Category = "Configuration" };
    public static readonly PermissionRecord ManagePlugins = new() { Name = "Admin area. Manage Plugins", SystemName = "ManagePlugins", Category = "Configuration" };
    public static readonly PermissionRecord ManageSystemLog = new() { Name = "Admin area. Manage System Log", SystemName = "ManageSystemLog", Category = "Configuration" };
    public static readonly PermissionRecord ManageMessageQueue = new() { Name = "Admin area. Manage Message Queue", SystemName = "ManageMessageQueue", Category = "Configuration" };
    public static readonly PermissionRecord ManageMaintenance = new() { Name = "Admin area. Manage Maintenance", SystemName = "ManageMaintenance", Category = "Configuration" };
    public static readonly PermissionRecord HtmlEditorManagePictures = new() { Name = "Admin area. HTML Editor. Manage pictures", SystemName = "HtmlEditor.ManagePictures", Category = "Configuration" };
    public static readonly PermissionRecord ManageScheduleTasks = new() { Name = "Admin area. Manage Schedule Tasks", SystemName = "ManageScheduleTasks", Category = "Configuration" };
    public static readonly PermissionRecord ManageAppSettings = new() { Name = "Admin area. Manage App Settings", SystemName = "ManageAppSettings", Category = "Configuration" };

    //public store permissions
    public static readonly PermissionRecord DisplayPrices = new() { Name = "Public store. Display Prices", SystemName = "DisplayPrices", Category = "PublicStore" };
    public static readonly PermissionRecord EnableShoppingCart = new() { Name = "Public store. Enable shopping cart", SystemName = "EnableShoppingCart", Category = "PublicStore" };
    public static readonly PermissionRecord EnableWishlist = new() { Name = "Public store. Enable wishlist", SystemName = "EnableWishlist", Category = "PublicStore" };
    public static readonly PermissionRecord PublicStoreAllowNavigation = new() { Name = "Public store. Allow navigation", SystemName = "PublicStoreAllowNavigation", Category = "PublicStore" };
    public static readonly PermissionRecord AccessClosedStore = new() { Name = "Public store. Access a closed store", SystemName = "AccessClosedStore", Category = "PublicStore" };

    //Security
    public static readonly PermissionRecord EnableMultiFactorAuthentication = new() { Name = "Security. Enable Multi-factor authentication", SystemName = "EnableMultiFactorAuthentication", Category = "Security" };

    /// 
    /// Get permissions
    /// 
    /// Permissions
    public virtual IEnumerable GetPermissions()
    {
        return new[]
        {
            AccessAdminPanel,
            AllowCustomerImpersonation,
            ManageProducts,
            ManageCategories,
            ManageManufacturers,
            ManageProductReviews,
            ManageProductTags,
            ManageAttributes,
            ManageCustomers,
            ManageVendors,
            ManageCurrentCarts,
            ManageOrders,
            ManageRecurringPayments,
            ManageGiftCards,
            ManageReturnRequests,
            OrderCountryReport,
            SalesSummaryReport,
            ManageAffiliates,
            ManageCampaigns,
            ManageDiscounts,
            ManageNewsletterSubscribers,
            ManagePolls,
            ManageNews,
            ManageBlog,
            ManageWidgets,
            ManageTopics,
            ManageForums,
            ManageMessageTemplates,
            ManageCountries,
            ManageLanguages,
            ManageSettings,
            ManagePaymentMethods,
            ManageExternalAuthenticationMethods,
            ManageMultifactorAuthenticationMethods,
            ManageTaxSettings,
            ManageShippingSettings,
            ManageCurrencies,
            ManageActivityLog,
            ManageAcl,
            ManageEmailAccounts,
            ManageStores,
            ManagePlugins,
            ManageSystemLog,
            ManageMessageQueue,
            ManageMaintenance,
            HtmlEditorManagePictures,
            ManageScheduleTasks,
            ManageAppSettings,
            DisplayPrices,
            EnableShoppingCart,
            EnableWishlist,
            PublicStoreAllowNavigation,
            AccessClosedStore,
            EnableMultiFactorAuthentication
        };
    }

    /// 
    /// Get default permissions
    /// 
    /// Permissions
    public virtual HashSet<(string systemRoleName, PermissionRecord[] permissions)> GetDefaultPermissions()
    {
        return new HashSet<(string, PermissionRecord[])>
        {
            (
                NopCustomerDefaults.AdministratorsRoleName,
                new[]
                {
                    AccessAdminPanel,
                    AllowCustomerImpersonation,
                    ManageProducts,
                    ManageCategories,
                    ManageManufacturers,
                    ManageProductReviews,
                    ManageProductTags,
                    ManageAttributes,
                    ManageCustomers,
                    ManageVendors,
                    ManageCurrentCarts,
                    ManageOrders,
                    ManageRecurringPayments,
                    ManageGiftCards,
                    ManageReturnRequests,
                    OrderCountryReport,
                    SalesSummaryReport,
                    ManageAffiliates,
                    ManageCampaigns,
                    ManageDiscounts,
                    ManageNewsletterSubscribers,
                    ManagePolls,
                    ManageNews,
                    ManageBlog,
                    ManageWidgets,
                    ManageTopics,
                    ManageForums,
                    ManageMessageTemplates,
                    ManageCountries,
                    ManageLanguages,
                    ManageSettings,
                    ManagePaymentMethods,
                    ManageExternalAuthenticationMethods,
                    ManageMultifactorAuthenticationMethods,
                    ManageTaxSettings,
                    ManageShippingSettings,
                    ManageCurrencies,
                    ManageActivityLog,
                    ManageAcl,
                    ManageEmailAccounts,
                    ManageStores,
                    ManagePlugins,
                    ManageSystemLog,
                    ManageMessageQueue,
                    ManageMaintenance,
                    HtmlEditorManagePictures,
                    ManageScheduleTasks,
                    ManageAppSettings,
                    DisplayPrices,
                    EnableShoppingCart,
                    EnableWishlist,
                    PublicStoreAllowNavigation,
                    AccessClosedStore,
                    EnableMultiFactorAuthentication
                }
            ),
            (
                NopCustomerDefaults.ForumModeratorsRoleName,
                new[]
                {
                    DisplayPrices,
                    EnableShoppingCart,
                    EnableWishlist,
                    PublicStoreAllowNavigation
                }
            ),
            (
                NopCustomerDefaults.GuestsRoleName,
                new[]
                {
                    DisplayPrices,
                    EnableShoppingCart,
                    EnableWishlist,
                    PublicStoreAllowNavigation
                }
            ),
            (
                NopCustomerDefaults.RegisteredRoleName,
                new[]
                {
                    DisplayPrices,
                    EnableShoppingCart,
                    EnableWishlist,
                    PublicStoreAllowNavigation,
                    EnableMultiFactorAuthentication
                }
            ),
            (
                NopCustomerDefaults.VendorsRoleName,
                new[]
                {
                    AccessAdminPanel,
                    ManageProducts,
                    ManageProductReviews,
                    ManageOrders
                }
            )
        };
    }
}