|
@@ -0,0 +1,117 @@
|
|
|
|
+import {AcsUserInfo} from "@core-models/AcsUserInfo";
|
|
|
|
+import {PrjMembers} from "@core-models/PrjMembers";
|
|
|
|
+import {PrjInfo} from "@core-models/PrjInfo";
|
|
|
|
+import {QueryTypes} from "sequelize";
|
|
|
|
+import {PrjPlanTask} from "@core-models/PrjPlanTask";
|
|
|
|
+
|
|
|
|
+/// 是否是项目特权账户
|
|
|
|
+export async function is_project_privileged_account(account_id: string): Promise<boolean> {
|
|
|
|
+ // 检查账户是否为特权账户
|
|
|
|
+ let result = await AcsUserInfo.findOne({where: {id: account_id}, raw: true});
|
|
|
|
+ if (result && result.ext_info.full_range === true) return true;
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否是项目组成员
|
|
|
|
+export async function is_project_member(account_id: string, project_id: string): Promise<boolean> {
|
|
|
|
+ // 检查账户是否为项目组成员
|
|
|
|
+ let result = await PrjMembers.findOne({
|
|
|
|
+ where: {member_id: account_id, prj_id: project_id, draft: false},
|
|
|
|
+ raw: true
|
|
|
|
+ });
|
|
|
|
+ if (result) return true;
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否是项目负责人
|
|
|
|
+export async function is_project_leader(account_id: string, project_id: string): Promise<boolean> {
|
|
|
|
+ let prj = await PrjInfo.findOne({where: {id: project_id}, raw: true});
|
|
|
|
+ if (prj && prj.leader_id === account_id) return true;
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否是项目商务负责人
|
|
|
|
+export async function is_project_business_leader(account_id: string, project_id: string): Promise<boolean> {
|
|
|
|
+ let prj = await PrjInfo.findOne({where: {id: project_id}, raw: true});
|
|
|
|
+ if (prj && prj.bizman_id === account_id) return true;
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否是项目审核组成员
|
|
|
|
+export async function is_project_checker(account_id: string, project_id: string): Promise<boolean> {
|
|
|
|
+ let result = await PrjInfo.sequelize!.query(`
|
|
|
|
+ select 1
|
|
|
|
+ from tb_prj_info prj_info, jsonb_array_elements(prj_info.checkers) AS checker_obj
|
|
|
|
+ where checker_obj->>'id' = :user_id and prj_info.id = :prj_id
|
|
|
|
+ `, {replacements: {user_id: account_id, prj_id: project_id}, type: QueryTypes.SELECT});
|
|
|
|
+
|
|
|
|
+ if (result && result.length > 0) return true;
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否是项目任务审核组成员
|
|
|
|
+export async function is_project_task_checker(account_id: string, project_id: string): Promise<boolean> {
|
|
|
|
+
|
|
|
|
+ let result = await PrjInfo.sequelize!.query(`
|
|
|
|
+ SELECT 1
|
|
|
|
+ FROM tb_prj_plan_task prj_task, jsonb_array_elements(prj_task.checkers) AS checker_obj
|
|
|
|
+ WHERE (checker_obj->>'handlers')::jsonb ? :user_id
|
|
|
|
+ and prj_task.prj_id = :prj_id
|
|
|
|
+ `, {replacements: {user_id: account_id, prj_id: project_id}, type: QueryTypes.SELECT});
|
|
|
|
+
|
|
|
|
+ if (result && result.length > 0) return true;
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否有权访问项目
|
|
|
|
+export async function is_project_accessible(account_id: string, project_id: string): Promise<boolean> {
|
|
|
|
+ let prj = await PrjInfo.findOne({where: {id: project_id}, raw: true});
|
|
|
|
+ if (prj && (
|
|
|
|
+ prj.leader_id === account_id ||
|
|
|
|
+ prj.bizman_id === account_id ||
|
|
|
|
+ await is_project_privileged_account(account_id) ||
|
|
|
|
+ await is_project_member(account_id, project_id) ||
|
|
|
|
+ await is_project_checker(account_id, project_id) ||
|
|
|
|
+ await is_project_task_checker(account_id, project_id)
|
|
|
|
+ )) return true;
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否有修改项目信息的权限
|
|
|
|
+export async function is_project_modifiable(account_id: string, project_id: string): Promise<boolean> {
|
|
|
|
+ if (
|
|
|
|
+ await is_project_leader(account_id, project_id) ||
|
|
|
|
+ await is_project_privileged_account(account_id)
|
|
|
|
+ ) return true;
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否有访问项目任务的权限
|
|
|
|
+export async function is_project_task_accessible(account_id: string, task_id: string): Promise<boolean> {
|
|
|
|
+ let task = await PrjPlanTask.findOne({where: {id: task_id}, raw: true});
|
|
|
|
+ if (task && (
|
|
|
|
+ task.handler_id === account_id ||
|
|
|
|
+ await is_project_accessible(account_id, task.prj_id)
|
|
|
|
+ )) return true;
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否有修改项目任务的权限
|
|
|
|
+export async function is_project_task_modifiable(account_id: string, task_id: string): Promise<boolean> {
|
|
|
|
+ let task = await PrjPlanTask.findOne({where: {id: task_id}, raw: true});
|
|
|
|
+ if (task && await is_project_modifiable(account_id, task.prj_id)) return true;
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// 是否有修改项目任务进度的权限
|
|
|
|
+export async function is_project_task_progress_modifiable(account_id: string, task_id: string): Promise<boolean> {
|
|
|
|
+ let task = await PrjPlanTask.findOne({where: {id: task_id}, raw: true});
|
|
|
|
+ if (task && (task.handler_id === account_id || await is_project_modifiable(account_id, task.prj_id))) return true;
|
|
|
|
+ return false;
|
|
|
|
+}
|