feat: drill-down en pestaña nueva, rol Vendedor y scripts demo
This commit is contained in:
@@ -9,10 +9,10 @@ export async function createInvitation(req: Request, res: Response, next: NextFu
|
||||
return res.status(400).json({ message: 'El email es requerido' });
|
||||
}
|
||||
|
||||
// Solo platform_admin puede crear invitaciones
|
||||
const isAdmin = await hasAnyPlatformRole(req.user!.userId, 'platform_admin');
|
||||
// Admin y Vendedor (platform_sales) pueden crear invitaciones
|
||||
const isAdmin = await hasAnyPlatformRole(req.user!.userId, 'platform_admin', 'platform_sales');
|
||||
if (!isAdmin) {
|
||||
return res.status(403).json({ message: 'Solo administradores pueden crear invitaciones' });
|
||||
return res.status(403).json({ message: 'Solo administradores o vendedores pueden crear invitaciones' });
|
||||
}
|
||||
|
||||
const invitation = await clientInvitationService.createInvitation({
|
||||
@@ -70,7 +70,7 @@ export async function registerFromInvitation(req: Request, res: Response, next:
|
||||
|
||||
export async function resendInvitation(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const isAdmin = await hasAnyPlatformRole(req.user!.userId, 'platform_admin');
|
||||
const isAdmin = await hasAnyPlatformRole(req.user!.userId, 'platform_admin', 'platform_sales');
|
||||
if (!isAdmin) {
|
||||
return res.status(403).json({ message: 'No autorizado' });
|
||||
}
|
||||
@@ -88,7 +88,7 @@ export async function resendInvitation(req: Request, res: Response, next: NextFu
|
||||
|
||||
export async function listInvitations(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const isAdmin = await hasAnyPlatformRole(req.user!.userId, 'platform_admin');
|
||||
const isAdmin = await hasAnyPlatformRole(req.user!.userId, 'platform_admin', 'platform_sales');
|
||||
if (!isAdmin) {
|
||||
return res.status(403).json({ message: 'No autorizado' });
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import type { Request, Response, NextFunction } from 'express';
|
||||
import * as trialInvitationService from '../services/trial-invitations.service.js';
|
||||
import { isGlobalAdmin } from '../utils/global-admin.js';
|
||||
import { hasAnyPlatformRole } from '../utils/platform-admin.js';
|
||||
import { prisma } from '../config/database.js';
|
||||
|
||||
async function requireGlobalAdmin(req: Request, res: Response): Promise<boolean> {
|
||||
const isAdmin = await isGlobalAdmin(req.user!.tenantId, req.user!.role, req.user!.userId);
|
||||
async function requireAdminOrSales(req: Request, res: Response): Promise<boolean> {
|
||||
const isAdmin = await hasAnyPlatformRole(req.user!.userId, 'platform_admin', 'platform_sales');
|
||||
if (!isAdmin) {
|
||||
res.status(403).json({ message: 'Solo el administrador global puede gestionar invitaciones de trial' });
|
||||
res.status(403).json({ message: 'Solo administradores o vendedores pueden gestionar invitaciones de trial' });
|
||||
}
|
||||
return isAdmin;
|
||||
}
|
||||
|
||||
export async function createInvitation(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
if (!(await requireGlobalAdmin(req, res))) return;
|
||||
if (!(await requireAdminOrSales(req, res))) return;
|
||||
|
||||
const { tenantId, plan, durationDays } = req.body;
|
||||
if (!tenantId || !durationDays || durationDays < 1 || durationDays > 365) {
|
||||
@@ -38,7 +38,7 @@ export async function createInvitation(req: Request, res: Response, next: NextFu
|
||||
|
||||
export async function getAllInvitations(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
if (!(await requireGlobalAdmin(req, res))) return;
|
||||
if (!(await requireAdminOrSales(req, res))) return;
|
||||
|
||||
const { tenantId, status } = req.query;
|
||||
const invitations = await trialInvitationService.getInvitations({
|
||||
@@ -85,7 +85,7 @@ export async function acceptInvitation(req: Request, res: Response, next: NextFu
|
||||
|
||||
export async function cancelInvitation(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
if (!(await requireGlobalAdmin(req, res))) return;
|
||||
if (!(await requireAdminOrSales(req, res))) return;
|
||||
|
||||
const id = typeof req.params.id === 'string' ? req.params.id : '';
|
||||
const result = await trialInvitationService.cancelInvitation(id);
|
||||
|
||||
Reference in New Issue
Block a user