mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-11 12:17:44 +02:00
EZQMS-729: Restrict spaces operations (#5500)
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<!--
|
||||
// Copyright © 2024 Hardcore Engineering Inc.
|
||||
//
|
||||
// Licensed under the Eclipse Public 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 https://www.eclipse.org/legal/epl-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.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Header, Breadcrumb, Label } from '@hcengineering/ui'
|
||||
import core, { Account, Ref, Role, RolesAssignment, SpaceType, TypedSpace, WithLookup } from '@hcengineering/core'
|
||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||
import { AccountArrayEditor } from '@hcengineering/contact-resources'
|
||||
|
||||
import setting from '../plugin'
|
||||
|
||||
export let visibleNav: boolean = true
|
||||
|
||||
const client = getClient()
|
||||
const hierarchy = client.getHierarchy()
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
let space: TypedSpace
|
||||
let spaceType: WithLookup<SpaceType>
|
||||
|
||||
const spaceQuery = createQuery()
|
||||
spaceQuery.query(
|
||||
core.class.TypedSpace,
|
||||
{
|
||||
_id: core.space.Space
|
||||
},
|
||||
(res) => {
|
||||
space = res[0]
|
||||
}
|
||||
)
|
||||
|
||||
const typeQuery = createQuery()
|
||||
$: if (space?.type !== undefined) {
|
||||
typeQuery.query(
|
||||
core.class.SpaceType,
|
||||
{
|
||||
_id: core.spaceType.SpacesType
|
||||
},
|
||||
(res) => {
|
||||
spaceType = res[0]
|
||||
},
|
||||
{
|
||||
lookup: {
|
||||
_id: { roles: core.class.Role }
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
$: roles = (spaceType?.$lookup?.roles ?? []) as Role[]
|
||||
|
||||
let rolesAssignment: RolesAssignment = {}
|
||||
$: {
|
||||
if (space !== undefined && spaceType?.targetClass !== undefined) {
|
||||
const asMixin = hierarchy.as(space, spaceType?.targetClass)
|
||||
|
||||
rolesAssignment = roles.reduce<RolesAssignment>((prev, { _id }) => {
|
||||
prev[_id] = (asMixin as any)[_id] ?? []
|
||||
|
||||
return prev
|
||||
}, {})
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRoleAssignmentChanged (roleId: Ref<Role>, newMembers: Ref<Account>[]): Promise<void> {
|
||||
await client.updateMixin(space._id, space._class, core.space.Space, spaceType.targetClass, {
|
||||
[roleId]: newMembers
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="hulyComponent">
|
||||
<Header minimize={!visibleNav} on:resize={(event) => dispatch('change', event.detail)}>
|
||||
<Breadcrumb icon={setting.icon.Views} label={setting.string.Spaces} size="large" isCurrent />
|
||||
</Header>
|
||||
<div class="hulyComponent-content__column content">
|
||||
{#each roles as role}
|
||||
<div class="antiGrid-row">
|
||||
<div class="antiGrid-row__header">
|
||||
{role.name}
|
||||
</div>
|
||||
<AccountArrayEditor
|
||||
value={rolesAssignment?.[role._id] ?? []}
|
||||
label={setting.string.Assignees}
|
||||
onChange={(refs) => {
|
||||
handleRoleAssignmentChanged(role._id, refs)
|
||||
}}
|
||||
kind="regular"
|
||||
size="large"
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.content {
|
||||
margin: 2rem 3.25rem;
|
||||
}
|
||||
</style>
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
const descriptors = client
|
||||
.getModel()
|
||||
.findAllSync(core.class.SpaceTypeDescriptor, {})
|
||||
.findAllSync(core.class.SpaceTypeDescriptor, { system: { $ne: true } })
|
||||
.filter((descriptor) => hasResource(descriptor._id as any as Resource<any>))
|
||||
|
||||
descriptor = descriptors[0]
|
||||
@@ -101,6 +101,7 @@
|
||||
<ObjectBox
|
||||
_class={core.class.SpaceTypeDescriptor}
|
||||
value={descriptor?._id}
|
||||
docQuery={{ system: { $ne: true } }}
|
||||
on:change={handleDescriptorSelected}
|
||||
kind="regular"
|
||||
size="small"
|
||||
|
||||
Reference in New Issue
Block a user