lib提交

This commit is contained in:
Wang Kejun 2022-05-10 15:23:22 +08:00
parent 60aa0ad725
commit 5b72315f16
11 changed files with 98 additions and 28 deletions

View File

@ -18,5 +18,6 @@ export declare abstract class GeneralRuntimeContext<ED extends EntityDict> exten
userId: 1;
playerId: 1;
}> | undefined>;
getTokenValue(): Promise<string | undefined>;
getScene(): string;
}

View File

@ -44,6 +44,9 @@ class GeneralRuntimeContext extends UniversalContext_1.UniversalContext {
return token;
}
}
async getTokenValue() {
return await this.getTokenFn();
}
getScene() {
return this.scene;
}

View File

@ -2,7 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const validator_1 = require("oak-domain/lib/utils/validator");
const types_1 = require("oak-domain/lib/types");
const check_1 = require("../utils/check");
const validator_2 = require("oak-domain/lib/utils/validator");
const checkers = [
{
type: 'data',
@ -13,14 +13,14 @@ const checkers = [
if (data instanceof Array) {
data.forEach(ele => {
const a = 'name';
(0, check_1.checkAttributesNotNull)(ele, ['name', 'detail', 'phone', 'areaId']);
(0, validator_2.checkAttributesNotNull)(ele, ['name', 'detail', 'phone', 'areaId']);
if (!(0, validator_1.isMobile)(ele.phone)) {
throw new types_1.OakInputIllegalException(['phone'], '手机号非法');
}
});
}
else {
(0, check_1.checkAttributesNotNull)(data, ['name', 'detail', 'phone', 'areaId']);
(0, validator_2.checkAttributesNotNull)(data, ['name', 'detail', 'phone', 'areaId']);
if (!(0, validator_1.isMobile)(data.phone)) {
throw new types_1.OakInputIllegalException(['phone'], '手机号非法');
}

View File

@ -4,6 +4,7 @@ const types_1 = require("oak-domain/lib/types");
const Exceptions_1 = require("../types/Exceptions");
const lodash_1 = require("lodash");
const filter_1 = require("oak-domain/lib/store/filter");
const check_1 = require("../utils/check");
const checkers = [
{
type: 'user',
@ -30,7 +31,22 @@ const checkers = [
return 0;
}
// 对获取token的权限进行精细化控制除了root
throw new types_1.OakUserUnpermittedException();
if (filter && filter.id === await context.getTokenValue()) {
return 0;
}
const isRoot = await (0, check_1.checkIsRoot)(context);
if (!isRoot) {
// 不是root只能访问自己的token
if (!filter) {
throw new types_1.OakUserUnpermittedException();
}
(0, lodash_1.assign)(operation, {
filter: (0, filter_1.addFilterSegment)(filter, {
id: await context.getTokenValue(),
})
});
}
return 0;
},
}
];

View File

@ -1,6 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actionDef_1 = require("oak-domain/lib/store/actionDef");
const types_1 = require("oak-domain/lib/types");
const check_1 = require("../utils/check");
const checkers = [
{
type: 'data',
@ -17,6 +19,19 @@ const checkers = [
{
type: 'user',
action: 'play',
entity: 'user',
checker: async ({ operation }, context) => {
const isRoot = await (0, check_1.checkIsRoot)(context);
if (!isRoot) {
throw new types_1.OakUserUnpermittedException();
}
const token = await context.getToken();
const { userId } = token;
if (userId === operation.filter.id) {
throw new types_1.OakRowInconsistencyException();
}
return 0;
},
}
];
exports.default = checkers;

View File

@ -1,5 +1,9 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
const constants_1 = require("../constants");
let NO_ANY_USER = true;
const triggers = [
@ -60,5 +64,26 @@ const triggers = [
return 0;
}
},
{
name: '当扮演某个用户时切换当前用户的token中的userId',
entity: 'user',
action: 'play',
when: 'after',
fn: async ({ operation }, context, params) => {
const { filter } = operation;
(0, assert_1.default)(filter.id);
const { id } = (await context.getToken());
await context.rowStore.operate('token', {
action: 'update',
data: {
userId: filter.id,
},
filter: {
id,
}
}, context);
return 1;
}
}
];
exports.default = triggers;

View File

@ -1,2 +1,3 @@
export declare function checkAttributesNotNull<T extends Record<string, any>>(data: T, attributes: Array<keyof T>, allowEmpty?: true): void;
export declare function checkAttributesScope<T extends Record<string, any>>(data: T, attributes: Array<keyof T>): void;
import { EntityDict } from "oak-app-domain";
import { GeneralRuntimeContext } from "../RuntimeContext";
export declare function checkIsRoot(context: GeneralRuntimeContext<EntityDict>): Promise<boolean>;

View File

@ -1,26 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkAttributesScope = exports.checkAttributesNotNull = void 0;
const types_1 = require("oak-domain/lib/types");
function checkAttributesNotNull(data, attributes, allowEmpty) {
const attrs = attributes.filter((attr) => {
if (data[attr] === null || data[attr] === '') {
return true;
}
if (!allowEmpty && !data.hasOwnProperty(attr)) {
return true;
}
});
if (attrs.length > 0) {
throw new types_1.OakInputIllegalException(attrs, '属性不能为空');
exports.checkIsRoot = void 0;
const constants_1 = require("../constants");
async function checkIsRoot(context) {
const token = await context.getToken();
if (!token) {
return false;
}
}
exports.checkAttributesNotNull = checkAttributesNotNull;
;
function checkAttributesScope(data, attributes) {
const attrs = attributes.filter(attr => !data.hasOwnProperty(attr));
if (attrs.length > 0) {
throw new types_1.OakInputIllegalException(attrs, '多余的属性');
const { playerId } = token;
const count = await context.rowStore.count('userRole', {
filter: {
userId: playerId,
roleId: constants_1.ROOT_ROLE_ID,
},
}, context);
if (count === 0) {
// 只有root允许扮演其他用户身份
return false;
}
return true;
}
exports.checkAttributesScope = checkAttributesScope;
exports.checkIsRoot = checkIsRoot;

View File

@ -1,12 +1,14 @@
/** index.wxss **/
@import "../../../styles/cell.less";
@import "../../../styles/mixins.less";
.page-body {
height: 100vh;
display: flex;
flex: 1;
flex-direction: column;
background-color: @background-color-base;
box-sizing: border-box;
.safe-area-inset-bottom();
}
.item-container {

View File

@ -1,5 +1,6 @@
/** index.wxss **/
@import "../../../styles/cell.less";
@import "../../../styles/mixins.less";
.page-body {
height: 100vh;
@ -7,6 +8,8 @@
flex: 1;
flex-direction: column;
background-color: @background-color-base;
box-sizing: border-box;
.safe-area-inset-bottom();
}
.g-cell-hover:extend(.g-cell) {

View File

@ -0,0 +1,7 @@
// 解决全屏幕机型底部适配问题
.safe-area-inset-bottom() {
padding-bottom: constant(safe-area-inset-bottom) !important; /* 兼容 iOS < 11.2 */
padding-bottom: env(safe-area-inset-bottom) !important; /* 兼容 iOS >= 11.2 */
}