/*
 * @Author: baozhoutao@steedos.com
 * @Date:  2023-03-18 15:05:39
 * @LastEditors: 孙浩林 sunhaolin@steedos.com
 * @LastEditTime: 2025-10-08 09:35:17
 * @Description: 
 */
const express = require("express");
const router = express.Router();
const { requireAuthentication } = require("@steedos/auth");
const PermissionManager = require('../manager/permission_manager');
const _ = require('lodash');

router.get('/api/workflow/v2/flow_permissions/:flow', requireAuthentication, async function (req, res) {
    let userSession = req.user;
    const { is_space_admin } = userSession;
    const { flow } = req.params;
    try {
        const permissions = await PermissionManager.getFlowPermissions(flow, userSession.userId);
        // 工作区管理员默认对流程有管理权限
        if (is_space_admin && !_.includes(permissions, 'admin')) {
            permissions.push('admin');
        }
        res.status(200).send({
            permissions: permissions
        })
    } catch (error) {
        console.error(error);
        res.status(200).send({
            error: error.message
        });
    }
});
exports.default = router;