2022-02-13 23:39:27 +08:00
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
2021-02-13 13:30:51 +08:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2021-02-13 12:15:19 +08:00
import React from "react" ;
2023-04-15 16:05:33 +08:00
import { Button , Card , Col , Input , InputNumber , Result , Row , Select , Spin , Switch } from "antd" ;
2021-02-13 12:15:19 +08:00
import * as UserBackend from "./backend/UserBackend" ;
import * as OrganizationBackend from "./backend/OrganizationBackend" ;
import * as Setting from "./Setting" ;
2021-02-19 23:23:59 +08:00
import i18next from "i18next" ;
2023-03-26 18:44:47 +08:00
import CropperDivModal from "./common/modal/CropperDivModal.js" ;
2021-04-19 01:14:41 +08:00
import * as ApplicationBackend from "./backend/ApplicationBackend" ;
2023-03-26 18:44:47 +08:00
import PasswordModal from "./common/modal/PasswordModal" ;
import ResetModal from "./common/modal/ResetModal" ;
import AffiliationSelect from "./common/select/AffiliationSelect" ;
2021-06-20 00:42:32 +08:00
import OAuthWidget from "./common/OAuthWidget" ;
2022-01-01 10:56:08 +08:00
import SamlWidget from "./common/SamlWidget" ;
2023-03-26 18:44:47 +08:00
import RegionSelect from "./common/select/RegionSelect" ;
import WebAuthnCredentialTable from "./table/WebauthnCredentialTable" ;
import ManagedAccountTable from "./table/ManagedAccountTable" ;
import PropertyTable from "./table/propertyTable" ;
import { CountryCodeSelect } from "./common/select/CountryCodeSelect" ;
2021-05-30 18:35:05 +08:00
2022-07-10 15:45:55 +08:00
const { Option } = Select ;
2021-02-13 12:15:19 +08:00
class UserEditPage extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
classes : props ,
2021-02-13 17:56:58 +08:00
organizationName : props . organizationName !== undefined ? props . organizationName : props . match . params . organizationName ,
userName : props . userName !== undefined ? props . userName : props . match . params . userName ,
2021-02-13 12:15:19 +08:00
user : null ,
2021-04-19 01:14:41 +08:00
application : null ,
2021-02-13 12:15:19 +08:00
organizations : [ ] ,
2022-01-15 18:29:10 +08:00
applications : [ ] ,
2022-02-25 18:16:02 +08:00
mode : props . location . mode !== undefined ? props . location . mode : "edit" ,
2022-04-16 15:10:03 +08:00
loading : true ,
2022-11-25 23:08:45 +08:00
returnUrl : null ,
2021-02-13 12:15:19 +08:00
} ;
}
2021-03-27 11:38:15 +08:00
UNSAFE _componentWillMount ( ) {
2021-02-13 12:15:19 +08:00
this . getUser ( ) ;
this . getOrganizations ( ) ;
2022-01-15 18:29:10 +08:00
this . getApplicationsByOrganization ( this . state . organizationName ) ;
2021-07-11 23:49:06 +08:00
this . getUserApplication ( ) ;
2022-11-25 23:08:45 +08:00
this . setReturnUrl ( ) ;
2021-02-13 12:15:19 +08:00
}
getUser ( ) {
UserBackend . getUser ( this . state . organizationName , this . state . userName )
2022-04-16 15:10:03 +08:00
. then ( ( data ) => {
if ( data . status === null || data . status !== "error" ) {
this . setState ( {
user : data ,
} ) ;
}
2021-02-13 12:15:19 +08:00
this . setState ( {
2022-04-16 15:10:03 +08:00
loading : false ,
2021-02-13 12:15:19 +08:00
} ) ;
} ) ;
}
getOrganizations ( ) {
OrganizationBackend . getOrganizations ( "admin" )
. then ( ( res ) => {
this . setState ( {
2021-03-28 00:48:34 +08:00
organizations : ( res . msg === undefined ) ? res : [ ] ,
2021-02-13 12:15:19 +08:00
} ) ;
} ) ;
}
2022-01-15 18:29:10 +08:00
getApplicationsByOrganization ( organizationName ) {
ApplicationBackend . getApplicationsByOrganization ( "admin" , organizationName )
. then ( ( res ) => {
this . setState ( {
applications : ( res . msg === undefined ) ? res : [ ] ,
} ) ;
} ) ;
}
2021-07-11 23:49:06 +08:00
getUserApplication ( ) {
ApplicationBackend . getUserApplication ( this . state . organizationName , this . state . userName )
2021-04-19 01:14:41 +08:00
. then ( ( application ) => {
this . setState ( {
application : application ,
} ) ;
} ) ;
}
2022-11-25 23:08:45 +08:00
setReturnUrl ( ) {
2022-09-23 12:01:21 +08:00
const searchParams = new URLSearchParams ( this . props . location . search ) ;
2022-11-25 23:08:45 +08:00
const returnUrl = searchParams . get ( "returnUrl" ) ;
if ( returnUrl !== null ) {
this . setState ( {
returnUrl : returnUrl ,
} ) ;
}
2022-09-23 12:01:21 +08:00
}
2021-02-13 12:15:19 +08:00
parseUserField ( key , value ) {
2023-04-15 16:05:33 +08:00
if ( [ "score" , "karma" , "ranking" ] . includes ( key ) ) {
value = Setting . myParseInt ( value ) ;
}
2021-02-13 12:15:19 +08:00
return value ;
}
updateUserField ( key , value ) {
value = this . parseUserField ( key , value ) ;
2022-08-08 23:35:24 +08:00
const user = this . state . user ;
2021-02-13 12:15:19 +08:00
user [ key ] = value ;
this . setState ( {
user : user ,
} ) ;
}
2021-06-20 00:42:32 +08:00
unlinked ( ) {
this . getUser ( ) ;
2021-04-18 23:14:46 +08:00
}
2022-09-29 22:24:05 +08:00
isSelf ( ) {
return ( this . state . user . id === this . props . account ? . id ) ;
}
2021-05-31 01:42:03 +08:00
isSelfOrAdmin ( ) {
2022-09-29 22:24:05 +08:00
return this . isSelf ( ) || Setting . isAdminUser ( this . props . account ) ;
2021-05-31 01:42:03 +08:00
}
2023-03-01 22:09:48 +08:00
getCountryCode ( ) {
return this . props . account . countryCode ;
}
2022-06-18 01:41:21 +08:00
renderAccountItem ( accountItem ) {
if ( ! accountItem . visible ) {
return null ;
}
const isAdmin = Setting . isAdminUser ( this . props . account ) ;
2022-06-21 17:08:08 +08:00
// return (
// <div>
// {
// JSON.stringify({accountItem: accountItem, isSelf: isSelf, isAdmin: isAdmin})
// }
// </div>
// )
2022-06-18 01:41:21 +08:00
if ( accountItem . viewRule === "Self" ) {
2022-09-29 22:24:05 +08:00
if ( ! this . isSelfOrAdmin ( ) ) {
2022-06-18 01:41:21 +08:00
return null ;
}
} else if ( accountItem . viewRule === "Admin" ) {
if ( ! isAdmin ) {
return null ;
}
}
let disabled = false ;
if ( accountItem . modifyRule === "Self" ) {
2022-09-29 22:24:05 +08:00
if ( ! this . isSelfOrAdmin ( ) ) {
2022-06-18 01:41:21 +08:00
disabled = true ;
}
} else if ( accountItem . modifyRule === "Admin" ) {
if ( ! isAdmin ) {
disabled = true ;
}
} else if ( accountItem . modifyRule === "Immutable" ) {
disabled = true ;
}
if ( accountItem . name === "Organization" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "10px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Organization" ) , i18next . t ( "general:Organization - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
2023-02-02 16:43:51 +08:00
< Select virtual = { false } style = { { width : "100%" } } disabled = { disabled } value = { this . state . user . owner } onChange = { ( value => {
this . getApplicationsByOrganization ( value ) ;
this . updateUserField ( "owner" , value ) ;
} ) } >
2021-02-13 12:15:19 +08:00
{
this . state . organizations . map ( ( organization , index ) => < Option key = { index } value = { organization . name } > { organization . name } < / O p t i o n > )
}
< / S e l e c t >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "ID" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( "ID" , i18next . t ( "general:ID - Tooltip" ) ) } :
2021-02-13 20:10:41 +08:00
< / C o l >
< Col span = { 22 } >
2022-06-18 01:41:21 +08:00
< Input value = { this . state . user . id } disabled = { disabled } / >
2021-02-13 20:10:41 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Name" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Name" ) , i18next . t ( "general:Name - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
2022-06-18 01:41:21 +08:00
< Input value = { this . state . user . name } disabled = { disabled } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "name" , e . target . value ) ;
2021-02-13 12:15:19 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Display name" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Display name" ) , i18next . t ( "general:Display name - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
2021-02-13 14:49:31 +08:00
< Input value = { this . state . user . displayName } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "displayName" , e . target . value ) ;
2021-02-13 12:15:19 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Avatar" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Avatar" ) , i18next . t ( "general:Avatar - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-02-19 23:23:59 +08:00
{ i18next . t ( "general:Preview" ) } :
2021-02-13 14:49:31 +08:00
< / C o l >
2021-04-26 18:21:28 +08:00
< Col span = { 22 } >
2021-03-27 11:38:15 +08:00
< a target = "_blank" rel = "noreferrer" href = { this . state . user . avatar } >
2022-07-10 15:45:55 +08:00
< img src = { this . state . user . avatar } alt = { this . state . user . avatar } height = { 90 } style = { { marginBottom : "20px" } } / >
2021-02-13 14:49:31 +08:00
< / a >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
2023-03-26 18:44:47 +08:00
< CropperDivModal buttonText = { ` ${ i18next . t ( "user:Upload a photo" ) } ... ` } title = { i18next . t ( "user:Upload a photo" ) } user = { this . state . user } organization = { this . state . organizations . find ( organization => organization . name === this . state . organizationName ) } / >
2021-03-14 15:50:36 +08:00
< / R o w >
2021-02-13 14:49:31 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "User type" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:User type" ) , i18next . t ( "general:User type - Tooltip" ) ) } :
2021-04-26 19:00:23 +08:00
< / C o l >
< Col span = { 22 } >
2023-01-12 23:11:11 +08:00
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . user . type } onChange = { ( value => { this . updateUserField ( "type" , value ) ; } ) }
options = { [ "normal-user" ] . map ( item => Setting . getOption ( item , item ) ) }
/ >
2021-04-26 19:00:23 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Password" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Password" ) , i18next . t ( "general:Password - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
2022-06-18 01:41:21 +08:00
< PasswordModal user = { this . state . user } account = { this . props . account } disabled = { disabled } / >
2021-02-13 12:15:19 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Email" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Email" ) , i18next . t ( "general:Email - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
2022-07-10 15:45:55 +08:00
< Col style = { { paddingRight : "20px" } } span = { 11 } >
2023-02-25 11:47:34 +08:00
< Input
value = { this . state . user . email }
style = { { width : "280Px" } }
disabled = { ! Setting . isLocalAdminUser ( this . props . account ) ? true : disabled }
onChange = { e => {
this . updateUserField ( "email" , e . target . value ) ;
} }
/ >
2021-05-15 20:44:40 +08:00
< / C o l >
2023-02-16 22:53:28 +08:00
< Col span = { Setting . isMobile ( ) ? 22 : 11 } >
2023-01-10 22:34:08 +08:00
{ /* backend auto get the current user, so admin can not edit. Just self can reset*/ }
2023-03-01 22:09:48 +08:00
{ this . isSelf ( ) ? < ResetModal application = { this . state . application } disabled = { disabled } buttonText = { i18next . t ( "user:Reset Email..." ) } destType = { "email" } / > : null }
2021-02-13 12:15:19 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Phone" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
2023-02-16 22:53:28 +08:00
< Col style = { { marginTop : "5px" } } span = { Setting . isMobile ( ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Phone" ) , i18next . t ( "general:Phone - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
2022-07-10 15:45:55 +08:00
< Col style = { { paddingRight : "20px" } } span = { 11 } >
2023-02-25 11:47:34 +08:00
< Input . Group compact style = { { width : "280Px" } } >
2023-03-05 21:52:40 +08:00
< CountryCodeSelect
2023-02-25 11:47:34 +08:00
style = { { width : "30%" } }
2023-02-25 15:46:54 +08:00
// disabled={!Setting.isLocalAdminUser(this.props.account) ? true : disabled}
2023-02-27 22:07:28 +08:00
value = { this . state . user . countryCode }
2023-02-25 11:47:34 +08:00
onChange = { ( value ) => {
this . updateUserField ( "countryCode" , value ) ;
} }
countryCodes = { this . state . application ? . organizationObj . countryCodes }
/ >
< Input value = { this . state . user . phone }
style = { { width : "70%" } }
disabled = { ! Setting . isLocalAdminUser ( this . props . account ) ? true : disabled }
2023-01-11 16:15:06 +08:00
onChange = { e => {
this . updateUserField ( "phone" , e . target . value ) ;
2023-02-25 11:47:34 +08:00
} } / >
< / I n p u t . G r o u p >
2021-05-15 20:44:40 +08:00
< / C o l >
2023-02-16 22:53:28 +08:00
< Col span = { Setting . isMobile ( ) ? 24 : 11 } >
2023-03-01 22:09:48 +08:00
{ this . isSelf ( ) ? ( < ResetModal application = { this . state . application } countryCode = { this . getCountryCode ( ) } disabled = { disabled } buttonText = { i18next . t ( "user:Reset Phone..." ) } destType = { "phone" } / > ) : null }
2021-02-13 12:15:19 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Country/Region" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-07-31 16:02:48 +08:00
{ Setting . getLabel ( i18next . t ( "user:Country/Region" ) , i18next . t ( "user:Country/Region - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
2023-03-26 18:44:47 +08:00
< RegionSelect defaultValue = { this . state . user . region } onChange = { ( value ) => {
2021-07-31 16:02:48 +08:00
this . updateUserField ( "region" , value ) ;
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Location" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-08-21 10:58:34 +08:00
{ Setting . getLabel ( i18next . t ( "user:Location" ) , i18next . t ( "user:Location - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . location } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "location" , e . target . value ) ;
2021-08-21 10:58:34 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2023-04-15 16:05:33 +08:00
} else if ( accountItem . name === "Address" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Address" ) , i18next . t ( "user:Address - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . address } onChange = { e => {
this . updateUserField ( "address" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Affiliation" ) {
return (
( this . state . application === null || this . state . user === null ) ? null : (
2022-07-10 15:45:55 +08:00
< AffiliationSelect labelSpan = { ( Setting . isMobile ( ) ) ? 22 : 2 } application = { this . state . application } user = { this . state . user } onUpdateUserField = { ( key , value ) => { return this . updateUserField ( key , value ) ; } } / >
2022-06-18 01:41:21 +08:00
)
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Title" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-08-21 10:58:34 +08:00
{ Setting . getLabel ( i18next . t ( "user:Title" ) , i18next . t ( "user:Title - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . title } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "title" , e . target . value ) ;
2021-08-21 10:58:34 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2023-04-15 16:05:33 +08:00
} else if ( accountItem . name === "ID card type" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:ID card type" ) , i18next . t ( "user:ID card type - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . idCardType } onChange = { e => {
this . updateUserField ( "idCardType" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "ID card" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:ID card" ) , i18next . t ( "user:ID card - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . idCard } onChange = { e => {
this . updateUserField ( "idCard" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Homepage" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-08-21 10:58:34 +08:00
{ Setting . getLabel ( i18next . t ( "user:Homepage" ) , i18next . t ( "user:Homepage - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . homepage } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "homepage" , e . target . value ) ;
2021-08-21 10:58:34 +08:00
} } / >
< / C o l >
2021-08-25 08:07:08 +08:00
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Bio" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-08-25 08:07:08 +08:00
{ Setting . getLabel ( i18next . t ( "user:Bio" ) , i18next . t ( "user:Bio - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . bio } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "bio" , e . target . value ) ;
2021-08-25 08:07:08 +08:00
} } / >
< / C o l >
2021-08-21 10:58:34 +08:00
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Tag" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "user:Tag" ) , i18next . t ( "user:Tag - Tooltip" ) ) } :
2021-02-14 21:21:42 +08:00
< / C o l >
< Col span = { 22 } >
2022-03-13 00:30:18 +08:00
{
this . state . application ? . organizationObj . tags ? . length > 0 ? (
2023-01-12 23:11:11 +08:00
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . user . tag }
onChange = { ( value => { this . updateUserField ( "tag" , value ) ; } ) }
options = { this . state . application . organizationObj . tags ? . map ( ( tag ) => {
const tokens = tag . split ( "|" ) ;
const value = tokens [ 0 ] ;
const displayValue = Setting . getLanguage ( ) !== "zh" ? tokens [ 0 ] : tokens [ 1 ] ;
return Setting . getOption ( displayValue , value ) ;
} ) } / >
2022-03-13 00:30:18 +08:00
) : (
< Input value = { this . state . user . tag } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "tag" , e . target . value ) ;
2022-03-13 00:30:18 +08:00
} } / >
)
}
2021-02-14 21:21:42 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2023-04-15 16:05:33 +08:00
} else if ( accountItem . name === "Language" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Language" ) , i18next . t ( "user:Language - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . language } onChange = { e => {
this . updateUserField ( "language" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "Gender" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Gender" ) , i18next . t ( "user:Gender - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . gender } onChange = { e => {
this . updateUserField ( "gender" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "Birthday" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Birthday" ) , i18next . t ( "user:Birthday - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . birthday } onChange = { e => {
this . updateUserField ( "birthday" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "Education" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Education" ) , i18next . t ( "user:Education - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . user . education } onChange = { e => {
this . updateUserField ( "education" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "Score" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Score" ) , i18next . t ( "user:Score - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< InputNumber value = { this . state . user . score } onChange = { value => {
this . updateUserField ( "score" , value ) ;
} } / >
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "Karma" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Karma" ) , i18next . t ( "user:Karma - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< InputNumber value = { this . state . user . karma } onChange = { value => {
this . updateUserField ( "karma" , value ) ;
} } / >
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "Ranking" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Ranking" ) , i18next . t ( "user:Ranking - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< InputNumber value = { this . state . user . ranking } onChange = { value => {
this . updateUserField ( "ranking" , value ) ;
} } / >
< / C o l >
< / R o w >
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Signup application" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-01-15 18:29:10 +08:00
{ Setting . getLabel ( i18next . t ( "general:Signup application" ) , i18next . t ( "general:Signup application - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
2023-01-12 23:11:11 +08:00
< Select virtual = { false } style = { { width : "100%" } } disabled = { disabled } value = { this . state . user . signupApplication }
onChange = { ( value => { this . updateUserField ( "signupApplication" , value ) ; } ) }
options = { this . state . applications . map ( ( application ) => Setting . getOption ( application . name , application . name ) )
} / >
2022-01-15 18:29:10 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-07-30 17:31:56 +08:00
} else if ( accountItem . name === "Roles" ) {
return (
< Row style = { { marginTop : "20px" , alignItems : "center" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "general:Roles" ) , i18next . t ( "general:Roles - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
{
Setting . getTags ( this . state . user . roles . map ( role => role . name ) )
}
< / C o l >
< / R o w >
) ;
} else if ( accountItem . name === "Permissions" ) {
return (
< Row style = { { marginTop : "20px" , alignItems : "center" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "general:Permissions" ) , i18next . t ( "general:Permissions - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
{
Setting . getTags ( this . state . user . permissions . map ( permission => permission . name ) )
}
< / C o l >
< / R o w >
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "3rd-party logins" ) {
return (
! this . isSelfOrAdmin ( ) ? null : (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-18 01:41:21 +08:00
{ Setting . getLabel ( i18next . t ( "user:3rd-party logins" ) , i18next . t ( "user:3rd-party logins - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< div style = { { marginBottom : 20 } } >
{
( this . state . application === null || this . state . user === null ) ? null : (
2023-01-12 23:11:11 +08:00
this . state . application ? . providers . filter ( providerItem => Setting . isProviderVisible ( providerItem ) ) . map ( ( providerItem ) =>
2022-06-18 01:41:21 +08:00
( providerItem . provider . category === "OAuth" ) ? (
2022-07-30 23:11:02 +08:00
< OAuthWidget key = { providerItem . name } labelSpan = { ( Setting . isMobile ( ) ) ? 10 : 3 } user = { this . state . user } application = { this . state . application } providerItem = { providerItem } account = { this . props . account } onUnlinked = { ( ) => { return this . unlinked ( ) ; } } / >
2022-06-18 01:41:21 +08:00
) : (
2022-07-10 15:45:55 +08:00
< SamlWidget key = { providerItem . name } labelSpan = { ( Setting . isMobile ( ) ) ? 10 : 3 } user = { this . state . user } application = { this . state . application } providerItem = { providerItem } onUnlinked = { ( ) => { return this . unlinked ( ) ; } } / >
2022-08-07 00:17:27 +08:00
)
2021-06-20 02:02:08 +08:00
)
2022-06-18 01:41:21 +08:00
)
}
< / d i v >
< / C o l >
< / R o w >
)
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Properties" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-12-31 15:27:53 +08:00
{ Setting . getLabel ( i18next . t ( "user:Properties" ) , i18next . t ( "user:Properties - Tooltip" ) ) } :
2022-06-18 01:41:21 +08:00
< / C o l >
< Col span = { 22 } >
2022-12-31 15:27:53 +08:00
< PropertyTable properties = { this . state . user . properties } onUpdateTable = { ( value ) => { this . updateUserField ( "properties" , value ) ; } } / >
2022-06-18 01:41:21 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Is admin" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-18 01:41:21 +08:00
{ Setting . getLabel ( i18next . t ( "user:Is admin" ) , i18next . t ( "user:Is admin - Tooltip" ) ) } :
< / C o l >
< Col span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-01-02 09:27:25 +08:00
< Switch disabled = { disabled } checked = { this . state . user . isAdmin } onChange = { checked => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "isAdmin" , checked ) ;
2022-06-18 01:41:21 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Is global admin" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-18 01:41:21 +08:00
{ Setting . getLabel ( i18next . t ( "user:Is global admin" ) , i18next . t ( "user:Is global admin - Tooltip" ) ) } :
< / C o l >
< Col span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-01-02 09:27:25 +08:00
< Switch disabled = { disabled } checked = { this . state . user . isGlobalAdmin } onChange = { checked => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "isGlobalAdmin" , checked ) ;
2022-06-18 01:41:21 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Is forbidden" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-18 01:41:21 +08:00
{ Setting . getLabel ( i18next . t ( "user:Is forbidden" ) , i18next . t ( "user:Is forbidden - Tooltip" ) ) } :
< / C o l >
< Col span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
< Switch checked = { this . state . user . isForbidden } onChange = { checked => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "isForbidden" , checked ) ;
2022-06-18 01:41:21 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-06-18 01:41:21 +08:00
} else if ( accountItem . name === "Is deleted" ) {
return (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-18 01:41:21 +08:00
{ Setting . getLabel ( i18next . t ( "user:Is deleted" ) , i18next . t ( "user:Is deleted - Tooltip" ) ) } :
< / C o l >
< Col span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
< Switch checked = { this . state . user . isDeleted } onChange = { checked => {
2022-07-10 15:45:55 +08:00
this . updateUserField ( "isDeleted" , checked ) ;
2022-06-18 01:41:21 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-12 20:45:22 +08:00
) ;
2022-08-22 00:25:39 +08:00
} else if ( accountItem . name === "WebAuthn credentials" ) {
2022-07-12 20:06:01 +08:00
return (
2022-07-12 20:45:22 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-07-12 20:06:01 +08:00
{ Setting . getLabel ( i18next . t ( "user:WebAuthn credentials" ) , i18next . t ( "user:WebAuthn credentials" ) ) } :
< / C o l >
< Col span = { 22 } >
2022-09-29 22:24:05 +08:00
< WebAuthnCredentialTable isSelf = { this . isSelf ( ) } table = { this . state . user . webauthnCredentials } updateTable = { ( table ) => { this . updateUserField ( "webauthnCredentials" , table ) ; } } refresh = { this . getUser . bind ( this ) } / >
2022-07-12 20:06:01 +08:00
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
) ;
2022-08-22 00:25:39 +08:00
} else if ( accountItem . name === "Managed accounts" ) {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "user:Managed accounts" ) , i18next . t ( "user:Managed accounts" ) ) } :
< / C o l >
< Col span = { 22 } >
< ManagedAccountTable
title = { i18next . t ( "user:Managed accounts" ) }
2023-02-02 13:53:18 +08:00
table = { this . state . user . managedAccounts }
2022-08-22 00:25:39 +08:00
onUpdateTable = { ( table ) => { this . updateUserField ( "managedAccounts" , table ) ; } }
applications = { this . state . applications }
/ >
< / C o l >
< / R o w >
) ;
2022-06-18 01:41:21 +08:00
}
}
renderUser ( ) {
return (
< Card size = "small" title = {
< div >
{ this . state . mode === "add" ? i18next . t ( "user:New User" ) : i18next . t ( "user:Edit User" ) } & nbsp ; & nbsp ; & nbsp ; & nbsp ;
< Button onClick = { ( ) => this . submitUserEdit ( false ) } > { i18next . t ( "general:Save" ) } < / B u t t o n >
2022-07-10 15:45:55 +08:00
< Button style = { { marginLeft : "20px" } } type = "primary" onClick = { ( ) => this . submitUserEdit ( true ) } > { i18next . t ( "general:Save & Exit" ) } < / B u t t o n >
{ this . state . mode === "add" ? < Button style = { { marginLeft : "20px" } } onClick = { ( ) => this . deleteUser ( ) } > { i18next . t ( "general:Cancel" ) } < / B u t t o n > : n u l l }
2022-06-18 01:41:21 +08:00
< / d i v >
2022-08-06 23:43:09 +08:00
} style = { ( Setting . isMobile ( ) ) ? { margin : "5px" } : { } } type = "inner" >
2021-02-15 22:14:19 +08:00
{
2022-06-21 15:26:58 +08:00
this . state . application ? . organizationObj . accountItems ? . map ( accountItem => {
return (
< React . Fragment key = { accountItem . name } >
{
this . renderAccountItem ( accountItem )
}
< / R e a c t . F r a g m e n t >
2022-07-10 15:45:55 +08:00
) ;
2022-06-21 15:26:58 +08:00
} )
2021-02-15 22:14:19 +08:00
}
2021-02-13 12:15:19 +08:00
< / C a r d >
2022-07-10 15:45:55 +08:00
) ;
2021-02-13 12:15:19 +08:00
}
2023-03-31 18:35:57 +08:00
submitUserEdit ( needExit ) {
2022-08-08 23:35:24 +08:00
const user = Setting . deepCopy ( this . state . user ) ;
2021-02-13 12:15:19 +08:00
UserBackend . updateUser ( this . state . organizationName , this . state . userName , user )
. then ( ( res ) => {
2022-11-29 20:32:47 +08:00
if ( res . status === "ok" ) {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "success" , i18next . t ( "general:Successfully saved" ) ) ;
2021-02-13 12:15:19 +08:00
this . setState ( {
organizationName : this . state . user . owner ,
userName : this . state . user . name ,
} ) ;
2021-02-13 17:56:58 +08:00
if ( this . props . history !== undefined ) {
2023-03-31 18:35:57 +08:00
if ( needExit ) {
const userListUrl = sessionStorage . getItem ( "userListUrl" ) ;
if ( userListUrl !== null ) {
this . props . history . push ( userListUrl ) ;
} else {
this . props . history . push ( "/users" ) ;
}
2021-12-12 18:51:12 +08:00
} else {
this . props . history . push ( ` /users/ ${ this . state . user . owner } / ${ this . state . user . name } ` ) ;
}
2022-09-23 12:01:21 +08:00
} else {
2023-03-31 18:35:57 +08:00
if ( needExit ) {
2022-11-25 23:08:45 +08:00
if ( this . state . returnUrl ) {
window . location . href = this . state . returnUrl ;
2022-09-23 12:01:21 +08:00
}
}
2021-02-13 17:56:58 +08:00
}
2021-02-13 12:15:19 +08:00
} else {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to save" ) } : ${ res . msg } ` ) ;
2022-07-10 15:45:55 +08:00
this . updateUserField ( "owner" , this . state . organizationName ) ;
this . updateUserField ( "name" , this . state . userName ) ;
2021-02-13 12:15:19 +08:00
}
} )
. catch ( error => {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to connect to server" ) } : ${ error } ` ) ;
2021-02-13 12:15:19 +08:00
} ) ;
}
2022-02-25 18:16:02 +08:00
deleteUser ( ) {
UserBackend . deleteUser ( this . state . user )
2022-12-02 00:06:28 +08:00
. then ( ( res ) => {
if ( res . status === "ok" ) {
this . props . history . push ( "/users" ) ;
} else {
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to delete" ) } : ${ res . msg } ` ) ;
}
2022-02-25 18:16:02 +08:00
} )
. catch ( error => {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to connect to server" ) } : ${ error } ` ) ;
2022-02-25 18:16:02 +08:00
} ) ;
}
2021-02-13 12:15:19 +08:00
render ( ) {
return (
< div >
2022-07-10 15:45:55 +08:00
{
2022-10-11 00:52:08 +08:00
this . state . loading ? < Spin size = "large" style = { { marginLeft : "50%" , marginTop : "10%" } } / > : (
2022-07-10 15:45:55 +08:00
this . state . user !== null ? this . renderUser ( ) :
< Result
status = "404"
title = "404 NOT FOUND"
subTitle = { i18next . t ( "general:Sorry, the user you visited does not exist or you are not authorized to access this user." ) }
extra = { < a href = "/" > < Button type = "primary" > { i18next . t ( "general:Back Home" ) } < / B u t t o n > < / a > }
/ >
)
}
{
this . state . user === null ? null :
< div style = { { marginTop : "20px" , marginLeft : "40px" } } >
< Button size = "large" onClick = { ( ) => this . submitUserEdit ( false ) } > { i18next . t ( "general:Save" ) } < / B u t t o n >
< Button style = { { marginLeft : "20px" } } type = "primary" size = "large" onClick = { ( ) => this . submitUserEdit ( true ) } > { i18next . t ( "general:Save & Exit" ) } < / B u t t o n >
{ this . state . mode === "add" ? < Button style = { { marginLeft : "20px" } } size = "large" onClick = { ( ) => this . deleteUser ( ) } > { i18next . t ( "general:Cancel" ) } < / B u t t o n > : n u l l }
< / d i v >
}
< / d i v >
2021-02-13 12:15:19 +08:00
) ;
}
}
export default UserEditPage ;