Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Changes to add client-setting as a scope type for client based settings #9214

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import React from 'react'

export type AdminRouteStateType = {
name: string
scope: string
scope: string | string[]
redirect?: string
component: React.LazyExoticComponent<() => JSX.Element>
access: boolean
Expand Down
3 changes: 2 additions & 1 deletion packages/client-core/src/admin/DefaultAdminRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { clientSettingPath } from '@etherealengine/engine/src/schemas/setting/client-setting.schema'
import Icon from '@etherealengine/ui/src/primitives/mui/Icon'
import React, { lazy } from 'react'
import { AdminRouteStateType } from './AllowedAdminRoutesState'
Expand Down Expand Up @@ -137,7 +138,7 @@ export const DefaultAdminRoutes: Record<string, AdminRouteStateType> = {
},
settings: {
name: 'user:dashboard.setting',
scope: 'settings',
scope: ['settings', clientSettingPath],
component: Setting,
access: false,
icon: <Icon type="Settings" style={{ color: 'white' }} />
Expand Down
5 changes: 3 additions & 2 deletions packages/client-core/src/admin/adminRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ const AdminRoutes = () => {

useEffect(() => {
for (const [route, state] of Object.entries(allowedRoutes)) {
const routeScope = state.scope.value
const hasScope =
state.scope.value === '' ||
routeScope === '' ||
scopes?.find((scope) => {
const [scopeKey, type] = scope.type.split(':')
return scopeKey === state.scope.value
return Array.isArray(routeScope) ? routeScope.includes(scopeKey) : scopeKey === routeScope
})
state.access.set(!!hasScope)
}
Expand Down
43 changes: 29 additions & 14 deletions packages/client-core/src/admin/components/Setting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import ListItemAvatar from '@etherealengine/ui/src/primitives/mui/ListItemAvatar
import ListItemText from '@etherealengine/ui/src/primitives/mui/ListItemText'
import Typography from '@etherealengine/ui/src/primitives/mui/Typography'

import { clientSettingPath } from '@etherealengine/engine/src/schemas/setting/client-setting.schema'
import { userHasAccess } from '../../../user/userHasAccess'
import styles from '../../styles/settings.module.scss'
import Authentication from './Authentication'
Expand All @@ -61,80 +62,92 @@ const settingItems = [
name: 'project',
title: 'Project',
icon: <Icon type="Code" sx={{ color: 'orange' }} />,
content: <Project />
content: <Project />,
scope: 'settings:read'
},
{
name: 'server',
title: 'Server',
icon: <Iconify icon="carbon:bare-metal-server" color="orange" />,
content: <Server />
content: <Server />,
scope: 'settings:read'
},
{
name: 'helm',
title: 'Helm Charts',
icon: <Icon type="Poll" sx={{ color: 'orange' }} />,
content: <Helm />
content: <Helm />,
scope: 'settings:read'
},
{
name: 'client',
title: 'Client',
icon: <Icon type="ViewCompact" sx={{ color: 'orange' }} />,
content: <Client />,
scope: 'settings_client:read'
scope: ['settings:read', `${clientSettingPath}:read`]
},
{
name: 'clientTheme',
title: 'Client Theme',
icon: <Icon type="FormatColorFill" sx={{ color: 'orange' }} />,
content: <ClientTheme />
content: <ClientTheme />,
scope: ['settings:read', `${clientSettingPath}:read`]
},
{
name: 'instanceServer',
title: 'Instance Server',
icon: <Icon type="Hub" sx={{ color: 'orange' }} />,
content: <InstanceServer />
content: <InstanceServer />,
scope: 'settings:read'
},
{
name: 'taskServer',
title: 'Task Server',
icon: <Icon type="ListAlt" sx={{ color: 'orange' }} />,
content: <TaskServer />
content: <TaskServer />,
scope: 'settings:read'
},
{
name: 'email',
title: 'Email',
icon: <Icon type="MailOutline" sx={{ color: 'orange' }} />,
content: <Email />
content: <Email />,
scope: 'settings:read'
},
{
name: 'authentication',
title: 'Authentication',
icon: <Icon type="Lock" sx={{ color: 'orange' }} />,
content: <Authentication />
content: <Authentication />,
scope: 'settings:read'
},
{
name: 'aws',
title: 'AWS',
icon: <Iconify icon="logos:aws" />,
content: <Aws />
content: <Aws />,
scope: 'settings:read'
},
{
name: 'chargebee',
title: 'Chargebee',
icon: <Iconify icon="logos:chargebee-icon" />,
content: <ChargeBee />
content: <ChargeBee />,
scope: 'settings:read'
},
{
name: 'redis',
title: 'Redis',
icon: <Iconify icon="logos:redis" />,
content: <Redis />
content: <Redis />,
scope: 'settings:read'
},
{
name: 'coil',
title: 'Coil',
icon: <Iconify icon="simple-icons:coil" color="orange" />,
content: <Coil />
content: <Coil />,
scope: 'settings:read'
}
]

Expand All @@ -147,7 +160,9 @@ const Sidebar = ({ selected, onChange }: SidebarProps) => {
return (
<List>
{settingItems
.filter((item) => (item.scope ? userHasAccess(item.scope) : true))
.filter((item) =>
Array.isArray(item.scope) ? item.scope.find((scope) => userHasAccess(scope)) : userHasAccess(item.scope)
barankyle marked this conversation as resolved.
Show resolved Hide resolved
)
.map((item) => (
<Fragment key={item.name}>
<ListItem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
CPAL-1.0 License

The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.

The Original Code is Ethereal Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.

All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

import { ScopeTypeType, scopeTypePath } from '@etherealengine/engine/src/schemas/scope/scope-type.schema'
import { clientSettingPath } from '@etherealengine/engine/src/schemas/setting/client-setting.schema'
import type { Knex } from 'knex'
import { getDateTimeSql } from '../../../util/datetime-sql'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(scopeTypePath)

if (tableExists === true) {
const scopeTypeData: ScopeTypeType[] = [
{
type: `${clientSettingPath}:read`,
createdAt: await getDateTimeSql(),
updatedAt: await getDateTimeSql()
},
{
type: `${clientSettingPath}:write`,
createdAt: await getDateTimeSql(),
updatedAt: await getDateTimeSql()
}
]
await trx.table(scopeTypePath).insert(scopeTypeData)
}
await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Knex } from 'knex'
import { scopeTypePath, ScopeTypeType } from '@etherealengine/engine/src/schemas/scope/scope-type.schema'
import appConfig from '@etherealengine/server-core/src/appconfig'

import { clientSettingPath } from '@etherealengine/engine/src/schemas/setting/client-setting.schema'
import { getDateTimeSql } from '../../util/datetime-sql'

export const scopeTypeSeed = [
Expand Down Expand Up @@ -116,10 +117,10 @@ export const scopeTypeSeed = [
type: 'settings:write'
},
{
type: 'settings_client:read'
type: `${clientSettingPath}:read`
},
{
type: 'settings_client:write'
type: `${clientSettingPath}:write`
},
{
type: 'server:read'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
ClientSettingData,
clientSettingDataValidator,
clientSettingPatchValidator,
clientSettingPath,
clientSettingQueryValidator
} from '@etherealengine/engine/src/schemas/setting/client-setting.schema'

Expand Down Expand Up @@ -133,18 +134,18 @@ export default {
find: [],
get: [],
create: [
iff(isProvider('external'), verifyScope('settings_client', 'write')),
iff(isProvider('external'), verifyScope(clientSettingPath, 'write')),
() => schemaHooks.validateData(clientSettingDataValidator),
schemaHooks.resolveData(clientSettingDataResolver)
],
update: [iff(isProvider('external'), verifyScope('settings_client', 'write'))],
update: [iff(isProvider('external'), verifyScope(clientSettingPath, 'write'))],
patch: [
iff(isProvider('external'), verifyScope('settings_client', 'write')),
iff(isProvider('external'), verifyScope(clientSettingPath, 'write')),
() => schemaHooks.validateData(clientSettingPatchValidator),
schemaHooks.resolveData(clientSettingPatchResolver),
updateWebManifest
],
remove: [iff(isProvider('external'), verifyScope('settings_client', 'write'))]
remove: [iff(isProvider('external'), verifyScope(clientSettingPath, 'write'))]
},

after: {
Expand Down