perf: add get public permission filter
This commit is contained in:
parent
f8e2f74d5e
commit
dc56548cdf
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/permission",
|
"name": "@kevisual/permission",
|
||||||
"version": "0.0.1",
|
"version": "0.0.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/config-permission.js",
|
"main": "dist/config-permission.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -36,7 +36,7 @@ type ConfigPermissionOptions = {
|
|||||||
/**
|
/**
|
||||||
* 所有者
|
* 所有者
|
||||||
*/
|
*/
|
||||||
owner: string;
|
owner?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,6 +49,23 @@ export class ConfigPermission {
|
|||||||
this.permission = permission || ({} as Permission);
|
this.permission = permission || ({} as Permission);
|
||||||
this.owner = owner;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
static create(opts: ConfigPermissionOptions) {
|
||||||
|
return new ConfigPermission(opts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserPermissionOptions = {
|
export type UserPermissionOptions = {
|
||||||
@ -162,7 +182,12 @@ export class UserPermission extends ConfigPermission {
|
|||||||
constructor({ permission, owner }: ConfigPermissionOptions) {
|
constructor({ permission, owner }: ConfigPermissionOptions) {
|
||||||
super({ permission, owner });
|
super({ permission, owner });
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 检查权限 20100 以上全是错误
|
||||||
|
*
|
||||||
|
* @param checkOptions
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
checkPermission(checkOptions: UserPermissionOptions) {
|
checkPermission(checkOptions: UserPermissionOptions) {
|
||||||
const { username, password } = checkOptions;
|
const { username, password } = checkOptions;
|
||||||
|
|
||||||
@ -210,15 +235,21 @@ export class UserPermission extends ConfigPermission {
|
|||||||
}
|
}
|
||||||
// 第三步,检查用户名
|
// 第三步,检查用户名
|
||||||
const usernamesCheck = this.checkUsernames(username);
|
const usernamesCheck = this.checkUsernames(username);
|
||||||
if (usernamesCheck) {
|
if (username && usernamesCheck) {
|
||||||
return {
|
return {
|
||||||
code: 20003,
|
code: 20003,
|
||||||
message: '使用用户名访问',
|
message: '使用用户名访问',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (username) {
|
||||||
|
return {
|
||||||
|
code: 20004,
|
||||||
|
meassage: '登陆的用户都能够访问',
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
code: 20101,
|
code: 20101,
|
||||||
message: '资源是私有的',
|
message: '资源是私有的,需要登陆',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
checkPermissionSuccess(checkOptions: UserPermissionOptions) {
|
checkPermissionSuccess(checkOptions: UserPermissionOptions) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user