Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

fix: remove unreachable IsStoreManager branches from Admin controllers (#807)

Krzysztof Pajak850707693055
diff --git a/src/Web/Grand.Web.Admin/Controllers/CourseController.cs b/src/Web/Grand.Web.Admin/Controllers/CourseController.cs
index 24013410f..e07575649 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CourseController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CourseController.cs
@@ -1,6 +1,5 @@
using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Marketing.Courses;
using Grand.Domain.Permissions;
@@ -27,7 +26,6 @@ public class CourseController : BaseAdminController
private readonly ICourseService _courseService;
private readonly ICourseSubjectService _courseSubjectService;
private readonly ICourseViewModelService _courseViewModelService;
- private readonly IGroupService _groupService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
@@ -41,8 +39,7 @@ public class CourseController : BaseAdminController
ICourseLessonService courseLessonService,
ICourseViewModelService courseViewModelService,
IContextAccessor contextAccessor,
- ILanguageService languageService,
- IGroupService groupService)
+ ILanguageService languageService)
{
_translationService = translationService;
_courseLevelService = courseLevelService;
@@ -52,7 +49,6 @@ public class CourseController : BaseAdminController
_courseViewModelService = courseViewModelService;
_contextAccessor = contextAccessor;
_languageService = languageService;
- _groupService = groupService;
}
@@ -155,9 +151,6 @@ public class CourseController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
-
var course = await _courseViewModelService.InsertCourseModel(model);
Success(_translationService.GetResource("Admin.Courses.Course.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = course.Id }) : RedirectToAction("List");
@@ -177,21 +170,6 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- {
- if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- course.Stores.Count > 1))
- {
- Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
- }
- else
- {
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("List");
- }
- }
-
var model = course.ToModel();
//locales
await AddLocales(_languageService, model.Locales, (locale, languageId) =>
@@ -220,15 +198,8 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = course.Id });
-
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
-
course = await _courseViewModelService.UpdateCourseModel(course, model);
Success(_translationService.GetResource("Admin.Courses.Course.Updated"));
@@ -258,10 +229,6 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = course.Id });
-
if (ModelState.IsValid)
{
await _courseViewModelService.DeleteCourse(course);
@@ -394,21 +361,6 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- {
- if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- course.Stores.Count > 1))
- {
- Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
- }
- else
- {
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("List");
- }
- }
-
var model = await _courseViewModelService.PrepareCourseLessonModel(courseId);
return View(model);
@@ -424,21 +376,6 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- {
- if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- course.Stores.Count > 1))
- {
- Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
- }
- else
- {
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("List");
- }
- }
-
if (ModelState.IsValid)
{
var lesson = await _courseViewModelService.InsertCourseLessonModel(model);
@@ -468,21 +405,6 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- {
- if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- course.Stores.Count > 1))
- {
- Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
- }
- else
- {
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("List");
- }
- }
-
var model = lesson.ToModel();
model = await _courseViewModelService.PrepareCourseLessonModel(lesson.CourseId, model);
return View(model);
@@ -503,9 +425,6 @@ public class CourseController : BaseAdminController
//No category found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = course.Id });
if (ModelState.IsValid)
{
lesson = await _courseViewModelService.UpdateCourseLessonModel(lesson, model);
@@ -541,9 +460,6 @@ public class CourseController : BaseAdminController
//No category found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = course.Id });
await _courseViewModelService.DeleteCourseLesson(lesson);
Success(_translationService.GetResource("Admin.Courses.Course.Lesson.Deleted"));
diff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
index 7dfb21515..1509f59c3 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
@@ -696,8 +696,6 @@ public class CustomerController : BaseAdminController
var model = new OrderListModel {
CustomerId = customerId
};
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var (orderModels, totalCount) =
await orderViewModelService.PrepareOrderModel(model, command.Page, command.PageSize);
@@ -723,13 +721,6 @@ public class CustomerController : BaseAdminController
if (order == null)
throw new ArgumentException("No order found with the specified id");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
- return Json(new DataSourceResult {
- Data = null,
- Total = 0
- });
-
var ordermodel = new OrderModel();
await orderViewModelService.PrepareOrderDetailsModel(ordermodel, order);
var gridModel = new DataSourceResult {
diff --git a/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs b/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs
index fa7c03553..2dc670d7d 100644
--- a/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs
@@ -35,7 +35,6 @@ public class DiscountController : BaseAdminController
ITranslationService translationService,
IContextAccessor contextAccessor,
IDateTimeService dateTimeService,
- IGroupService groupService,
IDiscountProviderLoader discountProviderLoader,
IMediator mediator)
{
@@ -44,7 +43,6 @@ public class DiscountController : BaseAdminController
_translationService = translationService;
_contextAccessor = contextAccessor;
_dateTimeService = dateTimeService;
- _groupService = groupService;
_discountProviderLoader = discountProviderLoader;
_mediator = mediator;
}
@@ -58,7 +56,6 @@ public class DiscountController : BaseAdminController
private readonly ITranslationService _translationService;
private readonly IContextAccessor _contextAccessor;
private readonly IDateTimeService _dateTimeService;
- private readonly IGroupService _groupService;
private readonly IDiscountProviderLoader _discountProviderLoader;
private readonly IMediator _mediator;
@@ -110,9 +107,6 @@ public class DiscountController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
-
var discount = await _discountViewModelService.InsertDiscountModel(model);
Success(_translationService.GetResource("admin.marketing.discounts.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = discount.Id }) : RedirectToAction("List");
@@ -133,21 +127,6 @@ public class DiscountController : BaseAdminController
//No discount found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- {
- if (!discount.LimitedToStores || (discount.LimitedToStores &&
- discount.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- discount.Stores.Count > 1))
- {
- Warning(_translationService.GetResource("admin.marketing.discounts.Permissions"));
- }
- else
- {
- if (!discount.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("List");
- }
- }
-
var model = discount.ToModel(_dateTimeService);
await _discountViewModelService.PrepareDiscountModel(model, discount);
@@ -164,15 +143,8 @@ public class DiscountController : BaseAdminController
//No discount found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!discount.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = discount.Id });
-
if (ModelState.IsValid)
{
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
-
discount = await _discountViewModelService.UpdateDiscountModel(discount, model);
Success(_translationService.GetResource("admin.marketing.discounts.Updated"));
if (continueEditing)
@@ -201,10 +173,6 @@ public class DiscountController : BaseAdminController
//No discount found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- if (!discount.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = discount.Id });
-
var usageHistory = await _mediator.Send(new GetDiscountUsageHistoryQuery { DiscountId = discount.Id });
if (usageHistory.Count > 0)
{
diff --git a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
index 46cc4a423..b033b87ea 100644
--- a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
@@ -53,8 +53,6 @@ public class HomeController : BaseAdminController
var model = new DashboardActivityModel();
var storeId = string.Empty;
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
model.OrdersPending =
(await _orderReportService.GetOrderAverageReportLine(storeId, os: (int)OrderStatusSystem.Pending))
@@ -137,9 +135,6 @@ public class HomeController : BaseAdminController
if (storeid != null)
storeid = storeid.Trim();
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- returnUrl = Url.Action("Index", "Home", new { area = Constants.AreaAdmin });
-
var store = await _storeService.GetStoreById(storeid);
if (store != null || storeid == "")
await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
diff --git a/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs b/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs
index bc8e3b3e1..409f1f01f 100644
--- a/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs
@@ -20,7 +20,6 @@ namespace Grand.Web.Admin.Controllers;
public class NewsLetterSubscriptionController : BaseAdminController
{
private readonly IDateTimeService _dateTimeService;
- private readonly IGroupService _groupService;
private readonly INewsletterCategoryService _newsletterCategoryService;
private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
private readonly IStoreService _storeService;
@@ -32,7 +31,6 @@ public class NewsLetterSubscriptionController : BaseAdminController
IDateTimeService dateTimeService,
ITranslationService translationService,
IStoreService storeService,
- IGroupService groupService,
IContextAccessor contextAccessor)
{
_newsLetterSubscriptionService = newsLetterSubscriptionService;
@@ -40,7 +38,6 @@ public class NewsLetterSubscriptionController : BaseAdminController
_dateTimeService = dateTimeService;
_translationService = translationService;
_storeService = storeService;
- _groupService = groupService;
_contextAccessor = contextAccessor;
}
@@ -122,9 +119,6 @@ public class NewsLetterSubscriptionController : BaseAdminController
break;
}
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
-
var newsletterSubscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(
model.SearchEmail,
model.StoreId, isActive, searchCategoryIds, command.Page - 1, command.PageSize);
@@ -189,9 +183,6 @@ public class NewsLetterSubscriptionController : BaseAdminController
break;
}
- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
-
var subscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
model.StoreId, isActive, searchCategoryIds);