oak-general-business/es/components/userRelation/upsert/index.js

97 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { assert } from 'oak-domain/lib/utils/assert';
export default OakComponent({
isList: true,
entity: 'relation',
projection: {
id: 1,
entity: 1,
entityId: 1,
name: 1,
display: 1,
},
data: {
grantByUserEntityGrant: false,
grantByEmail: false,
grantByMobile: false,
grantMethodCount: 0,
},
filters: [
{
filter() {
const { entity, entityId } = this.props;
const isRoot = this.features.token.isRoot();
const filter = {
entity: entity,
$or: [
{
entityId,
},
{
entityId: {
$exists: false,
},
},
],
};
if (!isRoot) {
const userId = this.features.token.getUserId();
filter.relationAuth$destRelation = {
sourceRelation: {
userRelation$relation: {
userId,
},
},
};
}
return filter;
},
},
],
formData({ data }) {
return {
relations: data,
};
},
properties: {
entity: '',
entityId: '',
redirectToAfterConfirm: {},
qrCodeType: '',
},
lifetimes: {
ready() {
const isRoot = this.features.token.isRoot();
const application = this.features.application.getApplication();
const { type, config } = application; // 这个页面总不可能是第一个页面吧application肯定初始化完成了
let grantByUserEntityGrant = false, grantByMobile = false, grantByEmail = false;
if (type.startsWith('wechat')) {
grantByUserEntityGrant = true;
}
else {
assert(type === 'web');
const passport = config.passport || [];
grantByEmail = passport.includes('email');
// 是超级管理员 不需要根据配置手机号来判断 by wkj
grantByMobile = isRoot || passport.includes('mobile');
grantByUserEntityGrant = passport.includes('wechat');
}
let grantMethodCount = 0;
if (grantByEmail) {
grantMethodCount++;
}
if (grantByMobile) {
grantMethodCount++;
}
if (grantByUserEntityGrant) {
grantMethodCount++;
}
this.setState({
grantMethodCount,
grantByUserEntityGrant,
grantByEmail,
grantByMobile,
});
},
},
});