perf: add get public permission filter

This commit is contained in:
熊潇 2025-05-20 10:47:44 +08:00
parent f8e2f74d5e
commit dc56548cdf
2 changed files with 36 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@kevisual/permission",
"version": "0.0.1",
"version": "0.0.3",
"description": "",
"main": "dist/config-permission.js",
"scripts": {

View File

@ -36,7 +36,7 @@ type ConfigPermissionOptions = {
/**
*
*/
owner: string;
owner?: string;
};
/**
@ -49,6 +49,23 @@ export class ConfigPermission {
this.permission = permission || ({} as Permission);
this.owner = owner;
}
/**
* permission的值
*/
getPublicPermission() {
if (!this.permission?.share) return {};
return {
share: this.permission.share,
};
}
static getDataPublicPermission(value: { data: { permission?: Permission }; [key: string]: any }) {
const { data } = value;
if (data.permission) {
data.permission = new ConfigPermission({ permission: data.permission }).getPublicPermission();
value.data = data;
}
return value;
}
/**
*
@ -143,6 +160,9 @@ export class ConfigPermission {
}
return false;
}
static create(opts: ConfigPermissionOptions) {
return new ConfigPermission(opts);
}
}
export type UserPermissionOptions = {
@ -162,7 +182,12 @@ export class UserPermission extends ConfigPermission {
constructor({ permission, owner }: ConfigPermissionOptions) {
super({ permission, owner });
}
/**
* 20100
*
* @param checkOptions
* @returns
*/
checkPermission(checkOptions: UserPermissionOptions) {
const { username, password } = checkOptions;
@ -210,15 +235,21 @@ export class UserPermission extends ConfigPermission {
}
// 第三步,检查用户名
const usernamesCheck = this.checkUsernames(username);
if (usernamesCheck) {
if (username && usernamesCheck) {
return {
code: 20003,
message: '使用用户名访问',
};
}
if (username) {
return {
code: 20004,
meassage: '登陆的用户都能够访问',
};
}
return {
code: 20101,
message: '资源是私有的',
message: '资源是私有的,需要登陆',
};
}
checkPermissionSuccess(checkOptions: UserPermissionOptions) {