Fix property empty issue

This commit is contained in:
Yang Luo
2023-08-14 12:09:38 +08:00
parent 891e8e21d8
commit b7a001ea39
7 changed files with 68 additions and 22 deletions

View File

@ -361,6 +361,9 @@ func (c *ApiController) UploadResource() {
return
}
if user.Properties == nil {
user.Properties = map[string]string{}
}
user.Properties[tag] = fileUrl
user.Properties["isIdCardVerified"] = "false"
_, err = object.UpdateUser(user.GetId(), user, []string{"properties"}, false)

View File

@ -309,8 +309,7 @@ func GetAllRoles(userId string) []string {
func GetBuiltInModel(modelText string) (model.Model, error) {
if modelText == "" {
modelText = `
[request_definition]
modelText = `[request_definition]
r = sub, obj, act
[policy_definition]

View File

@ -169,7 +169,7 @@ class EnforcerEditPage extends React.Component {
<Select virtual={false} disabled={Setting.builtInObject(this.state.enforcer)} style={{width: "100%"}} value={this.state.enforcer.model} onChange={(model => {
this.updateEnforcerField("model", model);
})}
options={this.state.models.map((model) => Setting.getOption(model.displayName, `${model.owner}/${model.name}`))
options={this.state.models.map((model) => Setting.getOption(`${model.owner}/${model.name}`, `${model.owner}/${model.name}`))
} />
</Col>
</Row>
@ -181,7 +181,7 @@ class EnforcerEditPage extends React.Component {
<Select virtual={false} disabled={Setting.builtInObject(this.state.enforcer)} style={{width: "100%"}} value={this.state.enforcer.adapter} onChange={(adapter => {
this.updateEnforcerField("adapter", adapter);
})}
options={this.state.adapters.map((adapter) => Setting.getOption(adapter.name, `${adapter.owner}/${adapter.name}`))
options={this.state.adapters.map((adapter) => Setting.getOption(`${adapter.owner}/${adapter.name}`, `${adapter.owner}/${adapter.name}`))
} />
</Col>
</Row>

View File

@ -75,7 +75,7 @@ class EnforcerListPage extends BaseListPage {
title: i18next.t("general:Name"),
dataIndex: "name",
key: "name",
width: "150px",
width: "200px",
fixed: "left",
sorter: true,
...this.getColumnSearchProps("name"),
@ -116,10 +116,42 @@ class EnforcerListPage extends BaseListPage {
title: i18next.t("general:Display name"),
dataIndex: "displayName",
key: "displayName",
width: "200px",
// width: "200px",
sorter: true,
...this.getColumnSearchProps("displayName"),
},
{
title: i18next.t("general:Model"),
dataIndex: "model",
key: "model",
width: "250px",
fixed: "left",
sorter: true,
...this.getColumnSearchProps("name"),
render: (text, record, index) => {
return (
<Link to={`/models/${text}`}>
{text}
</Link>
);
},
},
{
title: i18next.t("general:Adapter"),
dataIndex: "adapter",
key: "adapter",
width: "250px",
fixed: "left",
sorter: true,
...this.getColumnSearchProps("name"),
render: (text, record, index) => {
return (
<Link to={`/adapters/${text}`}>
{text}
</Link>
);
},
},
{
title: i18next.t("general:Is enabled"),
dataIndex: "isEnabled",
@ -136,7 +168,7 @@ class EnforcerListPage extends BaseListPage {
title: i18next.t("general:Action"),
dataIndex: "",
key: "op",
width: "170px",
width: "180px",
fixed: (Setting.isMobile()) ? "false" : "right",
render: (text, record, index) => {
return (

View File

@ -570,7 +570,7 @@ class UserEditPage extends React.Component {
{name: "ID card back", value: "idCardBack"},
{name: "ID card with person", value: "idCardWithPerson"},
].map((entry) => {
return this.renderImage(this.state.user.properties[entry.value] || "", this.getIdCardType(entry.name), this.getIdCardText(entry.name), entry.value, disabled);
return this.renderImage(this.state.user.properties === null ? "" : (this.state.user.properties[entry.value] || ""), this.getIdCardType(entry.name), this.getIdCardText(entry.name), entry.value, disabled);
})
}
</Row>
@ -995,11 +995,13 @@ class UserEditPage extends React.Component {
<Col span={4} style={{textAlign: "center", margin: "auto"}} key={tag}>
{
imgUrl ?
<div style={{marginBottom: "10px"}}>
<a target="_blank" rel="noreferrer" href={imgUrl} style={{marginBottom: "10px"}}>
<AccountAvatar src={imgUrl} alt={imgUrl} size={90} style={{marginBottom: "20px"}} />
<AccountAvatar src={imgUrl} alt={imgUrl} height={150} />
</a>
</div>
:
<Col style={{height: "78%", border: "1px dotted grey", borderRadius: 3, marginBottom: 5}}>
<Col style={{height: "78%", border: "1px dotted grey", borderRadius: 3, marginBottom: "10px"}}>
<div style={{fontSize: 30, margin: 10}}>+</div>
<div style={{verticalAlign: "middle", marginBottom: 10}}>{`Upload ${title}...`}</div>
</Col>

View File

@ -17,7 +17,7 @@ import {MetaMaskAvatar} from "react-metamask-avatar";
class AccountAvatar extends React.Component {
render() {
const {src, size} = this.props;
const {src, size, width, height} = this.props;
// The avatar for Metamask account is directly generated by an algorithm based on the address
// src = "metamask:0xC304b2cC0Be8E9ce10fF3Afd34820Ed306A23600";
const matchMetaMask = src.match(/^metamask:(\w+)$/);
@ -27,9 +27,19 @@ class AccountAvatar extends React.Component {
<MetaMaskAvatar address={address} size={size} />
);
}
if (size !== undefined) {
return (
<img width={size} height={size} src={src} />
);
} else if (width === undefined) {
return (
<img height={height} src={src} />
);
} else if (height === undefined) {
return (
<img width={width} src={src} />
);
}
}
}

View File

@ -33,11 +33,11 @@ class PolicyTable extends React.Component {
}
count = 0;
pageSize = 10;
pageSize = 100;
getIndex(index) {
// Need to be used in all place when modify table. Parameter is the row index in table, need to calculate the index in dataSource.
return index + (this.state.page - 1) * 10;
return index + (this.state.page - 1) * this.pageSize;
}
UNSAFE_componentWillMount() {
@ -165,7 +165,7 @@ class PolicyTable extends React.Component {
renderTable(table) {
const columns = [
{
title: "Rule Type",
title: i18next.t("adapter:Rule type"),
dataIndex: "Ptype",
width: "100px",
// render: (text, record, index) => {
@ -270,8 +270,9 @@ class PolicyTable extends React.Component {
},
},
{
title: "Option",
key: "option",
title: i18next.t("general:Action"),
dataIndex: "",
key: "op",
width: "100px",
render: (text, record, index) => {
const editable = this.isEditing(index);
@ -304,7 +305,6 @@ class PolicyTable extends React.Component {
onChange: (page) => this.setState({
page: page,
}),
disabled: this.state.editingIndex !== "" || Setting.builtInObject({owner: this.props.owner, name: this.props.name}),
current: this.state.page,
}}
columns={columns} dataSource={table} rowKey="key" size="middle" bordered