Browse Source

cmskit: reactions auth

pull/5016/head
Yunus Emre Kalkan 6 years ago
parent
commit
d63e614a8d
  1. 5
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Public.cshtml
  2. 10
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs
  3. 7
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js
  4. 28
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml
  5. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js

5
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Public.cshtml

@ -3,6 +3,7 @@
@using Microsoft.Extensions.Localization @using Microsoft.Extensions.Localization
@using Volo.CmsKit.Pages @using Volo.CmsKit.Pages
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelection
@model PublicModel @model PublicModel
@inject IStringLocalizer<AbpUiResource> Localizer @inject IStringLocalizer<AbpUiResource> Localizer
<h1>CMS Kit DEMO - Public</h1> <h1>CMS Kit DEMO - Public</h1>
@ -18,7 +19,9 @@
</footer> </footer>
</abp-blockquote> </abp-blockquote>
</abp-card-body> </abp-card-body>
@await Component.InvokeAsync(typeof(CommentingViewComponent), new { entityType = "publicQuote", entityId = "1", loginUrl="Account/Login?ReturnUrl=%2Fpublic" }) @await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new { entityType = "publicQuote", entityId = "1" })
<hr />
@await Component.InvokeAsync(typeof(CommentingViewComponent), new { entityType = "publicQuote", entityId = "1", loginUrl = "Account/Login?ReturnUrl=%2Fpublic" })
</abp-card> </abp-card>
<abp-card class="mb-3"> <abp-card class="mb-3">

