apply license
This commit is contained in:
51
src/utils/permissions.ts
Normal file
51
src/utils/permissions.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
// 权限检查工具类
|
||||
import type { PermissionConfig } from '@/types/license';
|
||||
import client from '@/plugins/kintoneClient.ts'
|
||||
|
||||
export class PermissionService {
|
||||
/**
|
||||
* 检查用户是否有管理插件的权限
|
||||
* 基于kintone的权限系统判断用户是否可以管理应用插件
|
||||
*/
|
||||
static async checkPermissions(): Promise<PermissionConfig> {
|
||||
try {
|
||||
// 获取应用信息
|
||||
const appId = kintone.app.getId() || kintone.mobile.app.getId();
|
||||
if (!appId) {
|
||||
return this.getDefaultPermissions();
|
||||
}
|
||||
|
||||
// 检查应用的管理权限
|
||||
const hasAdminRights = await this.checkAppAdminRights(appId);
|
||||
|
||||
return {
|
||||
canManagePlugins: hasAdminRights,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Failed to check permissions:', error);
|
||||
return this.getDefaultPermissions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查应用管理员权限
|
||||
*/
|
||||
private static async checkAppAdminRights(appId: number): Promise<boolean> {
|
||||
try {
|
||||
await client.app.getAppAcl({ app: appId });
|
||||
return true;
|
||||
} catch (error) {
|
||||
// 如果API调用失败,默认认为没有权限
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认权限配置(无权限)
|
||||
*/
|
||||
private static getDefaultPermissions(): PermissionConfig {
|
||||
return {
|
||||
canManagePlugins: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user