fix(partner): grant store staff open/close and media permissions by default
CI / verify (pull_request) Has been cancelled
CI / verify (pull_request) Has been cancelled
Default new sub-accounts to store:create+store:manage, backfill empty permissions on /partner/me, and treat legacy store staff as allowed to mutate. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { BadRequestException, Body, Controller, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common';
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
import { DEFAULT_PARTNER_STORE_STAFF_PERMISSIONS } from '@dukang/shared-types';
|
||||
import { SettlementService } from './settlement.service';
|
||||
import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
|
||||
import { PartnerPrimaryGuard } from '../../common/guards/partner-primary.guard';
|
||||
@@ -269,7 +270,7 @@ export class PartnerMeController {
|
||||
}
|
||||
|
||||
private async buildPartnerMe(actorId: bigint) {
|
||||
const account = await this.prisma.partnerAccount.findUniqueOrThrow({
|
||||
let account = await this.prisma.partnerAccount.findUniqueOrThrow({
|
||||
where: { id: actorId },
|
||||
});
|
||||
let primary = account;
|
||||
@@ -278,6 +279,23 @@ export class PartnerMeController {
|
||||
where: { id: account.parentAccountId },
|
||||
});
|
||||
}
|
||||
|
||||
// 门店类子账号若未配置权限,补齐开店/门店管理,便于开闭店与重传资料
|
||||
if (account.isPrimary !== 1) {
|
||||
const perms = Array.isArray(account.permissions) ? (account.permissions as string[]) : [];
|
||||
const hasStorePerm = perms.includes('store:create') || perms.includes('store:manage');
|
||||
const warehouseOnly =
|
||||
!hasStorePerm &&
|
||||
perms.length > 0 &&
|
||||
(perms.includes('warehouse:manage') || perms.includes('order:view'));
|
||||
if (!hasStorePerm && !warehouseOnly) {
|
||||
account = await this.prisma.partnerAccount.update({
|
||||
where: { id: account.id },
|
||||
data: { permissions: [...DEFAULT_PARTNER_STORE_STAFF_PERMISSIONS] },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const hasWarehouseAccess = await this.partnerCityService.hasManagedWarehouse(primary.id);
|
||||
return {
|
||||
id: account.id.toString(),
|
||||
|
||||
Reference in New Issue
Block a user