10
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Users; using Volo.Abp.Users;
using Volo.CmsKit.Reactions; using Volo.CmsKit.Reactions;
@ -30,12 +31,13 @@ namespace Volo.CmsKit.Public.Reactions
{ {
var summaries = await ReactionManager.GetSummariesAsync(entityType, entityId); var summaries = await ReactionManager.GetSummariesAsync(entityType, entityId);
var userReactions = (await UserReactionRepository var userReactions = CurrentUser.IsAuthenticated ?
(await UserReactionRepository
.GetListForUserAsync( .GetListForUserAsync(
CurrentUser.GetId(), CurrentUser.GetId(),
entityType, entityType,
entityId entityId
)).ToDictionary(x => x.ReactionName, x => x); )).ToDictionary(x => x.ReactionName, x => x) : null;
var reactionWithSelectionDtos = new List<ReactionWithSelectionDto>(); var reactionWithSelectionDtos = new List<ReactionWithSelectionDto>();
@ -46,7 +48,7 @@ namespace Volo.CmsKit.Public.Reactions
{ {
Reaction = ConvertToReactionDto(summary.Reaction), Reaction = ConvertToReactionDto(summary.Reaction),
Count = summary.Count, Count = summary.Count,
IsSelectedByCurrentUser = userReactions.ContainsKey(summary.Reaction.Name) IsSelectedByCurrentUser = userReactions?.ContainsKey(summary.Reaction.Name) ?? false
} }
); );
} }
@ -54,6 +56,7 @@ namespace Volo.CmsKit.Public.Reactions
return new ListResultDto<ReactionWithSelectionDto>(reactionWithSelectionDtos); return new ListResultDto<ReactionWithSelectionDto>(reactionWithSelectionDtos);
} }
[Authorize]
public virtual async Task CreateAsync(CreateReactionDto input) public virtual async Task CreateAsync(CreateReactionDto input)
{ {
await ReactionManager.CreateAsync( await ReactionManager.CreateAsync(
@ -64,6 +67,7 @@ namespace Volo.CmsKit.Public.Reactions
); );
} }
[Authorize]
public virtual async Task DeleteAsync(DeleteReactionDto input) public virtual async Task DeleteAsync(DeleteReactionDto input)
{ {
await ReactionManager.DeleteAsync( await ReactionManager.DeleteAsync(

7
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js

@ -87,7 +87,7 @@
abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) { abp.message.confirm(l("MessageDeletionConfirmationMessage"), function (ok) {
if (ok){ if (ok){
volo.cmsKit.comments.commentPublic.delete($link.data('id') volo.cmsKit.public.comments.commentPublic.delete($link.data('id')
).then(function () { ).then(function () {
widgetManager.refresh($widget); widgetManager.refresh($widget);
}); });
@ -103,7 +103,7 @@
$form.submit(function (e) { $form.submit(function (e) {
e.preventDefault(); e.preventDefault();
var formAsObject = $form.serializeFormToObject(); var formAsObject = $form.serializeFormToObject();
volo.cmsKit.comments.commentPublic.update( volo.cmsKit.public.comments.commentPublic.update(
formAsObject.id, formAsObject.id,
{ {
text: formAsObject.commentText text: formAsObject.commentText
@ -121,8 +121,7 @@
$form.submit(function (e) { $form.submit(function (e) {
e.preventDefault(); e.preventDefault();
var formAsObject = $form.serializeFormToObject(); var formAsObject = $form.serializeFormToObject();
console.log(formAsObject); volo.cmsKit.public.comments.commentPublic.create(
volo.cmsKit.comments.commentPublic.create(
$.extend(getFilters(), { $.extend(getFilters(), {
repliedCommentId: formAsObject.repliedCommentId, repliedCommentId: formAsObject.repliedCommentId,
text: formAsObject.commentText text: formAsObject.commentText

28
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/Default.cshtml

@ -1,17 +1,23 @@
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelection.ReactionSelectionViewComponent.ReactionSelectionViewModel @inject ICurrentUser CurrentUser
@using Volo.Abp.Users
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelection.ReactionSelectionViewComponent.ReactionSelectionViewModel
<span class="cms-reaction-area" data-entity-type="@Model.EntityType" data-entity-id="@Model.EntityId"> <span class="cms-reaction-area" data-entity-type="@Model.EntityType" data-entity-id="@Model.EntityId">
<a class="cms-reaction-select-icon" tabindex="0"><i class="fa fa-smile-o"></i></a>
<div class="cms-reaction-selection-popover-content" style="display: none"> @if (CurrentUser.IsAuthenticated)
@foreach (var reaction in Model.Reactions) {
{ <a class="cms-reaction-select-icon" tabindex="0"><i class="fa fa-smile-o"></i></a>
<span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name"> <div class="cms-reaction-selection-popover-content" style="display: none">
<img src="@reaction.Icon" width="18" height="18"/> @foreach (var reaction in Model.Reactions)
</span> {
} <span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name">
</div> <img src="@reaction.Icon" width="18" height="18"/>
</span>
}
</div>
}
@foreach (var reaction in Model.Reactions.Where(r => r.Count > 0)) @foreach (var reaction in Model.Reactions.Where(r => r.Count > 0))
{ {
<span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name"> <span class="mr-1 cms-reaction-icon @(reaction.IsSelectedByCurrentUser ? "cms-reaction-icon-selected" : "")" data-reaction-name="@reaction.Name" data-click-action="@(CurrentUser.IsAuthenticated ? "true" : "false")">
<img src="@reaction.Icon" width="18" height="18"/> <img src="@reaction.Icon" width="18" height="18"/>
@(reaction.Count) @(reaction.Count)
</span> </span>

8
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js

@ -26,11 +26,15 @@
function registerClickOfReactionIcons($container) { function registerClickOfReactionIcons($container) {
$container.find('.cms-reaction-icon').each(function () { $container.find('.cms-reaction-icon').each(function () {
var $icon = $(this); var $icon = $(this);
var reactionName = $icon.attr('data-reaction-name');
if ($icon.attr('data-click-action') === 'false'){
return;
}
$icon.click(function () { $icon.click(function () {
var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create';
volo.cmsKit.reactions.reactionPublic[methodName]( volo.cmsKit.public.reactions.reactionPublic[methodName](
$.extend(getFilters(), { $.extend(getFilters(), {
reactionName: $icon.attr('data-reaction-name') reactionName: reactionName
}) })
).then(function () { ).then(function () {
$selectIcon.popover('hide'); $selectIcon.popover('hide');

Loading…
Cancel
Save