55using Grand . Business . Core . Interfaces . Common . Stores ;
66using Grand . Domain . Permissions ;
77using Grand . Domain . Seo ;
8- using Grand . Infrastructure ;
9- using Grand . Web . Admin . Extensions ;
10- using Grand . Web . AdminShared . Extensions ;
118using Grand . Web . AdminShared . Extensions . Mapping ;
129using Grand . Web . AdminShared . Interfaces ;
1310using Grand . Web . AdminShared . Models . Blogs ;
@@ -31,8 +28,6 @@ public BlogController(
3128 ILanguageService languageService ,
3229 ITranslationService translationService ,
3330 IStoreService storeService ,
34- IContextAccessor contextAccessor ,
35- IGroupService groupService ,
3631 IDateTimeService dateTimeService ,
3732 IPictureViewModelService pictureViewModelService ,
3833 SeoSettings seoSettings )
@@ -42,8 +37,6 @@ public BlogController(
4237 _languageService = languageService ;
4338 _translationService = translationService ;
4439 _storeService = storeService ;
45- _contextAccessor = contextAccessor ;
46- _groupService = groupService ;
4740 _dateTimeService = dateTimeService ;
4841 _pictureViewModelService = pictureViewModelService ;
4942 _seoSettings = seoSettings ;
@@ -58,8 +51,6 @@ public BlogController(
5851 private readonly ILanguageService _languageService ;
5952 private readonly ITranslationService _translationService ;
6053 private readonly IStoreService _storeService ;
61- private readonly IContextAccessor _contextAccessor ;
62- private readonly IGroupService _groupService ;
6354 private readonly IDateTimeService _dateTimeService ;
6455 private readonly IPictureViewModelService _pictureViewModelService ;
6556 private readonly SeoSettings _seoSettings ;
@@ -96,7 +87,8 @@ public async Task<IActionResult> Create()
9687 ViewBag . AllLanguages = await _languageService . GetAllLanguages ( true ) ;
9788 var model = new BlogPostModel {
9889 //default values
99- AllowComments = true
90+ AllowComments = true ,
91+ CreateDate = DateTime . UtcNow
10092 } ;
10193 //locales
10294 await AddLocales ( _languageService , model . Locales ) ;
@@ -111,8 +103,6 @@ public async Task<IActionResult> Create(BlogPostModel model, bool continueEditin
111103 {
112104 if ( ModelState . IsValid )
113105 {
114- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
115- model . Stores = [ _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ] ;
116106 var blogPost = await _blogViewModelService . InsertBlogPostModel ( model ) ;
117107 Success ( _translationService . GetResource ( "Admin.Content.Blog.BlogPosts.Added" ) ) ;
118108 return continueEditing ? RedirectToAction ( "Edit" , new { id = blogPost . Id } ) : RedirectToAction ( "List" ) ;
@@ -132,21 +122,6 @@ public async Task<IActionResult> Edit(string id)
132122 //No blog post found with the specified id
133123 return RedirectToAction ( "List" ) ;
134124
135- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
136- {
137- if ( ! blogPost . LimitedToStores || ( blogPost . LimitedToStores &&
138- blogPost . Stores . Contains ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) &&
139- blogPost . Stores . Count > 1 ) )
140- {
141- Warning ( _translationService . GetResource ( "Admin.Content.Blog.BlogPosts.Permissions" ) ) ;
142- }
143- else
144- {
145- if ( ! blogPost . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
146- return RedirectToAction ( "List" ) ;
147- }
148- }
149-
150125 ViewBag . AllLanguages = await _languageService . GetAllLanguages ( true ) ;
151126 var model = blogPost . ToModel ( _dateTimeService ) ;
152127 //locales
@@ -173,15 +148,8 @@ public async Task<IActionResult> Edit(BlogPostModel model, bool continueEditing)
173148 //No blog post found with the specified id
174149 return RedirectToAction ( "List" ) ;
175150
176- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
177- if ( ! blogPost . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
178- return RedirectToAction ( "Edit" , new { id = blogPost . Id } ) ;
179-
180151 if ( ModelState . IsValid )
181152 {
182- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
183- model . Stores = [ _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ] ;
184-
185153 blogPost = await _blogViewModelService . UpdateBlogPostModel ( model , blogPost ) ;
186154
187155 Success ( _translationService . GetResource ( "Admin.Content.Blog.BlogPosts.Updated" ) ) ;
@@ -222,10 +190,6 @@ public async Task<IActionResult> Delete(string id)
222190 //No blog post found with the specified id
223191 return RedirectToAction ( "List" ) ;
224192
225- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
226- if ( ! blogPost . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
227- return RedirectToAction ( "Edit" , new { id = blogPost . Id } ) ;
228-
229193 if ( ModelState . IsValid )
230194 {
231195 await _blogService . DeleteBlogPost ( blogPost ) ;
@@ -295,7 +259,7 @@ public IActionResult CategoryList()
295259 [ HttpPost ]
296260 public async Task < IActionResult > CategoryList ( DataSourceRequest command )
297261 {
298- var categories = await _blogService . GetAllBlogCategories ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) ;
262+ var categories = await _blogService . GetAllBlogCategories ( "" ) ;
299263 var gridModel = new DataSourceResult {
300264 Data = categories ,
301265 Total = categories . Count
@@ -321,9 +285,6 @@ public async Task<IActionResult> CategoryCreate(BlogCategoryModel model, bool co
321285 {
322286 if ( ModelState . IsValid )
323287 {
324- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
325- model . Stores = [ _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ] ;
326-
327288 var blogCategory = model . ToEntity ( ) ;
328289 blogCategory . SeName = SeoExtensions . GetSeName (
329290 string . IsNullOrEmpty ( blogCategory . SeName ) ? blogCategory . Name : blogCategory . SeName ,
@@ -352,22 +313,6 @@ public async Task<IActionResult> CategoryEdit(string id)
352313 //No blog post found with the specified id
353314 return RedirectToAction ( "CategoryList" ) ;
354315
355- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
356- {
357- if ( ! blogCategory . LimitedToStores || ( blogCategory . LimitedToStores &&
358- blogCategory . Stores . Contains (
359- _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) &&
360- blogCategory . Stores . Count > 1 ) )
361- {
362- Warning ( _translationService . GetResource ( "Admin.Content.Blog.BlogCategory.Permissions" ) ) ;
363- }
364- else
365- {
366- if ( ! blogCategory . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
367- return RedirectToAction ( "List" ) ;
368- }
369- }
370-
371316 ViewBag . AllLanguages = await _languageService . GetAllLanguages ( true ) ;
372317 var model = blogCategory . ToModel ( ) ;
373318 //locales
@@ -388,15 +333,8 @@ public async Task<IActionResult> CategoryEdit(BlogCategoryModel model, bool cont
388333 //No blog post found with the specified id
389334 return RedirectToAction ( "CategoryList" ) ;
390335
391- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
392- if ( ! blogCategory . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
393- return RedirectToAction ( "CategoryEdit" , new { id = blogCategory . Id } ) ;
394-
395336 if ( ModelState . IsValid )
396337 {
397- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
398- model . Stores = [ _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ] ;
399-
400338 blogCategory = model . ToEntity ( blogCategory ) ;
401339 blogCategory . SeName = SeoExtensions . GetSeName (
402340 string . IsNullOrEmpty ( blogCategory . SeName ) ? blogCategory . Name : blogCategory . SeName ,
@@ -436,10 +374,6 @@ public async Task<IActionResult> CategoryDelete(string id)
436374 //No blog post found with the specified id
437375 return RedirectToAction ( "CategoryList" ) ;
438376
439- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
440- if ( ! blogcategory . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
441- return RedirectToAction ( "CategoryEdit" , new { id = blogcategory . Id } ) ;
442-
443377 if ( ModelState . IsValid )
444378 {
445379 await _blogService . DeleteBlogCategory ( blogcategory ) ;
@@ -488,10 +422,6 @@ public async Task<IActionResult> CategoryPostDelete(string categoryId, string id
488422 if ( blogCategory == null )
489423 return ErrorForKendoGridJson ( "blogCategory no exists" ) ;
490424
491- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
492- if ( ! blogCategory . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
493- return ErrorForKendoGridJson ( "blogCategory no permission" ) ;
494-
495425 if ( ModelState . IsValid )
496426 {
497427 var post = blogCategory . BlogPosts . FirstOrDefault ( x => x . Id == id ) ;
@@ -512,12 +442,8 @@ public async Task<IActionResult> BlogPostAddPopup(string categoryId)
512442 {
513443 var model = new AddBlogPostCategoryModel ( ) ;
514444 //stores
515- var storeId = _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ;
516-
517- model . AvailableStores . Add ( new SelectListItem
518- { Text = _translationService . GetResource ( "Admin.Common.All" ) , Value = " " } ) ;
519- foreach ( var s in ( await _storeService . GetAllStores ( ) ) . Where ( x =>
520- x . Id == storeId || string . IsNullOrWhiteSpace ( storeId ) ) )
445+ model . AvailableStores . Add ( new SelectListItem { Text = _translationService . GetResource ( "Admin.Common.All" ) , Value = " " } ) ;
446+ foreach ( var s in await _storeService . GetAllStores ( ) )
521447 model . AvailableStores . Add ( new SelectListItem { Text = s . Shortcut , Value = s . Id } ) ;
522448 model . CategoryId = categoryId ;
523449 return View ( model ) ;
@@ -529,9 +455,6 @@ public async Task<IActionResult> BlogPostAddPopupList(DataSourceRequest command,
529455 {
530456 var gridModel = new DataSourceResult ( ) ;
531457
532- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
533- model . SearchStoreId = _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ;
534-
535458 var posts = await _blogService . GetAllBlogPosts ( model . SearchStoreId , blogPostName : model . SearchBlogTitle ,
536459 pageIndex : command . Page - 1 , pageSize : command . PageSize ) ;
537460 gridModel . Data = posts . Select ( x => new { x . Id , Name = x . Title } ) ;
@@ -550,7 +473,7 @@ public async Task<IActionResult> BlogPostAddPopup(AddBlogPostCategoryModel model
550473 if ( blogCategory != null )
551474 foreach ( var id in model . SelectedBlogPostIds )
552475 {
553- var post = _blogService . GetBlogPostById ( id ) ;
476+ var post = await _blogService . GetBlogPostById ( id ) ;
554477 if ( post != null )
555478 if ( ! blogCategory . BlogPosts . Any ( x => x . BlogPostId == id ) )
556479 {
@@ -594,9 +517,6 @@ public async Task<IActionResult> CommentDelete(string id)
594517 throw new ArgumentException ( "No comment found with the specified id" ) ;
595518
596519 var blogPost = await _blogService . GetBlogPostById ( comment . BlogPostId ) ;
597- if ( await _groupService . IsStoreManager ( _contextAccessor . WorkContext . CurrentCustomer ) )
598- if ( ! blogPost . AccessToEntityByStore ( _contextAccessor . WorkContext . CurrentCustomer . StaffStoreId ) )
599- return ErrorForKendoGridJson ( "blogPost no permission" ) ;
600520
601521 if ( ModelState . IsValid )
602522 {
0 commit comments