116 lines
3.7 KiB
JavaScript
116 lines
3.7 KiB
JavaScript
export default OakComponent({
|
||
isList: true,
|
||
entity: 'relation',
|
||
projection: {
|
||
id: 1,
|
||
entity: 1,
|
||
entityId: 1,
|
||
name: 1,
|
||
display: 1,
|
||
},
|
||
data: {
|
||
enabled: [],
|
||
},
|
||
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: {},
|
||
claimUrl: '',
|
||
qrCodeType: '',
|
||
rule: 'single',
|
||
passwordRequired: false,
|
||
disabledMethods: [],
|
||
mode: undefined,
|
||
},
|
||
lifetimes: {
|
||
async ready() {
|
||
const { disabledMethods, mode } = this.props;
|
||
const { systemId } = this.features.application.getApplication();
|
||
const { data: passports } = await this.features.cache.refresh('passport', {
|
||
data: {
|
||
id: 1,
|
||
type: 1,
|
||
},
|
||
filter: {
|
||
systemId,
|
||
},
|
||
});
|
||
const passportTypes = passports.map(ele => ele.type);
|
||
const enabled = [];
|
||
switch (mode) {
|
||
case 'byMobile': {
|
||
if (passportTypes.includes('sms')) {
|
||
enabled.push('mobile');
|
||
}
|
||
else if (process.env.NODE_ENV === 'development') {
|
||
console.warn('mode定义byMobile,但系统设置的passport中没有sms登录');
|
||
}
|
||
break;
|
||
}
|
||
case 'byUserEntityGrant': {
|
||
enabled.push('userEntityGrant');
|
||
break;
|
||
}
|
||
case 'byEmail': {
|
||
if (passportTypes.includes('email')) {
|
||
enabled.push('email');
|
||
}
|
||
else if (process.env.NODE_ENV === 'development') {
|
||
console.warn('mode定义byEmail,但系统设置的passport中没有email登录');
|
||
}
|
||
break;
|
||
}
|
||
default: {
|
||
if (!disabledMethods?.includes('userEntityGrant')) {
|
||
enabled.push('userEntityGrant');
|
||
}
|
||
if (passportTypes.includes('sms') && !disabledMethods?.includes('mobile')) {
|
||
enabled.push('mobile');
|
||
}
|
||
if (passportTypes.includes('email') && !disabledMethods?.includes('email')) {
|
||
enabled.push('email');
|
||
}
|
||
}
|
||
}
|
||
this.setState({ enabled });
|
||
},
|
||
},
|
||
});
|