7a5ea75b50
CI/CD / CI · API (dotnet build + test) (push) Successful in 40s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 30s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m9s
CI/CD / CI · Admin Web (tsc) (push) Successful in 37s
CI/CD / CI · Website (tsc) (push) Successful in 45s
CI/CD / CI · Koja (tsc) (push) Has been cancelled
CI/CD / Deploy · all services (push) Has been cancelled
Closes the gap where the custom-role matrix was defined but unenforced — most write endpoints only checked café membership, so the API would accept writes a role's UI hid. Adds EnsurePermission(...) to all mutating/sensitive endpoints across 32 controllers, mapped to the granular catalog: - menu/inventory/coupons/customers/expenses/reservations/taxes/branches → CRUD perms - tables/queue/kitchen-stations/print-settings → manage perms - orders → ProcessOrders / EditOrder / VoidOrder / UpdateOrderStatus / HandlePayments, payment corrections → ManageFinancials - HR → CreateStaff / ManageSchedules / ReviewLeave / View+ManageSalaries / ManageStaffCredentials (self-service clock-in/leave preserved) - reports → ViewReports, export → ExportReports, audit → ViewAuditLog - billing → ManageBilling, sms → SendSms/ManageSmsSettings, reviews → ManageReviews, discover/public profile → ManageDiscoverProfile, café settings → ManageCafeSettings, custom roles → ManageRoles Removes legacy [Authorize(Roles=...)] attributes that would have overridden the permission model (orders, branch-menu, pos-device, print). Manual discount/comp have no backend endpoint yet (discounts come from coupons) — gated on the POS UI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
using FluentValidation;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Meezi.API.Models.Public;
|
|
using Meezi.API.Services;
|
|
using Meezi.Core.Authorization;
|
|
using Meezi.Core.Enums;
|
|
using Meezi.Core.Interfaces;
|
|
using Meezi.Infrastructure.Services.Platform;
|
|
using Meezi.Shared;
|
|
|
|
namespace Meezi.API.Controllers;
|
|
|
|
[Route("api/cafes/{cafeId}/reviews")]
|
|
public class CafeReviewsController : CafeApiControllerBase
|
|
{
|
|
private readonly IReviewService _reviews;
|
|
private readonly IValidator<ReplyCafeReviewRequest> _replyValidator;
|
|
private readonly IPlatformCatalogService _catalog;
|
|
|
|
public CafeReviewsController(
|
|
IReviewService reviews,
|
|
IValidator<ReplyCafeReviewRequest> replyValidator,
|
|
IPlatformCatalogService catalog)
|
|
{
|
|
_reviews = reviews;
|
|
_replyValidator = replyValidator;
|
|
_catalog = catalog;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> List(
|
|
string cafeId,
|
|
ITenantContext tenant,
|
|
CancellationToken ct,
|
|
[FromQuery] int page = 1,
|
|
[FromQuery] int pageSize = 20)
|
|
{
|
|
if (EnsureCafeAccess(cafeId, tenant) is { } denied) return denied;
|
|
var data = await _reviews.GetReviewsAsync(cafeId, page, pageSize, publicOnly: false, ct);
|
|
return Ok(new ApiResponse<IReadOnlyList<CafeReviewDto>>(true, data));
|
|
}
|
|
|
|
[HttpPatch("{reviewId}/reply")]
|
|
public async Task<IActionResult> Reply(
|
|
string cafeId,
|
|
string reviewId,
|
|
[FromBody] ReplyCafeReviewRequest request,
|
|
ITenantContext tenant,
|
|
CancellationToken ct = default)
|
|
{
|
|
if (EnsureCafeAccess(cafeId, tenant) is { } denied) return denied;
|
|
if (EnsurePermission(tenant, Permission.ManageReviews) is { } permDenied) return permDenied;
|
|
|
|
// Replying to reviews is a paid feature (Starter+).
|
|
var tier = tenant.PlanTier ?? PlanTier.Free;
|
|
if (!await _catalog.IsFeatureEnabledForCafeAsync(cafeId, tier, "review_reply", ct))
|
|
return StatusCode(403, new ApiResponse<object>(false, null,
|
|
new ApiError("PLAN_FEATURE_DISABLED", "Replying to reviews is not included in your plan. Please upgrade.")));
|
|
|
|
var validation = await _replyValidator.ValidateAsync(request, ct);
|
|
if (!validation.IsValid)
|
|
{
|
|
var first = validation.Errors.First();
|
|
return BadRequest(new ApiResponse<object>(false, null, new ApiError("VALIDATION_ERROR", first.ErrorMessage, first.PropertyName)));
|
|
}
|
|
|
|
var data = await _reviews.ReplyReviewAsync(cafeId, reviewId, request.Reply, ct);
|
|
if (data is null) return NotFoundError();
|
|
return Ok(new ApiResponse<CafeReviewDto>(true, data));
|
|
}
|
|
|
|
[HttpPatch("{reviewId}/visibility")]
|
|
public async Task<IActionResult> SetVisibility(
|
|
string cafeId,
|
|
string reviewId,
|
|
[FromBody] HideCafeReviewRequest request,
|
|
ITenantContext tenant,
|
|
CancellationToken ct = default)
|
|
{
|
|
if (EnsureCafeAccess(cafeId, tenant) is { } denied) return denied;
|
|
if (EnsurePermission(tenant, Permission.ManageReviews) is { } permDenied) return permDenied;
|
|
var data = await _reviews.SetHiddenAsync(cafeId, reviewId, request.IsHidden, ct);
|
|
if (data is null) return NotFoundError();
|
|
return Ok(new ApiResponse<CafeReviewDto>(true, data));
|
|
}
|
|
}
|