chore(ui): use isEnterprise to stay consistent with UsersPage

pull/5921/head
Pavel Zavora 2022-05-27 10:32:55 +02:00
parent 492424abf8
commit 577af75337
1 changed files with 16 additions and 16 deletions

View File

@ -108,11 +108,11 @@ const UserPage = ({
}, },
[user, password] [user, password]
) )
const isOSS = !hasRoleManagement(source) const isEnterprise = hasRoleManagement(source)
// admin // admin
const isAdmin = const isAdmin =
isOSS && !isEnterprise &&
!!user.permissions.find( !!user.permissions.find(
x => x.scope === 'all' && (x.allowed || []).includes('ALL') x => x.scope === 'all' && (x.allowed || []).includes('ALL')
) )
@ -141,7 +141,7 @@ const UserPage = ({
serverPermissions.find(x => x.scope === 'database')?.allowed || [], serverPermissions.find(x => x.scope === 'database')?.allowed || [],
serverPermissions.find(x => x.scope === 'all')?.allowed || [], serverPermissions.find(x => x.scope === 'all')?.allowed || [],
user.permissions.reduce((acc, perm) => { user.permissions.reduce((acc, perm) => {
if (isOSS && perm.scope !== 'database') { if (!isEnterprise && perm.scope !== 'database') {
return acc // do not include all permissions in OSS, they have separate administration return acc // do not include all permissions in OSS, they have separate administration
} }
const dbName = perm.name || '' const dbName = perm.name || ''
@ -150,7 +150,7 @@ const UserPage = ({
return acc return acc
}, {}), }, {}),
], ],
[serverPermissions, user, isOSS] [serverPermissions, user, isEnterprise]
) )
const [changedPermissions, setChangedPermissions] = useState< const [changedPermissions, setChangedPermissions] = useState<
Record<string, Record<string, boolean | undefined>> Record<string, Record<string, boolean | undefined>>
@ -228,30 +228,30 @@ const UserPage = ({
} }
return acc return acc
}, },
isOSS isEnterprise
? (user.permissions || []).filter(x => x.scope !== 'database') ? []
: [] : (user.permissions || []).filter(x => x.scope !== 'database')
) )
await updatePermissionsAsync(user, permissions) await updatePermissionsAsync(user, permissions)
} finally { } finally {
setRunning(false) setRunning(false)
} }
}, },
[user, changedPermissions, userDBPermissions, isOSS] [user, changedPermissions, userDBPermissions, isEnterprise]
) )
// roles // roles
const [allRoleNames, rolesRecord] = useMemo(() => { const [allRoleNames, rolesRecord] = useMemo(() => {
if (isOSS) { if (!isEnterprise) {
return [[], {}] return [[], {}]
} }
const rNames = (isOSS ? [] : roles).map(r => r.name).sort() const rNames = (isEnterprise ? roles : []).map(r => r.name).sort()
const urRecord = user.roles.reduce<Record<string, boolean>>((acc, r) => { const urRecord = user.roles.reduce<Record<string, boolean>>((acc, r) => {
acc[r.name] = true acc[r.name] = true
return acc return acc
}, {}) }, {})
return [rNames, urRecord] return [rNames, urRecord]
}, [user, roles, isOSS]) }, [user, roles, isEnterprise])
const [changedRolesRecord, setChangedRolesRecord] = useState< const [changedRolesRecord, setChangedRolesRecord] = useState<
Record<string, boolean> Record<string, boolean>
>({}) >({})
@ -320,9 +320,9 @@ const UserPage = ({
acc.push(db.name) acc.push(db.name)
return acc return acc
}, },
isOSS ? [] : [''] isEnterprise ? [''] : []
), ),
[isOSS, databases] [isEnterprise, databases]
) )
const body = const body =
user === FAKE_USER ? ( user === FAKE_USER ? (
@ -345,7 +345,7 @@ const UserPage = ({
running ? ComponentStatus.Disabled : ComponentStatus.Default running ? ComponentStatus.Disabled : ComponentStatus.Default
} }
/> />
{isOSS && ( {!isEnterprise && (
<ConfirmButton <ConfirmButton
type="btn-default" type="btn-default"
text={isAdmin ? 'Revoke Admin' : 'Grant Admin'} text={isAdmin ? 'Revoke Admin' : 'Grant Admin'}
@ -397,7 +397,7 @@ const UserPage = ({
</div> </div>
) : ( ) : (
<FancyScrollbar> <FancyScrollbar>
{!isOSS && ( {isEnterprise && (
<> <>
<div className="infludb-admin-section__header"> <div className="infludb-admin-section__header">
<h4> <h4>
@ -434,7 +434,7 @@ const UserPage = ({
)} )}
<div className="infludb-admin-section__header"> <div className="infludb-admin-section__header">
<h4> <h4>
{isOSS ? 'Database Permissions' : 'Permissions'} {isEnterprise ? 'Permissions' : 'Database Permissions'}
{permissionsChanged ? ' (unsaved)' : ''} {permissionsChanged ? ' (unsaved)' : ''}
</h4> </h4>
</div> </div>