Skip to content

Commit

Permalink
#3627 When you limit a topic page to a particular store you could sti…
Browse files Browse the repository at this point in the history
…ll view it on other stores
  • Loading branch information
AndreiMaz committed Mar 26, 2019
1 parent 8db131c commit 23c6ebe
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/Presentation/Nop.Web/Controllers/TopicController.cs
Expand Up @@ -47,10 +47,11 @@ public partial class TopicController : BasePublicController
[HttpsRequirement(SslRequirement.No)]
public virtual IActionResult TopicDetails(int topicId)
{
var model = _topicModelFactory.PrepareTopicModelById(topicId);
//allow administrators to preview any topic
var hasAdminAccess = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageTopics);
//access to Topics preview
if (model == null || (!model.Published && !hasAdminAccess))

var model = _topicModelFactory.PrepareTopicModelById(topicId, hasAdminAccess);
if (model == null)
return RedirectToRoute("Homepage");

//display "edit" (manage) link
Expand Down
3 changes: 2 additions & 1 deletion src/Presentation/Nop.Web/Factories/ITopicModelFactory.cs
Expand Up @@ -11,8 +11,9 @@ public partial interface ITopicModelFactory
/// Get the topic model by topic identifier
/// </summary>
/// <param name="topicId">Topic identifier</param>
/// <param name="showHidden">A value indicating whether to show hidden records</param>
/// <returns>Topic model</returns>
TopicModel PrepareTopicModelById(int topicId);
TopicModel PrepareTopicModelById(int topicId, bool showHidden = false);

/// <summary>
/// Get the topic model by topic system name
Expand Down
27 changes: 21 additions & 6 deletions src/Presentation/Nop.Web/Factories/TopicModelFactory.cs
Expand Up @@ -7,6 +7,7 @@
using Nop.Services.Localization;
using Nop.Services.Security;
using Nop.Services.Seo;
using Nop.Services.Stores;
using Nop.Services.Topics;
using Nop.Web.Infrastructure.Cache;
using Nop.Web.Models.Topics;
Expand All @@ -24,6 +25,7 @@ public partial class TopicModelFactory : ITopicModelFactory
private readonly ILocalizationService _localizationService;
private readonly IStaticCacheManager _cacheManager;
private readonly IStoreContext _storeContext;
private readonly IStoreMappingService _storeMappingService;
private readonly ITopicService _topicService;
private readonly ITopicTemplateService _topicTemplateService;
private readonly IUrlRecordService _urlRecordService;
Expand All @@ -37,6 +39,7 @@ public partial class TopicModelFactory : ITopicModelFactory
ILocalizationService localizationService,
IStaticCacheManager cacheManager,
IStoreContext storeContext,
IStoreMappingService storeMappingService,
ITopicService topicService,
ITopicTemplateService topicTemplateService,
IUrlRecordService urlRecordService,
Expand All @@ -46,6 +49,7 @@ public partial class TopicModelFactory : ITopicModelFactory
_localizationService = localizationService;
_cacheManager = cacheManager;
_storeContext = storeContext;
_storeMappingService = storeMappingService;
_topicService = topicService;
_topicTemplateService = topicTemplateService;
_urlRecordService = urlRecordService;
Expand Down Expand Up @@ -78,8 +82,7 @@ protected virtual TopicModel PrepareTopicModel(Topic topic)
MetaDescription = _localizationService.GetLocalized(topic, x => x.MetaDescription),
MetaTitle = _localizationService.GetLocalized(topic, x => x.MetaTitle),
SeName = _urlRecordService.GetSeName(topic),
TopicTemplateId = topic.TopicTemplateId,
Published = topic.Published
TopicTemplateId = topic.TopicTemplateId
};
return model;
}
Expand All @@ -92,20 +95,32 @@ protected virtual TopicModel PrepareTopicModel(Topic topic)
/// Get the topic model by topic identifier
/// </summary>
/// <param name="topicId">Topic identifier</param>
/// <param name="showHidden">A value indicating whether to show hidden records</param>
/// <returns>Topic model</returns>
public virtual TopicModel PrepareTopicModelById(int topicId)
public virtual TopicModel PrepareTopicModelById(int topicId, bool showHidden = false)
{
var cacheKey = string.Format(NopModelCacheDefaults.TopicModelByIdKey,
topicId,
_workContext.WorkingLanguage.Id,
_storeContext.CurrentStore.Id,
string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()));
string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()),
showHidden);
var cachedModel = _cacheManager.Get(cacheKey, () =>
{
var topic = _topicService.GetTopicById(topicId);
//ACL (access control list)
if (topic == null || !_aclService.Authorize(topic))
if (topic == null)
return null;
if (!showHidden)
{
if (!topic.Published ||
//ACL (access control list)
!_aclService.Authorize(topic) ||
//store mapping
!_storeMappingService.Authorize(topic))
return null;
}
return PrepareTopicModel(topic);
});

Expand Down
Expand Up @@ -215,8 +215,9 @@ public static partial class NopModelCacheDefaults
/// {1} : language id
/// {2} : store id
/// {3} : comma separated list of customer roles
/// {4} : show hidden records?
/// </remarks>
public static string TopicModelByIdKey => "Nop.pres.topic.details.byid-{0}-{1}-{2}-{3}";
public static string TopicModelByIdKey => "Nop.pres.topic.details.byid-{0}-{1}-{2}-{3}-{4}";
/// <summary>
/// Key for TopicModel caching
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Presentation/Nop.Web/Models/Topics/TopicModel.cs
Expand Up @@ -23,7 +23,5 @@ public partial class TopicModel : BaseNopEntityModel
public string SeName { get; set; }

public int TopicTemplateId { get; set; }

public bool Published { get; set; }
}
}

0 comments on commit 23c6ebe

Please sign in to comment.