Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new product Publish permissions #6346

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 6 additions & 80 deletions README.md
@@ -1,80 +1,6 @@
nopCommerce: free and open-source eCommerce solution
===========

[nopCommerce](https://www.nopcommerce.com/?utm_source=github&utm_medium=content&utm_campaign=homepage) is the best open-source eCommerce platform. nopCommerce is free, and it is the most popular ASP.NET Core shopping cart.

![nopCommerce demo](https://www.nopcommerce.com/images/github/responsive_devices_codeplex.png#v1)

### Key features ###

* The product is being developed and supported by the professional team since 2008.
* nopCommerce has been downloaded more than 3,000,000 times.
* The active developer community has more than 250,000 members.
* nopCommerce runs on .NET 6 with an MS SQL 2012 (or higher) backend database.
* nopCommerce is cross-platform, and you can run it on Windows, Linux, or Mac.
* nopCommerce supports Docker out of the box, so you can easily run nopCommerce on a Linux machine.
* nopCommerce supports PostgreSQL and MySQL databases.
* nopCommerce fully supports web farms. You can read more about it [here](https://docs.nopcommerce.com/en/developer/tutorials/web-farms.html?utm_source=github&utm_medium=referral&utm_campaign=documentation&utm_content=text).
* All methods in nopCommerce are async.
* nopCommerce supports multi-factor authentication out of the box.
* Start our [online course for developers](https://nopcommerce.com/training?utm_source=github&utm_medium=referral&utm_campaign=course&utm_content=text) and get the practical and technical skills you need to run and customize nopCommerce websites.

![Logo](https://www.nopcommerce.com/images/github/logos.png#v2)

nopCommerce architecture follows well-known software patterns and the best security practices. The source code is fully customizable. Pluggable and clear architecture makes it easy to develop custom functionality and follow any business requirements.

Using the latest Microsoft technologies, nopCommerce provides high performance, stability, and security. nopCommerce is also fully compatible with Azure and web farms.

Our clear and detailed [documentation](https://docs.nopcommerce.com/developer/index.html?utm_source=github&utm_medium=referral&utm_campaign=documentation&utm_content=text) and [online course](https://nopcommerce.com/training?utm_source=github&utm_medium=referral&utm_campaign=course&utm_content=text) for developers will help you start with nopCommerce easily.


### The advantages of working with nopCommerce ###

nopCommerce offers powerful [out-of-the-box features](https://www.nopcommerce.com/features?utm_source=github&utm_medium=referral&utm_campaign=features&utm_content=text) for creating an online store of any size and type.

nopCommerce is integrated with all the popular third-party services. You can find thousands of integrations on nopCommerce [Marketplace](https://www.nopcommerce.com/marketplace?utm_source=github&utm_medium=referral&utm_campaign=marketplace&utm_content=text).

The [Web API plugin](https://www.nopcommerce.com/web-api?utm_source=github&utm_medium=referral&utm_campaign=WebAPI&utm_content=text) by the nopCommerce team lets you build integrations with third-party services or mobile applications using REST. The Web API plugin is available with source code and covers all methods of nopCommerce: backend and frontend. You can read more about it [here](https://www.nopcommerce.com/web-api?utm_source=github&utm_medium=referral&utm_campaign=WebAPI&utm_content=text).

Friendly members of the [nopCommerce community](https://www.nopcommerce.com/boards?utm_source=github&utm_medium=referral&utm_campaign=forum&utm_content=text) will always help with advice and share their experiences. nopCommerce core development team provides [professional support](https://www.nopcommerce.com/nopcommerce-premium-support-services?utm_source=github&utm_medium=referral&utm_campaign=premium_support&utm_content=text) within 24 hours.


## Store demo ##

Evaluate the functionality and convenience of nopCommerce as a customer and store owner.

Front End | Admin area
----|------
[![ScreenShot](https://www.nopcommerce.com/images/github/public-demo.png#v1)](https://frontend.nopcommerce.com?utm_source=github&utm_medium=referral&utm_campaign=demo_store&utm_content=button) | [![ScreenShot](https://www.nopcommerce.com/images/github/admin-demo.png#v1)](https://admin-demo.nopcommerce.com/admin?utm_source=github&utm_medium=referral&utm_campaign=demo_store&utm_content=button)


### nopCommerce resources ###

nopCommerce official site: [https://www.nopcommerce.com](https://www.nopcommerce.com/?utm_source=github&utm_medium=referral&utm_campaign=homepage&utm_content=links)

* [Demo store](https://www.nopcommerce.com/demo?utm_source=github&utm_medium=referral&utm_campaign=demo_store&utm_content=links)
* [Download nopCommerce](https://www.nopcommerce.com/download-nopcommerce?utm_source=github&utm_medium=referral&utm_campaign=download_nop&utm_content=links)
* [Online course for developers](https://nopcommerce.com/training?utm_source=github&utm_medium=referral&utm_campaign=course&utm_content=links)
* [Feature list](https://www.nopcommerce.com/features?utm_source=github&utm_medium=referral&utm_campaign=features&utm_content=links)
* [Web API plugin](https://www.nopcommerce.com/web-api?utm_source=github&utm_medium=referral&utm_campaign=WebAPI&utm_content=links)
* [nopCommerce documentation](https://docs.nopcommerce.com?utm_source=github&utm_medium=referral&utm_campaign=documentation&utm_content=links)
* [Community forums](https://www.nopcommerce.com/boards?utm_source=github&utm_medium=referral&utm_campaign=forum&utm_content=links)
* [Premium support services](https://www.nopcommerce.com/nopcommerce-premium-support-services?utm_source=github&utm_medium=referral&utm_campaign=premium_support&utm_content=links)
* [Certified developer program](https://www.nopcommerce.com/certified-developer-program?utm_source=github&utm_medium=referral&utm_campaign=certified_developer&utm_content=links)
* [nopCommerce partners](https://www.nopcommerce.com/partners?utm_source=github&utm_medium=referral&utm_campaign=solution_partners&utm_content=links)

nopCommerce YouTube: [The Architecture behind the nopCommerce eCommerce Platform](https://www.youtube.com/watch?v=6gLbizzSA9o&list=PLnL_aDfmRHwtJmzeA7SxrpH3-XDY2ue0a)


### Earn with nopCommerce ###

60,000 stores worldwide are powered by nopCommerce, and 10,000 new stores open every year. nopCommerce [solution partners’ directory](https://www.nopcommerce.com/partners?utm_source=github&utm_medium=referral&utm_campaign=solution_partners&utm_content=text_become_partner) gets 80,000+ page views per year from store owners who are looking for a partner to build a store from scratch, migrate from another platform, or improve and customize an existing store.

Become a solution partner of nopCommerce and get new clients – [learn more](https://www.nopcommerce.com/become-partner?utm_source=github&utm_medium=referral&utm_campaign=become-partner&utm_content=learn_more).

Create a new graphical theme or develop a new plugin or integration and sell it on the nopCommerce [Marketplace](https://www.nopcommerce.com/marketplace?utm_source=github&utm_medium=referral&utm_campaign=marketplace&utm_content=text_sell_on_marketplace).


### Contribute ###

As a free and open-source project, we are very grateful to everyone who helps us to develop nopCommerce. Please find more details about the options and bonuses for contributors at [contribute page](https://www.nopcommerce.com/contribute?utm_source=github&utm_medium=referral&utm_campaign=contribute&utm_content=text).
Here I Add new product permissions for ADD or Edit.
add if condition in view to show the published field if the user has the permission PublishPermission
set the field published to false when editing the product if current user doesnt have the permission PublishPermission
set the field published always to false on create or Edit
add permission PublishPermission in the following permission provider (admin area).
set the field published always to false when importing products
Expand Up @@ -58,7 +58,7 @@ public partial class StandardPermissionProvider : IPermissionProvider
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 static readonly PermissionRecord ManagePublish = new() { Name = "Admin area. Manage Publish ", SystemName = "ManagePublish", Category = "Catalog" };
//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" };
Expand Down Expand Up @@ -132,7 +132,9 @@ public virtual IEnumerable<PermissionRecord> GetPermissions()
PublicStoreAllowNavigation,
AccessClosedStore,
AccessProfiling,
EnableMultiFactorAuthentication
EnableMultiFactorAuthentication,
ManagePublish

};
}

Expand Down Expand Up @@ -202,7 +204,9 @@ public virtual HashSet<(string systemRoleName, PermissionRecord[] permissions)>
PublicStoreAllowNavigation,
AccessClosedStore,
AccessProfiling,
EnableMultiFactorAuthentication
EnableMultiFactorAuthentication,
ManagePublish

}
),
(
Expand Down
Expand Up @@ -799,7 +799,7 @@ public virtual async Task<IActionResult> Create(bool showtour = false)

//prepare model
var model = await _productModelFactory.PrepareProductModelAsync(new ProductModel(), null);

model.CanPublish = await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePublish);
//show configuration tour
if (showtour)
{
Expand All @@ -819,6 +819,7 @@ public virtual async Task<IActionResult> Create(ProductModel model, bool continu
{
if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
var canPublish = await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePublish);

//validate maximum number of products per vendor
var currentVendor = await _workContext.GetCurrentVendorAsync();
Expand All @@ -841,6 +842,7 @@ public virtual async Task<IActionResult> Create(ProductModel model, bool continu
model.ShowOnHomepage = false;

//product
model.Published = canPublish ? model.Published : false;
var product = model.ToEntity<Product>();
product.CreatedOnUtc = DateTime.UtcNow;
product.UpdatedOnUtc = DateTime.UtcNow;
Expand Down Expand Up @@ -892,7 +894,7 @@ public virtual async Task<IActionResult> Create(ProductModel model, bool continu

//prepare model
model = await _productModelFactory.PrepareProductModelAsync(model, null, true);

model.CanPublish = canPublish;
//if we got this far, something failed, redisplay form
return View(model);
}
Expand All @@ -901,6 +903,7 @@ public virtual async Task<IActionResult> Edit(int id)
{
if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
var canPublish = await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePublish);

//try to get a product with the specified id
var product = await _productService.GetProductByIdAsync(id);
Expand All @@ -914,7 +917,7 @@ public virtual async Task<IActionResult> Edit(int id)

//prepare model
var model = await _productModelFactory.PrepareProductModelAsync(null, product);

model.CanPublish = canPublish;
return View(model);
}

Expand All @@ -923,6 +926,7 @@ public virtual async Task<IActionResult> Edit(ProductModel model, bool continueE
{
if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
var canPublish = await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePublish);

//try to get a product with the specified id
var product = await _productService.GetProductByIdAsync(model.Id);
Expand Down Expand Up @@ -963,6 +967,7 @@ public virtual async Task<IActionResult> Edit(ProductModel model, bool continueE
var previousProductType = product.ProductType;

//product
model.Published = canPublish ? model.Published : false;
product = model.ToEntity(product);

product.UpdatedOnUtc = DateTime.UtcNow;
Expand Down
Expand Up @@ -880,7 +880,7 @@ public virtual async Task<ProductModel> PrepareProductModelAsync(ProductModel mo
model.UnlimitedDownloads = true;
model.IsShipEnabled = true;
model.AllowCustomerReviews = true;
model.Published = true;
model.Published = false;
model.VisibleIndividually = true;
}

Expand Down
Expand Up @@ -394,6 +394,7 @@ public ProductModel()

public IList<ProductLocalizedModel> Locales { get; set; }

public bool CanPublish { get; set; }
//ACL (customer roles)
[NopResourceDisplayName("Admin.Catalog.Products.Fields.AclCustomerRoles")]
public IList<int> SelectedCustomerRoleIds { get; set; }
Expand Down
Expand Up @@ -306,7 +306,7 @@
</script>
</div>
</div>
<div class="form-group row @(Model.ProductEditorSettingsModel.Published ? null : "advanced-setting")">
<div class="form-group row @(Model.ProductEditorSettingsModel.Published ? null : "advanced-setting")"@(Model.CanPublish ? null : Html.Raw("style='display: none;'") )>
<div class="col-md-3">
<nop-label asp-for="Published" />
</div>
Expand Down